home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume20 / compress / patch01 < prev    next >
Encoding:
Text File  |  1991-06-29  |  13.2 KB  |  502 lines

  1. Newsgroups: comp.sources.misc
  2. From: Dave Mack <csu@alembic.ACS.COM>
  3. Subject:  v20i074:  compress - Compress 4.1, Patch01
  4. Message-ID: <1991Jun29.215502.3324@sparky.IMD.Sterling.COM>
  5. X-Md4-Signature: c02086e8d81dbff5552e42e53fd396b5
  6. Date: Sat, 29 Jun 1991 21:55:02 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: Dave Mack <csu@alembic.ACS.COM>
  10. Posting-number: Volume 20, Issue 74
  11. Archive-name: compress/patch01
  12. Patch-To: compress: Volume 20, Issue 64-65
  13. Environment: UNIX
  14.  
  15. Patch Priority: COSMIC 
  16.  
  17. This patch brings the version of compress 4.1 posted to comp.sources.misc
  18. up to patchlevel 1. It corrects one severe bug, a number of minor
  19. annoyances, and some diagnostic and documentation errors.
  20.  
  21. Please apply it using "patch [-d compress41-source-dir] < patch-file".
  22.  
  23. Dave Mack 
  24. ----- 
  25. diff -rc compress.posted/compress.1 compress41/compress.1
  26. *** compress.posted/compress.1    Fri Jun 28 19:07:12 1991
  27. --- compress41/compress.1    Fri Jun 28 19:08:45 1991
  28. ***************
  29. *** 51,65 ****
  30.   while keeping the same ownership modes, access and modification times.
  31.   If no files are specified, the standard input is compressed to the
  32.   standard output.
  33. ! Compressed files can be restored to their original form using
  34. ! .I uncompress
  35. ! or
  36. ! .I zcat.
  37. ! .PP
  38. ! The
  39.   .B \-f
  40. ! option will force compression of
  41. ! .I name.
  42.   If
  43.   .B \-f
  44.   is not given and
  45. --- 51,65 ----
  46.   while keeping the same ownership modes, access and modification times.
  47.   If no files are specified, the standard input is compressed to the
  48.   standard output.
  49. ! .I Compress
  50. ! will only attempt to compress regular files.
  51. ! In particular, it will ignore symbolic links. If a file has multiple
  52. ! hard links,
  53. ! .I compress
  54. ! will refuse to compress it unless the
  55.   .B \-f
  56. ! flag is given.
  57. ! .PP
  58.   If
  59.   .B \-f
  60.   is not given and
  61. ***************
  62. *** 67,82 ****
  63.   is run in the foreground,
  64.   the user is prompted as to whether an existing file should be overwritten.
  65.   .PP
  66.   The
  67.   .B \-c
  68.   option makes
  69.   .I compress/uncompress
  70.   write to the standard output; no files are changed.
  71. ! The nondestructive behavior of
  72.   .I zcat
  73. ! is identical to that of
  74.   .I uncompress
  75.   .B \-c.
  76.   .PP
  77.   If the
  78.   .B \-r
  79. --- 67,105 ----
  80.   is run in the foreground,
  81.   the user is prompted as to whether an existing file should be overwritten.
  82.   .PP
  83. + Compressed files can be restored to their original form using
  84. + .I uncompress
  85. + or
  86. + .I zcat.
  87. + .PP
  88. + .I uncompress
  89. + takes a list of files on its command line and replaces each
  90. + file whose name ends with
  91. + .B "\&.Z"
  92. + and which begins with the correct magic number with an uncompressed
  93. + file without the 
  94. + .B "\&.Z."
  95. + The uncompressed file will have the mode, ownership and
  96. + timestamps of the compressed file.
  97. + .PP
  98.   The
  99.   .B \-c
  100.   option makes
  101.   .I compress/uncompress
  102.   write to the standard output; no files are changed.
  103. ! .PP
  104.   .I zcat
  105. ! is identical to
  106.   .I uncompress
  107.   .B \-c.
  108. + .I zcat
  109. + uncompresses either a list of files on the command line or its
  110. + standard input and writes the uncompressed data on standard output.
  111. + .I zcat
  112. + will uncompress files that have the correct magic number whether
  113. + they have a
  114. + .B "\&.Z"
  115. + suffix or not.
  116.   .PP
  117.   If the
  118.   .B \-r
  119. ***************
  120. *** 87,92 ****
  121. --- 110,121 ----
  122.   .I compress
  123.   will descend into the directory and compress all the files it finds there.
  124.   .PP
  125. + The
  126. + .B \-V
  127. + flag tells each of these programs to print its version and patchlevel,
  128. + along with any preprocessor flags specified during compilation, on
  129. + stderr before doing any compression or uncompression.
  130. + .PP
  131.   .I Compress
  132.   uses the modified Lempel-Ziv algorithm popularized in
  133.   "A Technique for High Performance Data Compression",
  134. ***************
  135. *** 147,157 ****
  136.   a message is printed yielding the percentage of
  137.   reduction for each file compressed.
  138.   .PP
  139. - If the
  140. - .B \-V
  141. - option is specified, the current version and compile options are printed on
  142. - stderr.
  143. - .PP
  144.   Exit status is normally 0;
  145.   if the last file is larger after (attempted) compression, the status is 2;
  146.   if an error occurs, exit status is 1.
  147. --- 176,181 ----
  148. ***************
  149. *** 158,164 ****
  150.   .SH "SEE ALSO"
  151.   pack(1), compact(1)
  152.   .SH "DIAGNOSTICS"
  153. ! Usage: compress [\-dfvcV] [\-b maxbits] [file ...]
  154.   .in +8
  155.   Invalid options were specified on the command line.
  156.   .in -8
  157. --- 182,188 ----
  158.   .SH "SEE ALSO"
  159.   pack(1), compact(1)
  160.   .SH "DIAGNOSTICS"
  161. ! Usage: compress [\-dfvcVr] [\-b maxbits] [file ...]
  162.   .in +8
  163.   Invalid options were specified on the command line.
  164.   .in -8
  165. ***************
  166. *** 220,229 ****
  167.   (Relevant only for
  168.   .BR \-v \.)
  169.   .in -8
  170. ! -- not a regular file: unchanged
  171.   .in +8
  172. ! When the input file is not a regular file,
  173. ! (e.g. a directory), it is
  174.   left unaltered.
  175.   .in -8
  176.   -- has 
  177. --- 244,253 ----
  178.   (Relevant only for
  179.   .BR \-v \.)
  180.   .in -8
  181. ! -- not a regular file or directory: ignored
  182.   .in +8
  183. ! When the input file is not a regular file or directory,
  184. ! (e.g. a symbolic link, socket, FIFO, device file), it is
  185.   left unaltered.
  186.   .in -8
  187.   -- has 
  188. ***************
  189. *** 232,238 ****
  190.   .in +8
  191.   The input file has links; it is left unchanged.  See
  192.   .IR ln "(1)"
  193. ! for more information.
  194.   .in -8
  195.   -- file unchanged
  196.   .in +8
  197. --- 256,264 ----
  198.   .in +8
  199.   The input file has links; it is left unchanged.  See
  200.   .IR ln "(1)"
  201. ! for more information. Use the
  202. ! .B \-f
  203. ! flag to force compression of multiply-linked files.
  204.   .in -8
  205.   -- file unchanged
  206.   .in +8
  207. ***************
  208. *** 245,247 ****
  209. --- 271,284 ----
  210.   should be used for file transfer to architectures with 
  211.   a small process data space (64KB or less, as exhibited by the DEC PDP
  212.   series, the Intel 80286, etc.)
  213. + .PP
  214. + Invoking compress with a \-r
  215. + flag will occasionally cause it to produce spurious error warnings of the form
  216. + .PP
  217. + .in 8
  218. + "<filename>.Z already has .Z suffix - ignored"
  219. + .in -8
  220. + .PP
  221. + These warnings can be ignored. See the comments in compress.c:compdir()
  222. + for an explanation.
  223. diff -rc compress.posted/compress.c compress41/compress.c
  224. *** compress.posted/compress.c    Fri Jun 28 19:07:09 1991
  225. --- compress41/compress.c    Fri Jun 28 19:08:41 1991
  226. ***************
  227. *** 3,8 ****
  228. --- 3,11 ----
  229.    */
  230.   #define    min(a,b)    ((a>b) ? b : a)
  231.   
  232. + /* MAXPATHLEN - maximum length of a pathname we allow */
  233. + #define MAXPATHLEN 1024
  234.   /*
  235.    * machine variants which require cc -Dmachine:  pdp11, z8000, pcxt
  236.    */
  237. ***************
  238. *** 373,379 ****
  239.   #define    CLEAR    256    /* table clear output code */
  240.   
  241.   int force = 0;
  242. ! char ofname [100];
  243.   #ifdef DEBUG
  244.   int verbose = 0;
  245.   #endif /* DEBUG */
  246. --- 376,382 ----
  247.   #define    CLEAR    256    /* table clear output code */
  248.   
  249.   int force = 0;
  250. ! char ofname[MAXPATHLEN];
  251.   #ifdef DEBUG
  252.   int verbose = 0;
  253.   #endif /* DEBUG */
  254. ***************
  255. *** 386,391 ****
  256. --- 389,395 ----
  257.   
  258.   
  259.   int do_decomp = 0;
  260. + struct stat statbuf, insbuf;
  261.   
  262.   /*****************************************************************
  263.    * TAG( main )
  264. ***************
  265. *** 596,603 ****
  266.   comprexx(fileptr)
  267.   char **fileptr;
  268.   {
  269. !     struct stat statbuf,insbuf;
  270. !     char tempname[1024], *cp;
  271.   
  272.       strcpy(tempname,*fileptr);
  273.       errno = 0;
  274. --- 600,606 ----
  275.   comprexx(fileptr)
  276.   char **fileptr;
  277.   {
  278. !     char tempname[MAXPATHLEN], *cp;
  279.   
  280.       strcpy(tempname,*fileptr);
  281.       errno = 0;
  282. ***************
  283. *** 647,652 ****
  284. --- 650,658 ----
  285.       case S_IFDIR:    /* directory */
  286.         if (recursive)
  287.           compdir(tempname);
  288. +       else if ( ! quiet )
  289. +         fprintf(stderr,"%s is a directory -- ignored\n",
  290. +             tempname);
  291.         break;
  292.   
  293.       case S_IFREG:    /* regular file */
  294. ***************
  295. *** 697,706 ****
  296.           else {
  297.       /* COMPRESSION */
  298.           if (strcmp(tempname + strlen(tempname) - 2, ".Z") == 0) {
  299. !                 fprintf(stderr, "%s: already has .Z suffix -- no change\n",
  300. !                 tempname);
  301. !             return;
  302.           }
  303.           /* Open input file */
  304.           if ((freopen(tempname, "r", stdin)) == NULL) {
  305.               perror(tempname); return;
  306. --- 703,717 ----
  307.           else {
  308.       /* COMPRESSION */
  309.           if (strcmp(tempname + strlen(tempname) - 2, ".Z") == 0) {
  310. !           fprintf(stderr, "%s: already has .Z suffix -- no change\n",
  311. !               tempname);
  312. !           return;
  313.           }
  314. +         if (insbuf.st_nlink > 1 && (! force) ) {
  315. +           fprintf(stderr, "%s has %d other links: unchanged\n",
  316. +               tempname,insbuf.st_nlink - 1);
  317. +           return;
  318. +         }
  319.           /* Open input file */
  320.           if ((freopen(tempname, "r", stdin)) == NULL) {
  321.               perror(tempname); return;
  322. ***************
  323. *** 787,794 ****
  324.           if((exit_stat == 1) || (!quiet))
  325.               putc('\n', stderr);
  326.           }
  327.       default:
  328. !         break;
  329.       } /* end switch */
  330.       return;
  331.   } /* end comprexx */
  332. --- 798,808 ----
  333.           if((exit_stat == 1) || (!quiet))
  334.               putc('\n', stderr);
  335.           }
  336. +       break;
  337.       default:
  338. !       fprintf(stderr,"%s is not a directory or a regular file - ignored\n",
  339. !           tempname);
  340. !       break;
  341.       } /* end switch */
  342.       return;
  343.   } /* end comprexx */
  344. ***************
  345. *** 802,808 ****
  346.   #else
  347.       register struct dirent *dp;
  348.   #endif
  349. !     char nbuf[1024];
  350.       char *nptr = nbuf;
  351.       dirp = opendir(dir);
  352.       if (dirp == NULL) {
  353. --- 816,822 ----
  354.   #else
  355.       register struct dirent *dp;
  356.   #endif
  357. !     char nbuf[MAXPATHLEN];
  358.       char *nptr = nbuf;
  359.       dirp = opendir(dir);
  360.       if (dirp == NULL) {
  361. ***************
  362. *** 809,823 ****
  363.           printf("%s unreadable\n", dir);        /* not stderr! */
  364.           return ;
  365.       }
  366.       while (dp = readdir(dirp)) {
  367.           if (dp->d_ino == 0)
  368.               continue;
  369. !         if (strcmp(dp->d_name,".") == 0 || strcmp(dp->d_name,"..") == 0)
  370.               continue;
  371. !         strcpy(nbuf,dir);
  372. !         strcat(nbuf,"/");
  373. !         strcat(nbuf,dp->d_name);
  374. !         comprexx(&nptr);
  375.         }
  376.       closedir(dirp);
  377.       return;
  378. --- 823,856 ----
  379.           printf("%s unreadable\n", dir);        /* not stderr! */
  380.           return ;
  381.       }
  382. +     /*
  383. +     ** WARNING: the following algorithm will occasionally cause
  384. +     ** compress to produce error warnings of the form "<filename>.Z
  385. +     ** already has .Z suffix - ignored". This occurs when the
  386. +     ** .Z output file is inserted into the directory below
  387. +     ** readdir's current pointer.
  388. +     ** These warnings are harmless but annoying. The alternative
  389. +     ** to allowing this would be to store the entire directory
  390. +     ** list in memory, then compress the entries in the stored
  391. +     ** list. Given the depth-first recursive algorithm used here,
  392. +     ** this could use up a tremendous amount of memory. I don't
  393. +     ** think it's worth it. -- Dave Mack
  394. +     */
  395.       while (dp = readdir(dirp)) {
  396.           if (dp->d_ino == 0)
  397.               continue;
  398. !         if (strcmp(dp->d_name,".") == 0 ||
  399. !             strcmp(dp->d_name,"..") == 0)
  400.               continue;
  401. !         if ( (strlen(dir)+strlen(dp->d_name)+1) < (MAXPATHLEN - 1)){
  402. !           strcpy(nbuf,dir);
  403. !           strcat(nbuf,"/");
  404. !           strcat(nbuf,dp->d_name);
  405. !           comprexx(&nptr);
  406. !         }
  407. !         else {
  408. !           fprintf(stderr,"Pathname too long: %s/%s\n",dir,dp->d_name);
  409. !         }
  410.         }
  411.       closedir(dirp);
  412.       return;
  413. ***************
  414. *** 1407,1448 ****
  415.   copystat(ifname, ofname)
  416.   char *ifname, *ofname;
  417.   {
  418. -     struct stat statbuf;
  419.       int mode;
  420.       time_t timep[2];
  421.   
  422.       fclose(stdout);
  423. !     if (stat(ifname, &statbuf)) {        /* Get stat on input file */
  424. !     perror(ifname);
  425. !     return;
  426. !     }
  427. !     if ((statbuf.st_mode & S_IFMT/*0170000*/) != S_IFREG/*0100000*/) {
  428. !     if(quiet)
  429. !             fprintf(stderr, "%s: ", ifname);
  430. !     fprintf(stderr, " -- not a regular file: unchanged");
  431. !     exit_stat = 1;
  432. !     } else if (statbuf.st_nlink > 1 && (! force) ) {
  433. !     if(quiet)
  434. !             fprintf(stderr, "%s: ", ifname);
  435. !     fprintf(stderr, " -- has %d other links: unchanged",
  436. !         statbuf.st_nlink - 1);
  437. !     exit_stat = 1;
  438. !     } else if (exit_stat == 2 && (!force)) { /* No compression: remove file.Z */
  439.       if(!quiet)
  440. !         fprintf(stderr, " -- file unchanged");
  441.       } else {            /* ***** Successful Compression ***** */
  442.       exit_stat = 0;
  443. !     mode = statbuf.st_mode & 07777;
  444.       if (chmod(ofname, mode))        /* Copy modes */
  445.           perror(ofname);
  446. !     chown(ofname, statbuf.st_uid, statbuf.st_gid);    /* Copy ownership */
  447. !     timep[0] = statbuf.st_atime;
  448. !     timep[1] = statbuf.st_mtime;
  449.       utime(ofname, timep);    /* Update last accessed and modified times */
  450.       if (unlink(ifname))    /* Remove input file */
  451.           perror(ifname);
  452.       if(!quiet)
  453. !         fprintf(stderr, " -- replaced with %s", ofname);
  454.       return;        /* Successful return */
  455.       }
  456.   
  457. --- 1440,1466 ----
  458.   copystat(ifname, ofname)
  459.   char *ifname, *ofname;
  460.   {
  461.       int mode;
  462.       time_t timep[2];
  463.   
  464.       fclose(stdout);
  465. !     if (exit_stat == 2 && (!force)) { /* No compression: remove file.Z */
  466.       if(!quiet)
  467. !         fprintf(stderr, "No compression -- %s unchanged",
  468. !             ifname);
  469.       } else {            /* ***** Successful Compression ***** */
  470.       exit_stat = 0;
  471. !     mode = insbuf.st_mode & 07777;
  472.       if (chmod(ofname, mode))        /* Copy modes */
  473.           perror(ofname);
  474. !     chown(ofname, insbuf.st_uid, insbuf.st_gid);    /* Copy ownership */
  475. !     timep[0] = insbuf.st_atime;
  476. !     timep[1] = insbuf.st_mtime;
  477.       utime(ofname, timep);    /* Update last accessed and modified times */
  478.       if (unlink(ifname))    /* Remove input file */
  479.           perror(ifname);
  480.       if(!quiet)
  481. !         fprintf(stderr, " -- replaced with %s",ofname);
  482.       return;        /* Successful return */
  483.       }
  484.   
  485. diff -rc compress.posted/patchlevel.h compress41/patchlevel.h
  486. *** compress.posted/patchlevel.h    Fri Jun 28 19:07:16 1991
  487. --- compress41/patchlevel.h    Fri Jun 28 19:12:42 1991
  488. ***************
  489. *** 1 ****
  490. ! #define PATCHLEVEL 0
  491. --- 1 ----
  492. ! #define PATCHLEVEL 1
  493.  
  494. exit 0 # Just in case...
  495. -- 
  496. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  497. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  498. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  499. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  500.