home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / SmartPackage / Sources / funzip / funzip.diffs < prev    next >
Encoding:
Text File  |  1994-04-12  |  9.0 KB  |  248 lines

  1. *** funzip.c.51d3    Tue Feb  2 13:48:00 1993
  2. --- funzip.c    Tue May 11 13:47:12 1993
  3. ***************
  4. *** 1,6 ****
  5. ! /* funzip.c -- Not copyrighted 1992 by Mark Adler */
  6.   
  7. ! #define VERSION "2.3 of 14 December 1992"
  8.   
  9.   
  10.   /* You can do whatever you like with this source file, though I would
  11. --- 1,6 ----
  12. ! /* funzip.c -- Not copyrighted 1992,1993 by Mark Adler */
  13.   
  14. ! #define VERSION "3.0 of 11 May 1993"
  15.   
  16.   
  17.   /* You can do whatever you like with this source file, though I would
  18. ***************
  19. *** 39,44 ****
  20. --- 39,45 ----
  21.       2.3   14 Dec 92  M. Adler        replaced fseek (fails on stdin for SCO
  22.                                        Unix V.3.2.4).  added quietflg for
  23.                                        inflate.c.
  24. +     3.0   11 May 93  M. Adler        added gzip support
  25.    */
  26.   
  27.   
  28. ***************
  29. *** 72,91 ****
  30.   #endif
  31.   
  32.   /* PKZIP header definitions */
  33. ! #define LOCSIG 0x04034b50L      /* four-byte lead-in (lsb first) */
  34. ! #define LOCFLG 6                /* offset of bit flag */
  35.   #define  CRPFLG 1               /*  bit for encrypted entry */
  36.   #define  EXTFLG 8               /*  bit for extended local header */
  37. ! #define LOCHOW 8                /* offset of compression method */
  38. ! #define LOCTIM 10               /* file mod time (for decryption) */
  39. ! #define LOCCRC 14               /* offset of crc */
  40. ! #define LOCSIZ 18               /* offset of compressed size */
  41. ! #define LOCLEN 22               /* offset of uncompressed length */
  42. ! #define LOCFIL 26               /* offset of file name field length */
  43. ! #define LOCEXT 28               /* offset of extra field length */
  44. ! #define LOCHDR 30               /* size of local header, including sig */
  45.   #define EXTHDR 16               /* size of extended local header, inc sig */
  46.   
  47.   /* Macros for getting two-byte and four-byte header values */
  48.   #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
  49.   #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
  50. --- 73,108 ----
  51.   #endif
  52.   
  53.   /* PKZIP header definitions */
  54. ! #define ZIPMAG 0x4b50           /* two-byte zip lead-in */
  55. ! #define LOCREM 0x0403           /* remaining two bytes in zip signature */
  56. ! #define LOCSIG 0x04034b50L      /* full signature */
  57. ! #define LOCFLG 4                /* offset of bit flag */
  58.   #define  CRPFLG 1               /*  bit for encrypted entry */
  59.   #define  EXTFLG 8               /*  bit for extended local header */
  60. ! #define LOCHOW 6                /* offset of compression method */
  61. ! #define LOCTIM 8                /* file mod time (for decryption) */
  62. ! #define LOCCRC 12               /* offset of crc */
  63. ! #define LOCSIZ 16               /* offset of compressed size */
  64. ! #define LOCLEN 20               /* offset of uncompressed length */
  65. ! #define LOCFIL 24               /* offset of file name field length */
  66. ! #define LOCEXT 26               /* offset of extra field length */
  67. ! #define LOCHDR 28               /* size of local header, including LOCREM */
  68.   #define EXTHDR 16               /* size of extended local header, inc sig */
  69.   
  70. + /* GZIP header definitions */
  71. + #define GZPMAG 0x8b1f           /* two-byte gzip lead-in */
  72. + #define GZPHOW 0                /* offset of method number */
  73. + #define GZPFLG 1                /* offset of gzip flags */
  74. + #define  GZPMUL 2               /* bit for multiple-part gzip file */
  75. + #define  GZPISX 4               /* bit for extra field present */
  76. + #define  GZPISF 8               /* bit for filename present */
  77. + #define  GZPISC 16              /* bit for comment present */
  78. + #define  GZPISE 32              /* bit for encryption */
  79. + #define GZPTIM 2                /* offset of Unix file modification time */
  80. + #define GZPEXF 6                /* offset of extra flags */
  81. + #define GZPCOS 7                /* offset of operating system compressed on */
  82. + #define GZPHDR 8                /* length of minimal gzip header */
  83.   /* Macros for getting two-byte and four-byte header values */
  84.   #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
  85.   #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
  86. ***************
  87. *** 244,250 ****
  88.   /* Given a zip file on stdin, decompress the first entry to stdout. */
  89.   {
  90.     ush n;
  91. !   uch h[LOCHDR];               /* first local header */
  92.   #ifdef CRYPT
  93.     char *s = " [-password]";
  94.     char *p;                      /* password */
  95. --- 261,268 ----
  96.   /* Given a zip file on stdin, decompress the first entry to stdout. */
  97.   {
  98.     ush n;
  99. !   uch h[LOCHDR];                /* first local header (GZPHDR < LOCHDR) */
  100. !   int g;                        /* true if gzip format */
  101.   #ifdef CRYPT
  102.     char *s = " [-password]";
  103.     char *p;                      /* password */
  104. ***************
  105. *** 273,280 ****
  106.       fprintf(stderr, "usage: ... | funzip%s | ...\n", s);
  107.       fprintf(stderr, "       ... | funzip%s  > outfile\n", s);
  108.       fprintf(stderr, "       funzip%s infile.zip > outfile\n", s);
  109.       fprintf(stderr,
  110. !       "       extracts to stdout the first zip entry of stdin.\n");
  111.       exit(3);
  112.     }
  113.   
  114. --- 291,299 ----
  115.       fprintf(stderr, "usage: ... | funzip%s | ...\n", s);
  116.       fprintf(stderr, "       ... | funzip%s  > outfile\n", s);
  117.       fprintf(stderr, "       funzip%s infile.zip > outfile\n", s);
  118. +     fprintf(stderr, "       funzip%s infile.z > outfile\n", s);
  119.       fprintf(stderr,
  120. !     "       extracts to stdout the gzip file or first zip entry of stdin.\n");
  121.       exit(3);
  122.     }
  123.   
  124. ***************
  125. *** 301,315 ****
  126.       err(2, "cannot write to stdout");
  127.   
  128.     /* read local header, check validity, and skip name and extra fields */
  129. !   if (fread((char *)h, 1, LOCHDR, in) != LOCHDR || LG(h) != LOCSIG)
  130. !     err(3, "input not a zip file or empty");
  131. !   if (SH(h + LOCHOW) != STORED && SH(h + LOCHOW) != DEFLATED)
  132. !     err(3, "first entry not deflated or stored--can't funzip");
  133. !   for (n = SH(h + LOCFIL); n--; ) getc(in);
  134. !   for (n = SH(h + LOCEXT); n--; ) getc(in);
  135.   
  136.     /* if entry encrypted, decrypt and validate encryption header */
  137. !   if ((decrypt = h[LOCFLG] & CRPFLG) != 0)
  138.   #ifdef CRYPT
  139.       {
  140.         ush i, e;
  141. --- 320,362 ----
  142.       err(2, "cannot write to stdout");
  143.   
  144.     /* read local header, check validity, and skip name and extra fields */
  145. !   n = getc(in);  n |= getc(in) << 8;
  146. !   if (n == ZIPMAG)
  147. !   {
  148. !     if (fread((char *)h, 1, LOCHDR, in) != LOCHDR || SH(h) != LOCREM)
  149. !       err(3, "invalid zip file");
  150. !     if (SH(h + LOCHOW) != STORED && SH(h + LOCHOW) != DEFLATED)
  151. !       err(3, "first entry not deflated or stored--can't funzip");
  152. !     for (n = SH(h + LOCFIL); n--; ) getc(in);
  153. !     for (n = SH(h + LOCEXT); n--; ) getc(in);
  154. !     g = 0;
  155. !     decrypt = h[LOCFLG] & CRPFLG;
  156. !   }
  157. !   else if (n == GZPMAG)
  158. !   {
  159. !     if (fread((char *)h, 1, GZPHDR, in) != GZPHDR)
  160. !       err(3, "invalid gzip file");
  161. !     if (h[GZPHOW] != DEFLATED)
  162. !       err(3, "gzip file not deflated");
  163. !     if (h[GZPFLG] & GZPMUL)
  164. !       err(3, "cannot handle multi-part gzip files");
  165. !     if (h[GZPFLG] & GZPISX)
  166. !     {
  167. !       n = getc(in);  n |= getc(in) << 8;
  168. !       while (n--) getc(in);
  169. !     }
  170. !     if (h[GZPFLG] & GZPISF)
  171. !       while ((g = getc(in)) != 0 && g != EOF) ;
  172. !     if (h[GZPFLG] & GZPISC)
  173. !       while ((g = getc(in)) != 0 && g != EOF) ;
  174. !     g = 1;
  175. !     decrypt = h[GZPFLG] & GZPISE;
  176. !   }
  177. !   else
  178. !     err(3, "input not a zip or gzip file");
  179.   
  180.     /* if entry encrypted, decrypt and validate encryption header */
  181. !   if (decrypt)
  182.   #ifdef CRYPT
  183.       {
  184.         ush i, e;
  185. ***************
  186. *** 337,343 ****
  187.     updcrc(NULL, 0);
  188.   
  189.     /* decompress */
  190. !   if (h[LOCHOW])
  191.     {                             /* deflated entry */
  192.       int r;
  193.    
  194. --- 384,390 ----
  195.     updcrc(NULL, 0);
  196.   
  197.     /* decompress */
  198. !   if (g || h[LOCHOW])
  199.     {                             /* deflated entry */
  200.       int r;
  201.    
  202. ***************
  203. *** 369,386 ****
  204.     fflush(out);
  205.   
  206.     /* if extended header, get it */
  207. !   if ((h[LOCFLG] & EXTFLG) &&
  208. !       fread((char *)h + LOCCRC - 4, 1, EXTHDR, in) != EXTHDR)
  209. !     err(3, "zip file ended prematurely");
  210.   
  211.     /* validate decompression */
  212.     if (LG(h + LOCCRC) != updcrc(outbuf, 0))
  213.       err(4, "invalid compressed data--crc error");
  214. !   if (LG(h + LOCLEN) != outsiz)
  215.       err(4, "invalid compressed data--length error");
  216.   
  217.     /* check if there are more entries */
  218. !   if (fread((char *)h, 1, 4, in) == 4 && LG(h) == LOCSIG)
  219.       fprintf(stderr,
  220.         "funzip warning: zip file has more than one entry--rest ignored\n");
  221.   
  222. --- 416,439 ----
  223.     fflush(out);
  224.   
  225.     /* if extended header, get it */
  226. !   if (g)
  227. !   {
  228. !     if (fread((char *)h + LOCCRC, 1, 8, in) != 8)
  229. !       err(3, "gzip file ended prematurely");
  230. !   }
  231. !   else
  232. !     if ((h[LOCFLG] & EXTFLG) &&
  233. !         fread((char *)h + LOCCRC - 4, 1, EXTHDR, in) != EXTHDR)
  234. !       err(3, "zip file ended prematurely");
  235.   
  236.     /* validate decompression */
  237.     if (LG(h + LOCCRC) != updcrc(outbuf, 0))
  238.       err(4, "invalid compressed data--crc error");
  239. !   if (LG(h + (g ? LOCSIZ : LOCLEN)) != outsiz)
  240.       err(4, "invalid compressed data--length error");
  241.   
  242.     /* check if there are more entries */
  243. !   if (!g && fread((char *)h, 1, 4, in) == 4 && LG(h) == LOCSIG)
  244.       fprintf(stderr,
  245.         "funzip warning: zip file has more than one entry--rest ignored\n");
  246.   
  247.