[BACK]Return to pr.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / pr

Diff for /src/usr.bin/pr/pr.c between version 1.28 and 1.29

version 1.28, 2009/10/27 23:59:41 version 1.29, 2010/08/17 21:37:11
Line 181 
Line 181 
     int ips;      int ips;
     int ops;      int ops;
     int cps;      int cps;
     char *obuf;      char *obuf = NULL;
     char *lbuf;      char *lbuf;
     char *nbuf;      char *nbuf;
     char *hbuf;      char *hbuf = NULL;
     char *ohbuf;      char *ohbuf;
     FILE *inf;      FILE *inf;
     char *fname;      char *fname;
     int mor;      int mor;
       int error = 1;
   
     if (nmwd)      if (nmwd)
         num = nmwd + 1;          num = nmwd + 1;
Line 199 
Line 200 
     /*      /*
      * allocate line buffer       * allocate line buffer
      */       */
     if ((obuf = malloc((unsigned)LBUF + off)) == NULL) {      if ((obuf = malloc((unsigned)(LBUF + off)*sizeof(char))) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * allocate header buffer       * allocate header buffer
      */       */
     if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) {      if ((hbuf = malloc((unsigned)(HDBUF + offst)*sizeof(char))) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     ohbuf = hbuf + offst;      ohbuf = hbuf + offst;
     nbuf = obuf + offst;      nbuf = obuf + offst;
Line 258 
Line 255 
                     if (cnt >= 0) {                      if (cnt >= 0) {
                         if (!lrgln)                          if (!lrgln)
                             if (!linecnt && prhead(hbuf, fname, ++pagecnt))                              if (!linecnt && prhead(hbuf, fname, ++pagecnt))
                                  return(1);                                   goto out;
   
                         /*                          /*
                          * start new line or continue a long one                           * start new line or continue a long one
Line 267 
Line 264 
                             if (num)                              if (num)
                                 addnum(nbuf, num, ++lncnt);                                  addnum(nbuf, num, ++lncnt);
                             if (otln(obuf,cnt+off, &ips, &ops, mor))                              if (otln(obuf,cnt+off, &ips, &ops, mor))
                                 return(1);                                  goto out;
                         } else                          } else
                             if (otln(lbuf, cnt, &ips, &ops, mor))                              if (otln(lbuf, cnt, &ips, &ops, mor))
                                 return(1);                                  goto out;
   
                         /*                          /*
                          * if line bigger than buffer, get more                           * if line bigger than buffer, get more
Line 296 
Line 293 
                  * fill to end of page                   * fill to end of page
                  */                   */
                 if (prtail(lines - linecnt, lrgln))                  if (prtail(lines - linecnt, lrgln))
                     return(1);                      goto out;
   
                 /*                  /*
                  * unless END continue                   * unless END continue
Line 318 
Line 315 
     /*      /*
      * If we didn't process all the files, return error       * If we didn't process all the files, return error
      */       */
     if (eoptind < argc)      if (eoptind < argc) {
         return(1);          goto out;
     else      } else {
         return(0);          error = 0;
           goto out;
       }
   
   oomem:
       mfail();
   out:
       free(obuf);
       free(hbuf);
       if (inf != NULL && inf != stdin)
           (void)fclose(inf);
       return error;
 }  }
   
 /*  /*
Line 332 
Line 340 
 vertcol(int argc, char *argv[])  vertcol(int argc, char *argv[])
 {  {
     char *ptbf;      char *ptbf;
     char **lstdat;      char **lstdat = NULL;
     int i;      int i;
     int j;      int j;
     int pln;      int pln;
     int *indy;      int *indy = NULL;
     int cnt;      int cnt;
     int rc;      int rc;
     int cvc;      int cvc;
     int *lindy;      int *lindy = NULL;
     int lncnt;      int lncnt;
     int stp;      int stp;
     int pagecnt;      int pagecnt;
     int col = colwd + 1;      int col = colwd + 1;
     int mxlen = pgwd + offst + 1;      int mxlen = pgwd + offst + 1;
     int mclcnt = clcnt - 1;      int mclcnt = clcnt - 1;
     struct vcol *vc;      struct vcol *vc = NULL;
     int mvc;      int mvc;
     int tvc;      int tvc;
     int cw = nmwd + 1;      int cw = nmwd + 1;
     int fullcol;      int fullcol;
     char *buf;      char *buf = NULL;
     char *hbuf;      char *hbuf = NULL;
     char *ohbuf;      char *ohbuf;
     char *fname;      char *fname;
     FILE *inf;      FILE *inf = NULL;
     int ips = 0;      int ips = 0;
     int cps = 0;      int cps = 0;
     int ops = 0;      int ops = 0;
     int mor = 0;      int mor = 0;
       int error = 1;
   
     /*      /*
      * allocate page buffer       * allocate page buffer
      */       */
     if ((buf = calloc((unsigned)lines, mxlen)) == NULL) {      if ((buf = calloc((unsigned)lines, mxlen)) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * allocate page header       * allocate page header
      */       */
     if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) {      if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     ohbuf = hbuf + offst;      ohbuf = hbuf + offst;
     if (offst)      if (offst)
Line 386 
Line 391 
      * col pointers when no headers       * col pointers when no headers
      */       */
     mvc = lines * clcnt;      mvc = lines * clcnt;
     if ((vc=(struct vcol *)calloc((unsigned)mvc, sizeof(struct vcol))) == NULL) {      if ((vc=(struct vcol *)calloc((unsigned)mvc, sizeof(struct vcol))) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * pointer into page where last data per line is located       * pointer into page where last data per line is located
      */       */
     if ((lstdat = (char **)calloc((unsigned)lines, sizeof(char *))) == NULL){      if ((lstdat = (char **)calloc((unsigned)lines, sizeof(char *))) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * fast index lookups to locate start of lines       * fast index lookups to locate start of lines
      */       */
     if ((indy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) {      if ((indy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL)
         mfail();          goto oomem;
         return(1);      if ((lindy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL)
     }          goto oomem;
     if ((lindy = (int *)calloc((unsigned)lines, sizeof(int))) == NULL) {  
         mfail();  
         return(1);  
     }  
   
     if (nmwd)      if (nmwd)
         fullcol = col + cw;          fullcol = col + cw;
Line 541 
Line 538 
                  */                   */
                 if (vc[0].cnt >= 0) {                  if (vc[0].cnt >= 0) {
                     if (prhead(hbuf, fname, ++pagecnt))                      if (prhead(hbuf, fname, ++pagecnt))
                         return(1);                          goto out;
   
                     /*                      /*
                      * check to see if "last" page needs to be reordered                       * check to see if "last" page needs to be reordered
Line 556 
Line 553 
                             ips = 0;                              ips = 0;
                             ops = 0;                              ops = 0;
                             if (offst && otln(buf,offst,&ips,&ops,1))                              if (offst && otln(buf,offst,&ips,&ops,1))
                                 return(1);                                  goto out;
                             tvc = i;                              tvc = i;
   
                             for (j = 0; j < clcnt; ++j) {                              for (j = 0; j < clcnt; ++j) {
Line 581 
Line 578 
                                     cnt = fullcol;                                      cnt = fullcol;
   
                                 if (otln(vc[tvc].pt, cnt, &ips, &ops, 1))                                  if (otln(vc[tvc].pt, cnt, &ips, &ops, 1))
                                     return(1);                                      goto out;
                                 tvc += pln;                                  tvc += pln;
                                 if (tvc > cvc)                                  if (tvc > cvc)
                                     break;                                      break;
Line 590 
Line 587 
                              * terminate line                               * terminate line
                              */                               */
                             if (otln(buf, 0, &ips, &ops, 0))                              if (otln(buf, 0, &ips, &ops, 0))
                                 return(1);                                  goto out;
                         }                          }
   
                     } else {                      } else {
Line 615 
Line 612 
                                 ips = 0;                                  ips = 0;
                                 ops = 0;                                  ops = 0;
                                 if (otln(ptbf, j, &ips, &ops, 0))                                  if (otln(ptbf, j, &ips, &ops, 0))
                                     return(1);                                      goto out;
                             }                              }
                         }                          }
                     }                      }
Line 625 
Line 622 
                  * pad to end of page                   * pad to end of page
                  */                   */
                 if (prtail((lines - pln), 0))                  if (prtail((lines - pln), 0))
                     return(1);                      goto out;
   
                 /*                  /*
                  * if FORM continue                   * if FORM continue
Line 645 
Line 642 
             (void)fclose(inf);              (void)fclose(inf);
     }      }
   
     if (eoptind < argc)      if (eoptind < argc){
         return(1);          goto out;
     else      } else {
         return(0);          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;
   
 }  }
   
 /*  /*
Line 667 
Line 679 
     int rc;      int rc;
     int lncnt;      int lncnt;
     int pagecnt;      int pagecnt;
     char *buf;      char *buf = NULL;
     char *hbuf;      char *hbuf = NULL;
     char *ohbuf;      char *ohbuf;
     char *fname;      char *fname;
     FILE *inf;      FILE *inf = NULL;
     int cps = 0;      int cps = 0;
     int mor = 0;      int mor = 0;
     int ips = 0;      int ips = 0;
     int ops = 0;      int ops = 0;
       int error = 1;
   
     if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) {      if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * page header       * page header
      */       */
     if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) {      if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     ohbuf = hbuf + offst;      ohbuf = hbuf + offst;
     if (offst) {      if (offst) {
Line 739 
Line 748 
                         rc = inln(inf,ptbf,colwd,&cnt,&cps,1, &mor);                          rc = inln(inf,ptbf,colwd,&cnt,&cps,1, &mor);
                         if (cnt >= 0) {                          if (cnt >= 0) {
                             if (!i && !j && prhead(hbuf, fname, ++pagecnt))                              if (!i && !j && prhead(hbuf, fname, ++pagecnt))
                                 return(1);                                  goto out;
   
                             ptbf += cnt;                              ptbf += cnt;
                             lstdat = ptbf;                              lstdat = ptbf;
Line 769 
Line 778 
                      */                       */
                     if (j) {                      if (j) {
                         if (otln(buf, lstdat-buf, &ips, &ops, 0))                          if (otln(buf, lstdat-buf, &ips, &ops, 0))
                             return(1);                              goto out;
                     }                      }
   
                     if (rc != NORMAL)                      if (rc != NORMAL)
Line 797 
Line 806 
         if (inf != stdin)          if (inf != stdin)
             (void)fclose(inf);              (void)fclose(inf);
     }      }
     if (eoptind < argc)      if (eoptind < argc){
         return(1);          goto out;
     return(0);      } else {
           error = 0;
           goto out;
       }
   
   oomem:
       mfail();
   out:
       free(buf);
       free(hbuf);
       if (inf != NULL && inf != stdin)
           (void)fclose(inf);
       return error;
 }  }
   
 struct ferrlist {  struct ferrlist {
Line 872 
Line 893 
     int cnt;      int cnt;
     char *lstdat;      char *lstdat;
     int i;      int i;
     FILE **fbuf;      FILE **fbuf = NULL;
     int actf;      int actf;
     int lncnt;      int lncnt;
     int col;      int col;
     int pagecnt;      int pagecnt;
     int fproc;      int fproc;
     char *buf;      char *buf = NULL;
     char *hbuf;      char *hbuf = NULL;
     char *ohbuf;      char *ohbuf;
     char *fname;      char *fname;
     int ips = 0;      int ips = 0;
     int cps = 0;      int cps = 0;
     int ops = 0;      int ops = 0;
     int mor = 0;      int mor = 0;
       int error = 1;
   
     /*      /*
      * array of FILE *, one for each operand       * array of FILE *, one for each operand
      */       */
     if ((fbuf = (FILE **)calloc((unsigned)clcnt, sizeof(FILE *))) == NULL) {      if ((fbuf = (FILE **)calloc((unsigned)clcnt, sizeof(FILE *))) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * array of int *, one for each operand       * array of int *, one for each operand
      */       */
     if ((rc = (int *)calloc((unsigned)clcnt, sizeof(int))) == NULL) {      if ((rc = (int *)calloc((unsigned)clcnt, sizeof(int))) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
   
     /*      /*
      * page header       * page header
      */       */
     if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL) {      if ((hbuf = malloc((unsigned)HDBUF + offst)) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
     ohbuf = hbuf + offst;      ohbuf = hbuf + offst;
   
     /*      /*
Line 938 
Line 955 
     if (j)      if (j)
         clcnt = j;          clcnt = j;
     else      else
         return(1);          goto out;
   
     /*      /*
      * calculate page boundaries based on open file count       * calculate page boundaries based on open file count
Line 952 
Line 969 
     }      }
     if (colwd < 1) {      if (colwd < 1) {
         ferrout("pr: page width too small for %d columns\n", clcnt);          ferrout("pr: page width too small for %d columns\n", clcnt);
         return(1);          goto out;
     }      }
     col = colwd + 1;      col = colwd + 1;
   
     /*      /*
      * line buffer       * line buffer
      */       */
     if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL) {      if ((buf = malloc((unsigned)pgwd + offst + 1)) == NULL)
         mfail();          goto oomem;
         return(1);  
     }  
     if (offst) {      if (offst) {
         (void)memset(buf, (int)' ', offst);          (void)memset(buf, (int)' ', offst);
         (void)memset(hbuf, (int)' ', offst);          (void)memset(hbuf, (int)' ', offst);
Line 1053 
Line 1069 
                  */                   */
                 if (fproc != 0) {                  if (fproc != 0) {
                     if (!i && prhead(hbuf, fname, ++pagecnt))                      if (!i && prhead(hbuf, fname, ++pagecnt))
                         return(1);                          goto out;
   
                     /*                      /*
                      * output line                       * output line
                      */                       */
                     if (otln(buf, lstdat-buf, &ips, &ops, 0))                      if (otln(buf, lstdat-buf, &ips, &ops, 0))
                         return(1);                          goto out;
                 } else                  } else
                     break;                      break;
             }              }
Line 1080 
Line 1096 
         if (actf <= 0)          if (actf <= 0)
         break;          break;
     }      }
     if (eoptind < argc)      if (eoptind < argc){
         return(1);          goto out;
     return(0);      } 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;
 }  }
   
 /*  /*

Legend:
Removed from v.1.28  
changed lines
  Added in v.1.29