=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/pr/pr.c,v retrieving revision 1.28 retrieving revision 1.29 diff -c -r1.28 -r1.29 *** src/usr.bin/pr/pr.c 2009/10/27 23:59:41 1.28 --- src/usr.bin/pr/pr.c 2010/08/17 21:37:11 1.29 *************** *** 1,4 **** ! /* $OpenBSD: pr.c,v 1.28 2009/10/27 23:59:41 deraadt Exp $ */ /*- * Copyright (c) 1991 Keith Muller. --- 1,4 ---- ! /* $OpenBSD: pr.c,v 1.29 2010/08/17 21:37:11 jasper Exp $ */ /*- * Copyright (c) 1991 Keith Muller. *************** *** 181,194 **** int ips; int ops; int cps; ! char *obuf; char *lbuf; char *nbuf; ! char *hbuf; char *ohbuf; FILE *inf; char *fname; int mor; if (nmwd) num = nmwd + 1; --- 181,195 ---- int ips; int ops; int cps; ! char *obuf = NULL; char *lbuf; char *nbuf; ! char *hbuf = NULL; char *ohbuf; FILE *inf; char *fname; int mor; + int error = 1; if (nmwd) num = nmwd + 1; *************** *** 199,216 **** /* * allocate line buffer */ ! if ((obuf = malloc((unsigned)LBUF + off)) == NULL) { ! mfail(); ! return(1); ! } /* * allocate header buffer */ ! if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { ! mfail(); ! return(1); ! } ohbuf = hbuf + offst; nbuf = obuf + offst; --- 200,213 ---- /* * 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; *************** *** 258,264 **** if (cnt >= 0) { if (!lrgln) if (!linecnt && prhead(hbuf, fname, ++pagecnt)) ! return(1); /* * start new line or continue a long one --- 255,261 ---- if (cnt >= 0) { if (!lrgln) if (!linecnt && prhead(hbuf, fname, ++pagecnt)) ! goto out; /* * start new line or continue a long one *************** *** 267,276 **** if (num) addnum(nbuf, num, ++lncnt); if (otln(obuf,cnt+off, &ips, &ops, mor)) ! return(1); } else if (otln(lbuf, cnt, &ips, &ops, mor)) ! return(1); /* * if line bigger than buffer, get more --- 264,273 ---- 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 *************** *** 296,302 **** * fill to end of page */ if (prtail(lines - linecnt, lrgln)) ! return(1); /* * unless END continue --- 293,299 ---- * fill to end of page */ if (prtail(lines - linecnt, lrgln)) ! goto out; /* * unless END continue *************** *** 318,327 **** /* * If we didn't process all the files, return error */ ! if (eoptind < argc) ! return(1); ! else ! return(0); } /* --- 315,335 ---- /* * 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; } /* *************** *** 332,382 **** vertcol(int argc, char *argv[]) { char *ptbf; ! char **lstdat; int i; int j; int pln; ! int *indy; int cnt; int rc; int cvc; ! int *lindy; int lncnt; int stp; int pagecnt; int col = colwd + 1; int mxlen = pgwd + offst + 1; int mclcnt = clcnt - 1; ! struct vcol *vc; int mvc; int tvc; int cw = nmwd + 1; int fullcol; ! char *buf; ! char *hbuf; char *ohbuf; char *fname; ! FILE *inf; int ips = 0; int cps = 0; int ops = 0; int mor = 0; /* * allocate page buffer */ ! if ((buf = calloc((unsigned)lines, mxlen)) == NULL) { ! mfail(); ! return(1); ! } /* * allocate page header */ ! if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { ! mfail(); ! return(1); ! } ohbuf = hbuf + offst; if (offst) --- 340,387 ---- vertcol(int argc, char *argv[]) { char *ptbf; ! char **lstdat = NULL; int i; int j; int pln; ! int *indy = NULL; int cnt; int rc; 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; char *fname; ! FILE *inf = NULL; int ips = 0; int cps = 0; int ops = 0; int mor = 0; + int error = 1; /* * allocate page buffer */ ! if ((buf = calloc((unsigned)lines, mxlen)) == NULL) ! goto oomem; /* * allocate page header */ ! if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) ! goto oomem; ohbuf = hbuf + offst; if (offst) *************** *** 386,415 **** * col pointers when no headers */ mvc = lines * clcnt; ! if ((vc=(struct vcol *)calloc((unsigned)mvc, sizeof(struct vcol))) == NULL) { ! mfail(); ! return(1); ! } /* * pointer into page where last data per line is located */ ! if ((lstdat = (char **)calloc((unsigned)lines, sizeof(char *))) == NULL){ ! mfail(); ! return(1); ! } /* * fast index lookups to locate start of lines */ ! if ((indy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) { ! mfail(); ! return(1); ! } ! if ((lindy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) { ! mfail(); ! return(1); ! } if (nmwd) fullcol = col + cw; --- 391,412 ---- * col pointers when no headers */ mvc = lines * clcnt; ! if ((vc=(struct vcol *)calloc((unsigned)mvc, sizeof(struct vcol))) == NULL) ! goto oomem; /* * pointer into page where last data per line is located */ ! if ((lstdat = (char **)calloc((unsigned)lines, sizeof(char *))) == NULL) ! goto oomem; /* * fast index lookups to locate start of lines */ ! if ((indy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) ! goto oomem; ! if ((lindy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) ! goto oomem; if (nmwd) fullcol = col + cw; *************** *** 541,547 **** */ if (vc[0].cnt >= 0) { if (prhead(hbuf, fname, ++pagecnt)) ! return(1); /* * check to see if "last" page needs to be reordered --- 538,544 ---- */ if (vc[0].cnt >= 0) { if (prhead(hbuf, fname, ++pagecnt)) ! goto out; /* * check to see if "last" page needs to be reordered *************** *** 556,562 **** ips = 0; ops = 0; if (offst && otln(buf,offst,&ips,&ops,1)) ! return(1); tvc = i; for (j = 0; j < clcnt; ++j) { --- 553,559 ---- ips = 0; ops = 0; if (offst && otln(buf,offst,&ips,&ops,1)) ! goto out; tvc = i; for (j = 0; j < clcnt; ++j) { *************** *** 581,587 **** cnt = fullcol; if (otln(vc[tvc].pt, cnt, &ips, &ops, 1)) ! return(1); tvc += pln; if (tvc > cvc) break; --- 578,584 ---- cnt = fullcol; if (otln(vc[tvc].pt, cnt, &ips, &ops, 1)) ! goto out; tvc += pln; if (tvc > cvc) break; *************** *** 590,596 **** * terminate line */ if (otln(buf, 0, &ips, &ops, 0)) ! return(1); } } else { --- 587,593 ---- * terminate line */ if (otln(buf, 0, &ips, &ops, 0)) ! goto out; } } else { *************** *** 615,621 **** ips = 0; ops = 0; if (otln(ptbf, j, &ips, &ops, 0)) ! return(1); } } } --- 612,618 ---- ips = 0; ops = 0; if (otln(ptbf, j, &ips, &ops, 0)) ! goto out; } } } *************** *** 625,631 **** * pad to end of page */ if (prtail((lines - pln), 0)) ! return(1); /* * if FORM continue --- 622,628 ---- * pad to end of page */ if (prtail((lines - pln), 0)) ! goto out; /* * if FORM continue *************** *** 645,654 **** (void)fclose(inf); } ! if (eoptind < argc) ! return(1); ! else ! return(0); } /* --- 642,666 ---- (void)fclose(inf); } ! if (eoptind < argc){ ! goto out; ! } else { ! error = 0; ! goto out; ! } ! ! oomem: ! mfail(); ! out: ! free(buf); ! free(hbuf); ! free(vc); ! free(lstdat); ! free(lindy); ! if (inf != NULL && inf != stdin) ! (void)fclose(inf); ! return error; ! } /* *************** *** 667,694 **** int rc; int lncnt; int pagecnt; ! char *buf; ! char *hbuf; char *ohbuf; char *fname; ! FILE *inf; int cps = 0; int mor = 0; int ips = 0; int ops = 0; ! if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) { ! mfail(); ! return(1); ! } /* * page header */ ! if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { ! mfail(); ! return(1); ! } ohbuf = hbuf + offst; if (offst) { --- 679,703 ---- 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) { *************** *** 739,745 **** rc = inln(inf,ptbf,colwd,&cnt,&cps,1, &mor); if (cnt >= 0) { if (!i && !j && prhead(hbuf, fname, ++pagecnt)) ! return(1); ptbf += cnt; lstdat = ptbf; --- 748,754 ---- 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; *************** *** 769,775 **** */ if (j) { if (otln(buf, lstdat-buf, &ips, &ops, 0)) ! return(1); } if (rc != NORMAL) --- 778,784 ---- */ if (j) { if (otln(buf, lstdat-buf, &ips, &ops, 0)) ! goto out; } if (rc != NORMAL) *************** *** 797,805 **** if (inf != stdin) (void)fclose(inf); } ! if (eoptind < argc) ! return(1); ! return(0); } struct ferrlist { --- 806,826 ---- 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; } struct ferrlist { *************** *** 872,915 **** int cnt; char *lstdat; int i; ! FILE **fbuf; int actf; int lncnt; int col; int pagecnt; int fproc; ! char *buf; ! char *hbuf; char *ohbuf; char *fname; int ips = 0; int cps = 0; int ops = 0; int mor = 0; /* * array of FILE *, one for each operand */ ! if ((fbuf = (FILE **)calloc((unsigned)clcnt, sizeof(FILE *))) == NULL) { ! mfail(); ! return(1); ! } /* * array of int *, one for each operand */ ! if ((rc = (int *)calloc((unsigned)clcnt, sizeof(int))) == NULL) { ! mfail(); ! return(1); ! } /* * page header */ ! if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) { ! mfail(); ! return(1); ! } ohbuf = hbuf + offst; /* --- 893,932 ---- 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 = (FILE **)calloc((unsigned)clcnt, sizeof(FILE *))) == NULL) ! goto oomem; /* * array of int *, one for each operand */ ! if ((rc = (int *)calloc((unsigned)clcnt, sizeof(int))) == NULL) ! goto oomem; /* * page header */ ! if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) ! goto oomem; ! ohbuf = hbuf + offst; /* *************** *** 938,944 **** if (j) clcnt = j; else ! return(1); /* * calculate page boundaries based on open file count --- 955,961 ---- if (j) clcnt = j; else ! goto out; /* * calculate page boundaries based on open file count *************** *** 952,968 **** } if (colwd < 1) { ferrout("pr: page width too small for %d columns\n", clcnt); ! return(1); } col = colwd + 1; /* * line buffer */ ! if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) { ! mfail(); ! return(1); ! } if (offst) { (void)memset(buf, (int)' ', offst); (void)memset(hbuf, (int)' ', offst); --- 969,984 ---- } 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); *************** *** 1053,1065 **** */ if (fproc != 0) { if (!i && prhead(hbuf, fname, ++pagecnt)) ! return(1); /* * output line */ if (otln(buf, lstdat-buf, &ips, &ops, 0)) ! return(1); } else break; } --- 1069,1081 ---- */ 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; } *************** *** 1080,1088 **** if (actf <= 0) break; } ! if (eoptind < argc) ! return(1); ! return(0); } /* --- 1096,1121 ---- 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; } /*