#include #define LAST 0 /* pointer terminating argument list */ /* * FPRARGV outputs to the given stream the calling program's * argument list which is passed to the main program as argv. * The first argument is preceded by a tab, * the others by spaces except if the argument would produce * a line longer than 80 characters. * In that case a newline precedes the output. * The last argument is followed by a newline. * The number of characters output is returned, * or -1 is returned after an error. * LNARGV precomputes the number of characters to be output. * Written by Joseph Pallas on 9/17/80. * Modified by Robert L. Kirby on December 29 for initial tab. * cc -O -c fprargv.c */ int fprargv(fout, argv) FILE *fout; char **argv; { register char **ap; register char *cp; register int cnt; int total; int pos; static char buf; ap = argv; if((int)*ap == LAST) return(0); for(total = 0; (int)(cp = *ap) != LAST; ap++) { for(cnt = 0; *cp++ != '\0'; cnt++); if(total == 0) { buf = '\t'; pos = 8; } else if(pos + cnt > 79) { buf = '\n'; pos = 0; } else { buf = ' '; pos++; } if(fwrite(&buf, 1, 1, fout) != 1) return(-1); total++; if(cnt != 0 && fwrite(*ap, 1, cnt, fout) != cnt) return(-1); else { pos += cnt; total += cnt; } } fprintf(fout, "\n"); if (ferror(fout)) return(-1); return(++total); }