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

Diff for /src/usr.bin/paste/paste.c between version 1.23 and 1.24

version 1.23, 2018/01/02 06:56:41 version 1.24, 2018/08/04 16:14:03
Line 104 
Line 104 
 {  {
         SIMPLEQ_HEAD(, list) head = SIMPLEQ_HEAD_INITIALIZER(head);          SIMPLEQ_HEAD(, list) head = SIMPLEQ_HEAD_INITIALIZER(head);
         struct list *lp;          struct list *lp;
           char *line, *p;
           size_t len, linesize;
         int cnt;          int cnt;
         char ch, *p;  
         int opencnt, output;          int opencnt, output;
         char *buf, *lbuf;          char ch;
         size_t len;  
   
         for (cnt = 0; (p = *argv); ++argv, ++cnt) {          for (cnt = 0; (p = *argv); ++argv, ++cnt) {
                 if (!(lp = malloc(sizeof(struct list))))                  if (!(lp = malloc(sizeof(struct list))))
Line 123 
Line 123 
                 SIMPLEQ_INSERT_TAIL(&head, lp, entries);                  SIMPLEQ_INSERT_TAIL(&head, lp, entries);
         }          }
   
           line = NULL;
           linesize = 0;
   
         for (opencnt = cnt; opencnt;) {          for (opencnt = cnt; opencnt;) {
                 output = 0;                  output = 0;
                 SIMPLEQ_FOREACH(lp, &head, entries) {                  SIMPLEQ_FOREACH(lp, &head, entries) {
                         lbuf = NULL;  
                         if (!lp->fp) {                          if (!lp->fp) {
                                 if (output && lp->cnt &&                                  if (output && lp->cnt &&
                                     (ch = delim[(lp->cnt - 1) % delimcnt]))                                      (ch = delim[(lp->cnt - 1) % delimcnt]))
                                         putchar(ch);                                          putchar(ch);
                                 continue;                                  continue;
                         }                          }
                         if (!(buf = fgetln(lp->fp, &len))) {                          if ((len = getline(&line, &linesize, lp->fp)) == -1) {
                                   if (ferror(lp->fp))
                                           err(1, "%s", lp->fp == stdin ?
                                               "getline" : lp->name);
                                 if (!--opencnt)                                  if (!--opencnt)
                                         break;                                          break;
                                 if (lp->fp != stdin)                                  if (lp->fp != stdin)
Line 144 
Line 149 
                                         putchar(ch);                                          putchar(ch);
                                 continue;                                  continue;
                         }                          }
                         if (buf[len - 1] == '\n')                          if (line[len - 1] == '\n')
                                 buf[len - 1] = '\0';                                  line[len - 1] = '\0';
                         else {  
                                 if ((lbuf = malloc(len + 1)) == NULL)  
                                         err(1, "malloc");  
                                 memcpy(lbuf, buf, len);  
                                 lbuf[len] = '\0';  
                                 buf = lbuf;  
                         }  
                         /*                          /*
                          * make sure that we don't print any delimiters                           * make sure that we don't print any delimiters
                          * unless there's a non-empty file.                           * unless there's a non-empty file.
Line 164 
Line 162 
                                                 putchar(ch);                                                  putchar(ch);
                         } else if ((ch = delim[(lp->cnt - 1) % delimcnt]))                          } else if ((ch = delim[(lp->cnt - 1) % delimcnt]))
                                 putchar(ch);                                  putchar(ch);
                         (void)printf("%s", buf);                          fputs(line, stdout);
                         if (lbuf)  
                                 free(lbuf);  
                 }                  }
                 if (output)                  if (output)
                         putchar('\n');                          putchar('\n');
         }          }
           free(line);
 }  }
   
 void  void
 sequential(char **argv)  sequential(char **argv)
 {  {
         FILE *fp;          FILE *fp;
           char *line, *p;
           size_t len, linesize;
         int cnt;          int cnt;
         char ch, *p, *dp;  
         char *buf, *lbuf;  
         size_t len;  
   
           line = NULL;
           linesize = 0;
         for (; (p = *argv); ++argv) {          for (; (p = *argv); ++argv) {
                 lbuf = NULL;  
                 if (p[0] == '-' && !p[1])                  if (p[0] == '-' && !p[1])
                         fp = stdin;                          fp = stdin;
                 else if (!(fp = fopen(p, "r"))) {                  else if (!(fp = fopen(p, "r"))) {
                         warn("%s", p);                          warn("%s", p);
                         continue;                          continue;
                 }                  }
                 if ((buf = fgetln(fp, &len))) {                  cnt = -1;
                         for (cnt = 0, dp = delim;;) {                  while ((len = getline(&line, &linesize, fp)) != -1) {
                                 if (buf[len - 1] == '\n')                          if (line[len - 1] == '\n')
                                         buf[len - 1] = '\0';                                  line[len - 1] = '\0';
                                 else {                          if (cnt >= 0)
                                         if ((lbuf = malloc(len + 1)) == NULL)                                  putchar(delim[cnt]);
                                                 err(1, "malloc");                          if (++cnt == delimcnt)
                                         memcpy(lbuf, buf, len);                                  cnt = 0;
                                         lbuf[len] = '\0';                          fputs(line, stdout);
                                         buf = lbuf;  
                                 }  
                                 (void)printf("%s", buf);  
                                 if (!(buf = fgetln(fp, &len)))  
                                         break;  
                                 if ((ch = *dp++))  
                                         putchar(ch);  
                                 if (++cnt == delimcnt) {  
                                         dp = delim;  
                                         cnt = 0;  
                                 }  
                         }  
                         putchar('\n');  
                 }                  }
                   if (ferror(fp))
                           err(1, "%s", fp == stdin ? "getline" : p);
                   if (cnt >= 0)
                           putchar('\n');
                 if (fp != stdin)                  if (fp != stdin)
                         (void)fclose(fp);                          (void)fclose(fp);
                 free(lbuf);  
         }          }
           free(line);
 }  }
   
 int  int

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24