int write(int fileno, /* File number */ char *buf, /* The address of destination buffer */ int count) /* The number of chacter to write */ #endif { long i; /* A variable for counter */ unsigned char c; /* An output character */ /* Checking the mode of file , output each character */ /* Checking the attribute for Write-Only, Read-Only or Read-Write */ if(flmod[fileno]&O_WRONLY || flmod[fileno]&O_RDWR) { if( fileno == STDIN ) return -1; /* Standard Input */ else if( (fileno == STDOUT) || (fileno == STDERR) ) /* Standard Error/output */ { for( i = count; i > 0; --i ) { c = *buf++; charput(c); } return count; /*Return the number of written characters */ } else return -1; /* Incorrect file number */ } else return -1; /* An error */ }
/* * Collect the actual parameters for this macro. TRUE if ok. */ FILE_LOCAL int expcollect() { int c; int paren; /* For embedded ()'s */ for (;;) { paren = 0; /* Collect next arg. */ while ((c = skipws()) == '\n') /* Skip over whitespace */ wrongline = TRUE; /* and newlines. */ if (c == ')') /* At end of all args? */ { /* * Note that there is a guard byte in parm[] * so we don't have to check for overflow here. */ *parmp = EOS; /* Make sure terminated */ break; /* Exit collection loop */ } else if (nargs >= LASTPARM) cfatal("Too many arguments in macro expansion", NULLST); parlist[nargs++] = parmp; /* At start of new arg */ for (;; c = cget()) /* Collect arg's bytes */ { if (c == EOF_CHAR) { cerror("end of file within macro argument", NULLST); return FALSE; /* Sorry. */ } else if (c == '\\') /* Quote next character */ { charput(c); /* Save the \ for later */ charput(cget()); /* Save the next char. */ continue; /* And go get another */ } else if (type[c] == QUO) /* Start of string? */ { scanstring(c, charput); /* Scan it off */ continue; /* Go get next char */ } else if (c == '(') /* Worry about balance */ paren++; /* To know about commas */ else if (c == ')') /* Other side too */ { if (paren == 0) /* At the end? */ { unget(); /* Look at it later */ break; /* Exit arg getter. */ } paren--; /* More to come. */ } else if (c == ',' && paren == 0) /* Comma delimits args */ break; else if (c == '\n') /* Newline inside arg? */ wrongline = TRUE; /* We'll need a #line */ charput(c); /* Store this one */ } /* Collect an argument */ charput(EOS); /* Terminate argument */ #if OSL_DEBUG_LEVEL > 1 if (debug) fprintf( pCppOut, "parm[%d] = \"%s\"\n", nargs, parlist[nargs - 1]); #endif } /* Collect all args. */ return TRUE; /* Normal return */ }
INLINE FILE_LOCAL ReturnCode expcollect(struct Global *global) { /* * Collect the actual parameters for this macro. */ int c; int paren; /* For embedded ()'s */ ReturnCode ret; for (;;) { paren = 0; /* Collect next arg. */ while ((c = skipws(global)) == '\n')/* Skip over whitespace */ global->wrongline = TRUE; /* and newlines. */ if (c == ')') { /* At end of all args? */ /* * Note that there is a guard byte in parm[] * so we don't have to check for overflow here. */ *global->parmp = EOS; /* Make sure terminated */ break; /* Exit collection loop */ } else if (global->nargs >= LASTPARM) { cfatal(global, FATAL_TOO_MANY_ARGUMENTS_EXPANSION); return(FPP_TOO_MANY_ARGUMENTS); } global->parlist[global->nargs++] = global->parmp; /* At start of new arg */ for (;; c = cget(global)) { /* Collect arg's bytes */ if (c == EOF_CHAR) { cerror(global, ERROR_EOF_IN_ARGUMENT); return(FPP_EOF_IN_MACRO); /* Sorry. */ } else if (c == '\\') { /* Quote next character */ charput(global, c); /* Save the \ for later */ charput(global, cget(global)); /* Save the next char. */ continue; /* And go get another */ } else if (type[c] == QUO) { /* Start of string? */ ret=scanstring(global, c, (ReturnCode (*)(struct Global *, int))charput); /* Scan it off */ if(ret) return(ret); continue; /* Go get next char */ } else if (c == '(') /* Worry about balance */ paren++; /* To know about commas */ else if (c == ')') { /* Other side too */ if (paren == 0) { /* At the end? */ unget(global); /* Look at it later */ break; /* Exit arg getter. */ } paren--; /* More to come. */ } else if (c == ',' && paren == 0) /* Comma delimits args */ break; else if (c == '\n') /* Newline inside arg? */ global->wrongline = TRUE; /* We'll need a #line */ charput(global, c); /* Store this one */ } /* Collect an argument */ charput(global, EOS); /* Terminate argument */ } /* Collect all args. */ return(FPP_OK); /* Normal return */ }