[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.80 and 1.81

version 1.80, 2013/04/17 17:43:55 version 1.81, 2014/01/27 17:13:10
Line 41 
Line 41 
 #include <libgen.h>  #include <libgen.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
   #include <stdbool.h>
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
 #include <fcntl.h>  #include <fcntl.h>
Line 53 
Line 54 
 extern char *__progname;  extern char *__progname;
   
 const struct compressor {  const struct compressor {
         char *name;          const char *name;
         char *suffix;          const char *suffix;
         u_char *magic;          const u_char *magic;
           const char *comp_opts;
           const char *decomp_opts;
           const char *cat_opts;
         void *(*open)(int, const char *, char *, int, u_int32_t, int);          void *(*open)(int, const char *, char *, int, u_int32_t, int);
         int (*read)(void *, char *, int);          int (*read)(void *, char *, int);
         int (*write)(void *, const char *, int);          int (*write)(void *, const char *, int);
         int (*close)(void *, struct z_info *, const char *, struct stat *);          int (*close)(void *, struct z_info *, const char *, struct stat *);
 } c_table[] = {  } c_table[] = {
 #define M_DEFLATE (&c_table[0])  #define M_DEFLATE (&c_table[0])
   { "deflate", ".gz", "\037\213", gz_open, gz_read, gz_write, gz_close },          {
                   "deflate",
                   ".gz",
                   "\037\213",
                   "123456789ab:cdfhLlNnOo:qrS:tVv",
                   "cfhLlNno:qrtVv",
                   "fhqr",
                   gz_open,
                   gz_read,
                   gz_write,
                   gz_close
           },
 #define M_COMPRESS (&c_table[1])  #define M_COMPRESS (&c_table[1])
 #ifndef SMALL  #ifndef SMALL
   { "compress", ".Z", "\037\235", z_open,  zread,   zwrite,   z_close },          {
                   "compress",
                   ".Z",
                   "\037\235",
                   "123456789ab:cdfghlNnOo:qrS:tv",
                   "cfhlNno:qrtv",
                   "fghqr",
                   z_open,
                   zread,
                   zwrite,
                   z_close
           },
 #endif /* SMALL */  #endif /* SMALL */
 #if 0  #if 0
 #define M_LZH (&c_table[2])  #define M_LZH (&c_table[2])
Line 79 
Line 105 
 };  };
   
 #ifndef SMALL  #ifndef SMALL
 const struct compressor null_method =  const struct compressor null_method = {
 { "null", ".nul", "XX", null_open, null_read, null_write, null_close };          "null",
           ".nul",
           "XX",
           "123456789ab:cdfghlNnOo:qrS:tv",
           "cfhlNno:qrtv",
           "fghqr",
           null_open,
           null_read,
           null_write,
           null_close
   };
 #endif /* SMALL */  #endif /* SMALL */
   
 int permission(const char *);  int permission(const char *);
Line 126 
Line 162 
         FTS *ftsp;          FTS *ftsp;
         FTSENT *entry;          FTSENT *entry;
         const struct compressor *method;          const struct compressor *method;
         const char *s;          const char *optstr, *s;
         char *p, *infile;          char *p, *infile;
         char outfile[MAXPATHLEN], _infile[MAXPATHLEN], suffix[16];          char outfile[MAXPATHLEN], _infile[MAXPATHLEN], suffix[16];
         int bits, ch, error, rc, cflag, oflag;          int bits, ch, error, rc, cflag, oflag;
         static const char *optstr[3] = {  
                 "123456789ab:cdfghLlNnOo:qrS:tVv",  
                 "cfhlNno:qrtVv",  
                 "fghqr"  
         };  
   
         bits = cflag = oflag = 0;          bits = cflag = oflag = 0;
         storename = -1;          storename = -1;
Line 143 
Line 174 
                 method = M_DEFLATE;                  method = M_DEFLATE;
                 bits = 6;                  bits = 6;
                 p++;                  p++;
         } else          } else {
 #ifdef SMALL  #ifdef SMALL
                 method = M_DEFLATE;                  method = M_DEFLATE;
 #else  #else
                 method = M_COMPRESS;                  method = M_COMPRESS;
 #endif /* SMALL */  #endif /* SMALL */
           }
           optstr = method->comp_opts;
   
         decomp = 0;          decomp = 0;
         pmode = MODE_COMP;          pmode = MODE_COMP;
Line 196 
Line 229 
                 }                  }
         }          }
   
         while ((ch = getopt_long(argc, argv, optstr[pmode], longopts, NULL)) != -1)          optstr += pmode;
           while ((ch = getopt_long(argc, argv, optstr, longopts, NULL)) != -1)
                 switch (ch) {                  switch (ch) {
                 case '1':                  case '1':
                 case '2':                  case '2':
Line 894 
Line 928 
 __dead void  __dead void
 usage(int status)  usage(int status)
 {  {
           const bool gzip = (__progname[0] == 'g');
   
         switch (pmode) {          switch (pmode) {
         case MODE_COMP:          case MODE_COMP:
                 fprintf(stderr, "usage: %s [-123456789cdfghLlNnOqrtVv] "                  fprintf(stderr, "usage: %s [-123456789cdf%sh%slNnOqrt%sv] "
                     "[-b bits] [-o filename] [-S suffix]\n"                      "[-b bits] [-o filename] [-S suffix]\n"
                     "       %*s [file ...]\n",                      "       %*s [file ...]\n", __progname,
                     __progname, (int)strlen(__progname), "");                      !gzip ? "g" : "", gzip ? "L" : "", gzip ? "V" : "",
                       (int)strlen(__progname), "");
                 break;                  break;
         case MODE_DECOMP:          case MODE_DECOMP:
                 fprintf(stderr, "usage: %s [-cfhlNnqrtVv] [-o filename] "                  fprintf(stderr, "usage: %s [-cfh%slNnqrt%sv] [-o filename] "
                     "[file ...]\n", __progname);                      "[file ...]\n", __progname,
                       gzip ? "L" : "", gzip ? "V" : "");
                 break;                  break;
         case MODE_CAT:          case MODE_CAT:
                 fprintf(stderr, "usage: %s [-fghqr] [file ...]\n", __progname);                  fprintf(stderr, "usage: %s [-f%shqr] [file ...]\n",
                       __progname, gzip ? "" : "g");
                 break;                  break;
         }          }
         exit(status);          exit(status);

Legend:
Removed from v.1.80  
changed lines
  Added in v.1.81