home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / vmsnet / sources / 329 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  47.1 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!rutgers!network.ucsd.edu!mvb.saic.com!vmsnet-sources
  2. From: goathunter@wkuvx1.bitnet
  3. Newsgroups: vmsnet.sources
  4. Subject: Zip v1.9 & UnZip v5.0, part 12/22
  5. Message-ID: <8009655@MVB.SAIC.COM>
  6. Date: 1 Sep 92 22:52:17 GMT
  7. Organization: Western Kentucky University, Bowling Green, KY
  8. Lines: 1456
  9. Approved: Mark.Berryman@Mvb.Saic.Com
  10.  
  11. Submitted-by: goathunter@wkuvx1.bitnet
  12. Posting-number: Volume 3, Issue 134
  13. Archive-name: zip_unzip/part12
  14.  
  15. -+-+-+-+-+-+-+-+ START OF PART 12 -+-+-+-+-+-+-+-+
  16. X    unsigned long signature;  /*    4 bytes */
  17. X    FInfo finfo;              /*   16 bytes */
  18. X    unsigned long lCrDat;     /*    4 bytes */
  19. X    unsigned long lMdDat;     /*    4 bytes */
  20. X    unsigned long flags ;     /*    4 bytes */
  21. X    unsigned long lDirID;     /*    4 bytes */
  22. X    char rguchVolName`5B28`5D;    /*   28 bytes */
  23. X                              /*------------*/
  24. X`7D MACINFO;                    /* = 68 bytes for size of data */
  25. X#endif /* MACOS */
  26. X
  27. X/*--------------------------------------------------------------------------
  28. V-
  29. X    And finally, some random extra stuff:
  30. X  --------------------------------------------------------------------------
  31. V-*/
  32. X
  33. X#ifdef MINIX
  34. X#  include <stdio.h>
  35. X#endif
  36. X
  37. X#ifdef SHORT_NAMES         /* Mark Williams C, ...? */
  38. X#  define extract_or_test_files    xtr_or_tst_files
  39. X#  define extract_or_test_member   xtr_or_tst_member
  40. X#endif
  41. X
  42. X#ifdef MTS
  43. X#  include <unix.h>          /* Some important non-ANSI routines */
  44. X#  define mkdir(s,n) (-1)    /* No "make directory" capability */
  45. X#  define EBCDIC             /* Set EBCDIC conversion on */
  46. X#endif
  47. X
  48. X
  49. X
  50. X
  51. X
  52. X/*************/
  53. X/*  Defines  */
  54. X/*************/
  55. X
  56. X#ifndef WSIZE
  57. X#  define WSIZE 0x8000       /* window size--must be a power of two, and */
  58. X#endif /* !WSIZE */          /*  at least 32K for zip's deflate method */
  59. X
  60. X#define DIR_BLKSIZ    64     /* number of directory entries per block
  61. X                              *  (should fit in 4096 bytes, usually) */
  62. X#ifndef INBUFSIZ
  63. X#  define INBUFSIZ    2048   /* works for MS-DOS small model */
  64. X#endif /* !INBUFSIZ */
  65. X
  66. X/*
  67. X * If <limits.h> exists on most systems, should include that, since it may
  68. X * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX
  69. V,
  70. X * _POSIX_PATH_MAX.
  71. X */
  72. X#ifdef DOS_OS2
  73. X#  include <limits.h>
  74. X#endif /* DOS_OS2 */
  75. X
  76. X#ifdef _MAX_PATH
  77. X#  define FILNAMSIZ       (_MAX_PATH)
  78. X#else /* !_MAX_PATH */
  79. X#  define FILNAMSIZ       1025
  80. X#endif /* ?_MAX_PATH */
  81. X
  82. X#ifndef PATH_MAX
  83. X#  ifdef MAXPATHLEN                /* defined in <sys/param.h> some systems
  84. V */
  85. X#    define PATH_MAX      MAXPATHLEN
  86. X#  else
  87. X#    if FILENAME_MAX > 255         /* used like PATH_MAX on some systems */
  88. X#      define PATH_MAX    FILENAME_MAX
  89. X#    else
  90. X#      define PATH_MAX    (FILNAMSIZ - 1)
  91. X#    endif
  92. X#  endif /* ?MAXPATHLEN */
  93. X#endif /* !PATH_MAX */
  94. X
  95. X#define OUTBUFSIZ         INBUFSIZ
  96. X
  97. X#define ZSUFX             ".zip"
  98. X#define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
  99. X#define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
  100. X#define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for *
  101. V/
  102. X#define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
  103. X
  104. X#define SKIP              0    /* choice of activities for do_string() */
  105. X#define DISPLAY           1
  106. X#define FILENAME          2
  107. X#define EXTRA_FIELD       3
  108. X
  109. X#define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
  110. X#define EXISTS_AND_OLDER  0
  111. X#define EXISTS_AND_NEWER  1
  112. X
  113. X#define DOS_OS2_FAT_      0    /* version_made_by codes (central dir) */
  114. X#define AMIGA_            1
  115. X#define VMS_              2    /* make sure these are not defined on */
  116. X#define UNIX_             3    /*  the respective systems!!  (like, for */
  117. X#define VM_CMS_           4    /*  instance, "VMS", or "UNIX":  CFLAGS = */
  118. X#define ATARI_            5    /*  -O -DUNIX) */
  119. X#define OS2_HPFS_         6
  120. X#define MAC_              7
  121. X#define Z_SYSTEM_         8
  122. X#define CPM_              9
  123. X/* #define TOPS20_   10?  (TOPS20_ is to be defined in PKZIP 2.0...)  */
  124. X#define NUM_HOSTS         10   /* index of last system + 1 */
  125. X
  126. X#define STORED            0    /* compression methods */
  127. X#define SHRUNK            1
  128. X#define REDUCED1          2
  129. X#define REDUCED2          3
  130. X#define REDUCED3          4
  131. X#define REDUCED4          5
  132. X#define IMPLODED          6
  133. X#define TOKENIZED         7
  134. X#define DEFLATED          8
  135. X#define NUM_METHODS       9    /* index of last method + 1 */
  136. X/* don't forget to update list_files() appropriately if NUM_METHODS changes
  137. V */
  138. X
  139. X#define DF_MDY            0    /* date format 10/26/91 (USA only) */
  140. X#define DF_DMY            1    /* date format 26/10/91 (most of the world) *
  141. V/
  142. X#define DF_YMD            2    /* date format 91/10/26 (a few countries) */
  143. X
  144. X#define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
  145. X#define VMS_VERSION       42   /* if OS-needed-to-extract is VMS:  can do */
  146. X
  147. X/*--------------------------------------------------------------------------
  148. V-
  149. X    True sizes of the various headers, as defined by PKWare--so it is not
  150. X    likely that these will ever change.  But if they do, make sure both thes
  151. Ve
  152. X    defines AND the typedefs below get updated accordingly.
  153. X  --------------------------------------------------------------------------
  154. V-*/
  155. X#define LREC_SIZE     26    /* lengths of local file headers, central */
  156. X#define CREC_SIZE     42    /*  directory headers, and the end-of-    */
  157. X#define ECREC_SIZE    18    /*  central-dir record, respectively      */
  158. X
  159. X#define MAX_BITS      13                 /* used in unShrink() */
  160. X#define HSIZE         (1 << MAX_BITS)    /* size of global work area */
  161. X
  162. X#define LF      10    /* '\n' on ASCII machines.  Must be 10 due to EBCDIC *
  163. V/
  164. X#define CR      13    /* '\r' on ASCII machines.  Must be 13 due to EBCDIC *
  165. V/
  166. X#define CTRLZ   26    /* DOS & OS/2 EOF marker (used in file_io.c, vms.c) */
  167. X
  168. X#ifdef EBCDIC
  169. X#  define ascii_to_native(c)   ebcdic`5B(c)`5D
  170. X#  define NATIVE    "EBCDIC"
  171. X#endif
  172. X
  173. X#if MPW
  174. X#  define FFLUSH    putc('\n',stderr);
  175. X#else /* !MPW */
  176. X#  define FFLUSH    fflush(stderr);
  177. X#endif /* ?MPW */
  178. X
  179. X#ifdef VMS
  180. X#  define ENV_UNZIP     "UNZIP_OPTS"      /* name of environment variable */
  181. X#  define ENV_ZIPINFO   "ZIPINFO_OPTS"
  182. X#else /* !VMS */
  183. X#  define ENV_UNZIP     "UNZIP"
  184. X#  define ENV_ZIPINFO   "ZIPINFO"
  185. X#endif /* ?VMS */
  186. X
  187. X#ifdef CRYPT
  188. X#  define PWLEN         80
  189. X#  define DECRYPT(b)    (update_keys(t=((b)&0xff)`5Edecrypt_byte()),t)
  190. X#endif /* CRYPT */
  191. X
  192. X#ifdef QQ  /* Newtware version */
  193. X#  define QCOND   (!quietflg)   /* for no file comments with -vq or -vqq */
  194. X#else      /* (original) Bill Davidsen version  */
  195. X#  define QCOND   (which_hdr)   /* no way to kill file comments with -v, -l
  196. V */
  197. X#endif
  198. X
  199. X#ifndef TRUE
  200. X#  define TRUE      1   /* sort of obvious */
  201. X#endif
  202. X#ifndef FALSE
  203. X#  define FALSE     0
  204. X#endif
  205. X
  206. X#ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   *
  207. V/
  208. X#  define SEEK_SET  0   /*  since they're not (in many cases), do so here. *
  209. V/
  210. X#  define SEEK_CUR  1
  211. X#  define SEEK_END  2
  212. X#endif
  213. X
  214. X#ifndef S_IRUSR
  215. X#  define S_IRWXU       00700       /* read, write, execute: owner */
  216. X#  define S_IRUSR       00400       /* read permission: owner */
  217. X#  define S_IWUSR       00200       /* write permission: owner */
  218. X#  define S_IXUSR       00100       /* execute permission: owner */
  219. X#  define S_IRWXG       00070       /* read, write, execute: group */
  220. X#  define S_IRGRP       00040       /* read permission: group */
  221. X#  define S_IWGRP       00020       /* write permission: group */
  222. X#  define S_IXGRP       00010       /* execute permission: group */
  223. X#  define S_IRWXO       00007       /* read, write, execute: other */
  224. X#  define S_IROTH       00004       /* read permission: other */
  225. X#  define S_IWOTH       00002       /* write permission: other */
  226. X#  define S_IXOTH       00001       /* execute permission: other */
  227. X#endif /* !S_IRUSR */
  228. X
  229. X#ifdef ZIPINFO      /* these are individually checked because SysV doesn't *
  230. V/
  231. X#  ifndef S_IFBLK   /*  have some of them, Microsoft C others, etc. */
  232. X#    define   S_IFBLK     0060000     /* block special */
  233. X#  endif
  234. X#  ifndef S_IFIFO  /* in Borland C, not MSC */
  235. X#    define   S_IFIFO     0010000     /* fifo */
  236. X#  endif
  237. X#  ifndef S_IFLNK  /* in BSD, not SysV */
  238. X#    define   S_IFLNK     0120000     /* symbolic link */
  239. X#  endif
  240. X#  ifndef S_IFSOCK  /* in BSD, not SysV */
  241. X#    define   S_IFSOCK    0140000     /* socket */
  242. X#  endif
  243. X#  ifndef S_ISUID
  244. X#    define S_ISUID       04000       /* set user id on execution */
  245. X#  endif
  246. X#  ifndef S_ISGID
  247. X#    define S_ISGID       02000       /* set group id on execution */
  248. X#  endif
  249. X#  ifndef S_ISVTX
  250. X#    define S_ISVTX       01000       /* directory permissions control */
  251. X#  endif
  252. X#  ifndef S_ENFMT
  253. X#    define S_ENFMT       S_ISGID     /* record locking enforcement flag */
  254. X#  endif
  255. X#endif /* ZIPINFO */
  256. X
  257. X
  258. X
  259. X
  260. X
  261. X/**************/
  262. X/*  Typedefs  */
  263. X/**************/
  264. X
  265. X#ifndef _BULL_SOURCE                /* Bull has it defined somewhere already
  266. V */
  267. X   typedef unsigned char  byte;     /* code assumes UNSIGNED bytes */
  268. X#endif /* !_BULL_SOURCE */
  269. X
  270. Xtypedef char              boolean;
  271. Xtypedef long              longint;
  272. Xtypedef unsigned short    UWORD;
  273. Xtypedef unsigned long     ULONG;
  274. X
  275. Xtypedef struct min_info `7B
  276. X    unsigned unix_attr;
  277. X    unsigned dos_attr;
  278. X    int hostnum;
  279. X    longint offset;
  280. X    ULONG compr_size;        /* compressed size (needed if extended header)
  281. V */
  282. X    ULONG crc;               /* crc (needed if extended header) */
  283. X    unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing
  284. V */
  285. X    unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
  286. X    unsigned text : 1;       /* file is text or binary */
  287. X    unsigned lcflag : 1;     /* convert filename to lowercase */
  288. X`7D min_info;
  289. X
  290. Xtypedef struct VMStimbuf `7B
  291. X    char *revdate;           /* (both correspond to Unix modtime/st_mtime) *
  292. V/
  293. X    char *credate;
  294. X`7D VMStimbuf;
  295. X
  296. X/*--------------------------------------------------------------------------
  297. V-
  298. X    Zipfile layout declarations.  If these headers ever change, make sure th
  299. Ve
  300. X    xxREC_SIZE defines (above) change with them!
  301. X  --------------------------------------------------------------------------
  302. V-*/
  303. X
  304. X   typedef byte   local_byte_hdr`5B LREC_SIZE `5D;
  305. X#      define L_VERSION_NEEDED_TO_EXTRACT_0     0
  306. X#      define L_VERSION_NEEDED_TO_EXTRACT_1     1
  307. X#      define L_GENERAL_PURPOSE_BIT_FLAG        2
  308. X#      define L_COMPRESSION_METHOD              4
  309. X#      define L_LAST_MOD_FILE_TIME              6
  310. X#      define L_LAST_MOD_FILE_DATE              8
  311. X#      define L_CRC32                           10
  312. X#      define L_COMPRESSED_SIZE                 14
  313. X#      define L_UNCOMPRESSED_SIZE               18
  314. X#      define L_FILENAME_LENGTH                 22
  315. X#      define L_EXTRA_FIELD_LENGTH              24
  316. X
  317. X   typedef byte   cdir_byte_hdr`5B CREC_SIZE `5D;
  318. X#      define C_VERSION_MADE_BY_0               0
  319. X#      define C_VERSION_MADE_BY_1               1
  320. X#      define C_VERSION_NEEDED_TO_EXTRACT_0     2
  321. X#      define C_VERSION_NEEDED_TO_EXTRACT_1     3
  322. X#      define C_GENERAL_PURPOSE_BIT_FLAG        4
  323. X#      define C_COMPRESSION_METHOD              6
  324. X#      define C_LAST_MOD_FILE_TIME              8
  325. X#      define C_LAST_MOD_FILE_DATE              10
  326. X#      define C_CRC32                           12
  327. X#      define C_COMPRESSED_SIZE                 16
  328. X#      define C_UNCOMPRESSED_SIZE               20
  329. X#      define C_FILENAME_LENGTH                 24
  330. X#      define C_EXTRA_FIELD_LENGTH              26
  331. X#      define C_FILE_COMMENT_LENGTH             28
  332. X#      define C_DISK_NUMBER_START               30
  333. X#      define C_INTERNAL_FILE_ATTRIBUTES        32
  334. X#      define C_EXTERNAL_FILE_ATTRIBUTES        34
  335. X#      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
  336. X
  337. X   typedef byte   ec_byte_rec`5B ECREC_SIZE+4 `5D;
  338. X/*     define SIGNATURE                         0   space-holder only */
  339. X#      define NUMBER_THIS_DISK                  4
  340. X#      define NUM_DISK_WITH_START_CENTRAL_DIR   6
  341. X#      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
  342. X#      define TOTAL_ENTRIES_CENTRAL_DIR         10
  343. X#      define SIZE_CENTRAL_DIRECTORY            12
  344. X#      define OFFSET_START_CENTRAL_DIRECTORY    16
  345. X#      define ZIPFILE_COMMENT_LENGTH            20
  346. X
  347. X
  348. X   typedef struct local_file_header `7B                 /* LOCAL */
  349. X       byte version_needed_to_extract`5B2`5D;
  350. X       UWORD general_purpose_bit_flag;
  351. X       UWORD compression_method;
  352. X       UWORD last_mod_file_time;
  353. X       UWORD last_mod_file_date;
  354. X       ULONG crc32;
  355. X       ULONG compressed_size;
  356. X       ULONG uncompressed_size;
  357. X       UWORD filename_length;
  358. X       UWORD extra_field_length;
  359. X   `7D local_file_hdr;
  360. X
  361. X   typedef struct central_directory_file_header `7B     /* CENTRAL */
  362. X       byte version_made_by`5B2`5D;
  363. X       byte version_needed_to_extract`5B2`5D;
  364. X       UWORD general_purpose_bit_flag;
  365. X       UWORD compression_method;
  366. X       UWORD last_mod_file_time;
  367. X       UWORD last_mod_file_date;
  368. X       ULONG crc32;
  369. X       ULONG compressed_size;
  370. X       ULONG uncompressed_size;
  371. X       UWORD filename_length;
  372. X       UWORD extra_field_length;
  373. X       UWORD file_comment_length;
  374. X       UWORD disk_number_start;
  375. X       UWORD internal_file_attributes;
  376. X       ULONG external_file_attributes;
  377. X       ULONG relative_offset_local_header;
  378. X   `7D cdir_file_hdr;
  379. X
  380. X   typedef struct end_central_dir_record `7B            /* END CENTRAL */
  381. X       UWORD number_this_disk;
  382. X       UWORD num_disk_with_start_central_dir;
  383. X       UWORD num_entries_centrl_dir_ths_disk;
  384. X       UWORD total_entries_central_dir;
  385. X       ULONG size_central_directory;
  386. X       ULONG offset_start_central_directory;
  387. X       UWORD zipfile_comment_length;
  388. X   `7D ecdir_rec;
  389. X
  390. X
  391. X
  392. X
  393. X
  394. X/*************************/
  395. X/*  Function Prototypes  */
  396. X/*************************/
  397. X
  398. X#ifndef __
  399. X#  define __   OF
  400. X#endif
  401. X
  402. X/*--------------------------------------------------------------------------
  403. V-
  404. X    Functions in unzip.c and/or zipinfo.c:
  405. X  --------------------------------------------------------------------------
  406. V-*/
  407. X
  408. Xint    usage                     __((int error));
  409. Xint    process_zipfile           __((void));
  410. Xint    find_end_central_dir      __((void));
  411. Xint    process_end_central_dir   __((void));
  412. Xint    list_files                __((void));                      /* unzip.c
  413. V */
  414. Xint    process_cdir_file_hdr     __((void));                      /* unzip.c
  415. V */
  416. Xint    process_local_file_hdr    __((void));                      /* unzip.c
  417. V */
  418. Xint    process_central_dir       __((void));
  419. Xint    long_info                 __((void));                    /* zipinfo.c
  420. V */
  421. Xint    short_info                __((void));                    /* zipinfo.c
  422. V */
  423. Xchar   *zipinfo_time             __((UWORD *datez, UWORD *timez));
  424. X
  425. X/*--------------------------------------------------------------------------
  426. V-
  427. X    Functions in extract.c:
  428. X  --------------------------------------------------------------------------
  429. V-*/
  430. X
  431. Xint    extract_or_test_files     __((void));
  432. X/* static int   store_info               __((void)); */
  433. X/* static int   extract_or_test_member   __((void)); */
  434. Xint    memextract                __((byte *, ULONG, byte *, ULONG));
  435. Xint    FlushMemory               __((void));
  436. Xint    ReadMemoryByte            __((UWORD *x));
  437. X
  438. X/*--------------------------------------------------------------------------
  439. V-
  440. X    Decompression functions:
  441. X  --------------------------------------------------------------------------
  442. V-*/
  443. X
  444. Xint    explode                   __((void));                    /* explode.c
  445. V */
  446. X
  447. Xvoid   inflate                   __((void));                    /* inflate.c
  448. V */
  449. X
  450. Xvoid   unReduce                  __((void));                   /* unreduce.c
  451. V */
  452. X/* static void  LoadFollowers    __((void));                    * unreduce.c
  453. V */
  454. X
  455. Xvoid   unShrink                  __((void));                   /* unshrink.c
  456. V */
  457. X/* static void  partial_clear    __((void));                    * unshrink.c
  458. V */
  459. X
  460. X/*--------------------------------------------------------------------------
  461. V-
  462. X    Functions in file_io.c and crypt.c:
  463. X  --------------------------------------------------------------------------
  464. V-*/
  465. X
  466. Xint    open_input_file           __((void));                    /* file_io.c
  467. V */
  468. Xint    readbuf                   __((char *buf, register unsigned len));
  469. Xint    create_output_file        __((void));             /* file_io.c, vms.c
  470. V */
  471. Xint    FillBitBuffer             __((void));                    /* file_io.c
  472. V */
  473. Xint    ReadByte                  __((UWORD *x));                /* file_io.c
  474. V */
  475. Xint    FlushOutput               __((void));             /* file_io.c, vms.c
  476. V */
  477. X/* static int   dos2unix         __((unsigned char *, int));     * file_io.c
  478. V */
  479. Xvoid   set_file_time_and_close   __((void));                    /* file_io.c
  480. V */
  481. Xvoid   handler                   __((int signal));              /* file_io.c
  482. V */
  483. Xint    echo                      __((int opt));                 /* file_io.c
  484. V */
  485. Xvoid   echoff                    __((int f));                   /* file_io.c
  486. V */
  487. Xvoid   echon                     __((void));                    /* file_io.c
  488. V */
  489. Xchar   *getp                     __((char *, char *, int));     /* file_io.c
  490. V */
  491. X
  492. Xint    decrypt_byte              __((void));                      /* crypt.c
  493. V */
  494. Xvoid   update_keys               __((int));                       /* crypt.c
  495. V */
  496. Xvoid   init_keys                 __((char *));                    /* crypt.c
  497. V */
  498. X
  499. X/*--------------------------------------------------------------------------
  500. V-
  501. X    Macintosh file_io functions:
  502. X  --------------------------------------------------------------------------
  503. V-*/
  504. X
  505. X#ifdef MACOS
  506. X/* static int   IsHFSDisk        __((int)); */
  507. X   void     macfstest            __((int));
  508. X   int      macmkdir             __((char *, short, long));
  509. X   void     ResolveMacVol        __((short, short *, long *, StringPtr));
  510. X   short    macopen              __((char *, short, short, long));
  511. X   short    maccreat             __((char *, short, long, OSType, OSType));
  512. X   short    macread              __((short, char *, unsigned));
  513. X   short    macwrite             __((short, char *, unsigned));
  514. X   short    macclose             __((short));
  515. X   long     maclseek             __((short, long, short));
  516. X#endif
  517. X
  518. X/*--------------------------------------------------------------------------
  519. V-
  520. X    OS/2 file_io functions:
  521. X  --------------------------------------------------------------------------
  522. V-*/
  523. X
  524. Xvoid     ChangeNameForFAT  __((char *name));                   /* os2unzip.c
  525. V */
  526. Xint      IsFileNameValid   __((char *name));                   /* os2unzip.c
  527. V */
  528. Xint      GetCountryInfo    __((void));                         /* os2unzip.c
  529. V */
  530. Xlong     GetFileTime       __((char *name));                   /* os2unzip.c
  531. V */
  532. Xvoid     SetPathInfo __((char *path, UWORD moddate, UWORD modtime, int flags
  533. V));
  534. Xint      SetLongNameEA     __((char *name, char *longname));   /* os2unzip.c
  535. V */
  536. Xint      IsEA              __((void *extra_field));            /* os2unzip.c
  537. V */
  538. XULONG    SizeOfEAs         __((void *extra_field));            /* os2unzip.c
  539. V */
  540. Xvoid     SetEAs            __((char *path, void *eablock));    /* os2unzip.c
  541. V */
  542. Xint      IsUpperNLS        __((int nChr));                     /* os2unzip.c
  543. V */
  544. Xint      ToLowerNLS        __((int nChr));                     /* os2unzip.c
  545. V */
  546. X
  547. X/*--------------------------------------------------------------------------
  548. V-
  549. X    VMS file_io functions:
  550. X  --------------------------------------------------------------------------
  551. V-*/
  552. X
  553. Xint      check_format      __((void));                              /* vms.c
  554. V */
  555. Xint      find_vms_attrs    __((void));                              /* vms.c
  556. V */
  557. Xint      CloseOutputFile   __((void));                              /* vms.c
  558. V */
  559. X/* static byte *extract_block __((struct extra_block *, int *, byte *, int))
  560. V;*/
  561. X/* static int  _flush_blocks  __((int final_flag));                  * vms.c
  562. V */
  563. X/* static int  _flush_records __((int final_flag));                  * vms.c
  564. V */
  565. X/* static int  WriteBuffer    __((unsigned char *buf, int len));     * vms.c
  566. V */
  567. X/* static int  WriteRecord    __((unsigned char *rec, int len));     * vms.c
  568. V */
  569. X/* static void message        __((int string, char *status));        * vms.c
  570. V */
  571. X
  572. Xint      VMSmunch          __((char *, int, char *));          /* VMSmunch.c
  573. V */
  574. X
  575. X/*--------------------------------------------------------------------------
  576. V-
  577. X    Functions in match.c, mapname.c, misc.c, etc.:
  578. X  --------------------------------------------------------------------------
  579. V-*/
  580. X
  581. Xint      match             __((char *string, char *pattern));     /* match.c
  582. V */
  583. X
  584. Xint      mapname           __((int create_dirs));               /* mapname.c
  585. V */
  586. X
  587. Xvoid     UpdateCRC         __((register unsigned char *s, register int len))
  588. V;
  589. Xint      do_string         __((unsigned int len, int option));     /* misc.c
  590. V */
  591. Xtime_t   dos_to_unix_time  __((unsigned ddate, unsigned dtime));   /* misc.c
  592. V */
  593. Xint      check_for_newer   __((char *filename));                   /* misc.c
  594. V */
  595. Xint      dateformat        __((void));                             /* misc.c
  596. V */
  597. XUWORD    makeword          __((byte *b));                          /* misc.c
  598. V */
  599. XULONG    makelong          __((byte *sig));                        /* misc.c
  600. V */
  601. Xvoid     return_VMS        __((int zip_error));                    /* misc.c
  602. V */
  603. X
  604. Xvoid     envargs           __((int *, char ***, char *));       /* envargs.c
  605. V */
  606. X
  607. X#ifdef AMIGA
  608. X   int   utime             __((char *file, time_t timep`5B`5D));      /* uti
  609. Vme.c */
  610. X#endif /* AMIGA */
  611. X
  612. X#ifdef ZMEM   /* these MUST be ifdef'd because of conflicts with the std def
  613. V */
  614. X   char  *memset           __((register char *buf, register char init,
  615. X                               register unsigned int len));        /* misc.c
  616. V */
  617. X   char  *memcpy           __((register char *dst, register char *src,
  618. X                               register unsigned int len));        /* misc.c
  619. V */
  620. X#endif /* ZMEM */
  621. X
  622. X
  623. X
  624. X
  625. X
  626. X/************/
  627. X/*  Macros  */
  628. X/************/
  629. X
  630. X#ifndef MAX
  631. X#  define MAX(a,b)   ((a) > (b) ? (a) : (b))
  632. X#endif
  633. X
  634. X#ifndef MIN
  635. X#  define MIN(a,b)   ((a) < (b) ? (a) : (b))
  636. X#endif
  637. X
  638. X
  639. X#define LSEEK(abs_offset) `7Blongint request=(abs_offset)+extra_bytes,\
  640. X   inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
  641. X   if(request<0) `7Bfprintf(stderr, SeekMsg, ReportMsg); return(3);`7D\
  642. X   else if(bufstart!=cur_zipfile_bufstart)\
  643. X   `7Bcur_zipfile_bufstart=lseek(zipfd,bufstart,SEEK_SET);\
  644. X   if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
  645. X   inptr=inbuf+(int)inbuf_offset; incnt-=(int)inbuf_offset;`7D else\
  646. X   `7Bincnt+=(inptr-inbuf)-(int)inbuf_offset; inptr=inbuf+(int)inbuf_offset;
  647. V`7D`7D
  648. X
  649. X/*
  650. X *  Seek to the block boundary of the block which includes abs_offset,
  651. X *  then read block into input buffer and set pointers appropriately.
  652. X *  If block is already in the buffer, just set the pointers.  This macro
  653. X *  is used by process_end_central_dir (unzip.c) and do_string (misc.c).
  654. X *  A slightly modified version is embedded within extract_or_test_files
  655. X *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
  656. X *
  657. X *  macro LSEEK(abs_offset)
  658. X *      ULONG   abs_offset;
  659. X *  `7B
  660. X *      longint   request = abs_offset + extra_bytes;
  661. X *      longint   inbuf_offset = request % INBUFSIZ;
  662. X *      longint   bufstart = request - inbuf_offset;
  663. X *
  664. X *      if (request < 0) `7B
  665. X *          fprintf(stderr, SeekMsg, ReportMsg);
  666. X *          return(3);             /-* 3:  severe error in zipfile *-/
  667. X *      `7D else if (bufstart != cur_zipfile_bufstart) `7B
  668. X *          cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
  669. X *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
  670. X *              return(51);        /-* 51:  unexpected EOF *-/
  671. X *          inptr = inbuf + (int)inbuf_offset;
  672. X *          incnt -= (int)inbuf_offset;
  673. X *      `7D else `7B
  674. X *          incnt += (inptr-inbuf) - (int)inbuf_offset;
  675. X *          inptr = inbuf + (int)inbuf_offset;
  676. X *      `7D
  677. X *  `7D
  678. X *
  679. X */
  680. X
  681. X
  682. X#define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
  683. X  `7Berror_in_archive=error; if(error>1) return error;`7D
  684. X
  685. X/*
  686. X *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
  687. X *  and unzip.c in several functions.
  688. X *
  689. X *  macro SKIP_(length)
  690. X *      UWORD   length;
  691. X *  `7B
  692. X *      if (length && ((error = do_string(length, SKIP)) != 0)) `7B
  693. X *          error_in_archive = error;   /-* might be warning *-/
  694. X *          if (error > 1)              /-* fatal *-/
  695. X *              return (error);
  696. X *      `7D
  697. X *  `7D
  698. X *
  699. X */
  700. X
  701. X
  702. X#define OUTB(intc) `7B*outptr++=(byte)(intc); if (++outcnt==OUTBUFSIZ)\
  703. X  FlushOutput();`7D
  704. X
  705. X/*
  706. X *  macro OUTB(intc)
  707. X *  `7B
  708. X *      *outptr++ = (byte)(intc);
  709. X *      if (++outcnt == OUTBUFSIZ)
  710. X *          FlushOutput();
  711. X *  `7D
  712. X *
  713. X */
  714. X
  715. X
  716. X#define READBIT(nbits,zdest) `7Bif(nbits>bits_left) FillBitBuffer();\
  717. X  zdest=(int)((UWORD)bitbuf&mask_bits`5Bnbits`5D);bitbuf>>=nbits;bits_left-=
  718. Vnbits;`7D
  719. X
  720. X/*
  721. X * macro READBIT(nbits,zdest)
  722. X *  `7B
  723. X *      if (nbits > bits_left)
  724. X *          FillBitBuffer();
  725. X *      zdest = (int)((UWORD)bitbuf & mask_bits`5Bnbits`5D);
  726. X *      bitbuf >>= nbits;
  727. X *      bits_left -= nbits;
  728. X *  `7D
  729. X *
  730. X */
  731. X
  732. X
  733. X#define PEEKBIT(nbits) (nbits>bits_left? (FillBitBuffer(),\
  734. X  (UWORD)bitbuf & mask_bits`5Bnbits`5D) : (UWORD)bitbuf & mask_bits`5Bnbits`
  735. V5D)
  736. X
  737. X
  738. X#define NUKE_CRs(buf,len) `7Bregister int i,j; for (i=j=0; j<len;\
  739. X  (buf)`5Bi++`5D=(buf)`5Bj++`5D) if ((buf)`5Bj`5D=='\r') ++j; len=i;`7D
  740. X
  741. X/*
  742. X *  Remove all the ASCII carriage returns from buffer buf (length len),
  743. X *  shortening as necessary (note that len gets modified in the process,
  744. X *  so it CANNOT be an expression).  This macro is intended to be used
  745. X *  BEFORE A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
  746. X *  if-test gets performed one time too many, but it doesn't matter.
  747. X *
  748. X *  macro NUKE_CRs(buf,len)
  749. X *  `7B
  750. X *      register int   i, j;
  751. X *
  752. X *      for (i = j = 0;  j < len;  (buf)`5Bi++`5D = (buf)`5Bj++`5D)
  753. X *          if ((buf)`5Bj`5D == CR)
  754. X *              ++j;
  755. X *      len = i;
  756. X *  `7D
  757. X *
  758. X */
  759. X
  760. X
  761. X#define TOLOWER(str1,str2) `7Bchar *ps1,*ps2; ps1=(str1)-1; ps2=(str2);\
  762. X  while(*++ps1) *ps2++=(char)(isupper((int)(*ps1))?tolower((int)(*ps1)):*ps1
  763. V);\
  764. X  *ps2='\0';`7D
  765. X
  766. X/*
  767. X *  Copy the zero-terminated string in str1 into str2, converting any
  768. X *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
  769. X *  as well, of course.  str1 and str2 may be the same character array.
  770. X *
  771. X *  macro TOLOWER( str1, str2 )
  772. X *  `7B
  773. X *      char  *ps1, *ps2;
  774. X *
  775. X *      ps1 = (str1) - 1;
  776. X *      ps2 = (str2);
  777. X *      while (*++ps1)
  778. X *          *ps2++ = (char)(isupper((int)(*ps1))? tolower((int)(*ps1)) : *ps
  779. V1);
  780. X *      *ps2='\0';
  781. X *  `7D
  782. X *
  783. X *  NOTES:  This macro makes no assumptions about the characteristics of
  784. X *    the tolower() function or macro (beyond its existence), nor does it
  785. X *    make assumptions about the structure of the character set (i.e., it
  786. X *    should work on EBCDIC machines, too).  The fact that either or both
  787. X *    of isupper() and tolower() may be macros has been taken into account;
  788. X *    watch out for "side effects" (in the C sense) when modifying this
  789. X *    macro.
  790. X */
  791. X
  792. X
  793. X#ifndef ascii_to_native
  794. X#  define ascii_to_native(c)   (c)
  795. X#  define A_TO_N(str1)
  796. X#else
  797. X#  ifndef NATIVE
  798. X#    define NATIVE     "native chars"
  799. X#  endif
  800. X#  define A_TO_N(str1) `7Bregister unsigned char *ps1;\
  801. X     for (ps1=str1; *ps1; ps1++) *ps1=ascii_to_native(*ps1);`7D
  802. X#endif
  803. X
  804. X/*
  805. X *  Translate the zero-terminated string in str1 from ASCII to the native
  806. X *  character set. The translation is performed in-place and uses the
  807. X *  ascii_to_native macro to translate each character.
  808. X *
  809. X *  macro A_TO_N( str1 )
  810. X *  `7B
  811. X *      register unsigned char *ps1;
  812. X *
  813. X *      for (ps1 = str1;  *ps1;  ++ps1)
  814. X *          *ps1 = ascii_to_native(*ps1);
  815. X *  `7D
  816. X *
  817. X *  NOTE:  Using the ascii_to_native macro means that is it the only part of
  818. X *    unzip which knows which translation table (if any) is actually in use
  819. X *    to produce the native character set.  This makes adding new character
  820. X *    set translation tables easy, insofar as all that is needed is an
  821. X *    appropriate ascii_to_native macro definition and the translation
  822. X *    table itself.  Currently, the only non-ASCII native character set
  823. X *    implemented is EBCDIC, but this may not always be so.
  824. X */
  825. X
  826. X
  827. X
  828. X
  829. X
  830. X/*************/
  831. X/*  Globals  */
  832. X/*************/
  833. X
  834. X   extern int       aflag;
  835. X/* extern int       bflag;   reserved */
  836. X   extern int       cflag;
  837. X   extern int       fflag;
  838. X   extern int       jflag;
  839. X   extern int       overwrite_none;
  840. X   extern int       overwrite_all;
  841. X   extern int       force_flag;
  842. X   extern int       quietflg;
  843. X#ifdef DOS_OS2
  844. X   extern int       sflag;
  845. X#endif
  846. X   extern int       tflag;
  847. X   extern int       uflag;
  848. X   extern int       V_flag;
  849. X#ifdef VMS
  850. X   extern int       secinf;
  851. X#endif
  852. X#ifdef MACOS
  853. X   extern int       hfsflag;
  854. X#endif
  855. X   extern int       process_all_files;
  856. X   extern longint   csize;
  857. X   extern longint   ucsize;
  858. X   extern char      *fnames`5B`5D;
  859. X   extern char      **fnv;
  860. X   extern char      sig`5B`5D;
  861. X   extern char      answerbuf`5B`5D;
  862. X   extern min_info  *pInfo;
  863. X   extern char      *key;
  864. X   extern ULONG     keys`5B`5D;
  865. X
  866. X#ifdef MACOS
  867. X   union work `7B
  868. X     struct `7B
  869. X       short *Prefix_of;        /* (8193 * sizeof(short)) */
  870. X       byte *Suffix_of;
  871. X       byte *Stack;
  872. X     `7D shrink;
  873. X     byte *Slide;
  874. X   `7D;
  875. X#else
  876. X   union work `7B
  877. X     struct `7B
  878. X       short Prefix_of`5BHSIZE + 2`5D;      /* (8194 * sizeof(short)) */
  879. X       byte Suffix_of`5BHSIZE + 2`5D;       /* also s-f length_nodes (smalle
  880. Vr) */
  881. X       byte Stack`5BHSIZE + 2`5D;           /* also s-f distance_nodes (smal
  882. Vler) */
  883. X     `7D shrink;
  884. X     byte Slide`5BWSIZE`5D;
  885. X   `7D;
  886. X#endif
  887. X   extern union work area;
  888. X
  889. X#  define prefix_of area.shrink.Prefix_of
  890. X#  define suffix_of area.shrink.Suffix_of
  891. X#  define stack area.shrink.Stack
  892. X#  define slide area.Slide
  893. X
  894. X   extern ULONG     crc32val;
  895. X   extern UWORD     mask_bits`5B`5D;
  896. X
  897. X   extern byte      *inbuf;
  898. X   extern byte      *inptr;
  899. X   extern int       incnt;
  900. X   extern ULONG     bitbuf;
  901. X   extern int       bits_left;
  902. X   extern boolean   zipeof;
  903. X   extern int       zipfd;
  904. X#ifdef MSWIN
  905. X   extern char      *zipfn;
  906. X#else
  907. X   extern char      zipfn`5B`5D;
  908. X#endif
  909. X   extern longint   extra_bytes;
  910. X   extern longint   cur_zipfile_bufstart;
  911. X   extern byte      *extra_field;
  912. X   extern char      local_hdr_sig`5B`5D;
  913. X   extern char      central_hdr_sig`5B`5D;
  914. X   extern char      end_central_sig`5B`5D;
  915. X   extern local_file_hdr  lrec;
  916. X   extern cdir_file_hdr   crec;
  917. X   extern ecdir_rec       ecrec;
  918. X   extern struct stat     statbuf;
  919. X
  920. X   extern byte      *outbuf;
  921. X   extern byte      *outptr;
  922. X#ifdef MSWIN
  923. X   extern byte __far *outout;
  924. X   extern char     *filename;
  925. X#else
  926. X   extern byte      *outout;
  927. X   extern char      filename`5B`5D;
  928. X#endif
  929. X   extern longint   outpos;
  930. X   extern int       outcnt;
  931. X   extern int       outfd;
  932. X   extern int       mem_mode;
  933. X   extern int       disk_full;
  934. X
  935. X   extern char      *EndSigMsg;
  936. X   extern char      *CentSigMsg;
  937. X   extern char      *SeekMsg;
  938. X   extern char      *ReportMsg;
  939. X
  940. X#ifdef DECLARE_ERRNO
  941. X   extern int       errno;
  942. X#endif
  943. X
  944. X#ifdef EBCDIC
  945. X   extern byte      ebcdic`5B`5D;
  946. X#endif
  947. X
  948. X#ifdef MACOS
  949. X   extern short     gnVRefNum;
  950. X   extern long      glDirID;
  951. X   extern OSType    gostCreator;
  952. X   extern OSType    gostType;
  953. X   extern boolean   fMacZipped;
  954. X   extern boolean   macflag;
  955. X   extern short     giCursor;
  956. X   extern CursHandle rghCursor`5B`5D;
  957. X#endif
  958. $ CALL UNPACK [.UNZIP50]UNZIP.H;1 2002099974
  959. $ create 'f'
  960. X.!
  961. X.!  File:`09UNZIP.RNH
  962. X.!
  963. X.!  Author:`09Hunter Goatley
  964. X.!
  965. X.!  Date:`09October 23, 1991
  966. X.!
  967. X.!  Description:
  968. X.!
  969. X.!`09RUNOFF source file for portable UNZIP on-line help for VMS.
  970. X.!`09Adapted from UNZIP.MAN, distributed with UNZIP.
  971. X.!
  972. X.!`09To build:`09$ RUNOFF UNZIP.RNH
  973. X.!`09`09`09$ LIBR/HELP/INSERT libr UNZIP
  974. X.!
  975. X.!  Modification history:
  976. X.!
  977. X.!`0901-001`09`09Hunter Goatley`09`0923-OCT-1991 09:21
  978. X.!`09`09Genesis.
  979. X.!`0901-002`09`09Cave Newt`09`0916-MAR-1992 22:37
  980. X.!`09`09Update for UnZip 4.2.
  981. X.!`0901-003`09`09Igor Mandrichenko`0923-MAY-1992 22:14
  982. X.!`09`09Add -X option to command syntax.
  983. X.!`0901-004`09`09Cave Newt`09`0924-MAY-1992 13:30
  984. X.!`09`09Add UNZIP_OPTS environment variable help.
  985. X.!
  986. X.noflags
  987. X.lm4 .rm72
  988. X.indent -4
  989. X1 UNZIP
  990. X.br
  991. XUnZip is used to extract files compressed and packaged by Zip (see HELP ZIP
  992. Xfor information on ZIP).
  993. X.sk
  994. XFor a brief help on Zip and Unzip, run each without specifying any
  995. Xparameters on the command line.
  996. X.sk
  997. XUNZIP will list, test, or extract from a ZIP archive.  ZIP archives are comm
  998. Vonly
  999. Xfound on MS-DOS systems; a VMS version of ZIP can also be found here.
  1000. X.sk
  1001. XArchive member extraction is implied by the absence of the -c, -p, -t, -l, -
  1002. Vv or
  1003. X-z options.  All archive members are processed unless a filespec is provided
  1004. V to
  1005. Xspecify a subset of the archive members.  The filespec is similar to an egre
  1006. Vp
  1007. Xexpression, and may contain:
  1008. X.sk
  1009. X.literal
  1010. X     *       matches a sequence of 0 or more characters
  1011. X     ?       matches exactly 1 character
  1012. X     \nnn    matches the character having octal code nnn
  1013. X     `5B...`5D   matches any single character found inside the brackets;
  1014. X             ranges are specified by a beginning character,
  1015. X             a hyphen, and an ending character.  If a '!' follows
  1016. X             the left bracket, then the range of characters
  1017. X             matched is complemented with respect to the ASCII
  1018. X             character set.
  1019. X.end literal
  1020. X.sk
  1021. XFormat:
  1022. X.sk;.lm+1;.literal
  1023. XUNZIP `5B-cflptuvxz`5BajnoqUVX`5D`5D file`5B.zip`5D `5Bfilespec...`5D
  1024. X.end literal;.lm-1
  1025. X.!--------------------------------------------------------------------------
  1026. V----
  1027. X.indent -4
  1028. X2 Parameters
  1029. X.sk;.indent -4
  1030. Xfile`5B.zip`5D
  1031. X.sk
  1032. XFile specification for the ZIP archive.  The suffix .ZIP is applied if the
  1033. Xspecified file does not exist.  Note that self-extracting ZIP files are
  1034. Xsupported; just specify the .EXE suffix yourself.
  1035. X.sk;.indent -4
  1036. X`5Bfilespec`5D
  1037. X.sk
  1038. XAn optional list of archive members to be processed.  Expressions may be
  1039. Xused to match multiple members.  Expressions should be enclosed in double-qu
  1040. Votes
  1041. Xto prevent interpretation by DCL.  Multiple filenames should be separated by
  1042. Xblanks.
  1043. X.!--------------------------------------------------------------------------
  1044. V----
  1045. X.indent -4
  1046. X2 Options
  1047. X.br
  1048. XThe default action of UnZip is to extract all zipfile entries.  The followin
  1049. Vg
  1050. Xoptions and modifiers can be provided:
  1051. X.sk;.literal
  1052. X   -c   extract files to SYS$OUTPUT (terminal)
  1053. X   -f   freshen existing files (replace if newer); create none
  1054. X   -l   list archive files (short format)
  1055. X   -p   extract files to SYS$OUTPUT; no informational messages
  1056. X   -t   test archive files
  1057. X   -u   update existing files; create new ones if needed
  1058. X   -v   list archive files (verbose format)
  1059. X   -x   extract files in archive (default)
  1060. X   -z   display only the archive comment
  1061. X.end literal;.sk;.literal
  1062. X MODIFIERS
  1063. X   -a   convert to VMS textfile format (only use for TEXT files!)
  1064. X   -j   junk paths (don't recreate archive's directory structure)
  1065. X   -n   never overwrite existing files; don't prompt
  1066. X   -o   OK to overwrite files without prompting
  1067. X   -q   perform operations quietly (-qq => even quieter)
  1068. X   -U   leave filenames uppercase if created under MS-DOS, VMS, etc.
  1069. X   -V   retain (VMS) file version numbers
  1070. X   -X   restore owner/protection info (may require privileges)
  1071. X.end literal;.sk
  1072. X! `5Bthis should probably be a separate section`5D:
  1073. XIn addition, default options may be specified via the UNZIP_OPTS logical.
  1074. XFor example, the following will cause UnZip to restore owner/protection
  1075. Xinformation and perform all operations at quiet-level 1 by default:
  1076. X.sk;.literal
  1077. X    define UNZIP_OPTS "-qX"
  1078. X.end literal;.sk
  1079. XNote that the quotation marks are required to preserve lowercase options.
  1080. XTo negate a default option on the command line, add one or more minus`20
  1081. Xsigns before the option letter, in addition to the leading switch character
  1082. X`60-':
  1083. X.sk;.literal
  1084. X    unzip --ql zipfile
  1085. X.end literal
  1086. Xor
  1087. X.literal
  1088. X    unzip -l-q zipfile
  1089. X.end literal;.sk
  1090. XAt present it is not possible to decrement an option below zero--that is,
  1091. Xmore than a few minuses have no effect.
  1092. X.sk
  1093. XUNZIP_OPTS may be defined as a symbol rather than a logical, but if both
  1094. Xare defined, the logical is used.
  1095. X.!--------------------------------------------------------------------------
  1096. V---
  1097. X.indent -4
  1098. X2 Authors
  1099. X.br
  1100. XSamuel H. Smith, Usenet contributors, and Info-ZIP.
  1101. X.sk
  1102. XVMS on-line help ported from UNZIP.MAN by Hunter Goatley.
  1103. $ CALL UNPACK [.UNZIP50]UNZIP.RNH;1 1141060954
  1104. $ create 'f'
  1105. X/*************************************************************************
  1106. X *                                                                       *
  1107. X * Copyright (C) 1992 Igor Mandrichenko.                                 *
  1108. X * Permission is granted to any individual or institution to use, copy,  *
  1109. X * or redistribute this software so long as all of the original files    *
  1110. X * are included unmodified, that it is not sold for profit, and that     *
  1111. X * this copyright notice is retained.                                    *
  1112. X *                                                                       *
  1113. X *************************************************************************/
  1114. X
  1115. X/*
  1116. X *    vms.c  by Igor Mandrichenko
  1117. X *    version 1.2-1
  1118. X *
  1119. X *    This module contains routines to extract VMS file attributes
  1120. X *    from extra field and create file with these attributes.  This
  1121. X *    source is mainly based on sources of file_io.c from UNZIP 4.1
  1122. X *    by Info-ZIP.  `5BInfo-ZIP note:  very little of this code is from
  1123. X *    file_io.c; it has virtually been written from the ground up.
  1124. X *    Of the few lines which are from the older code, most are mine
  1125. X *    (G. Roelofs) and I make no claims upon them.  On the contrary,
  1126. X *    my/our thanks to Igor for his contributions!`5D
  1127. X */
  1128. X
  1129. X/*
  1130. X *      Revision history:
  1131. X *      1.0-1   Mandrichenko    16-feb-1992
  1132. X *              Recognize -c option
  1133. X *      1.0-2   Mandrichenko    17-feb-1992
  1134. X *              Do not use ASYnchroneous mode.
  1135. X *      1.0-3   Mandrichenko    2-mar-1992
  1136. X *              Make code more standard
  1137. X *              Use lrec instead of crec -- unzip4.2p does not provide
  1138. X *              crec now.
  1139. X *      1.1     Mandrichenko    5-mar-1992
  1140. X *              Make use of asynchronous output.
  1141. X *              Be ready to extract RMS blocks of invalid size (because diff
  1142. X *              VMS version used to compress).
  1143. X *      1.1-1   Mandrichenko    11-mar-1992
  1144. X *              Use internal file attributes saved in pInfo to decide
  1145. X *              if the file is text.  `5BGRR:  temporarily disabled, since
  1146. X *              no way to override and force binary extraction`5D
  1147. X *      1.1-2   Mandrichenko    13-mar-1992
  1148. X *              Do not restore owner/protection info if -X not specified.
  1149. X *      1.1-3   Mandrichenko    30-may-1992
  1150. X *              Set revision date/time to creation date/time if none specifi
  1151. Ved
  1152. X *              Take quiet flag into account.
  1153. X *      1.1-4   Cave Newt       14-jun-1992
  1154. X *              Check zipfile for variable-length format (unzip and zipinfo)
  1155. V.
  1156. X *`091.2`09Mandrichenko`0921-jun-1992
  1157. X *`09`09Use deflation/inflation for compression of extra blocks
  1158. X *`09`09Free all allocated space
  1159. X *`091.2-1`09Mandrichenko`0923-jun-1992
  1160. X *`09`09Interactively select an action when file exists
  1161. X */
  1162. X
  1163. X#ifdef VMS`09`09`09/*      VMS only !      */
  1164. X
  1165. X#ifndef SYI$_VERSION
  1166. X#define SYI$_VERSION 4096`09/* VMS 5.4 definition */
  1167. X#endif
  1168. X
  1169. X#ifndef VAXC
  1170. X`09`09`09`09/* This definition may be missed */
  1171. Xstruct XAB `7B
  1172. X    unsigned char xab$b_cod;
  1173. X    unsigned char xab$b_bln;
  1174. X    short int xabdef$$_fill_1;
  1175. X    char *xab$l_nxt;
  1176. X`7D;
  1177. X
  1178. X#endif
  1179. X
  1180. X#include "unzip.h"
  1181. X#include <ctype.h>
  1182. X#include <descrip.h>
  1183. X#include <syidef.h>
  1184. X
  1185. X#define ERR(s) !((s) & 1)
  1186. X
  1187. X#define BUFS512 8192*2`09`09/* Must be a multiple of 512 */
  1188. X
  1189. X/*
  1190. X*   Local static storage
  1191. X*/
  1192. Xstatic struct FAB fileblk;
  1193. Xstatic struct XABDAT dattim;
  1194. Xstatic struct XABRDT rdt;
  1195. Xstatic struct RAB rab;
  1196. X
  1197. Xstatic struct FAB *outfab = 0;
  1198. Xstatic struct RAB *outrab = 0;
  1199. Xstatic struct XABFHC *xabfhc = 0;
  1200. Xstatic struct XABDAT *xabdat = 0;
  1201. Xstatic struct XABRDT *xabrdt = 0;
  1202. Xstatic struct XABPRO *xabpro = 0;
  1203. Xstatic struct XABKEY *xabkey = 0;
  1204. Xstatic struct XABALL *xaball = 0;
  1205. Xstruct XAB *first_xab = 0L, *last_xab = 0L;
  1206. X
  1207. Xstatic char query = 0;
  1208. Xstatic int text_file = 0;
  1209. X
  1210. Xstatic char locbuf`5BBUFS512`5D;
  1211. Xstatic int loccnt = 0;
  1212. Xstatic char *locptr;
  1213. X
  1214. Xstatic int WriteBuffer();
  1215. Xstatic int _flush_blocks();
  1216. Xstatic int _flush_records();
  1217. Xstatic byte *extract_block();
  1218. Xstatic void message();
  1219. Xstatic int get_vms_version();
  1220. Xstatic void free_up();
  1221. Xstatic int replace();
  1222. X
  1223. Xstruct bufdsc
  1224. X`7B
  1225. X    struct bufdsc *next;
  1226. X    byte *buf;
  1227. X    int bufcnt;
  1228. X`7D;
  1229. X
  1230. Xstatic struct bufdsc b1, b2, *curbuf;
  1231. Xstatic byte buf1`5BBUFS512`5D, buf2`5BBUFS512`5D;
  1232. X
  1233. X
  1234. Xint check_format()`09`09/* return non-0 if format is variable-length */
  1235. X`7B
  1236. X    int rtype;
  1237. X    struct FAB fab;
  1238. X
  1239. X    fab = cc$rms_fab;
  1240. X    fab.fab$l_fna = zipfn;
  1241. X    fab.fab$b_fns = strlen(zipfn);
  1242. X    sys$open(&fab);
  1243. X    rtype = fab.fab$b_rfm;
  1244. X    sys$close(&fab);
  1245. X
  1246. X    if (rtype == FAB$C_VAR `7C`7C rtype == FAB$C_VFC)
  1247. X    `7B
  1248. X`09fprintf(stderr,
  1249. X`09`09"\n     Error:  zipfile is in variable-length record format.  Please\n
  1250. V\
  1251. X     run \"bilf l %s\" to convert the zipfile to stream-LF\n\
  1252. X     record format.  (Bilf.exe, bilf.c and make_bilf.com are included\n\
  1253. X     in the VMS UnZip source distribution.)\n\n", zipfn);
  1254. X`09return 2;`09`09/* 2:  error in zipfile */
  1255. X    `7D
  1256. X
  1257. X    return 0;
  1258. X`7D
  1259. X
  1260. X
  1261. X#ifndef ZIPINFO
  1262. X
  1263. Xint create_output_file()
  1264. X`7B`09`09`09`09/* return non-0 if sys$create failed */
  1265. X    int ierr, yr, mo, dy, hh, mm, ss;
  1266. X    char timbuf`5B24`5D;`09`09/* length = first entry in "stupid" + 1 */
  1267. X    int attr_given = 0;`09`09/* =1 if VMS attributes are present in
  1268. X`09`09`09`09*     extra_field */
  1269. X
  1270. X    rab = cc$rms_rab;`09`09/* fill FAB & RAB with default values */
  1271. X    fileblk = cc$rms_fab;
  1272. X
  1273. X    text_file =/* pInfo->text `7C`7C */aflag `7C`7C cflag;
  1274. X
  1275. X    if (attr_given = find_vms_attrs())
  1276. X    `7B
  1277. X`09text_file = 0;
  1278. X`09if (cflag)
  1279. X`09`7B
  1280. X`09    printf("Cannot put VMS file %s to stdout.\n",
  1281. X`09`09   filename);
  1282. X`09    free_up();
  1283. X`09    return 50;
  1284. X`09`7D
  1285. X    `7D
  1286. X
  1287. X    if (!attr_given)
  1288. X    `7B
  1289. X`09outfab = &fileblk;
  1290. X`09outfab->fab$l_xab = 0L;
  1291. X`09if (text_file)
  1292. X`09`7B
  1293. X`09    outfab->fab$b_rfm = FAB$C_VAR;`09/* variable length records */
  1294. X`09    outfab->fab$b_rat = FAB$M_CR;`09/* carriage-return carriage ctrl */
  1295. X`09`7D
  1296. X`09else
  1297. X`09`7B
  1298. X`09    outfab->fab$b_rfm = FAB$C_STMLF;`09/* stream-LF record format */
  1299. X`09    outfab->fab$b_rat = FAB$M_CR;`09/* carriage-return carriage ctrl */
  1300. X`09`7D
  1301. X    `7D
  1302. X
  1303. X    if (!cflag)
  1304. X`09outfab->fab$l_fna = filename;
  1305. X    else
  1306. X`09outfab->fab$l_fna = "sys$output:";
  1307. X
  1308. X    outfab->fab$b_fns = strlen(outfab->fab$l_fna);
  1309. X
  1310. X    if ((!attr_given) `7C`7C xabdat == 0 `7C`7C xabrdt == 0)`09/* Use date/t
  1311. Vime info
  1312. X`09`09`09`09`09`09`09 *  from zipfile if
  1313. X`09`09`09`09`09`09`09 *  no attributes given
  1314. X`09`09`09`09`09`09`09 */
  1315. X    `7B
  1316. X`09static char *month`5B`5D =
  1317. X`09    `7B"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
  1318. X`09     "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"`7D;
  1319. X
  1320. X`09/*  fixed-length string descriptor: */
  1321. X`09struct dsc$descriptor stupid =
  1322. X`09    `7B23, DSC$K_DTYPE_T, DSC$K_CLASS_S, timbuf`7D;
  1323. X
  1324. X`09yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + 1980;
  1325. X`09mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
  1326. X`09dy = (lrec.last_mod_file_date & 0x1f);
  1327. X`09hh = (lrec.last_mod_file_time >> 11) & 0x1f;
  1328. X`09mm = (lrec.last_mod_file_time >> 5) & 0x3f;
  1329. X`09ss = (lrec.last_mod_file_time & 0x1f) * 2;
  1330. X
  1331. X`09dattim = cc$rms_xabdat;`09/* fill XABs with default values */
  1332. X`09rdt = cc$rms_xabrdt;
  1333. X`09sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00", dy, month`5Bmo`5D, yr,
  1334. X`09`09hh, mm, ss);
  1335. X`09sys$bintim(&stupid, &dattim.xab$q_cdt);
  1336. X`09memcpy(&rdt.xab$q_rdt, &dattim.xab$q_cdt, sizeof(rdt.xab$q_rdt));
  1337. X
  1338. X`09if ((!attr_given) `7C`7C xabdat == 0L)
  1339. X`09`7B
  1340. X`09    dattim.xab$l_nxt = outfab->fab$l_xab;
  1341. X`09    outfab->fab$l_xab = &dattim;
  1342. X`09`7D
  1343. X    `7D
  1344. X
  1345. X    outfab->fab$w_ifi = 0;`09/* Clear IFI. It may be nonzero after ZIP */
  1346. X
  1347. X    ierr = sys$create(outfab);
  1348. X    if (ierr == RMS$_FEX)
  1349. X`09ierr = replace();
  1350. X
  1351. X    if (ierr == 0)`09`09/* Canceled */
  1352. X`09return free_up(), 1;
  1353. X
  1354. X    if (ERR(ierr))
  1355. X    `7B
  1356. X`09char buf`5B256`5D;
  1357. X
  1358. X`09sprintf(buf, "`5B Cannot create output file %s `5D\n", filename);
  1359. X`09message(buf, ierr);
  1360. X`09message("", outfab->fab$l_stv);
  1361. X`09free_up();
  1362. X`09return (1);
  1363. X    `7D
  1364. X
  1365. X    if (!text_file && !cflag)`09/* Do not reopen text files and stdout
  1366. X`09`09`09`09*  Just open them in right mode         */
  1367. X    `7B
  1368. X`09/*
  1369. X`09*       Reopen file for Block I/O with no XABs.
  1370. X`09*/
  1371. X`09if ((ierr = sys$close(outfab)) != RMS$_NORMAL)
  1372. X`09`7B
  1373. X#ifdef DEBUG
  1374. X`09    message("`5B create_output_file: sys$close failed `5D\n", ierr);
  1375. X`09    message("", outfab->fab$l_stv);
  1376. X#endif
  1377. X`09    fprintf(stderr, "Can't create output file:  %s\n", filename);
  1378. X`09    free_up();
  1379. X`09    return (1);
  1380. X`09`7D
  1381. X
  1382. X
  1383. X`09outfab->fab$b_fac = FAB$M_BIO `7C FAB$M_PUT;`09/* Get ready for block
  1384. X`09`09`09`09`09`09`09 * output */
  1385. X`09outfab->fab$l_xab = 0L;`09/* Unlink all XABs */
  1386. X
  1387. X`09if ((ierr = sys$open(outfab)) != RMS$_NORMAL)
  1388. X`09`7B
  1389. X`09    char buf`5B256`5D;
  1390. X
  1391. X`09    sprintf(buf, "`5B Cannot open output file %s `5D\n", filename);
  1392. X`09    message(buf, ierr);
  1393. X`09    message("", outfab->fab$l_stv);
  1394. X`09    free_up();
  1395. X`09    return (1);
  1396. X`09`7D
  1397. X    `7D
  1398. X
  1399. X    outrab = &rab;
  1400. X    rab.rab$l_fab = outfab;
  1401. X    if (!text_file) rab.rab$l_rop `7C= RAB$M_BIO;
  1402. X    if (!text_file) rab.rab$l_rop `7C= RAB$M_ASY;
  1403. X    rab.rab$b_rac = RAB$C_SEQ;
  1404. X
  1405. X    if ((ierr = sys$connect(outrab)) != RMS$_NORMAL)
  1406. X    `7B
  1407. X#ifdef DEBUG
  1408. X`09message("create_output_file: sys$connect failed.\n", ierr);
  1409. X`09message("", outfab->fab$l_stv);
  1410. X#endif
  1411. X`09fprintf(stderr, "Can't create output file:  %s\n", filename);
  1412. X`09free_up();
  1413. X`09return (1);
  1414. X    `7D
  1415. X
  1416. X    locptr = &locbuf`5B0`5D;
  1417. X    loccnt = 0;
  1418. X
  1419. X    b1.buf = &buf1`5B0`5D;
  1420. X    b1.bufcnt = 0;
  1421. X    b1.next = &b2;
  1422. X    b2.buf = &buf2`5B0`5D;
  1423. X    b2.bufcnt = 0;
  1424. X    b2.next = &b1;
  1425. X    curbuf = &b1;
  1426. X
  1427. X    return (0);
  1428. X`7D
  1429. X
  1430. Xstatic int replace()
  1431. X`7B`09`09`09`09/*
  1432. X`09`09`09`09*`09File exists. Inquire user about futher action.
  1433. X`09`09`09`09*/
  1434. X    char answ`5B10`5D;
  1435. X    struct NAM nam;
  1436. X    int ierr;
  1437. X
  1438. X    if (query == 0)
  1439. X    `7B
  1440. X`09do
  1441. X`09`7B
  1442. X`09    fprintf(stderr,
  1443. X`09`09    "Replace %s : `5Bo`5Dverwrite, new `5Bv`5Dersion or `5Bc`5Dancel (
  1444. VO,V,C - all) ? ",
  1445. X`09`09    filename);
  1446. X`09    fflush(stderr);
  1447. X`09`7D while (fgets(answ, 9, stderr) == NULL && !isalpha(answ`5B0`5D)
  1448. X`09`09 && tolower(answ`5B0`5D) != 'o'
  1449. X`09`09 && tolower(answ`5B0`5D) != 'v'
  1450. X`09`09 && tolower(answ`5B0`5D) != 'c');
  1451. X
  1452. X`09if (isupper(answ`5B0`5D))
  1453. X`09    query = answ`5B0`5D = tolower(answ`5B0`5D);
  1454. X    `7D
  1455. X    else
  1456. X`09answ`5B0`5D = query;
  1457. X
  1458. X    switch (answ`5B0`5D)
  1459. X    `7B
  1460. X`09case 'c':
  1461. X`09    ierr = 0;
  1462. X`09    break;
  1463. X`09case 'v':
  1464. X`09    nam = cc$rms_nam;
  1465. X`09    nam.nam$l_rsa = filename;
  1466. +-+-+-+-+-+-+-+-  END  OF PART 12 +-+-+-+-+-+-+-+-
  1467.