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

Diff for /src/usr.bin/uniq/uniq.c between version 1.14 and 1.15

version 1.14, 2003/06/03 02:56:21 version 1.15, 2006/04/07 05:10:02
Line 46 
Line 46 
 static char rcsid[] = "$OpenBSD$";  static char rcsid[] = "$OpenBSD$";
 #endif /* not lint */  #endif /* not lint */
   
   #include <ctype.h>
   #include <err.h>
 #include <errno.h>  #include <errno.h>
   #include <limits.h>
 #include <stdio.h>  #include <stdio.h>
 #include <ctype.h>  
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
 #include <err.h>  
   
 #define MAXLINELEN      (8 * 1024)  #define MAXLINELEN      (8 * 1024)
   
Line 63 
Line 64 
 void     show(FILE *, char *);  void     show(FILE *, char *);
 char    *skip(char *);  char    *skip(char *);
 void     obsolete(char *[]);  void     obsolete(char *[]);
 void     usage(void);  __dead void     usage(void);
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
Line 71 
Line 72 
         char *t1, *t2;          char *t1, *t2;
         FILE *ifp = NULL, *ofp = NULL;          FILE *ifp = NULL, *ofp = NULL;
         int ch;          int ch;
         char *prevline, *thisline, *p;          char *prevline, *thisline;
   
         obsolete(argv);          obsolete(argv);
         while ((ch = getopt(argc, argv, "cdf:s:u")) != -1)          while ((ch = getopt(argc, argv, "cdf:s:u")) != -1) {
                   const char *errstr;
   
                 switch (ch) {                  switch (ch) {
                 case 'c':                  case 'c':
                         cflag = 1;                          cflag = 1;
Line 83 
Line 86 
                         dflag = 1;                          dflag = 1;
                         break;                          break;
                 case 'f':                  case 'f':
                         numfields = strtol(optarg, &p, 10);                          numfields = (int)strtonum(optarg, 0, INT_MAX,
                         if (numfields < 0 || *p)                              &errstr);
                                 errx(1, "illegal field skip value: %s", optarg);                          if (errstr)
                                   errx(1, "field skip value is %s: %s",
                                       errstr, optarg);
                         break;                          break;
                 case 's':                  case 's':
                         numchars = strtol(optarg, &p, 10);                          numchars = (int)strtonum(optarg, 0, INT_MAX,
                         if (numchars < 0 || *p)                              &errstr);
                                 errx(1, "illegal character skip value: %s", optarg);                          if (errstr)
                                   errx(1,
                                       "character skip value is %s: %s",
                                       errstr, optarg);
                         break;                          break;
                 case 'u':                  case 'u':
                         uflag = 1;                          uflag = 1;
                         break;                          break;
                 case '?':  
                 default:                  default:
                         usage();                          usage();
                   }
         }          }
   
         argc -= optind;          argc -= optind;
         argv +=optind;          argv += optind;
   
         /* If no flags are set, default is -d -u. */          /* If no flags are set, default is -d -u. */
         if (cflag) {          if (cflag) {
Line 170 
Line 178 
   
         if (cflag && *str)          if (cflag && *str)
                 (void)fprintf(ofp, "%4d %s", repeats + 1, str);                  (void)fprintf(ofp, "%4d %s", repeats + 1, str);
         if (dflag && repeats || uflag && !repeats)          if ((dflag && repeats) || (uflag && !repeats))
                 (void)fprintf(ofp, "%s", str);                  (void)fprintf(ofp, "%s", str);
 }  }
   
Line 187 
Line 195 
                         }                          }
                 } else if (!infield)                  } else if (!infield)
                         infield = 1;                          infield = 1;
         for (nchars = numchars; nchars-- && *str; ++str);          for (nchars = numchars; nchars-- && *str; ++str)
         return(str);                  ;
           return (str);
 }  }
   
 FILE *  FILE *
Line 200 
Line 209 
                 return(*mode == 'r' ? stdin : stdout);                  return(*mode == 'r' ? stdin : stdout);
         if ((fp = fopen(name, mode)) == NULL)          if ((fp = fopen(name, mode)) == NULL)
                 err(1, "%s", name);                  err(1, "%s", name);
         return(fp);          return (fp);
 }  }
   
 void  void
 obsolete(char *argv[])  obsolete(char *argv[])
 {  {
         int len;          size_t len;
         char *ap, *p, *start;          char *ap, *p, *start;
   
         while ((ap = *++argv)) {          while ((ap = *++argv)) {
Line 232 
Line 241 
         }          }
 }  }
   
 void  __dead void
 usage(void)  usage(void)
 {  {
           extern char *__progname;
   
         (void)fprintf(stderr,          (void)fprintf(stderr,
             "usage: uniq [-c | -du] [-f fields] [-s chars] [input [output]]\n");              "usage: %s [-c | -d | -u] [-f fields] [-s chars] [input_file [output_file]]\n",
               __progname);
         exit(1);          exit(1);
 }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15