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

Diff for /src/usr.bin/cut/cut.c between version 1.6 and 1.7

version 1.6, 1998/11/28 03:41:46 version 1.7, 2000/06/04 23:52:19
Line 153 
Line 153 
          * overlapping lists.  We also handle "-3-5" although there's no           * overlapping lists.  We also handle "-3-5" although there's no
          * real reason too.           * real reason too.
          */           */
         for (; p = strsep(&list, ", \t");) {          while ((p = strsep(&list, ", \t"))) {
                 setautostart = start = stop = 0;                  setautostart = start = stop = 0;
                 if (*p == '-') {                  if (*p == '-') {
                         ++p;                          ++p;
Line 182 
Line 182 
                             stop, _POSIX2_LINE_MAX);                              stop, _POSIX2_LINE_MAX);
                 if (maxval < stop)                  if (maxval < stop)
                         maxval = stop;                          maxval = stop;
                 for (pos = positions + start; start++ <= stop; *pos++ = 1);                  for (pos = positions + start; start++ <= stop; *pos++ = 1)
                           ;
         }          }
   
         /* overlapping ranges */          /* overlapping ranges */
Line 213 
Line 214 
                         if (*pos++)                          if (*pos++)
                                 (void)putchar(ch);                                  (void)putchar(ch);
                 }                  }
                 if (ch != '\n')                  if (ch != '\n') {
                         if (autostop)                          if (autostop)
                                 while ((ch = getc(fp)) != EOF && ch != '\n')                                  while ((ch = getc(fp)) != EOF && ch != '\n')
                                         (void)putchar(ch);                                          (void)putchar(ch);
                         else                          else
                                 while ((ch = getc(fp)) != EOF && ch != '\n');                                  while ((ch = getc(fp)) != EOF && ch != '\n')
                                           ;
                   }
                 (void)putchar('\n');                  (void)putchar('\n');
         }          }
 }  }
Line 231 
Line 234 
         register int ch, field, isdelim;          register int ch, field, isdelim;
         register char *pos, *p, sep;          register char *pos, *p, sep;
         int output;          int output;
         char lbuf[_POSIX2_LINE_MAX + 1];          size_t len;
           char *lbuf, *tbuf;
   
         for (sep = dchar; fgets(lbuf, sizeof(lbuf), fp);) {          for (sep = dchar, tbuf = NULL; (lbuf = fgetln(fp, &len));) {
                 output = 0;                  output = 0;
                   if (lbuf[len - 1] != '\n') {
                           /* no newline at the end of the last line so add one */
                           if ((tbuf = (char *)malloc(len + 1)) == NULL)
                                   err(1, NULL);
                           memcpy(tbuf, lbuf, len);
                           tbuf[len] = '\n';
                           lbuf = tbuf;
                   }
                 for (isdelim = 0, p = lbuf;; ++p) {                  for (isdelim = 0, p = lbuf;; ++p) {
                         if (!(ch = *p))                          ch = *p;
                                 errx(1, "%s: line too long.", fname);  
                         /* this should work if newline is delimiter */                          /* this should work if newline is delimiter */
                         if (ch == sep)                          if (ch == sep)
                                 isdelim = 1;                                  isdelim = 1;
                         if (ch == '\n') {                          if (ch == '\n') {
                                 if (!isdelim && !sflag)                                  if (!isdelim && !sflag)
                                         (void)printf("%s", lbuf);                                          (void)fwrite(lbuf, len, 1, stdout);
                                 break;                                  break;
                         }                          }
                 }                  }
Line 258 
Line 269 
                                 while ((ch = *p++) != '\n' && ch != sep)                                  while ((ch = *p++) != '\n' && ch != sep)
                                         (void)putchar(ch);                                          (void)putchar(ch);
                         } else                          } else
                                 while ((ch = *p++) != '\n' && ch != sep);                                  while ((ch = *p++) != '\n' && ch != sep)
                                           ;
                         if (ch == '\n')                          if (ch == '\n')
                                 break;                                  break;
                 }                  }
                 if (ch != '\n')                  if (ch != '\n') {
                         if (autostop) {                          if (autostop) {
                                 if (output)                                  if (output)
                                         (void)putchar(sep);                                          (void)putchar(sep);
                                 for (; (ch = *p) != '\n'; ++p)                                  for (; (ch = *p) != '\n'; ++p)
                                         (void)putchar(ch);                                          (void)putchar(ch);
                         } else                          } else
                                 for (; (ch = *p) != '\n'; ++p);                                  for (; (ch = *p) != '\n'; ++p)
                                           ;
                   }
                 (void)putchar('\n');                  (void)putchar('\n');
         }          }
           if (tbuf)
                   free(tbuf);
 }  }
   
 void  void

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7