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

Diff for /src/usr.bin/compress/main.c between version 1.34 and 1.35

version 1.34, 2003/07/14 18:42:20 version 1.35, 2003/07/14 18:57:31
Line 94 
Line 94 
 int decompress(const char *, const char *, const struct compressor *,  int decompress(const char *, const char *, const struct compressor *,
     int, struct stat *);      int, struct stat *);
 const struct compressor *check_method(int, struct stat *, const char *);  const struct compressor *check_method(int, struct stat *, const char *);
   char *set_outfile(char *, char *, size_t);
   
 #define OPTSTRING       "123456789ab:cdfghlLnNOo:qrS:tvV"  #define OPTSTRING       "123456789ab:cdfghlLnNOo:qrS:tvV"
 const struct option longopts[] = {  const struct option longopts[] = {
Line 347 
Line 348 
                         strlcpy(outfile, "/dev/stdout", sizeof outfile);                          strlcpy(outfile, "/dev/stdout", sizeof outfile);
                 else if (!oflag) {                  else if (!oflag) {
                         if (decomp) {                          if (decomp) {
                                 const struct compressor *m = method;                                  if (set_outfile(infile, outfile,
                                       sizeof outfile) == NULL) {
                                 if ((s = strrchr(infile, '.')) != NULL &&  
                                     strcmp(s, suffix) != 0) {  
                                         for (m = &c_table[0];  
                                             m->name && strcmp(s, m->suffix);  
                                             m++)  
                                                 ;  
                                 }  
                                 if (s == NULL || m->name == NULL) {  
                                         if (!recurse)                                          if (!recurse)
                                                 warnx("%s: unknown suffix: "                                                  warnx("%s: unknown suffix: "
                                                     "ignored", infile);                                                      "ignored", infile);
                                         continue;                                          continue;
                                 }                                  }
                                 method = m;  
                                 strlcpy(outfile, infile,  
                                     min(sizeof(outfile), (s - infile) + 1));  
                         } else {                          } else {
                                 if (snprintf(outfile, sizeof(outfile),                                  if (snprintf(outfile, sizeof(outfile),
                                     "%s%s", infile, suffix) >= sizeof(outfile)) {                                      "%s%s", infile, suffix) >= sizeof(outfile)) {
Line 637 
Line 627 
         while (ch != '\n' && ch != EOF)          while (ch != '\n' && ch != EOF)
                 ch = getchar();                  ch = getchar();
         return (first == 'y');          return (first == 'y');
   }
   
   /*
    * Set outfile based on the suffix.  In most cases we just strip
    * off the suffix but things like .tgz and .taz are special.
    */
   char *
   set_outfile(char *infile, char *outfile, size_t osize)
   {
           int i;
           char *s;
           static char *suffixes[] = { ".Z", ".gz", ".z", ".tgz", ".taz",
                                       "-Z", "-gz", "-z", "_Z", "_gz", "_z",
                                       NULL };
   
           if ((s = strrchr(infile, '.')) == NULL &&
               (s = strrchr(infile, '-')) == NULL &&
               (s = strrchr(infile, '_')) == NULL)
                   return (NULL);
   
           for (i = 0; suffixes[i] != NULL; i++) {
                   if (strcmp(s, suffixes[i]) == 0) {
                           (void)strlcpy(outfile, infile, osize);
                           s = outfile + (s - infile);
                           /*
                            * Convert .tgz and .taz -> .tar,
                            * else drop the suffix.
                            */
                           if (strcmp(s, ".tgz") == 0) {
                                   s[2] = 'a';
                                   s[3] = 'r';
                           } else if (strcmp(s, ".taz") == 0)
                                   s[3] = 'r';
                           else
                                   s[0] = '\0';
                           return (outfile);
                   }
           }
           return (NULL);
 }  }
   
 __dead void  __dead void

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.35