# #define LAST 0 /* pointer terminating argument list */ #define ERROR -1 /* * PRARGV outputs to the given file descriptor 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 prargv.c; ar r libg.a prargv.o; rm prargv.o */ int prargv(fdout, argv) int fdout; 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(write(fdout, &buf, 1) != 1) return(ERROR); total++; if(cnt != 0 && write(fdout, *ap, cnt) != cnt) return(ERROR); else { pos += cnt; total += cnt; } } if(write(fdout, "\n", 1) != 1) return(ERROR); return(++total); }