int main(int argc, char **argv) { int ch; int k, retcode; infile = stdin; diagfile = stderr; #if 1 /* RAGGE */ char file[] = "/tmp/initfile.XXXXXX"; char buf[100]; close(mkstemp(file)); sprintf(buf, "sort > %s", file); initfile = popen(buf, "w"); #endif #define DONE(c) { retcode = c; goto finis; } while ((ch = getopt(argc, argv, "qw:UuOdpC1I:Z:X:")) != -1) switch (ch) { case 'q': quietflag = YES; break; case 'w': if(optarg[0]=='6' && optarg[1]=='6') { ftn66flag = YES; } else nowarnflag = YES; break; case 'U': shiftcase = NO; break; case 'u': undeftype = YES; break; case 'O': optimflag = YES; #ifdef notyet xdeljumps = 1; xtemps = 1; #endif break; case 'd': debugflag = YES; break; case 'p': profileflag = YES; break; case 'C': checksubs = YES; break; case '1': onetripflag = YES; break; case 'I': if(*optarg == '2') tyint = TYSHORT; else if(*optarg == '4') { shortsubs = NO; tyint = TYLONG; } else if(*optarg == 's') shortsubs = YES; else fatal1("invalid flag -I%c\n", *optarg); tylogical = tyint; break; case 'Z': /* pass2 debugging */ while (*optarg) switch (*optarg++) { case 'b': /* basic block and SSA building */ ++b2debug; break; case 'c': /* code printout */ ++c2debug; break; case 'e': /* print tree upon pass2 enter */ ++e2debug; break; case 'f': /* instruction matching */ ++f2debug; break; case 'g': ++g2debug; break; case 'n': ++ndebug; break; case 'o': ++o2debug; break; case 'r': /* register alloc/graph coloring */ ++r2debug; break; case 's': /* shape matching */ ++s2debug; break; case 't': ++t2debug; break; case 'u': /* Sethi-Ullman debugging */ ++u2debug; break; case 'x': ++x2debug; break; default: fprintf(stderr, "unknown Z flag '%c'\n", optarg[-1]); exit(1); } break; case 'X': /* pass1 debugging */ while (*optarg) switch (*optarg++) { case 'm': /* memory allocation */ ++mflag; break; case 't': /* tree debugging */ tflag++; break; default: usage(); } break; default: usage(); } argc -= optind; argv += optind; mkdope(); initkey(); if (argc > 0) { if (inilex(copys(argv[0]))) DONE(1); if (!quietflag) fprintf(diagfile, "%s:\n", argv[0]); if (argc != 1) if (freopen(argv[1], "w", stdout) == NULL) { fprintf(stderr, "open output file '%s':", argv[1]); perror(NULL); exit(1); } } else { inilex(copys("")); } fileinit(); procinit(); if((k = yyparse())) { fprintf(diagfile, "Bad parse, return code %d\n", k); DONE(1); } if(nerr > 0) DONE(1); if(parstate != OUTSIDE) { warn("missing END statement"); endproc(); } doext(); preven(ALIDOUBLE); prtail(); puteof(); DONE(0); finis: pclose(initfile); retcode |= dodata(file); unlink(file); done(retcode); return(retcode); }
/* * horzcol: print files with more than one column of output across a page */ int horzcol(int argc, char *argv[]) { char *ptbf; int pln; int cnt = -1; char *lstdat; int col = colwd + 1; int j; int i; int lncnt; int pagecnt; char *buf; char *hbuf; char *ohbuf; const char *fname; FILE *inf; int ips = 0; int cps = 0; int ops = 0; int mor = 0; if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) { mfail(); return(1); } /* * page header */ if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) { free(buf); mfail(); return(1); } ohbuf = hbuf + offst; if (offst) { (void)memset(buf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); } /* * loop by file */ while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) { if (pgnm) { if (inskip(inf, pgnm, lines)) continue; pagecnt = pgnm; } else pagecnt = 1; lncnt = 0; /* * loop by page */ for(;;) { ttypause(pagecnt); /* * loop by line */ for (i = 0; i < lines; ++i) { ptbf = buf + offst; lstdat = ptbf; j = 0; /* * loop by col */ for(;;) { if (nmwd) { /* * add number to column */ addnum(ptbf, nmwd, ++lncnt); ptbf += nmwd; *ptbf++ = nmchar; } /* * input line */ if ((cnt = inln(inf,ptbf,colwd,&cps,1, &mor)) < 0) break; ptbf += cnt; lstdat = ptbf; /* * if last line skip padding */ if (++j >= clcnt) break; /* * pad to end of column */ if (sflag) *ptbf++ = schar; else if ((pln = col - cnt) > 0) { (void)memset(ptbf,(int)' ',pln); ptbf += pln; } } /* * determine line length */ if ((j = lstdat - buf) <= offst) break; if (!i && !nohead && prhead(hbuf, fname, pagecnt)) goto err; /* * output line */ if (otln(buf, j, &ips, &ops, 0)) goto err; } /* * pad to end of page */ if (i && prtail(lines-i, 0)) goto err; /* * if EOF go to next file */ if (cnt < 0) break; ++pagecnt; } if (inf != stdin) (void)fclose(inf); } if (eoptind < argc) goto err; free(hbuf); free(buf); return(0); err: free(hbuf); free(buf); return(1); }
/* * mulfile: print files with more than one column of output and * more than one file concurrently */ int mulfile(int argc, char *argv[]) { char *ptbf; int j; int pln; int cnt; char *lstdat; int i; FILE **fbuf = NULL; int actf; int lncnt; int col; int pagecnt; int fproc; char *buf = NULL; char *hbuf = NULL; char *ohbuf; const char *fname; int ips = 0; int cps = 0; int ops = 0; int mor = 0; int retval = 1; /* * array of FILE *, one for each operand */ if ((fbuf = (FILE **)malloc((unsigned)clcnt*sizeof(FILE *))) == NULL) { mfail(); goto out; } /* * page header */ if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) { mfail(); goto out; } ohbuf = hbuf + offst; /* * do not know how many columns yet. The number of operands provide an * upper bound on the number of columns. We use the number of files * we can open successfully to set the number of columns. The operation * of the merge operation (-m) in relation to unsuccessful file opens * is unspecified by posix. */ j = 0; while (j < clcnt) { if ((fbuf[j] = nxtfile(argc, argv, &fname, ohbuf, 1)) == NULL) break; if (pgnm && (inskip(fbuf[j], pgnm, lines))) fbuf[j] = NULL; ++j; } /* * if no files, exit */ if (!j) goto out; /* * calculate page boundaries based on open file count */ clcnt = j; if (nmwd) { colwd = (pgwd - clcnt - nmwd)/clcnt; pgwd = ((colwd + 1) * clcnt) - nmwd - 2; } else { colwd = (pgwd + 1 - clcnt)/clcnt; pgwd = ((colwd + 1) * clcnt) - 1; } if (colwd < 1) { (void)fprintf(err, "pr: page width too small for %d columns\n", clcnt); goto out; } actf = clcnt; col = colwd + 1; /* * line buffer */ if ((buf = malloc((unsigned)(pgwd+offst+1)*sizeof(char))) == NULL) { mfail(); goto out; } if (offst) { (void)memset(buf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); } if (pgnm) pagecnt = pgnm; else pagecnt = 1; lncnt = 0; /* * continue to loop while any file still has data */ while (actf > 0) { ttypause(pagecnt); /* * loop by line */ for (i = 0; i < lines; ++i) { ptbf = buf + offst; lstdat = ptbf; if (nmwd) { /* * add line number to line */ addnum(ptbf, nmwd, ++lncnt); ptbf += nmwd; *ptbf++ = nmchar; } j = 0; fproc = 0; /* * loop by column */ for (j = 0; j < clcnt; ++j) { if (fbuf[j] == NULL) { /* * empty column; EOF */ cnt = 0; } else if ((cnt = inln(fbuf[j], ptbf, colwd, &cps, 1, &mor)) < 0) { /* * EOF hit; no data */ if (fbuf[j] != stdin) (void)fclose(fbuf[j]); fbuf[j] = NULL; --actf; cnt = 0; } else { /* * process file data */ ptbf += cnt; lstdat = ptbf; fproc++; } /* * if last ACTIVE column, done with line */ if (fproc >= actf) break; /* * pad to end of column */ if (sflag) { *ptbf++ = schar; } else if ((pln = col - cnt) > 0) { (void)memset(ptbf, (int)' ', pln); ptbf += pln; } } /* * calculate data in line */ if ((j = lstdat - buf) <= offst) break; if (!i && !nohead && prhead(hbuf, fname, pagecnt)) goto out; /* * output line */ if (otln(buf, j, &ips, &ops, 0)) goto out; /* * if no more active files, done */ if (actf <= 0) { ++i; break; } } /* * pad to end of page */ if (i && prtail(lines-i, 0)) goto out; ++pagecnt; } if (eoptind < argc) goto out; retval = 0; out: free(buf); free(hbuf); free(fbuf); return(retval); }
/* * vertcol: print files with more than one column of output down a page */ int vertcol(int argc, char *argv[]) { char *ptbf; char **lstdat = NULL; int i; int j; int cnt = -1; int pln; int *indy = NULL; int cvc; int *lindy = NULL; int lncnt; int stp; int pagecnt; int col = colwd + 1; int mxlen = pgwd + offst + 1; int mclcnt = clcnt - 1; struct vcol *vc = NULL; int mvc; int tvc; int cw = nmwd + 1; int fullcol; char *buf = NULL; char *hbuf = NULL; char *ohbuf; const char *fname; FILE *inf; int ips = 0; int cps = 0; int ops = 0; int mor = 0; int retval = 1; /* * allocate page buffer */ if ((buf = malloc((unsigned)lines*mxlen*sizeof(char))) == NULL) { mfail(); return(1); } /* * allocate page header */ if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) { mfail(); goto out; } ohbuf = hbuf + offst; if (offst) (void)memset(hbuf, (int)' ', offst); /* * col pointers when no headers */ mvc = lines * clcnt; if ((vc = (struct vcol *)malloc((unsigned)mvc*sizeof(struct vcol))) == NULL) { mfail(); goto out; } /* * pointer into page where last data per line is located */ if ((lstdat = (char **)malloc((unsigned)lines*sizeof(char *))) == NULL){ mfail(); goto out; } /* * fast index lookups to locate start of lines */ if ((indy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) { mfail(); goto out; } if ((lindy = (int *)malloc((unsigned)lines*sizeof(int))) == NULL) { mfail(); goto out; } if (nmwd) fullcol = col + cw; else fullcol = col; /* * initialize buffer lookup indexes and offset area */ for (j = 0; j < lines; ++j) { lindy[j] = j * mxlen; indy[j] = lindy[j] + offst; if (offst) { ptbf = buf + lindy[j]; (void)memset(ptbf, (int)' ', offst); ptbf += offst; } else ptbf = buf + indy[j]; lstdat[j] = ptbf; } /* * loop by file */ while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) { if (pgnm) { /* * skip to requested page */ if (inskip(inf, pgnm, lines)) continue; pagecnt = pgnm; } else pagecnt = 1; lncnt = 0; /* * loop by page */ for(;;) { ttypause(pagecnt); /* * loop by column */ cvc = 0; for (i = 0; i < clcnt; ++i) { j = 0; /* * if last column, do not pad */ if (i == mclcnt) stp = 1; else stp = 0; /* * loop by line */ for(;;) { /* * is this first column */ if (!i) { ptbf = buf + indy[j]; lstdat[j] = ptbf; } else ptbf = lstdat[j]; vc[cvc].pt = ptbf; /* * add number */ if (nmwd) { addnum(ptbf, nmwd, ++lncnt); ptbf += nmwd; *ptbf++ = nmchar; } /* * input next line */ cnt = inln(inf,ptbf,colwd,&cps,1,&mor); vc[cvc++].cnt = cnt; if (cnt < 0) break; ptbf += cnt; /* * pad all but last column on page */ if (!stp) { /* * pad to end of column */ if (sflag) *ptbf++ = schar; else if ((pln = col-cnt) > 0) { (void)memset(ptbf, (int)' ',pln); ptbf += pln; } } /* * remember last char in line */ lstdat[j] = ptbf; if (++j >= lines) break; } if (cnt < 0) break; } /* * when -t (no header) is specified the spec requires * the min number of lines. The last page may not have * balanced length columns. To fix this we must reorder * the columns. This is a very slow technique so it is * only used under limited conditions. Without -t, the * balancing of text columns is unspecified. To NOT * balance the last page, add the global variable * nohead to the if statement below e.g. * * if ((cnt < 0) && nohead && cvc ...... */ --cvc; /* * check to see if last page needs to be reordered */ if ((cnt < 0) && cvc && ((mvc-cvc) >= clcnt)){ pln = cvc/clcnt; if (cvc % clcnt) ++pln; /* * print header */ if (!nohead && prhead(hbuf, fname, pagecnt)) goto out; for (i = 0; i < pln; ++i) { ips = 0; ops = 0; if (offst && otln(buf,offst,&ips,&ops,1)) goto out; tvc = i; for (j = 0; j < clcnt; ++j) { /* * determine column length */ if (j == mclcnt) { /* * last column */ cnt = vc[tvc].cnt; if (nmwd) cnt += cw; } else if (sflag) { /* * single ch between */ cnt = vc[tvc].cnt + 1; if (nmwd) cnt += cw; } else cnt = fullcol; if (otln(vc[tvc].pt, cnt, &ips, &ops, 1)) goto out; tvc += pln; if (tvc >= cvc) break; } /* * terminate line */ if (otln(buf, 0, &ips, &ops, 0)) goto out; } /* * pad to end of page */ if (prtail((lines - pln), 0)) goto out; /* * done with output, go to next file */ break; } /* * determine how many lines to output */ if (i > 0) pln = lines; else pln = j; /* * print header */ if (pln && !nohead && prhead(hbuf, fname, pagecnt)) goto out; /* * output each line */ for (i = 0; i < pln; ++i) { ptbf = buf + lindy[i]; if ((j = lstdat[i] - ptbf) <= offst) break; if (otln(ptbf, j, &ips, &ops, 0)) goto out; } /* * pad to end of page */ if (pln && prtail((lines - pln), 0)) goto out; /* * if EOF go to next file */ if (cnt < 0) break; ++pagecnt; } if (inf != stdin) (void)fclose(inf); } if (eoptind < argc) goto out; retval = 0; out: free(lindy); free(indy); free(lstdat); free(vc); free(hbuf); free(buf); return(retval); }
/* * onecol: print files with only one column of output. * Line length is unlimited. */ int onecol(int argc, char *argv[]) { int cnt = -1; int off; int lrgln; int linecnt; int num; int lncnt; int pagecnt; int ips; int ops; int cps; char *obuf; char *lbuf; char *nbuf; char *hbuf; char *ohbuf; FILE *inf; const char *fname; int mor; if (nmwd) num = nmwd + 1; else num = 0; off = num + offst; /* * allocate line buffer */ if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) { mfail(); return(1); } /* * allocate header buffer */ if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) { free(obuf); mfail(); return(1); } ohbuf = hbuf + offst; nbuf = obuf + offst; lbuf = nbuf + num; if (num) nbuf[--num] = nmchar; if (offst) { (void)memset(obuf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); } /* * loop by file */ while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) { if (pgnm) { /* * skip to specified page */ if (inskip(inf, pgnm, lines)) continue; pagecnt = pgnm; } else pagecnt = 1; lncnt = 0; /* * loop by page */ for(;;) { linecnt = 0; lrgln = 0; ops = 0; ips = 0; cps = 0; ttypause(pagecnt); /* * loop by line */ while (linecnt < lines) { /* * input next line */ if ((cnt = inln(inf,lbuf,LBUF,&cps,0,&mor)) < 0) break; if (!linecnt && !nohead && prhead(hbuf, fname, pagecnt)) goto err; /* * start of new line. */ if (!lrgln) { if (num) addnum(nbuf, num, ++lncnt); if (otln(obuf,cnt+off, &ips, &ops, mor)) goto err; } else if (otln(lbuf, cnt, &ips, &ops, mor)) goto err; /* * if line bigger than buffer, get more */ if (mor) { lrgln = 1; continue; } /* * whole line rcvd. reset tab proc. state */ ++linecnt; lrgln = 0; ops = 0; ips = 0; } /* * fill to end of page */ if (linecnt && prtail(lines-linecnt-lrgln, lrgln)) goto err; /* * On EOF go to next file */ if (cnt < 0) break; ++pagecnt; } if (inf != stdin) (void)fclose(inf); } if (eoptind < argc) goto err; free(hbuf); free(obuf); return(0); err: free(hbuf); free(obuf); return(1); }
/* * mulfile: print files with more than one column of output and * more than one file concurrently */ int mulfile(int argc, char *argv[]) { char *ptbf; int j; int pln; int *rc; int cnt; char *lstdat; int i; FILE **fbuf = NULL; int actf; int lncnt; int col; int pagecnt; int fproc; char *buf = NULL; char *hbuf = NULL; char *ohbuf; char *fname; int ips = 0; int cps = 0; int ops = 0; int mor = 0; int error = 1; /* * array of FILE *, one for each operand */ if ((fbuf = calloc((unsigned)clcnt, sizeof(FILE *))) == NULL) goto oomem; /* * array of int *, one for each operand */ if ((rc = calloc((unsigned)clcnt, sizeof(int))) == NULL) goto oomem; /* * page header */ if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) goto oomem; ohbuf = hbuf + offst; /* * do not know how many columns yet. The number of operands provide an * upper bound on the number of columns. We use the number of files * we can open successfully to set the number of columns. The operation * of the merge operation (-m) in relation to unsuccessful file opens * is unspecified by posix. * * XXX - this seems moderately bogus, you'd think that specifying * "pr -2 a b c d" would run though all the files in pairs, but * the existing code says up two files, or fewer if one is bogus. * fixing it would require modifying the looping structure, so be it. */ j = 0; while (j < clcnt) { if ((fbuf[j] = nxtfile(argc, argv, &fname, ohbuf, 1)) != NULL) { rc[j] = NORMAL; j++; } } /* * if no files, exit */ if (j) clcnt = j; else goto out; /* * calculate page boundaries based on open file count */ if (nmwd) { colwd = (pgwd - clcnt - nmwd)/clcnt; pgwd = ((colwd + 1) * clcnt) - nmwd - 2; } else { colwd = (pgwd + 1 - clcnt)/clcnt; pgwd = ((colwd + 1) * clcnt) - 1; } if (colwd < 1) { ferrout("pr: page width too small for %d columns\n", clcnt); goto out; } col = colwd + 1; /* * line buffer */ if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) goto oomem; if (offst) { (void)memset(buf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); } pagecnt = 0; lncnt = 0; actf = clcnt; /* * continue to loop while any file still has data */ while (actf > 0) { /* * loop on "form" */ for (;;) { /* * loop by line */ for (i = 0; i < lines; ++i) { ptbf = buf + offst; lstdat = ptbf; if (nmwd) { /* * add line number to line */ addnum(ptbf, nmwd, ++lncnt); ptbf += nmwd; *ptbf++ = nmchar; } fproc = 0; /* * loop by column */ for (j = 0; j < clcnt; ++j) { if (rc[j] == NORMAL ) { rc[j] = inln(fbuf[j], ptbf, colwd, &cnt, &cps, 1, &mor); if (cnt >= 0) { /* * process file data */ ptbf += cnt; lstdat = ptbf; fproc++; } else cnt = 0; if (rc[j] == END) { /* * EOF close file */ if (fbuf[j] != stdin) (void)fclose(fbuf[j]); --actf; } } else cnt = 0; /* * if last ACTIVE column, done with line */ if (fproc >= actf) break; /* * pad to end of column */ if (sflag) { *ptbf++ = schar; } else { if (cnt >= 0) pln = col - cnt; else pln = col; if (pln > 0) { (void)memset(ptbf, (int)' ', pln); ptbf += pln; } } } /* * if there was anything to do, print it */ if (fproc != 0) { if (!i && prhead(hbuf, fname, ++pagecnt)) goto out; /* * output line */ if (otln(buf, lstdat-buf, &ips, &ops, 0)) goto out; } else break; } /* * pad to end of page */ if (prtail(lines - i, 0)) return(1); for (j = 0; j < clcnt; ++j) if (rc[j] != END) rc[j] = NORMAL; if (actf <= 0) break; } if (actf <= 0) break; } if (eoptind < argc){ goto out; } else { error = 0; goto out; } oomem: mfail(); out: if (fbuf) { for (j = 0; j < clcnt; j++) { if (fbuf[j] && fbuf[j] != stdin) (void)fclose(fbuf[j]); } free(fbuf); } free(hbuf); free(buf); return error; }
/* * horzcol: print files with more than one column of output across a page */ int horzcol(int argc, char *argv[]) { char *ptbf; int pln; char *lstdat; int col = colwd + 1; int j; int i; int cnt; int rc; int lncnt; int pagecnt; char *buf = NULL; char *hbuf = NULL; char *ohbuf; char *fname; FILE *inf = NULL; int cps = 0; int mor = 0; int ips = 0; int ops = 0; int error = 1; if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) goto oomem; /* * page header */ if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) goto oomem; ohbuf = hbuf + offst; if (offst) { (void)memset(buf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); } /* * loop by file */ while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) { pagecnt = 0; lncnt = 0; /* * loop by form */ for (;;) { /* * loop by page */ for(;;) { /* * loop by line */ for (i = 0; i < lines; ++i) { ptbf = buf + offst; lstdat = ptbf; j = 0; /* * loop by col */ for(;;) { if (nmwd) { /* * add number to column */ addnum(ptbf, nmwd, ++lncnt); ptbf += nmwd; *ptbf++ = nmchar; } /* * input line */ rc = inln(inf,ptbf,colwd,&cnt,&cps,1, &mor); if (cnt >= 0) { if (!i && !j && prhead(hbuf, fname, ++pagecnt)) goto out; ptbf += cnt; lstdat = ptbf; /* * if last line skip padding */ if (++j >= clcnt) break; /* * pad to end of column */ if (sflag) *ptbf++ = schar; else if ((pln = col - cnt) > 0) { (void)memset(ptbf,(int)' ',pln); ptbf += pln; } } if (rc != NORMAL) break; } /* * output line if any columns on it */ if (j) { if (otln(buf, lstdat-buf, &ips, &ops, 0)) goto out; } if (rc != NORMAL) break; } /* * pad to end of page */ if (prtail(lines - i, 0)) return(1); /* * if FORM continue */ if (rc == END) break; } /* * if EOF go to next file */ if (rc == END) break; } if (inf != stdin) (void)fclose(inf); } if (eoptind < argc){ goto out; } else { error = 0; goto out; } oomem: mfail(); out: free(buf); free(hbuf); if (inf != NULL && inf != stdin) (void)fclose(inf); return error; }
/* * onecol: print files with only one column of output. * Line length is unlimited. */ int onecol(int argc, char *argv[]) { int off; int lrgln; int linecnt; int num; int cnt; int rc; int lncnt; int pagecnt; int ips; int ops; int cps; char *obuf = NULL; char *lbuf; char *nbuf; char *hbuf = NULL; char *ohbuf; FILE *inf = NULL; char *fname; int mor; int error = 1; if (nmwd) num = nmwd + 1; else num = 0; off = num + offst; /* * allocate line buffer */ if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL) goto oomem; /* * allocate header buffer */ if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL) goto oomem; ohbuf = hbuf + offst; nbuf = obuf + offst; lbuf = nbuf + num; if (num) nbuf[--num] = nmchar; if (offst) { (void)memset(obuf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); } /* * loop by file */ while ((inf = nxtfile(argc, argv, &fname, ohbuf, 0)) != NULL) { pagecnt = 0; lncnt = 0; /* * loop by "form" */ for(;;) { /* * loop by page */ for(;;) { linecnt = 0; lrgln = 0; ops = 0; ips = 0; cps = 0; /* * loop by line */ while (linecnt < lines) { /* * input next line */ rc = inln(inf,lbuf,LBUF,&cnt,&cps,0,&mor); if (cnt >= 0) { if (!lrgln) if (!linecnt && prhead(hbuf, fname, ++pagecnt)) goto out; /* * start new line or continue a long one */ if (!lrgln) { if (num) addnum(nbuf, num, ++lncnt); if (otln(obuf,cnt+off, &ips, &ops, mor)) goto out; } else if (otln(lbuf, cnt, &ips, &ops, mor)) goto out; /* * if line bigger than buffer, get more */ if (mor) { lrgln = 1; } else { /* * whole line rcvd. reset tab proc. state */ ++linecnt; lrgln = 0; ops = 0; ips = 0; } } if (rc != NORMAL) break; } /* * fill to end of page */ if (prtail(lines - linecnt, lrgln)) goto out; /* * unless END continue */ if (rc == END) break; } /* * On EOF go to next file */ if (rc == END) break; } if (inf != stdin) (void)fclose(inf); } /* * If we didn't process all the files, return error */ if (eoptind < argc) { goto out; } else { error = 0; goto out; } oomem: mfail(); out: free(obuf); free(hbuf); if (inf != NULL && inf != stdin) (void)fclose(inf); return error; }