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

Diff for /src/usr.bin/split/split.c between version 1.11 and 1.12

version 1.11, 2006/08/09 12:04:21 version 1.12, 2006/08/09 22:42:08
Line 67 
Line 67 
 char     fname[MAXPATHLEN];             /* File name prefix. */  char     fname[MAXPATHLEN];             /* File name prefix. */
 regex_t  rgx;  regex_t  rgx;
 int      pflag;  int      pflag;
   int      sufflen = 2;                   /* File name suffix length. */
   
 void newfile(void);  void newfile(void);
 void split1(void);  void split1(void);
Line 78 
Line 79 
 {  {
         int ch;          int ch;
         char *ep, *p;          char *ep, *p;
           const char *errstr;
   
         while ((ch = getopt(argc, argv, "0123456789b:l:p:-")) != -1)          while ((ch = getopt(argc, argv, "0123456789a:b:l:p:-")) != -1)
                 switch (ch) {                  switch (ch) {
                 case '0': case '1': case '2': case '3': case '4':                  case '0': case '1': case '2': case '3': case '4':
                 case '5': case '6': case '7': case '8': case '9':                  case '5': case '6': case '7': case '8': case '9':
Line 104 
Line 106 
                                 usage();                                  usage();
                         ifd = 0;                          ifd = 0;
                         break;                          break;
                   case 'a':               /* suffix length. */
                           sufflen = strtonum(optarg, 1, NAME_MAX, &errstr);
                           if (errstr)
                                   errx(EX_USAGE, "%s: %s", optarg, errstr);
                           break;
                 case 'b':               /* Byte count. */                  case 'b':               /* Byte count. */
                         if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 ||                          if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 ||
                             (*ep != '\0' && *ep != 'k' && *ep != 'm'))                              (*ep != '\0' && *ep != 'k' && *ep != 'm'))
Line 143 
Line 150 
         if (*argv != NULL)          if (*argv != NULL)
                 usage();                  usage();
   
           if (strlen(fname) + sufflen >= sizeof(fname))
                   errx(EX_USAGE, "suffix is too long");
         if (pflag && (numlines != 0 || bytecnt != 0))          if (pflag && (numlines != 0 || bytecnt != 0))
                 usage();                  usage();
   
Line 271 
Line 280 
 void  void
 newfile(void)  newfile(void)
 {  {
         static long fnum;          static char *suffix, *sufftail;
         static int defname;          static int defname;
         static char *fpnt;  
   
         if (ofd == -1) {          if (ofd == -1) {
                 if (fname[0] == '\0') {                  if (fname[0] == '\0') {
                         fname[0] = 'x';                          fname[0] = 'x';
                         fpnt = fname + 1;                          suffix = fname + 1;
                         defname = 1;                          defname = 1;
                 } else {                  } else {
                         fpnt = fname + strlen(fname);                          suffix = fname + strlen(fname);
                         defname = 0;                          defname = 0;
                 }                  }
                   memset(suffix, 'a', sufflen);
                   suffix[sufflen] = '\0';
                   sufftail = suffix + sufflen - 1;
                   --sufftail[0];          /* incremented later */
                 ofd = fileno(stdout);                  ofd = fileno(stdout);
         }          }
         /*  
          * Hack to increase max files; original code wandered through          if (sufftail[0] == 'z') {
          * magic characters.  Maximum files is 3 * 26 * 26 == 2028                  int i;
          */  
 #define MAXFILES        676                  /* Increment the non-tail portion of the suffix. */
         if (fnum == MAXFILES) {                  for (i = sufflen - 2; i >= 0; i--) {
                 if (!defname || fname[0] == 'z')                          if (suffix[i] != 'z') {
                         errx(EX_DATAERR, "too many files");                                  suffix[i]++;
                 ++fname[0];                                  break;
                 fnum = 0;                          }
         }                  }
         fpnt[0] = fnum / 26 + 'a';                  if (i < 0) {
         fpnt[1] = fnum % 26 + 'a';                          /* Hack to support y and z prefix if no name spec'd. */
         ++fnum;                          if (!defname || fname[0] == 'z')
                                   errx(EX_DATAERR, "too many files");
                           ++fname[0];
                           memset(suffix, 'a', sufflen);
                   } else
                           sufftail[0] = 'a';      /* reset tail */
           } else
                   ++sufftail[0];
   
         if (!freopen(fname, "w", stdout))          if (!freopen(fname, "w", stdout))
                 err(EX_IOERR, "%s", fname);                  err(EX_IOERR, "%s", fname);
         file_open = 1;          file_open = 1;
Line 310 
Line 330 
 {  {
         extern char *__progname;          extern char *__progname;
   
         (void)fprintf(stderr,          (void)fprintf(stderr, "usage: %s [-a suffix_length] "
 "usage: %s [-b byte_count[k|m] | -l line_count | -p pattern] [file [name]]\n",              "[-b byte_count[k|m] | -l line_count | -p pattern] [file [name]]\n",
 __progname);              __progname);
         exit(EX_USAGE);          exit(EX_USAGE);
 }  }

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12