home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume29 / unzip / part04 < prev    next >
Encoding:
Text File  |  1992-04-02  |  54.3 KB  |  1,473 lines

  1. Newsgroups: comp.sources.misc
  2. From: info-zip@cs.ucla.edu (Info-Zip)
  3. Subject:  v29i034:  unzip - Info-ZIP's portable UnZip v4.2, Part04/12
  4. Message-ID: <1992Apr3.063111.28746@sparky.imd.sterling.com>
  5. X-Md4-Signature: 5ba03d0fba8f2b65bf1342f085188ca8
  6. Date: Fri, 3 Apr 1992 06:31:11 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: info-zip@cs.ucla.edu (Info-Zip)
  10. Posting-number: Volume 29, Issue 34
  11. Archive-name: unzip/part04
  12. Environment: Unix, VMS, OS/2, MS-DOS, Amiga, Macintosh
  13. Supersedes: unzip, Volume 19, Issues 96-101
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  VMS/make_unzip_vaxc.com mapname.c unzip.h
  22. # Wrapped by kent@sparky on Mon Mar 30 01:45:52 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 4 (of 12)."'
  26. if test -f 'VMS/make_unzip_vaxc.com' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'VMS/make_unzip_vaxc.com'\"
  28. else
  29.   echo shar: Extracting \"'VMS/make_unzip_vaxc.com'\" \(1132 characters\)
  30.   sed "s/^X//" >'VMS/make_unzip_vaxc.com' <<'END_OF_FILE'
  31. X$ !
  32. X$ !        "Makefile" for VMS versions of unzip and zipinfo
  33. X$ !            (version:  no crypt + no inflate)
  34. X$ !
  35. X$ ! Find out current disk and directory
  36. X$ !
  37. X$ my_name = f$env("procedure")
  38. X$ here = f$parse(my_name,,,"device") + f$parse(my_name,,,"directory")
  39. X$ set verify    ! like "echo on", eh?
  40. X$ !
  41. X$ ! Do unzip:
  42. X$ !
  43. X$ cc unzip,extract,file_io,-
  44. X    mapname,match,misc,unimplod,unreduce,unshrink,vms,VMSmunch
  45. X$ link unzip,extract,file_io,mapname,match,misc,-
  46. X    unimplod,unreduce,unshrink,vms,VMSmunch, sys$input:/opt
  47. X sys$share:vaxcrtl.exe/shareable
  48. X! Next line:  put a similar line (full pathname for unzip.exe) in login.com.
  49. X! Remember to include leading "$" before disk name.
  50. X$ unzip == "$''here'unzip.exe"        ! set up symbol to use unzip
  51. X$ !
  52. X$ ! Do zipinfo:
  53. X$ !
  54. X$ cc zipinfo
  55. X$ rename misc.c misc_.c;*
  56. X$ cc /def=(ZIPINFO) misc_
  57. X$ rename misc_.c misc.c;*
  58. X$ link zipinfo,match,misc_,VMSmunch,sys$input:/opt
  59. X sys$share:vaxcrtl.exe/shareable
  60. X! Next line:  put a similar line (full pathname for unzip.exe) in login.com.
  61. X! Remember to include leading "$" before disk name.
  62. X$ zipinfo == "$''here'zipinfo.exe"    ! set up symbol to use zipinfo
  63. X$ set noverify
  64. END_OF_FILE
  65.   if test 1132 -ne `wc -c <'VMS/make_unzip_vaxc.com'`; then
  66.     echo shar: \"'VMS/make_unzip_vaxc.com'\" unpacked with wrong size!
  67.   fi
  68.   # end of 'VMS/make_unzip_vaxc.com'
  69. fi
  70. if test -f 'mapname.c' -a "${1}" != "-c" ; then 
  71.   echo shar: Will not clobber existing file \"'mapname.c'\"
  72. else
  73.   echo shar: Extracting \"'mapname.c'\" \(14090 characters\)
  74.   sed "s/^X//" >'mapname.c' <<'END_OF_FILE'
  75. X/*---------------------------------------------------------------------------
  76. X
  77. X  mapname.c
  78. X
  79. X  This routine changes DEC-20, VAX/VMS, and DOS-style filenames into normal
  80. X  Unix names (and vice versa, in some cases); it also creates any necessary 
  81. X  directories, if the -d switch was specified.
  82. X
  83. X  ---------------------------------------------------------------------------
  84. X
  85. X  Notes:
  86. X
  87. X     - Unix allows multiple dots in directory names; MS-DOS and OS/2 FAT
  88. X       allow one; VMS does not allow any.  Things are almost as bad with
  89. X       regular filenames (VMS allows a single dot but TOPS-20 allows two,
  90. X       if you count the one in front of the version number).  As of v4.04,
  91. X       mapname converts directory-name dots to underscores on VMS, but it
  92. X       otherwise leaves the dots alone.  Since it is now possible to create
  93. X       zipfiles under Unix, this whole routine pretty much needs to be
  94. X       rewritten (different routines for each output OS, and different 
  95. X       rules for different parts of the path name).
  96. X     - If each zip program stores local-format names (like the VMS one did
  97. X       at one time), it would probably be best to convert to an intermedi-
  98. X       ate format first (assuming we're not extracting under the same OS 
  99. X       as that under which the zipfile was created), then from that to the 
  100. X       current operating system's format.
  101. X     - The strcpy and strcat operations on both cdp and filename may over-
  102. X       write memory, since they don't check lengths.  With a kilobyte in
  103. X       which to work, this is probably not that big a deal, but it could
  104. X       cause problems eventually.
  105. X
  106. X  ------------------------------------------------------------------------- */
  107. X
  108. X
  109. X#include "unzip.h"
  110. X
  111. X
  112. X/*******************/
  113. X/* Mapname Defines */
  114. X/*******************/
  115. X
  116. X#ifdef VMS
  117. X#  define PERMS   0
  118. X#else
  119. X#  define PERMS   0777
  120. X#endif
  121. X
  122. X#ifndef NO_MKDIR
  123. X#  ifdef DOS_OS2
  124. X#    if (_MSC_VER >= 600)       /* have special MSC mkdir prototype */
  125. X#      include <direct.h>
  126. X#    else                       /* own prototype because dir.h conflicts? */
  127. X       int mkdir(const char *path);
  128. X#    endif /* ?(MSC 6.0 or later) */
  129. X#    define MKDIR(path,mode)   mkdir(path)
  130. X#  else /* !DOS_OS2 */
  131. X#    ifdef MACOS
  132. X#      define MKDIR(path,mode)   mkdir(path)
  133. X#    else /* !MACOS */
  134. X#      define MKDIR(path,mode)   mkdir(path,mode)
  135. X#    endif /* ?MACOS */
  136. X#  endif /* ?DOS_OS2 */
  137. X#endif /* !NO_MKDIR */
  138. X
  139. X
  140. X
  141. X
  142. X/************************/
  143. X/*  Function mapname()  */
  144. X/************************/
  145. X
  146. Xint mapname(create_dirs)   /* return 0 if no error, 1 if caution (filename */
  147. X    int create_dirs;       /*  truncated), 2 if warning (skip file because */
  148. X{                          /*  dir doesn't exist), 3 if error (skip file) */
  149. X#ifdef NO_MKDIR
  150. X    char command[FILNAMSIZ+40]; /* buffer for system() call */
  151. X#endif
  152. X#ifdef VMS
  153. X    int stat_val;               /* temp. holder for stat() return value */
  154. X    char *dp, *xp;              /* pointers to directory name */
  155. X#endif
  156. X#ifdef OS2
  157. X    char *last;
  158. X    extern int longname;        /* used also in file_io.c:  set EAs */
  159. X    extern char longfilename[]; /*  AFTER file created and closed */
  160. X#endif
  161. X    char name[FILNAMSIZ];       /* file name buffer */
  162. X    char *pp, *cp, *cdp;        /* character pointers */
  163. X    char delim = '\0';          /* directory delimiter */
  164. X    int dc = 0;                 /* counters */
  165. X    int quote = FALSE;          /* flags */
  166. X    int indir = FALSE;
  167. X    int done = FALSE;
  168. X    register int workch;        /* hold the character being tested */
  169. X
  170. X
  171. X/*---------------------------------------------------------------------------
  172. X    Initialize various pointers and counters and stuff.
  173. X  ---------------------------------------------------------------------------*/
  174. X
  175. X#ifdef MAP_DEBUG
  176. X    fprintf(stderr, "%s ", filename);   /* echo name of this file */
  177. X#endif
  178. X    pp = name;                  /* Point to translation buffer */
  179. X    *name = '\0';               /* Initialize buffer */
  180. X
  181. X    if (!jflag) {               /* -j => junk pathnames */
  182. X        cdp = (char *) malloc(strlen(filename) + 3);  /* place for holding */
  183. X        if (cdp == NULL) {                            /*  directory name */
  184. X            fprintf(stderr, "mapname:  out of memory [%s]\n", filename);
  185. X            return 3;
  186. X        }
  187. X#ifdef VMS
  188. X        *cdp++ = '[';
  189. X        xp = cdp;               /* always points to last non-NULL char */
  190. X        *cdp++ = '.';
  191. X#endif /* VMS */
  192. X#ifdef MACOS
  193. X        *cdp = ':';             /* the Mac uses ':' as a directory separator */
  194. X        cdp[1] = '\0';
  195. X#else /* !MACOS */
  196. X        *cdp = '\0';
  197. X#endif /* ?MACOS */
  198. X    }
  199. X    dc = 0;                     /* Filename dot counter */
  200. X
  201. X/*---------------------------------------------------------------------------
  202. X    Begin main loop through characters in filename.
  203. X  ---------------------------------------------------------------------------*/
  204. X
  205. X    for (cp = filename; (workch = *cp++) != 0  &&  !done;) {
  206. X
  207. X        if (quote) {            /* If this char quoted... */
  208. X            *pp++ = workch;     /*  include it literally. */
  209. X            quote = FALSE;
  210. X        } else if (indir) {     /* If in directory name... */
  211. X            if (workch == delim)
  212. X                indir = FALSE;  /*  look for end delimiter. */
  213. X        } else
  214. X            switch (workch) {
  215. X            case '<':           /* Discard DEC-20 directory name */
  216. X                indir = TRUE;
  217. X                delim = '>';
  218. X                break;
  219. X            case '[':           /* Discard VMS directory name */
  220. X                indir = TRUE;
  221. X                delim = ']';
  222. X                break;
  223. X            case '/':           /* Discard Unix path name... */
  224. X            case '\\':          /*  or MS-DOS path name...
  225. X                                 *  IF -j flag was given. */
  226. X                /*
  227. X                 * Special processing case:  if -j flag was not specified on
  228. X                 * command line and create_dirs is TRUE, create any necessary
  229. X                 * directories included in the pathname.  Creation of dirs is
  230. X                 * straightforward on BSD and MS-DOS machines but requires use
  231. X                 * of the system() command on SysV systems (or any others which
  232. X                 * don't have mkdir()).  The stat() check is necessary with
  233. X                 * MSC because it doesn't have an EEXIST errno, and it saves
  234. X                 * the overhead of multiple system() calls on SysV machines.
  235. X                 */
  236. X
  237. X                if (!jflag) {
  238. X                    *pp = '\0';
  239. X#ifdef VMS
  240. X                    dp = name;
  241. X                    while (*++xp = *dp++)   /* copy name to cdp, while */
  242. X                        if (*xp == '.')     /*   changing all dots... */
  243. X                            *xp = '_';      /*   ...to underscores */
  244. X                    strcpy(xp, ".dir");    /* add extension for stat check */
  245. X                    stat_val = stat(cdp, &statbuf);
  246. X                    *xp = '\0';         /* remove extension for all else */
  247. X                    if (stat_val) {     /* doesn't exist, so create */
  248. X#else /* !VMS */
  249. X                    strcat(cdp, name);
  250. X#ifdef OS2
  251. X                    if (longname = !IsFileNameValid(cdp)) {
  252. X                        last = strrchr(cdp, '/');
  253. X                        strcpy(longfilename, last ? last + 1 : cdp);
  254. X                        fprintf(stderr, "caution:  renaming directory \"%s\"",
  255. X                          cdp);
  256. X                        ChangeNameForFAT(cdp);
  257. X                        fprintf(stderr, " to \"%s\"\n", cdp);
  258. X                    }
  259. X#endif /* OS2 */
  260. X                    if (stat(cdp, &statbuf)) {  /* doesn't exist, so create */
  261. X#endif /* ?VMS */
  262. X                        if (!create_dirs) /* told not to create (freshening) */
  263. X                            return 2;
  264. X#ifdef NO_MKDIR
  265. X                        sprintf(command,
  266. X                          "IFS=\" \t\n\" /bin/mkdir %s 2>/dev/null", cdp);
  267. X                        if (system(command)) {
  268. X#else /* !NO_MKDIR */
  269. X                        if (MKDIR(cdp, PERMS) == -1) {
  270. X#endif /* ?NO_MKDIR */
  271. X                            perror(cdp);
  272. X                            free(cdp);
  273. X                            fprintf(stderr, "mapame:  unable to process [%s]\n",
  274. X                              filename);
  275. X                            return 3;
  276. X                        }
  277. X#ifdef OS2
  278. X                        if (longname)
  279. X                            SetLongNameEA(cdp, longfilename);
  280. X#endif /* OS2 */
  281. X                    } else if (!(statbuf.st_mode & S_IFDIR)) {
  282. X                        fprintf(stderr,
  283. X                          "mapname:  %s exists but is not a directory\n", cdp);
  284. X                        free(cdp);
  285. X                        fprintf(stderr, "mapame:  unable to process [%s]\n",
  286. X                          filename);
  287. X                        return 3;
  288. X                    }
  289. X#ifdef VMS
  290. X                    *xp = '/';  /* for now... (mkdir()) */
  291. X#else /* !VMS */
  292. X#ifdef MACOS
  293. X                    strcat(cdp, ":");
  294. X#else /* !MACOS */
  295. X                    strcat(cdp, "/");
  296. X#endif /* ?MACOS */
  297. X#endif /* ?VMS */
  298. X                }
  299. X                pp = name;
  300. X                break;
  301. X            case ':':
  302. X#ifdef UNIX                       /* colon is a valid character in Unix */
  303. X                *pp++ = workch;   /*  filenames, so keep it; anywhere else, */
  304. X#else /* !UNIX */                 /*  change it to an underscore (should  */
  305. X                *pp++ = '_';      /*  NOT have stored drive/node names!!) */
  306. X#endif /* ?UNIX */
  307. X             /* pp = name;  (OLD) discard DEC dev: or node:: name */
  308. X                break;
  309. X            case '.':                   /* DEC-20 generation number
  310. X                                         * or MS-DOS type */
  311. X#ifdef NUKE_DOTS
  312. X                if (++dc == 1)          /* Keep first dot */
  313. X                    *pp++ = workch;
  314. X#else /* !NUKE_DOTS */
  315. X                ++dc;                   /* Not used, but what the hell. */
  316. X                *pp++ = workch;
  317. X#endif /* ?NUKE_DOTS */
  318. X                break;
  319. X            case ';':                   /* VMS generation or DEC-20 attrib */
  320. X                if (V_flag)             /* If requested, save VMS ";##" */
  321. X                    *pp++ = workch;     /*  version info; else discard */
  322. X                else                    /*  everything starting with */
  323. X                    done = TRUE;        /*  semicolon.  (Worry about */
  324. X                break;                  /*  DEC-20 later.) */
  325. X            case '\026':                /* Control-V quote for special chars */
  326. X                quote = TRUE;           /* Set flag for next time. */
  327. X                break;
  328. X            case ' ':
  329. X#if defined(VMS) || defined(MTS)
  330. X                *pp++ = '_';            /* change spaces to underscore */
  331. X#else /* !(VMS || MTS) */               /*  under VMS and MTS, and under DOS */
  332. X#ifdef DOS_OS2                          /*  and OS/2 if -s not specified. */
  333. X                if (!sflag)
  334. X                    *pp++ = '_';
  335. X                else
  336. X#endif /* DOS_OS2 */
  337. X                *pp++ = workch;         /* otherwise, leave as spaces */
  338. X#endif /* ?(VMS || MTS) */
  339. X                break;
  340. X            default:
  341. X                if (isprint(workch))    /* other printable, just keep */
  342. X                    *pp++ = workch;
  343. X            }                   /* end switch */
  344. X    }                           /* end for loop */
  345. X    *pp = '\0';                 /* done with name:  terminate it */
  346. X
  347. X/*---------------------------------------------------------------------------
  348. X    We COULD check for existing names right now, create a "unique" name, etc.
  349. X    At present, we do this in extract_or_test_files() (immediately after we
  350. X    return from here).  If conversion went bad, the name'll either be nulled
  351. X    out (in which case we'll return non-0), or following procedures won't be
  352. X    able to create the extracted file and other error msgs will result.
  353. X  ---------------------------------------------------------------------------*/
  354. X
  355. X    if (*name == '\0') {
  356. X        fprintf(stderr, "mapname:  conversion of [%s] failed\n", filename);
  357. X        return 3;
  358. X    }
  359. X
  360. X#ifdef OS2   /* (if necessary, can use outbuf for temp filename holder) */
  361. X    if (longname = !IsFileNameValid(name)) {  /* THIS time, save for file_io */
  362. X        last = strrchr(name, '/');
  363. X        last = last ? last + 1 : name;  /* should ALWAYS be name... */
  364. X        strcpy(longfilename, last);
  365. X        fprintf(stderr, "caution:  renaming \"%s\"", name);
  366. X        ChangeNameForFAT(last);
  367. X        fprintf(stderr, " to \"%s\"\n", name);
  368. X    }
  369. X#endif /* OS2 */
  370. X
  371. X    if (!jflag) {
  372. X#ifdef VMS
  373. X        *xp++ = ']';            /* proper end-of-dir-name delimiter */
  374. X        if (xp == cdp) {        /* no path-name stuff, so... */
  375. X            strcpy(filename, name);  /* copy file name into global */
  376. X            cdp -= 2;           /*   prepare to free malloc'd space */
  377. X        } else {                /* we've added path-name stuff... */
  378. X            *xp = '\0';         /*   so terminate... */
  379. X            dp = cdp;           /*   and convert to VMS subdir separators:  */
  380. X            while (*++dp)       /*   (skip first char:  better not be "/") */
  381. X                if (*dp == '/') /*   change all slashes */
  382. X                    *dp = '.';  /*     to dots */
  383. X            cdp -= 2;           /*   include leading bracket and dot */
  384. X            strcpy(filename, cdp);   /* copy VMS-style path name into global */
  385. X            strcat(filename, name);  /* concatenate file name to global */
  386. X        }
  387. X#else /* !VMS */
  388. X        strcpy(filename, cdp);  /* Either "" or slash-terminated path */
  389. X        strcat(filename, name); /* append file name to path name */
  390. X#endif /* ?VMS */
  391. X        free(cdp);
  392. X    } else
  393. X        strcpy(filename, name); /* copy converted name into global */
  394. X
  395. X#if PATH_MAX < (FILNAMSIZ - 1)
  396. X    /* check the length of the file name and truncate if necessary */
  397. X    if (PATH_MAX < strlen(filename)) {
  398. X        fprintf(stderr, "caution:  truncating filename.\n");
  399. X        filename[PATH_MAX] = '\0';
  400. X        fprintf(stderr, "[ %s ]\n", filename);
  401. X        return 1;             /* 1:  warning error */
  402. X    }
  403. X#endif
  404. X
  405. X    return 0;
  406. X}
  407. END_OF_FILE
  408.   if test 14090 -ne `wc -c <'mapname.c'`; then
  409.     echo shar: \"'mapname.c'\" unpacked with wrong size!
  410.   fi
  411.   # end of 'mapname.c'
  412. fi
  413. if test -f 'unzip.h' -a "${1}" != "-c" ; then 
  414.   echo shar: Will not clobber existing file \"'unzip.h'\"
  415. else
  416.   echo shar: Extracting \"'unzip.h'\" \(36246 characters\)
  417.   sed "s/^X//" >'unzip.h' <<'END_OF_FILE'
  418. X/*---------------------------------------------------------------------------
  419. X
  420. X  unzip.h
  421. X
  422. X  This header file is used by all of the unzip source files.  Its contents
  423. X  are divided into seven more-or-less separate sections:  predefined macros,
  424. X  OS-dependent includes, (mostly) OS-independent defines, typedefs, function 
  425. X  prototypes (or "prototypes," in the case of non-ANSI compilers), macros, 
  426. X  and global-variable declarations.
  427. X
  428. X  ---------------------------------------------------------------------------*/
  429. X
  430. X
  431. X
  432. X/*****************************************/
  433. X/*  Predefined, Machine-specific Macros  */
  434. X/*****************************************/
  435. X
  436. X#if defined(ultrix) || defined(bsd4_2) || defined(sun)
  437. X#  if !defined(BSD) && !defined(__SYSTEM_FIVE)
  438. X#    define BSD
  439. X#  endif /* !BSD && !__SYSTEM_FIVE */
  440. X#endif /* ultrix || bsd4_2 || sun */
  441. X
  442. X/* [1992.1.21:  ALL machines now "NOTINT16"; NOTINT16 and ULONG_ removed] */
  443. X#if 0
  444. X#  if defined(mips) || defined(sun) || defined(CRAY)
  445. X#    ifndef NOTINT16
  446. X#      define NOTINT16
  447. X#    endif /* !NOTINT16 */
  448. X#  endif /* mips || sun || CRAY */
  449. X
  450. X#  if defined(vax) || defined(MSDOS) || defined(__MSDOS__)
  451. X#    ifdef NOTINT16
  452. X#      undef NOTINT16
  453. X#    endif /* NOTINT16 */
  454. X#  endif /* vax || MSDOS || __MSDOS__ */
  455. X#endif /* 0 */
  456. X
  457. X#ifdef CRAY
  458. X#  ifdef ZMEM
  459. X#    undef ZMEM
  460. X#  endif /* ZMEM */
  461. X#  ifndef TERMIO
  462. X#    define TERMIO
  463. X#  endif /* !TERMIO */
  464. X#endif /* CRAY */
  465. X
  466. X#ifdef CONVEX
  467. X#  ifndef TERMIO
  468. X#    define TERMIO
  469. X#  endif /* !TERMIO */
  470. X#endif /* CONVEX */
  471. X
  472. X/* the i386 test below is to catch SCO Unix (which has redefinition
  473. X * warnings if param.h is included), but it probably doesn't hurt if
  474. X * other 386 Unixes get nailed, too--are there any 386 BSD systems?
  475. X * param.h is mostly included for "BSD", I think...
  476. X */
  477. X#if defined(MINIX) || (defined(i386) && defined(unix))
  478. X#  define NO_PARAM_H
  479. X#endif /* MINIX || (i386 && unix) */
  480. X
  481. X#if defined(__IBMC__) && defined(__32BIT__) && !defined(IBMC32)
  482. X#  define IBMC32
  483. X#endif /* __IBMC__ && __32BIT__ && !IBMC32 */
  484. X
  485. X
  486. X
  487. X
  488. X
  489. X/***************************/
  490. X/*  OS-Dependent Includes  */
  491. X/***************************/
  492. X
  493. X#ifndef MINIX            /* Minix needs it after all the other includes (?) */
  494. X#  include <stdio.h>     /* this is your standard header for all C compiles */
  495. X#endif
  496. X#include <ctype.h>
  497. X#include <errno.h>       /* used in mapname() */
  498. X#define DECLARE_ERRNO    /* everybody except MSC 6.0 */
  499. X#ifdef VMS               /* sigh...you just KNEW someone had to break this.  */
  500. X#  include <types.h>     /*  (placed up here instead of in VMS section below */
  501. X#  include <stat.h>      /*   because types.h is used in some other headers) */
  502. X#else  /* almost everybody */
  503. X#  if defined(THINK_C) || defined(MPW) /* for Macs */
  504. X#    include <stddef.h>
  505. X#  else
  506. X#    include <sys/types.h> /* off_t, time_t, dev_t, ... */
  507. X#    include <sys/stat.h>  /* Everybody seems to need this. */
  508. X#  endif
  509. X#endif
  510. X
  511. X
  512. X/*---------------------------------------------------------------------------
  513. X    Next, a word from our Unix (mostly) sponsors:
  514. X  ---------------------------------------------------------------------------*/
  515. X
  516. X#ifdef UNIX
  517. X#  ifdef AMIGA
  518. X#    include <libraries/dos.h>
  519. X#  else /* !AMIGA */
  520. X#    ifndef NO_PARAM_H
  521. X#if 0  /* [GRR: this is an alternate fix for SCO's redefinition bug] */
  522. X#      ifdef NGROUPS_MAX
  523. X#        undef NGROUPS_MAX     /* SCO bug:  defined again in <param.h> */
  524. X#      endif /* NGROUPS_MAX */
  525. X#endif /* 0 */
  526. X#      include <sys/param.h>   /* conflict with <sys/types.h>, some systems? */
  527. X#    endif /* !NO_PARAM_H */
  528. X#  endif /* ?AMIGA */
  529. X
  530. X#  ifndef BSIZE
  531. X#    ifdef MINIX
  532. X#      define BSIZE   1024
  533. X#    else /* !MINIX */
  534. X#      define BSIZE   DEV_BSIZE  /* assume common for all Unix systems */
  535. X#    endif /* ?MINIX */
  536. X#  endif
  537. X
  538. X#  ifndef BSD
  539. X#    if !defined(AMIGA) && !defined(MINIX)
  540. X#      define NO_MKDIR           /* for mapname() */
  541. X#    endif /* !AMIGA && !MINIX */
  542. X#    ifndef SKIP_TIME_H          /* temporary fix for VMS gcc and Amdahl cc */
  543. X#      include <time.h>          /*  in decryption version */
  544. X#    endif /* !SKIP_TIME_H */
  545. X     struct tm *gmtime(), *localtime();
  546. X#  else   /* BSD */
  547. X#    ifndef SKIP_TIME_H          /* temporary fix for Sun 3 cc, etc. */
  548. X#      include <sys/time.h>      /*  in decryption version */
  549. X#    endif /* !SKIP_TIME_H */
  550. X#    include <sys/timeb.h>
  551. X#  endif
  552. X
  553. X#else   /* !UNIX */
  554. X#  define BSIZE   512               /* disk block size */
  555. X#endif /* ?UNIX */
  556. X
  557. X#if defined(V7) || defined(BSD)
  558. X#  define strchr    index
  559. X#  define strrchr   rindex
  560. X#endif
  561. X
  562. X/*---------------------------------------------------------------------------
  563. X    And now, our MS-DOS and OS/2 corner:
  564. X  ---------------------------------------------------------------------------*/
  565. X
  566. X#ifdef __TURBOC__
  567. X#  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS2    */
  568. X#  include <sys/timeb.h>      /* for structure ftime                        */
  569. X#  ifndef __BORLANDC__        /* There appears to be a bug (?) in Borland's */
  570. X#    include <mem.h>          /*   MEM.H related to __STDC__ and far poin-  */
  571. X#  endif                      /*   ters. (dpk)  [mem.h included for memcpy] */
  572. X#else                         /* NOT Turbo C...                             */
  573. X#  ifdef MSDOS                /*   but still MS-DOS, so we'll assume it's   */
  574. X#    ifndef MSC               /*   Microsoft's compiler and fake the ID, if */
  575. X#      define MSC             /*   necessary (it is in 5.0; apparently not  */
  576. X#    endif                    /*   in 5.1 and 6.0)                          */
  577. X#    include <dos.h>          /* _dos_setftime()                            */
  578. X#  endif
  579. X#  ifdef OS2                  /* stuff for DOS and OS/2 family version */
  580. X#    if !defined(IBMC32) && !defined(MSC) && !defined(__BORLANDC__)
  581. X#      define MSC             /* assume Microsoft if not ID'd already */
  582. X#    endif
  583. X#    define INCL_BASE
  584. X#    define INCL_NOPM
  585. X#    include <os2.h>          /* DosQFileInfo(), DosSetFileInfo()? */
  586. X#  endif
  587. X#endif
  588. X
  589. X#ifdef IBMC32
  590. X#  define DOS_OS2
  591. X#  define S_IFMT 0xF000
  592. X#  define timezone _timezone
  593. X#endif
  594. X
  595. X#ifdef EMX32
  596. X#  define DOS_OS2
  597. X#  define __32BIT__
  598. X#  define DosGetCtryInfo   DosQueryCtryInfo
  599. X#  define DosQFileInfo     DosQueryFileInfo
  600. X#  define far
  601. X#endif
  602. X#ifdef MSC                    /* defined for all versions of MSC now         */
  603. X#  define DOS_OS2             /* Turbo C under DOS, MSC under DOS or OS/2    */
  604. X#  ifndef __STDC__            /* MSC 5.0 and 5.1 aren't truly ANSI-standard, */
  605. X#    define __STDC__ 1        /*   but they understand prototypes...so       */
  606. X#  endif                      /*   they're close enough for our purposes     */
  607. X#  if defined(_MSC_VER) && (_MSC_VER >= 600)      /* new with 5.1 or 6.0 ... */
  608. X#    undef DECLARE_ERRNO      /* errno is now a function in a dynamic link   */
  609. X#  endif                      /*   library (or something)--incompatible with */
  610. X#endif                        /*   the usual "extern int errno" declaration  */
  611. X
  612. X#ifdef DOS_OS2                /* defined for both Turbo C, MSC */
  613. X#  include <io.h>             /* lseek(), open(), setftime(), dup(), creat() */
  614. X#  ifndef SKIP_TIME_H         /* also included in crypt.c */
  615. X#    include <time.h>         /* localtime() */
  616. X#  endif /* !SKIP_TIME_H */
  617. X#endif
  618. X
  619. X/*---------------------------------------------------------------------------
  620. X    Followed by some VMS (mostly) stuff:
  621. X  ---------------------------------------------------------------------------*/
  622. X
  623. X#ifdef VMS
  624. X#  ifndef SKIP_TIME_H  /* temporary bugfix for VMS gcc in decryption version */
  625. X#    include <time.h>           /* the usual non-BSD time functions */
  626. X#  endif /* !SKIP_TIME_H */
  627. X#  include <file.h>             /* same things as fcntl.h has */
  628. X#  include <rmsdef.h>           /* RMS error codes */
  629. X#  include "fatdef.h"           /* RMS-related things used by VMSmunch */
  630. X#  include "VMSmunch.h"         /* VMSmunch argument definitions */
  631. X#  define UNIX                  /* can share most of same code from now on */
  632. X#  define RETURN   return_VMS   /* VMS interprets return codes incorrectly */
  633. X#else /* !VMS */
  634. X#  define RETURN   return       /* only used in main() */
  635. X#  ifdef V7
  636. X#    define O_RDONLY  0
  637. X#    define O_WRONLY  1
  638. X#    define O_RDWR    2
  639. X#  else /* !V7 */
  640. X#    ifdef MTS
  641. X#      include <sys/file.h>     /* MTS uses this instead of fcntl.h */
  642. X#      include <timeb.h>
  643. X#      ifndef SKIP_TIME_H       /* also included in crypt.c */
  644. X#        include <time.h>
  645. X#      endif /* !SKIP_TIME_H */
  646. X#    else /* !MTS */
  647. X#      ifdef COHERENT           /* Coherent 3.10/Mark Williams C */
  648. X#        include <sys/fcntl.h>
  649. X#        define SHORT_NAMES
  650. X#        define tzset  settz
  651. X#      else /* !COHERENT */
  652. X#        include <fcntl.h>      /* #define O_BINARY 0x8000 (no CR/LF */
  653. X#      endif /* ?COHERENT */    /*   translation), as used in open() */
  654. X#    endif /* ?MTS */
  655. X#  endif /* ?V7 */
  656. X#endif /* ?VMS */
  657. X
  658. X/*---------------------------------------------------------------------------
  659. X    And some Mac stuff for good measure:
  660. X  ---------------------------------------------------------------------------*/
  661. X
  662. X#ifdef THINK_C
  663. X#  define MACOS
  664. X#  ifndef __STDC__            /* If Think C hasn't defined __STDC__ ... */
  665. X#    define __STDC__ 1        /* make sure it's defined: it needs it */
  666. X#  else /* __STDC__ defined */
  667. X#    if !__STDC__             /* Sometimes __STDC__ is defined as 0. */
  668. X#      undef __STDC__         /* It needs to be 1 or required header */
  669. X#      define __STDC__ 1      /* files are not properly included. */
  670. X#    endif /* !__STDC__ */
  671. X#  endif /* ?defined(__STDC__) */
  672. X#  include <unix.h>
  673. X#  include "macstat.h"
  674. X#endif
  675. X
  676. X#ifdef MPW
  677. X#  define MACOS
  678. X#  include <Files.h>
  679. X#  include "macstat.h"
  680. X#  define CtoPstr c2pstr
  681. X#  define PtoCstr p2cstr
  682. X#  ifndef TRUE
  683. X#    define TRUE     1
  684. X#  endif
  685. X#  ifndef FALSE
  686. X#    define FALSE    0
  687. X#  endif
  688. X#  ifdef CR
  689. X#    undef  CR
  690. X#  endif
  691. X#endif
  692. X
  693. X/*---------------------------------------------------------------------------
  694. X    And finally, some random extra stuff:
  695. X  ---------------------------------------------------------------------------*/
  696. X
  697. X#if __STDC__
  698. X#  include <stdlib.h>      /* standard library prototypes, malloc(), etc. */
  699. X#  include <string.h>      /* defines strcpy, strcmp, memcpy, etc. */
  700. X#else
  701. X   char *malloc();
  702. X   char *strchr(), *strrchr();
  703. X   long lseek();
  704. X#endif
  705. X
  706. X#ifdef MINIX
  707. X#  include <stdio.h>
  708. X#endif
  709. X
  710. X#ifdef SHORT_NAMES         /* Mark Williams C, ...? */
  711. X#  define extract_or_test_files    xtr_or_tst_files
  712. X#  define extract_or_test_member   xtr_or_tst_member
  713. X#endif
  714. X
  715. X
  716. X
  717. X
  718. X
  719. X/*************/
  720. X/*  Defines  */
  721. X/*************/
  722. X
  723. X#define INBUFSIZ          BUFSIZ   /* same as stdio uses */
  724. X#define DIR_BLKSIZ        64       /* number of directory entries per block
  725. X                                    *  (should fit in 4096 bytes, usually) */
  726. X/*
  727. X * If <limits.h> exists on most systems, should include that, since it may
  728. X * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX,
  729. X * _POSIX_PATH_MAX.
  730. X */
  731. X#ifdef DOS_OS2
  732. X#  include <limits.h>
  733. X#endif /* ?DOS_OS2 */
  734. X
  735. X#ifdef _MAX_PATH
  736. X#  define FILNAMSIZ       (_MAX_PATH)
  737. X#else /* !_MAX_PATH */
  738. X#  define FILNAMSIZ       1025
  739. X#endif /* ?_MAX_PATH */
  740. X
  741. X#ifndef PATH_MAX
  742. X#  ifdef MAXPATHLEN                /* defined in <sys/param.h> some systems */
  743. X#    define PATH_MAX      MAXPATHLEN
  744. X#  else
  745. X#    if FILENAME_MAX > 255         /* used like PATH_MAX on some systems */
  746. X#      define PATH_MAX    FILENAME_MAX
  747. X#    else
  748. X#      define PATH_MAX    (FILNAMSIZ - 1)
  749. X#    endif
  750. X#  endif /* ?MAXPATHLEN */
  751. X#endif /* !PATH_MAX */
  752. X
  753. X#ifdef ZIPINFO
  754. X#  define OUTBUFSIZ       BUFSIZ   /* zipinfo needs less than unzip does    */
  755. X#else
  756. X#  define OUTBUFSIZ       0x2000   /* unImplode needs power of 2, >= 0x2000 */
  757. X#endif
  758. X
  759. X#define ZSUFX             ".zip"
  760. X#define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
  761. X#define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip not */
  762. X#define END_CENTRAL_SIG   "\113\005\006"   /*  mistaken for zipfile itself) */
  763. X
  764. X#define SKIP              0    /* choice of activities for do_string() */
  765. X#define DISPLAY           1
  766. X#define FILENAME          2
  767. X#define EXTRA_FIELD       3
  768. X
  769. X#define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  770. X#define EXISTS_AND_OLDER  0
  771. X#define EXISTS_AND_NEWER  1
  772. X
  773. X#define DOS_OS2_FAT_      0    /* version_made_by codes (central dir) */
  774. X#define AMIGA_            1
  775. X#define VMS_              2    /* MAKE SURE THESE ARE NOT DEFINED ON */
  776. X#define UNIX_             3    /* THE RESPECTIVE SYSTEMS!!  (like, for */
  777. X#define VM_CMS_           4    /* instance, "VMS", or "UNIX":  CFLAGS = */
  778. X#define ATARI_            5    /*  -O -DUNIX) */
  779. X#define OS2_HPFS_         6
  780. X#define MAC_              7
  781. X#define Z_SYSTEM_         8
  782. X#define CPM_              9
  783. X/* #define TOPS20_   10?  (TOPS20_ is to be defined in PKZIP 2.0...)  */
  784. X#define NUM_HOSTS         10   /* index of last system + 1 */
  785. X
  786. X#define STORED            0    /* compression methods */
  787. X#define SHRUNK            1
  788. X#define REDUCED1          2
  789. X#define REDUCED2          3
  790. X#define REDUCED3          4
  791. X#define REDUCED4          5
  792. X#define IMPLODED          6
  793. X#define TOKENIZED         7
  794. X#define DEFLATED          8
  795. X#define NUM_METHODS       9    /* index of last method + 1 */
  796. X/* don't forget to update list_files() appropriately if NUM_METHODS changes */
  797. X
  798. X#define DF_MDY            0    /* date format 10/26/91 (USA only) */
  799. X#define DF_DMY            1    /* date format 26/10/91 (most of the world) */
  800. X#define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  801. X
  802. X#define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  803. X#define VMS_VERSION       42   /* if OS-needed-to-extract is VMS:  can do */
  804. X
  805. X/*---------------------------------------------------------------------------
  806. X    True sizes of the various headers, as defined by PKWare--so it is not
  807. X    likely that these will ever change.  But if they do, make sure both these
  808. X    defines AND the typedefs below get updated accordingly.
  809. X  ---------------------------------------------------------------------------*/
  810. X
  811. X#define LREC_SIZE     26    /* lengths of local file headers, central */
  812. X#define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  813. X#define ECREC_SIZE    18    /*  central-dir record, respectively      */
  814. X
  815. X
  816. X#define MAX_BITS      13                 /* used in unShrink() */
  817. X#define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  818. X
  819. X#define LF   10   /* '\n' on ASCII machines.  Must be 10 due to EBCDIC */
  820. X#define CR   13   /* '\r' on ASCII machines.  Must be 13 due to EBCDIC */
  821. X
  822. X#ifdef EBCDIC
  823. X#  define ascii_to_native(c)   ebcdic[(c)]
  824. X#  define NATIVE    "EBCDIC"
  825. X#endif
  826. X
  827. X#ifdef AMIGA
  828. X#  define FFLUSH    fflush(stderr);
  829. X#else /* !AMIGA */
  830. X#  if MPW
  831. X#    define FFLUSH    putc('\n',stderr);
  832. X#  else
  833. X#    define FFLUSH
  834. X#  endif
  835. X#endif /* ?AMIGA */
  836. X
  837. X#ifdef CRYPT
  838. X#  define OF __
  839. X#  define PWLEN        80
  840. X#  define DECRYPT(b)   (update_keys(t=((b)&0xff)^decrypt_byte()),t)
  841. X#endif /* CRYPT */
  842. X
  843. X#ifdef QQ  /* Newtware version */
  844. X#  define QCOND    (quietflg < 2)    /* -xq only kills comments */
  845. X#  define QCOND2   (!quietflg)       /* for no file comments with -vq[q] */
  846. X#else      /* (original) Bill Davidsen version  */
  847. X#  define QCOND    (!quietflg)       /* -xq[q] both kill "extracting:" msgs */
  848. X#  define QCOND2   (which_hdr)       /* file comments with -v, -vq, -vqq */
  849. X#endif
  850. X
  851. X#ifndef TRUE
  852. X#  define TRUE      1   /* sort of obvious */
  853. X#  define FALSE     0
  854. X#endif
  855. X
  856. X#ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   */
  857. X#  define SEEK_SET  0   /*  since they're not (in many cases), do so here. */
  858. X#  define SEEK_CUR  1
  859. X#  define SEEK_END  2
  860. X#endif
  861. X
  862. X#ifndef S_IRUSR
  863. X#  define S_IRWXU       00700       /* read, write, execute: owner */
  864. X#  define S_IRUSR       00400       /* read permission: owner */
  865. X#  define S_IWUSR       00200       /* write permission: owner */
  866. X#  define S_IXUSR       00100       /* execute permission: owner */
  867. X#  define S_IRWXG       00070       /* read, write, execute: group */
  868. X#  define S_IRGRP       00040       /* read permission: group */
  869. X#  define S_IWGRP       00020       /* write permission: group */
  870. X#  define S_IXGRP       00010       /* execute permission: group */
  871. X#  define S_IRWXO       00007       /* read, write, execute: other */
  872. X#  define S_IROTH       00004       /* read permission: other */
  873. X#  define S_IWOTH       00002       /* write permission: other */
  874. X#  define S_IXOTH       00001       /* execute permission: other */
  875. X#endif /* !S_IRUSR */
  876. X
  877. X#ifdef ZIPINFO      /* these are individually checked because SysV doesn't */
  878. X#  ifndef S_IFBLK   /*  have some of them, Microsoft C others, etc. */
  879. X#    define   S_IFBLK     0060000     /* block special */
  880. X#  endif
  881. X#  ifndef S_IFIFO  /* in Borland C, not MSC */
  882. X#    define   S_IFIFO     0010000     /* fifo */
  883. X#  endif
  884. X#  ifndef S_IFLNK  /* in BSD, not SysV */
  885. X#    define   S_IFLNK     0120000     /* symbolic link */
  886. X#  endif
  887. X#  ifndef S_IFSOCK  /* in BSD, not SysV */
  888. X#    define   S_IFSOCK    0140000     /* socket */
  889. X#  endif
  890. X#  ifndef S_ISUID
  891. X#    define S_ISUID       04000       /* set user id on execution */
  892. X#  endif
  893. X#  ifndef S_ISGID
  894. X#    define S_ISGID       02000       /* set group id on execution */
  895. X#  endif
  896. X#  ifndef S_ISVTX
  897. X#    define S_ISVTX       01000       /* directory permissions control */
  898. X#  endif
  899. X#  ifndef S_ENFMT
  900. X#    define S_ENFMT       S_ISGID     /* record locking enforcement flag */
  901. X#  endif
  902. X#endif /* ZIPINFO */
  903. X
  904. X
  905. X
  906. X
  907. X
  908. X/**************/
  909. X/*  Typedefs  */
  910. X/**************/
  911. X
  912. X#ifndef _BULL_SOURCE                /* Bull has it defined somewhere already */
  913. X   typedef unsigned char  byte;     /* code assumes UNSIGNED bytes */
  914. X#endif /* !_BULL_SOURCE */
  915. X
  916. Xtypedef char              boolean;
  917. Xtypedef long              longint;
  918. Xtypedef unsigned short    UWORD;
  919. X#if !defined(IBMC32) && !defined(EMX32)
  920. X   typedef unsigned long  ULONG;
  921. X#endif
  922. X
  923. Xtypedef struct min_info {
  924. X    unsigned unix_attr;
  925. X    unsigned dos_attr;
  926. X    int hostnum;
  927. X    longint offset;
  928. X/*  ULONG crc;  */           /* did need to check decryption (use local now) */
  929. X    unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing */
  930. X    unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  931. X    unsigned text : 1;       /* file is text or binary */
  932. X    unsigned lcflag : 1;     /* convert filename to lowercase */
  933. X} min_info;
  934. X
  935. X/*---------------------------------------------------------------------------
  936. X    Zipfile layout declarations.  If these headers ever change, make sure the
  937. X    xxREC_SIZE defines (above) change with them!
  938. X  ---------------------------------------------------------------------------*/
  939. X
  940. X   typedef byte   local_byte_hdr[ LREC_SIZE ];
  941. X#      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  942. X#      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  943. X#      define L_GENERAL_PURPOSE_BIT_FLAG        2
  944. X#      define L_COMPRESSION_METHOD              4
  945. X#      define L_LAST_MOD_FILE_TIME              6
  946. X#      define L_LAST_MOD_FILE_DATE              8
  947. X#      define L_CRC32                           10
  948. X#      define L_COMPRESSED_SIZE                 14
  949. X#      define L_UNCOMPRESSED_SIZE               18
  950. X#      define L_FILENAME_LENGTH                 22
  951. X#      define L_EXTRA_FIELD_LENGTH              24
  952. X
  953. X   typedef byte   cdir_byte_hdr[ CREC_SIZE ];
  954. X#      define C_VERSION_MADE_BY_0               0
  955. X#      define C_VERSION_MADE_BY_1               1
  956. X#      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  957. X#      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  958. X#      define C_GENERAL_PURPOSE_BIT_FLAG        4
  959. X#      define C_COMPRESSION_METHOD              6
  960. X#      define C_LAST_MOD_FILE_TIME              8
  961. X#      define C_LAST_MOD_FILE_DATE              10
  962. X#      define C_CRC32                           12
  963. X#      define C_COMPRESSED_SIZE                 16
  964. X#      define C_UNCOMPRESSED_SIZE               20
  965. X#      define C_FILENAME_LENGTH                 24
  966. X#      define C_EXTRA_FIELD_LENGTH              26
  967. X#      define C_FILE_COMMENT_LENGTH             28
  968. X#      define C_DISK_NUMBER_START               30
  969. X#      define C_INTERNAL_FILE_ATTRIBUTES        32
  970. X#      define C_EXTERNAL_FILE_ATTRIBUTES        34
  971. X#      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  972. X
  973. X   typedef byte   ec_byte_rec[ ECREC_SIZE+4 ];
  974. X/*     define SIGNATURE                         0   space-holder only */
  975. X#      define NUMBER_THIS_DISK                  4
  976. X#      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  977. X#      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  978. X#      define TOTAL_ENTRIES_CENTRAL_DIR         10
  979. X#      define SIZE_CENTRAL_DIRECTORY            12
  980. X#      define OFFSET_START_CENTRAL_DIRECTORY    16
  981. X#      define ZIPFILE_COMMENT_LENGTH            20
  982. X
  983. X
  984. X   typedef struct local_file_header {                 /* LOCAL */
  985. X       byte version_needed_to_extract[2];
  986. X       UWORD general_purpose_bit_flag;
  987. X       UWORD compression_method;
  988. X       UWORD last_mod_file_time;
  989. X       UWORD last_mod_file_date;
  990. X       ULONG crc32;
  991. X       ULONG compressed_size;
  992. X       ULONG uncompressed_size;
  993. X       UWORD filename_length;
  994. X       UWORD extra_field_length;
  995. X   } local_file_hdr;
  996. X
  997. X   typedef struct central_directory_file_header {     /* CENTRAL */
  998. X       byte version_made_by[2];
  999. X       byte version_needed_to_extract[2];
  1000. X       UWORD general_purpose_bit_flag;
  1001. X       UWORD compression_method;
  1002. X       UWORD last_mod_file_time;
  1003. X       UWORD last_mod_file_date;
  1004. X       ULONG crc32;
  1005. X       ULONG compressed_size;
  1006. X       ULONG uncompressed_size;
  1007. X       UWORD filename_length;
  1008. X       UWORD extra_field_length;
  1009. X       UWORD file_comment_length;
  1010. X       UWORD disk_number_start;
  1011. X       UWORD internal_file_attributes;
  1012. X       ULONG external_file_attributes;
  1013. X       ULONG relative_offset_local_header;
  1014. X   } cdir_file_hdr;
  1015. X
  1016. X   typedef struct end_central_dir_record {            /* END CENTRAL */
  1017. X       UWORD number_this_disk;
  1018. X       UWORD num_disk_with_start_central_dir;
  1019. X       UWORD num_entries_centrl_dir_ths_disk;
  1020. X       UWORD total_entries_central_dir;
  1021. X       ULONG size_central_directory;
  1022. X       ULONG offset_start_central_directory;
  1023. X       UWORD zipfile_comment_length;
  1024. X   } ecdir_rec;
  1025. X
  1026. X
  1027. X
  1028. X
  1029. X
  1030. X/*************************/
  1031. X/*  Function Prototypes  */
  1032. X/*************************/
  1033. X
  1034. X#ifndef __              /* This is a common macro, but the name "__" was */
  1035. X#  if __STDC__          /*  swiped from the fine folks at Cray Research, */
  1036. X#    define __(X)   X   /*  Inc. (thanks, guys!).  Keep interior stuff   */
  1037. X#  else                 /*  parenthesized...                             */
  1038. X#    define __(X)   ()
  1039. X#  endif
  1040. X#endif
  1041. X
  1042. X/*---------------------------------------------------------------------------
  1043. X    Functions in unzip.c and/or zipinfo.c:
  1044. X  ---------------------------------------------------------------------------*/
  1045. X
  1046. Xint    usage                     __( (int error) );
  1047. Xint    process_zipfile           __( (void) );
  1048. Xint    find_end_central_dir      __( (void) );
  1049. Xint    process_end_central_dir   __( (void) );
  1050. Xint    list_files                __( (void) );
  1051. Xint    process_cdir_file_hdr     __( (void) );
  1052. Xint    process_local_file_hdr    __( (void) );
  1053. Xint    process_central_dir       __( (void) );
  1054. Xint    long_info                 __( (void) );
  1055. Xint    short_info                __( (void) );
  1056. Xchar   *zipinfo_time             __( (UWORD *datez, UWORD *timez) );
  1057. X
  1058. X/*---------------------------------------------------------------------------
  1059. X    Functions in extract.c:
  1060. X  ---------------------------------------------------------------------------*/
  1061. X
  1062. Xint    extract_or_test_files     __( (void) );
  1063. X/*
  1064. X * static int   store_info               __( (void) );
  1065. X * static int   extract_or_test_member   __( (void) );
  1066. X */
  1067. X
  1068. X/*---------------------------------------------------------------------------
  1069. X    Functions in file_io.c and crypt.c:
  1070. X  ---------------------------------------------------------------------------*/
  1071. X
  1072. Xint    open_input_file           __( (void) );
  1073. Xint    readbuf                   __( (char *buf, register unsigned size) );
  1074. Xint    create_output_file        __( (void) );
  1075. Xint    FillBitBuffer             __( (void) );
  1076. Xint    ReadByte                  __( (UWORD *x) );
  1077. Xint    FlushOutput               __( (void) );
  1078. X/*
  1079. X * static int   dos2unix         __( (unsigned char *buf, int len) );
  1080. X */
  1081. Xvoid   set_file_time_and_close   __( (void) );
  1082. Xchar   *getp                     __( (char *, char *, int) );
  1083. X
  1084. Xint    decrypt_byte              __( (void) );
  1085. Xvoid   update_keys               __( (int) );
  1086. Xvoid   init_keys                 __( (char *) );
  1087. X
  1088. X/*---------------------------------------------------------------------------
  1089. X    Macintosh file_io functions:
  1090. X  ---------------------------------------------------------------------------*/
  1091. X
  1092. X#ifdef MACOS
  1093. X/*
  1094. X * static int   IsHFSDisk        __( (int wAppVRefNum) );
  1095. X */
  1096. Xvoid   macfstest                 __( (int vrefnum) );
  1097. Xint    mkdir                     __( (char *path) );
  1098. X#ifndef MCH_MACINTOSH            /* The next prototype upsets Aztec C. */
  1099. Xvoid   SetMacVol                 __( (char *pch, short wVRefNum) );
  1100. X#endif
  1101. X#endif
  1102. X
  1103. X/*---------------------------------------------------------------------------
  1104. X    Uncompression functions (all internal compression routines, enclosed in
  1105. X    comments below, are prototyped in their respective files and are invisi-
  1106. X    ble to external functions):
  1107. X  ---------------------------------------------------------------------------*/
  1108. X
  1109. Xvoid   inflate                  __( (void) );                  /* inflate.c */
  1110. X/*
  1111. X */
  1112. X
  1113. Xvoid   unImplode                __( (void) );                  /* unimplod.c */
  1114. X/*
  1115. X * static void   ReadLengths     __( (sf_tree *tree) );
  1116. X * static void   SortLengths     __( (sf_tree *tree) );
  1117. X * static void   GenerateTrees   __( (sf_tree *tree, sf_node *nodes) );
  1118. X * static void   LoadTree        __( (sf_tree *tree, int treesize, sf_node *nodes) );
  1119. X * static void   LoadTrees       __( (void) );
  1120. X * static void   ReadTree        __( (register sf_node *nodes, int *dest) );
  1121. X */
  1122. X
  1123. Xvoid   unReduce                 __( (void) );                  /* unreduce.c */
  1124. X/*
  1125. X * static void   LoadFollowers   __( (void) );
  1126. X */
  1127. X
  1128. Xvoid   unShrink                 __( (void) );                  /* unshrink.c */
  1129. X/*
  1130. X * static void   partial_clear   __( (void) );
  1131. X */
  1132. X
  1133. X/*---------------------------------------------------------------------------
  1134. X    Functions in match.c, mapname.c, misc.c, etc.:
  1135. X  ---------------------------------------------------------------------------*/
  1136. X
  1137. Xint      match             __( (char *string, char *pattern) );   /* match.c */
  1138. X/*
  1139. X * static BOOLEAN   do_list      __( (register char *string, char *pattern) );
  1140. X * static void      list_parse   __( (char **patp, char *lowp, char *highp) );
  1141. X * static char      nextch       __( (char **patp) );
  1142. X */
  1143. X
  1144. Xint      mapname           __( (int create_dirs) );             /* mapname.c */
  1145. X
  1146. Xvoid     UpdateCRC         __( (register unsigned char *s, register int len) );
  1147. Xint      do_string         __( (unsigned int len, int option) );   /* misc.c */
  1148. Xtime_t   dos_to_unix_time  __( (unsigned ddate, unsigned dtime) ); /* misc.c */
  1149. Xint      check_for_newer   __( (char *filename) );                 /* misc.c */
  1150. Xint      dateformat        __( (void) );                           /* misc.c */
  1151. XUWORD    makeword          __( (byte *b) );                        /* misc.c */
  1152. XULONG    makelong          __( (byte *sig) );                      /* misc.c */
  1153. Xvoid     return_VMS        __( (int zip_error) );                  /* misc.c */
  1154. X#ifdef ZMEM
  1155. X   char  *memset           __( (register char *buf, register char init, register unsigned int len) );
  1156. X   char  *memcpy           __( (register char *dst, register char *src, register unsigned int len) );
  1157. X#endif      /* These guys MUST be ifdef'd because their definition  */
  1158. X            /*  conflicts with the standard one.  Others (makeword, */
  1159. X            /*  makelong, return_VMS) don't matter.                 */
  1160. X
  1161. Xint      VMSmunch          __( (char *filename, int action, char *extra) );
  1162. X#ifdef AMIGA
  1163. X   int   utime             __( (char *file, time_t timep[]) );
  1164. X#endif
  1165. X
  1166. X
  1167. X
  1168. X
  1169. X
  1170. X/************/
  1171. X/*  Macros  */
  1172. X/************/
  1173. X
  1174. X#ifndef min    /* MSC defines this in stdlib.h */
  1175. X#  define min(a,b)   ((a) < (b) ? (a) : (b))
  1176. X#endif
  1177. X
  1178. X
  1179. X#define LSEEK(abs_offset) {longint request=(abs_offset)+extra_bytes,\
  1180. X   inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  1181. X   if(request<0) {fprintf(stderr, SeekMsg, ReportMsg); return(3);}\
  1182. X   else if(bufstart!=cur_zipfile_bufstart)\
  1183. X   {cur_zipfile_bufstart=lseek(zipfd,bufstart,SEEK_SET);\
  1184. X   if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
  1185. X   inptr=inbuf+inbuf_offset; incnt-=inbuf_offset;}\
  1186. X   else {incnt+=(inptr-inbuf)-inbuf_offset; inptr=inbuf+inbuf_offset;}}
  1187. X
  1188. X/*
  1189. X *  Seek to the block boundary of the block which includes abs_offset,
  1190. X *  then read block into input buffer and set pointers appropriately.
  1191. X *  If block is already in the buffer, just set the pointers.  This macro
  1192. X *  is used by process_end_central_dir (unzip.c) and do_string (misc.c).
  1193. X *  A slightly modified version is embedded within extract_or_test_files
  1194. X *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  1195. X *
  1196. X *  macro LSEEK(abs_offset)
  1197. X *      longint   abs_offset;
  1198. X *  {
  1199. X *      longint   request = abs_offset + extra_bytes;
  1200. X *      longint   inbuf_offset = request % INBUFSIZ;
  1201. X *      longint   bufstart = request - inbuf_offset;
  1202. X *
  1203. X *      if (request < 0) {
  1204. X *          fprintf(stderr, SeekMsg, ReportMsg);
  1205. X *          return(3);             /-* 3:  severe error in zipfile *-/
  1206. X *      } else if (bufstart != cur_zipfile_bufstart) {
  1207. X *          cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
  1208. X *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  1209. X *              return(51);        /-* 51:  unexpected EOF *-/
  1210. X *          inptr = inbuf + inbuf_offset;
  1211. X *          incnt -= inbuf_offset;
  1212. X *      } else {
  1213. X *          incnt += (inptr-inbuf) - inbuf_offset;
  1214. X *          inptr = inbuf + inbuf_offset;
  1215. X *      }
  1216. X *  }
  1217. X *
  1218. X */
  1219. X
  1220. X
  1221. X#define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
  1222. X  {error_in_archive=error; if(error>1) return error;}
  1223. X
  1224. X/*
  1225. X *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  1226. X *  and unzip.c in several functions.
  1227. X *
  1228. X *  macro SKIP_(length)
  1229. X *      UWORD   length;
  1230. X *  {
  1231. X *      if (length && ((error = do_string(length, SKIP)) != 0)) {
  1232. X *          error_in_archive = error;   /-* might be warning *-/
  1233. X *          if (error > 1)              /-* fatal *-/
  1234. X *              return (error);
  1235. X *      }
  1236. X *  }
  1237. X *
  1238. X */
  1239. X
  1240. X
  1241. X#define OUTB(intc) {*outptr++=intc; if (++outcnt==OUTBUFSIZ) FlushOutput();}
  1242. X
  1243. X/*
  1244. X *  macro OUTB(intc)
  1245. X *  {
  1246. X *      *outptr++ = intc;
  1247. X *      if (++outcnt == OUTBUFSIZ)
  1248. X *          FlushOutput();
  1249. X *  }
  1250. X *
  1251. X */
  1252. X
  1253. X
  1254. X#define READBIT(nbits,zdest) {if(nbits>bits_left) FillBitBuffer();\
  1255. X  zdest=(int)(bitbuf&mask_bits[nbits]); bitbuf>>=nbits; bits_left-=nbits;}
  1256. X
  1257. X/*
  1258. X * macro READBIT(nbits,zdest)
  1259. X *  {
  1260. X *      if (nbits > bits_left)
  1261. X *          FillBitBuffer();
  1262. X *      zdest = (int)(bitbuf & mask_bits[nbits]);
  1263. X *      bitbuf >>= nbits;
  1264. X *      bits_left -= nbits;
  1265. X *  }
  1266. X *
  1267. X */
  1268. X
  1269. X
  1270. X#define PEEKBIT(nbits) ( nbits > bits_left ? (FillBitBuffer(), bitbuf & mask_bits[nbits]) : bitbuf & mask_bits[nbits] )
  1271. X
  1272. X
  1273. X#define NUKE_CRs(buf,len) {register int i,j; for (i=j=0; j<len; (buf)[i++]=(buf)[j++]) if ((buf)[j]=='\r') ++j; len=i;}
  1274. X
  1275. X/*
  1276. X *  Remove all the ASCII carriage returns from buffer buf (length len),
  1277. X *  shortening as necessary (note that len gets modified in the process,
  1278. X *  so it CANNOT be an expression).  This macro is intended to be used
  1279. X *  BEFORE A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
  1280. X *  if-test gets performed one time too many, but it doesn't matter.
  1281. X *
  1282. X *  macro NUKE_CRs( buf, len )
  1283. X *    {
  1284. X *      register int   i, j;
  1285. X *
  1286. X *      for ( i = j = 0  ;  j < len  ;  (buf)[i++] = (buf)[j++] )
  1287. X *        if ( (buf)[j] == CR )
  1288. X *          ++j;
  1289. X *      len = i;
  1290. X *    }
  1291. X *
  1292. X */
  1293. X
  1294. X
  1295. X#define TOLOWER(str1,str2) {char *ps1,*ps2; ps1=(str1)-1; ps2=(str2); while(*++ps1) *ps2++=(isupper(*ps1))?tolower(*ps1):*ps1; *ps2='\0';}
  1296. X
  1297. X/*
  1298. X *  Copy the zero-terminated string in str1 into str2, converting any
  1299. X *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  1300. X *  as well, of course.  str1 and str2 may be the same character array.
  1301. X *
  1302. X *  macro TOLOWER( str1, str2 )
  1303. X *    {
  1304. X *      register char   *ps1, *ps2;
  1305. X *
  1306. X *      ps1 = (str1) - 1;
  1307. X *      ps2 = (str2);
  1308. X *      while ( *++ps1 )
  1309. X *        *ps2++ = (isupper(*ps1)) ?  tolower(*ps1)  :  *ps1;
  1310. X *      *ps2='\0';
  1311. X *    }
  1312. X *
  1313. X *  NOTES:  This macro makes no assumptions about the characteristics of
  1314. X *    the tolower() function or macro (beyond its existence), nor does it
  1315. X *    make assumptions about the structure of the character set (i.e., it
  1316. X *    should work on EBCDIC machines, too).  The fact that either or both
  1317. X *    of isupper() and tolower() may be macros has been taken into account;
  1318. X *    watch out for "side effects" (in the C sense) when modifying this
  1319. X *    macro.
  1320. X */
  1321. X
  1322. X
  1323. X#ifndef ascii_to_native
  1324. X
  1325. X#  define ascii_to_native(c)   (c)
  1326. X#  define A_TO_N(str1)
  1327. X
  1328. X#else
  1329. X
  1330. X#  ifndef NATIVE
  1331. X#    define NATIVE     "native chars"
  1332. X#  endif
  1333. X#  define A_TO_N(str1) { register unsigned char *ps1; for (ps1 = str1; *ps1; ps1++) *ps1 = (ascii_to_native(*ps1)); }
  1334. X
  1335. X/*
  1336. X *   Translate the zero-terminated string in str1 from ASCII to the native
  1337. X *   character set. The translation is performed in-place and uses the
  1338. X *   ascii_to_native macro to translate each character.
  1339. X *
  1340. X *   macro A_TO_N( str1 )
  1341. X *     {
  1342. X *       register unsigned char *ps1;
  1343. X *
  1344. X *       for ( ps1 = str1; *ps1; ps1++ )
  1345. X *         *ps1 = ( ascii_to_native( *ps1 ) );
  1346. X *     }
  1347. X *
  1348. X *   NOTE: Using the ascii_to_native macro means that is it the only part of
  1349. X *     unzip which knows which translation table (if any) is actually in use
  1350. X *     to produce the native character set. This makes adding new character
  1351. X *     set translation tables easy insofar as all that is needed is an
  1352. X *     appropriate ascii_to_native macro definition and the translation
  1353. X *     table itself. Currently, the only non-ASCII native character set
  1354. X *     implemented is EBCDIC but this may not always be so.
  1355. X */
  1356. X
  1357. X#endif
  1358. X
  1359. X
  1360. X
  1361. X
  1362. X
  1363. X/*************/
  1364. X/*  Globals  */
  1365. X/*************/
  1366. X
  1367. X   extern int       aflag;
  1368. X/* extern int       bflag;   reserved */
  1369. X   extern int       cflag;
  1370. X   extern int       fflag;
  1371. X   extern int       jflag;
  1372. X   extern int       overwrite_none;
  1373. X   extern int       overwrite_all;
  1374. X   extern int       force_flag;
  1375. X   extern int       quietflg;
  1376. X#ifdef DOS_OS2
  1377. X   extern int       sflag;
  1378. X#endif
  1379. X   extern int       tflag;
  1380. X   extern int       uflag;
  1381. X   extern int       V_flag;
  1382. X#ifdef VMS
  1383. X   extern int       secinf;
  1384. X#endif
  1385. X#ifdef MACOS
  1386. X   extern int       hfsflag;
  1387. X#endif
  1388. X   extern int       process_all_files;
  1389. X   extern longint   csize;
  1390. X   extern longint   ucsize;
  1391. X   extern char      *fnames[];
  1392. X   extern char      **fnv;
  1393. X   extern char      sig[];
  1394. X   extern char      answerbuf[];
  1395. X   extern min_info  *pInfo;
  1396. X   extern char      *key;
  1397. X   extern ULONG     keys[];
  1398. X
  1399. X   extern short     prefix_of[];
  1400. X#ifdef MACOS
  1401. X   extern byte      *suffix_of;
  1402. X   extern byte      *stack;
  1403. X#else
  1404. X   extern byte      suffix_of[];
  1405. X   extern byte      stack[];
  1406. X#endif
  1407. X   extern ULONG     crc32val;
  1408. X   extern ULONG     mask_bits[];
  1409. X
  1410. X   extern byte      *inbuf;
  1411. X   extern byte      *inptr;
  1412. X   extern int       incnt;
  1413. X   extern ULONG     bitbuf;
  1414. X   extern int       bits_left;
  1415. X   extern boolean   zipeof;
  1416. X   extern int       zipfd;
  1417. X   extern char      zipfn[];
  1418. X   extern longint   extra_bytes;
  1419. X   extern longint   cur_zipfile_bufstart;
  1420. X   extern byte      *extra_field;
  1421. X   extern char      local_hdr_sig[];
  1422. X   extern char      central_hdr_sig[];
  1423. X   extern char      end_central_sig[];
  1424. X   extern local_file_hdr  lrec;
  1425. X   extern cdir_file_hdr   crec;
  1426. X   extern ecdir_rec       ecrec;
  1427. X   extern struct stat     statbuf;
  1428. X
  1429. X   extern byte      *outbuf;
  1430. X   extern byte      *outptr;
  1431. X   extern byte      *outout;
  1432. X   extern longint   outpos;
  1433. X   extern int       outcnt;
  1434. X   extern int       outfd;
  1435. X   extern int       disk_full;
  1436. X   extern char      filename[];
  1437. X
  1438. X   extern char      *EndSigMsg;
  1439. X   extern char      *CentSigMsg;
  1440. X   extern char      *SeekMsg;
  1441. X   extern char      *ReportMsg;
  1442. X
  1443. X#ifdef DECLARE_ERRNO
  1444. X   extern int       errno;
  1445. X#endif
  1446. X
  1447. X#ifdef EBCDIC
  1448. X   extern byte      ebcdic[];
  1449. X#endif
  1450. END_OF_FILE
  1451.   if test 36246 -ne `wc -c <'unzip.h'`; then
  1452.     echo shar: \"'unzip.h'\" unpacked with wrong size!
  1453.   fi
  1454.   # end of 'unzip.h'
  1455. fi
  1456. echo shar: End of archive 4 \(of 12\).
  1457. cp /dev/null ark4isdone
  1458. MISSING=""
  1459. for I in 1 2 3 4 5 6 7 8 9 10 11 12 ; do
  1460.     if test ! -f ark${I}isdone ; then
  1461.     MISSING="${MISSING} ${I}"
  1462.     fi
  1463. done
  1464. if test "${MISSING}" = "" ; then
  1465.     echo You have unpacked all 12 archives.
  1466.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1467. else
  1468.     echo You still must unpack the following archives:
  1469.     echo "        " ${MISSING}
  1470. fi
  1471. exit 0
  1472. exit 0 # Just in case...
  1473.