1: #include "../h/rt.h"
   2: 
   3: /*
   4:  * write(a,b,...) - write arguments.
   5:  */
   6: 
   7: Xwrite(nargs)
   8: int nargs;
   9:    {
  10:    register int n;
  11:    char sbuf[MAXSTRING];
  12:    struct descrip arg;
  13:    FILE *f;
  14:    extern char *alcstr();
  15: 
  16:    f = stdout;
  17:    arg = nullstr;
  18: 
  19:    /*
  20:     * Loop through the arguments, dereferencing each in turn.
  21:     */
  22:    for (n = 1; n <= nargs; n++) {
  23:       arg = ARG(n);
  24:       DeRef(arg)
  25: 
  26:       if (!QUAL(arg) && TYPE(arg) == T_FILE) {/* Current argument is a file */
  27:          /*
  28:           * If this isn't the first argument, output a newline to the current
  29:           *  file and flush it.
  30:           */
  31:          if (n > 1) {
  32:             putc('\n', f);
  33:             fflush(f);
  34:             }
  35:          /*
  36:           * Switch the current file to the file named by the current argument
  37:           *  providing it is a file.  arg is made to be a empty string to
  38:           *  avoid a special case.
  39:           */
  40:          if ((BLKLOC(arg)->file.status & FS_WRITE) == 0)
  41:             runerr(213, &arg);
  42:          f = BLKLOC(arg)->file.fd;
  43:          arg = nullstr;
  44:          }
  45:       else {    /* Current argument is a string */
  46:          /*
  47:           * On first argument, check to be sure that &output is open
  48:           *  for output.
  49:           */
  50:          if (n == 1 && (k_output.status & FS_WRITE) == 0)
  51:             runerr(213, NULL);
  52:          /*
  53:           * Convert the argument to a string, defaulting to a empty string.
  54:           */
  55:          defany(&arg, &nullstr);
  56:          if (cvstr(&arg, sbuf) == NULL)
  57:             runerr(109, &arg);
  58:          /*
  59:           * Output the string.
  60:           */
  61:          putstr(f, STRLOC(arg), STRLEN(arg));
  62:          }
  63:       }
  64:    /*
  65:     * Append a newline to the file and flush it.
  66:     */
  67:    putc('\n', f);
  68:    fflush(f);
  69:    /*
  70:     * If the beginning of the last string output lies in sbuf,
  71:     *  allocate it as a real string.  Note that some of the string
  72:     *  conversions don't always leave the converted string at the
  73:     *  start of the conversion buffer, hence the range check.
  74:     */
  75:    if (STRLOC(arg) >= sbuf && STRLOC(arg) < sbuf + MAXSTRING) {
  76:       sneed(STRLEN(arg));
  77:       STRLOC(arg) = alcstr(STRLOC(arg), STRLEN(arg));
  78:       }
  79:    /*
  80:     * Return the string corresponding to the last argument.
  81:     */
  82:    ARG(0) = arg;
  83:    }
  84: 
  85: Procblock(write,-1)

Defined functions

Xwrite defined in line 7; never used
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 666
Valid CSS Valid XHTML 1.0 Strict