🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: vmsnet.sources
Article #82

Zip v1.9 & UnZip v5.0, part 12/22

#82
From: goathunter
Date: Tue, 01 Sep 1992 22:52
1456 lines
49679 bytes
Submitted-by: goathunter@wkuvx1.bitnet
Posting-number: Volume 3, Issue 134
Archive-name: zip_unzip/part12

-+-+-+-+-+-+-+-+ START OF PART 12 -+-+-+-+-+-+-+-+
X    unsigned long signature;  /*    4 bytes */
X    FInfo finfo;              /*   16 bytes */
X    unsigned long lCrDat;     /*    4 bytes */
X    unsigned long lMdDat;     /*    4 bytes */
X    unsigned long flags ;     /*    4 bytes */
X    unsigned long lDirID;     /*    4 bytes */
X    char rguchVolName`5B28`5D;    /*   28 bytes */
X                              /*------------*/
X`7D MACINFO;                    /* = 68 bytes for size of data */
X#endif /* MACOS */
X
X/*--------------------------------------------------------------------------
V-
X    And finally, some random extra stuff:
X  --------------------------------------------------------------------------
V-*/
X
X#ifdef MINIX
X#  include <stdio.h>
X#endif
X
X#ifdef SHORT_NAMES         /* Mark Williams C, ...? */
X#  define extract_or_test_files    xtr_or_tst_files
X#  define extract_or_test_member   xtr_or_tst_member
X#endif
X
X#ifdef MTS
X#  include <unix.h>          /* Some important non-ANSI routines */
X#  define mkdir(s,n) (-1)    /* No "make directory" capability */
X#  define EBCDIC             /* Set EBCDIC conversion on */
X#endif
X
X
X
X
X
X/*************/
X/*  Defines  */
X/*************/
X
X#ifndef WSIZE
X#  define WSIZE 0x8000       /* window size--must be a power of two, and */
X#endif /* !WSIZE */          /*  at least 32K for zip's deflate method */
X
X#define DIR_BLKSIZ    64     /* number of directory entries per block
X                              *  (should fit in 4096 bytes, usually) */
X#ifndef INBUFSIZ
X#  define INBUFSIZ    2048   /* works for MS-DOS small model */
X#endif /* !INBUFSIZ */
X
X/*
X * If <limits.h> exists on most systems, should include that, since it may
X * define some or all of the following:  NAME_MAX, PATH_MAX, _POSIX_NAME_MAX
V,
X * _POSIX_PATH_MAX.
X */
X#ifdef DOS_OS2
X#  include <limits.h>
X#endif /* DOS_OS2 */
X
X#ifdef _MAX_PATH
X#  define FILNAMSIZ       (_MAX_PATH)
X#else /* !_MAX_PATH */
X#  define FILNAMSIZ       1025
X#endif /* ?_MAX_PATH */
X
X#ifndef PATH_MAX
X#  ifdef MAXPATHLEN                /* defined in <sys/param.h> some systems
V */
X#    define PATH_MAX      MAXPATHLEN
X#  else
X#    if FILENAME_MAX > 255         /* used like PATH_MAX on some systems */
X#      define PATH_MAX    FILENAME_MAX
X#    else
X#      define PATH_MAX    (FILNAMSIZ - 1)
X#    endif
X#  endif /* ?MAXPATHLEN */
X#endif /* !PATH_MAX */
X
X#define OUTBUFSIZ         INBUFSIZ
X
X#define ZSUFX             ".zip"
X#define CENTRAL_HDR_SIG   "\113\001\002"   /* the infamous "PK" signature */
X#define LOCAL_HDR_SIG     "\113\003\004"   /*  bytes, sans "P" (so unzip */
X#define END_CENTRAL_SIG   "\113\005\006"   /*  executable not mistaken for *
V/
X#define EXTD_LOCAL_SIG    "\113\007\010"   /*  zipfile itself) */
X
X#define SKIP              0    /* choice of activities for do_string() */
X#define DISPLAY           1
X#define FILENAME          2
X#define EXTRA_FIELD       3
X
X#define DOES_NOT_EXIST    -1   /* return values for check_for_newer() */
X#define EXISTS_AND_OLDER  0
X#define EXISTS_AND_NEWER  1
X
X#define DOS_OS2_FAT_      0    /* version_made_by codes (central dir) */
X#define AMIGA_            1
X#define VMS_              2    /* make sure these are not defined on */
X#define UNIX_             3    /*  the respective systems!!  (like, for */
X#define VM_CMS_           4    /*  instance, "VMS", or "UNIX":  CFLAGS = */
X#define ATARI_            5    /*  -O -DUNIX) */
X#define OS2_HPFS_         6
X#define MAC_              7
X#define Z_SYSTEM_         8
X#define CPM_              9
X/* #define TOPS20_   10?  (TOPS20_ is to be defined in PKZIP 2.0...)  */
X#define NUM_HOSTS         10   /* index of last system + 1 */
X
X#define STORED            0    /* compression methods */
X#define SHRUNK            1
X#define REDUCED1          2
X#define REDUCED2          3
X#define REDUCED3          4
X#define REDUCED4          5
X#define IMPLODED          6
X#define TOKENIZED         7
X#define DEFLATED          8
X#define NUM_METHODS       9    /* index of last method + 1 */
X/* don't forget to update list_files() appropriately if NUM_METHODS changes
V */
X
X#define DF_MDY            0    /* date format 10/26/91 (USA only) */
X#define DF_DMY            1    /* date format 26/10/91 (most of the world) *
V/
X#define DF_YMD            2    /* date format 91/10/26 (a few countries) */
X
X#define UNZIP_VERSION     20   /* compatible with PKUNZIP 2.0 */
X#define VMS_VERSION       42   /* if OS-needed-to-extract is VMS:  can do */
X
X/*--------------------------------------------------------------------------
V-
X    True sizes of the various headers, as defined by PKWare--so it is not
X    likely that these will ever change.  But if they do, make sure both thes
Ve
X    defines AND the typedefs below get updated accordingly.
X  --------------------------------------------------------------------------
V-*/
X#define LREC_SIZE     26    /* lengths of local file headers, central */
X#define CREC_SIZE     42    /*  directory headers, and the end-of-    */
X#define ECREC_SIZE    18    /*  central-dir record, respectively      */
X
X#define MAX_BITS      13                 /* used in unShrink() */
X#define HSIZE         (1 << MAX_BITS)    /* size of global work area */
X
X#define LF      10    /* '\n' on ASCII machines.  Must be 10 due to EBCDIC *
V/
X#define CR      13    /* '\r' on ASCII machines.  Must be 13 due to EBCDIC *
V/
X#define CTRLZ   26    /* DOS & OS/2 EOF marker (used in file_io.c, vms.c) */
X
X#ifdef EBCDIC
X#  define ascii_to_native(c)   ebcdic`5B(c)`5D
X#  define NATIVE    "EBCDIC"
X#endif
X
X#if MPW
X#  define FFLUSH    putc('\n',stderr);
X#else /* !MPW */
X#  define FFLUSH    fflush(stderr);
X#endif /* ?MPW */
X
X#ifdef VMS
X#  define ENV_UNZIP     "UNZIP_OPTS"      /* name of environment variable */
X#  define ENV_ZIPINFO   "ZIPINFO_OPTS"
X#else /* !VMS */
X#  define ENV_UNZIP     "UNZIP"
X#  define ENV_ZIPINFO   "ZIPINFO"
X#endif /* ?VMS */
X
X#ifdef CRYPT
X#  define PWLEN         80
X#  define DECRYPT(b)    (update_keys(t=((b)&0xff)`5Edecrypt_byte()),t)
X#endif /* CRYPT */
X
X#ifdef QQ  /* Newtware version */
X#  define QCOND   (!quietflg)   /* for no file comments with -vq or -vqq */
X#else      /* (original) Bill Davidsen version  */
X#  define QCOND   (which_hdr)   /* no way to kill file comments with -v, -l
V */
X#endif
X
X#ifndef TRUE
X#  define TRUE      1   /* sort of obvious */
X#endif
X#ifndef FALSE
X#  define FALSE     0
X#endif
X
X#ifndef SEEK_SET        /* These should all be declared in stdio.h!  But   *
V/
X#  define SEEK_SET  0   /*  since they're not (in many cases), do so here. *
V/
X#  define SEEK_CUR  1
X#  define SEEK_END  2
X#endif
X
X#ifndef S_IRUSR
X#  define S_IRWXU       00700       /* read, write, execute: owner */
X#  define S_IRUSR       00400       /* read permission: owner */
X#  define S_IWUSR       00200       /* write permission: owner */
X#  define S_IXUSR       00100       /* execute permission: owner */
X#  define S_IRWXG       00070       /* read, write, execute: group */
X#  define S_IRGRP       00040       /* read permission: group */
X#  define S_IWGRP       00020       /* write permission: group */
X#  define S_IXGRP       00010       /* execute permission: group */
X#  define S_IRWXO       00007       /* read, write, execute: other */
X#  define S_IROTH       00004       /* read permission: other */
X#  define S_IWOTH       00002       /* write permission: other */
X#  define S_IXOTH       00001       /* execute permission: other */
X#endif /* !S_IRUSR */
X
X#ifdef ZIPINFO      /* these are individually checked because SysV doesn't *
V/
X#  ifndef S_IFBLK   /*  have some of them, Microsoft C others, etc. */
X#    define   S_IFBLK     0060000     /* block special */
X#  endif
X#  ifndef S_IFIFO  /* in Borland C, not MSC */
X#    define   S_IFIFO     0010000     /* fifo */
X#  endif
X#  ifndef S_IFLNK  /* in BSD, not SysV */
X#    define   S_IFLNK     0120000     /* symbolic link */
X#  endif
X#  ifndef S_IFSOCK  /* in BSD, not SysV */
X#    define   S_IFSOCK    0140000     /* socket */
X#  endif
X#  ifndef S_ISUID
X#    define S_ISUID       04000       /* set user id on execution */
X#  endif
X#  ifndef S_ISGID
X#    define S_ISGID       02000       /* set group id on execution */
X#  endif
X#  ifndef S_ISVTX
X#    define S_ISVTX       01000       /* directory permissions control */
X#  endif
X#  ifndef S_ENFMT
X#    define S_ENFMT       S_ISGID     /* record locking enforcement flag */
X#  endif
X#endif /* ZIPINFO */
X
X
X
X
X
X/**************/
X/*  Typedefs  */
X/**************/
X
X#ifndef _BULL_SOURCE                /* Bull has it defined somewhere already
V */
X   typedef unsigned char  byte;     /* code assumes UNSIGNED bytes */
X#endif /* !_BULL_SOURCE */
X
Xtypedef char              boolean;
Xtypedef long              longint;
Xtypedef unsigned short    UWORD;
Xtypedef unsigned long     ULONG;
X
Xtypedef struct min_info `7B
X    unsigned unix_attr;
X    unsigned dos_attr;
X    int hostnum;
X    longint offset;
X    ULONG compr_size;        /* compressed size (needed if extended header)
V */
X    ULONG crc;               /* crc (needed if extended header) */
X    unsigned encrypted : 1;  /* file encrypted: decrypt before uncompressing
V */
X    unsigned ExtLocHdr : 1;  /* use time instead of CRC for decrypt check */
X    unsigned text : 1;       /* file is text or binary */
X    unsigned lcflag : 1;     /* convert filename to lowercase */
X`7D min_info;
X
Xtypedef struct VMStimbuf `7B
X    char *revdate;           /* (both correspond to Unix modtime/st_mtime) *
V/
X    char *credate;
X`7D VMStimbuf;
X
X/*--------------------------------------------------------------------------
V-
X    Zipfile layout declarations.  If these headers ever change, make sure th
Ve
X    xxREC_SIZE defines (above) change with them!
X  --------------------------------------------------------------------------
V-*/
X
X   typedef byte   local_byte_hdr`5B LREC_SIZE `5D;
X#      define L_VERSION_NEEDED_TO_EXTRACT_0     0
X#      define L_VERSION_NEEDED_TO_EXTRACT_1     1
X#      define L_GENERAL_PURPOSE_BIT_FLAG        2
X#      define L_COMPRESSION_METHOD              4
X#      define L_LAST_MOD_FILE_TIME              6
X#      define L_LAST_MOD_FILE_DATE              8
X#      define L_CRC32                           10
X#      define L_COMPRESSED_SIZE                 14
X#      define L_UNCOMPRESSED_SIZE               18
X#      define L_FILENAME_LENGTH                 22
X#      define L_EXTRA_FIELD_LENGTH              24
X
X   typedef byte   cdir_byte_hdr`5B CREC_SIZE `5D;
X#      define C_VERSION_MADE_BY_0               0
X#      define C_VERSION_MADE_BY_1               1
X#      define C_VERSION_NEEDED_TO_EXTRACT_0     2
X#      define C_VERSION_NEEDED_TO_EXTRACT_1     3
X#      define C_GENERAL_PURPOSE_BIT_FLAG        4
X#      define C_COMPRESSION_METHOD              6
X#      define C_LAST_MOD_FILE_TIME              8
X#      define C_LAST_MOD_FILE_DATE              10
X#      define C_CRC32                           12
X#      define C_COMPRESSED_SIZE                 16
X#      define C_UNCOMPRESSED_SIZE               20
X#      define C_FILENAME_LENGTH                 24
X#      define C_EXTRA_FIELD_LENGTH              26
X#      define C_FILE_COMMENT_LENGTH             28
X#      define C_DISK_NUMBER_START               30
X#      define C_INTERNAL_FILE_ATTRIBUTES        32
X#      define C_EXTERNAL_FILE_ATTRIBUTES        34
X#      define C_RELATIVE_OFFSET_LOCAL_HEADER    38
X
X   typedef byte   ec_byte_rec`5B ECREC_SIZE+4 `5D;
X/*     define SIGNATURE                         0   space-holder only */
X#      define NUMBER_THIS_DISK                  4
X#      define NUM_DISK_WITH_START_CENTRAL_DIR   6
X#      define NUM_ENTRIES_CENTRL_DIR_THS_DISK   8
X#      define TOTAL_ENTRIES_CENTRAL_DIR         10
X#      define SIZE_CENTRAL_DIRECTORY            12
X#      define OFFSET_START_CENTRAL_DIRECTORY    16
X#      define ZIPFILE_COMMENT_LENGTH            20
X
X
X   typedef struct local_file_header `7B                 /* LOCAL */
X       byte version_needed_to_extract`5B2`5D;
X       UWORD general_purpose_bit_flag;
X       UWORD compression_method;
X       UWORD last_mod_file_time;
X       UWORD last_mod_file_date;
X       ULONG crc32;
X       ULONG compressed_size;
X       ULONG uncompressed_size;
X       UWORD filename_length;
X       UWORD extra_field_length;
X   `7D local_file_hdr;
X
X   typedef struct central_directory_file_header `7B     /* CENTRAL */
X       byte version_made_by`5B2`5D;
X       byte version_needed_to_extract`5B2`5D;
X       UWORD general_purpose_bit_flag;
X       UWORD compression_method;
X       UWORD last_mod_file_time;
X       UWORD last_mod_file_date;
X       ULONG crc32;
X       ULONG compressed_size;
X       ULONG uncompressed_size;
X       UWORD filename_length;
X       UWORD extra_field_length;
X       UWORD file_comment_length;
X       UWORD disk_number_start;
X       UWORD internal_file_attributes;
X       ULONG external_file_attributes;
X       ULONG relative_offset_local_header;
X   `7D cdir_file_hdr;
X
X   typedef struct end_central_dir_record `7B            /* END CENTRAL */
X       UWORD number_this_disk;
X       UWORD num_disk_with_start_central_dir;
X       UWORD num_entries_centrl_dir_ths_disk;
X       UWORD total_entries_central_dir;
X       ULONG size_central_directory;
X       ULONG offset_start_central_directory;
X       UWORD zipfile_comment_length;
X   `7D ecdir_rec;
X
X
X
X
X
X/*************************/
X/*  Function Prototypes  */
X/*************************/
X
X#ifndef __
X#  define __   OF
X#endif
X
X/*--------------------------------------------------------------------------
V-
X    Functions in unzip.c and/or zipinfo.c:
X  --------------------------------------------------------------------------
V-*/
X
Xint    usage                     __((int error));
Xint    process_zipfile           __((void));
Xint    find_end_central_dir      __((void));
Xint    process_end_central_dir   __((void));
Xint    list_files                __((void));                      /* unzip.c
V */
Xint    process_cdir_file_hdr     __((void));                      /* unzip.c
V */
Xint    process_local_file_hdr    __((void));                      /* unzip.c
V */
Xint    process_central_dir       __((void));
Xint    long_info                 __((void));                    /* zipinfo.c
V */
Xint    short_info                __((void));                    /* zipinfo.c
V */
Xchar   *zipinfo_time             __((UWORD *datez, UWORD *timez));
X
X/*--------------------------------------------------------------------------
V-
X    Functions in extract.c:
X  --------------------------------------------------------------------------
V-*/
X
Xint    extract_or_test_files     __((void));
X/* static int   store_info               __((void)); */
X/* static int   extract_or_test_member   __((void)); */
Xint    memextract                __((byte *, ULONG, byte *, ULONG));
Xint    FlushMemory               __((void));
Xint    ReadMemoryByte            __((UWORD *x));
X
X/*--------------------------------------------------------------------------
V-
X    Decompression functions:
X  --------------------------------------------------------------------------
V-*/
X
Xint    explode                   __((void));                    /* explode.c
V */
X
Xvoid   inflate                   __((void));                    /* inflate.c
V */
X
Xvoid   unReduce                  __((void));                   /* unreduce.c
V */
X/* static void  LoadFollowers    __((void));                    * unreduce.c
V */
X
Xvoid   unShrink                  __((void));                   /* unshrink.c
V */
X/* static void  partial_clear    __((void));                    * unshrink.c
V */
X
X/*--------------------------------------------------------------------------
V-
X    Functions in file_io.c and crypt.c:
X  --------------------------------------------------------------------------
V-*/
X
Xint    open_input_file           __((void));                    /* file_io.c
V */
Xint    readbuf                   __((char *buf, register unsigned len));
Xint    create_output_file        __((void));             /* file_io.c, vms.c
V */
Xint    FillBitBuffer             __((void));                    /* file_io.c
V */
Xint    ReadByte                  __((UWORD *x));                /* file_io.c
V */
Xint    FlushOutput               __((void));             /* file_io.c, vms.c
V */
X/* static int   dos2unix         __((unsigned char *, int));     * file_io.c
V */
Xvoid   set_file_time_and_close   __((void));                    /* file_io.c
V */
Xvoid   handler                   __((int signal));              /* file_io.c
V */
Xint    echo                      __((int opt));                 /* file_io.c
V */
Xvoid   echoff                    __((int f));                   /* file_io.c
V */
Xvoid   echon                     __((void));                    /* file_io.c
V */
Xchar   *getp                     __((char *, char *, int));     /* file_io.c
V */
X
Xint    decrypt_byte              __((void));                      /* crypt.c
V */
Xvoid   update_keys               __((int));                       /* crypt.c
V */
Xvoid   init_keys                 __((char *));                    /* crypt.c
V */
X
X/*--------------------------------------------------------------------------
V-
X    Macintosh file_io functions:
X  --------------------------------------------------------------------------
V-*/
X
X#ifdef MACOS
X/* static int   IsHFSDisk        __((int)); */
X   void     macfstest            __((int));
X   int      macmkdir             __((char *, short, long));
X   void     ResolveMacVol        __((short, short *, long *, StringPtr));
X   short    macopen              __((char *, short, short, long));
X   short    maccreat             __((char *, short, long, OSType, OSType));
X   short    macread              __((short, char *, unsigned));
X   short    macwrite             __((short, char *, unsigned));
X   short    macclose             __((short));
X   long     maclseek             __((short, long, short));
X#endif
X
X/*--------------------------------------------------------------------------
V-
X    OS/2 file_io functions:
X  --------------------------------------------------------------------------
V-*/
X
Xvoid     ChangeNameForFAT  __((char *name));                   /* os2unzip.c
V */
Xint      IsFileNameValid   __((char *name));                   /* os2unzip.c
V */
Xint      GetCountryInfo    __((void));                         /* os2unzip.c
V */
Xlong     GetFileTime       __((char *name));                   /* os2unzip.c
V */
Xvoid     SetPathInfo __((char *path, UWORD moddate, UWORD modtime, int flags
V));
Xint      SetLongNameEA     __((char *name, char *longname));   /* os2unzip.c
V */
Xint      IsEA              __((void *extra_field));            /* os2unzip.c
V */
XULONG    SizeOfEAs         __((void *extra_field));            /* os2unzip.c
V */
Xvoid     SetEAs            __((char *path, void *eablock));    /* os2unzip.c
V */
Xint      IsUpperNLS        __((int nChr));                     /* os2unzip.c
V */
Xint      ToLowerNLS        __((int nChr));                     /* os2unzip.c
V */
X
X/*--------------------------------------------------------------------------
V-
X    VMS file_io functions:
X  --------------------------------------------------------------------------
V-*/
X
Xint      check_format      __((void));                              /* vms.c
V */
Xint      find_vms_attrs    __((void));                              /* vms.c
V */
Xint      CloseOutputFile   __((void));                              /* vms.c
V */
X/* static byte *extract_block __((struct extra_block *, int *, byte *, int))
V;*/
X/* static int  _flush_blocks  __((int final_flag));                  * vms.c
V */
X/* static int  _flush_records __((int final_flag));                  * vms.c
V */
X/* static int  WriteBuffer    __((unsigned char *buf, int len));     * vms.c
V */
X/* static int  WriteRecord    __((unsigned char *rec, int len));     * vms.c
V */
X/* static void message        __((int string, char *status));        * vms.c
V */
X
Xint      VMSmunch          __((char *, int, char *));          /* VMSmunch.c
V */
X
X/*--------------------------------------------------------------------------
V-
X    Functions in match.c, mapname.c, misc.c, etc.:
X  --------------------------------------------------------------------------
V-*/
X
Xint      match             __((char *string, char *pattern));     /* match.c
V */
X
Xint      mapname           __((int create_dirs));               /* mapname.c
V */
X
Xvoid     UpdateCRC         __((register unsigned char *s, register int len))
V;
Xint      do_string         __((unsigned int len, int option));     /* misc.c
V */
Xtime_t   dos_to_unix_time  __((unsigned ddate, unsigned dtime));   /* misc.c
V */
Xint      check_for_newer   __((char *filename));                   /* misc.c
V */
Xint      dateformat        __((void));                             /* misc.c
V */
XUWORD    makeword          __((byte *b));                          /* misc.c
V */
XULONG    makelong          __((byte *sig));                        /* misc.c
V */
Xvoid     return_VMS        __((int zip_error));                    /* misc.c
V */
X
Xvoid     envargs           __((int *, char ***, char *));       /* envargs.c
V */
X
X#ifdef AMIGA
X   int   utime             __((char *file, time_t timep`5B`5D));      /* uti
Vme.c */
X#endif /* AMIGA */
X
X#ifdef ZMEM   /* these MUST be ifdef'd because of conflicts with the std def
V */
X   char  *memset           __((register char *buf, register char init,
X                               register unsigned int len));        /* misc.c
V */
X   char  *memcpy           __((register char *dst, register char *src,
X                               register unsigned int len));        /* misc.c
V */
X#endif /* ZMEM */
X
X
X
X
X
X/************/
X/*  Macros  */
X/************/
X
X#ifndef MAX
X#  define MAX(a,b)   ((a) > (b) ? (a) : (b))
X#endif
X
X#ifndef MIN
X#  define MIN(a,b)   ((a) < (b) ? (a) : (b))
X#endif
X
X
X#define LSEEK(abs_offset) `7Blongint request=(abs_offset)+extra_bytes,\
X   inbuf_offset=request%INBUFSIZ, bufstart=request-inbuf_offset;\
X   if(request<0) `7Bfprintf(stderr, SeekMsg, ReportMsg); return(3);`7D\
X   else if(bufstart!=cur_zipfile_bufstart)\
X   `7Bcur_zipfile_bufstart=lseek(zipfd,bufstart,SEEK_SET);\
X   if((incnt=read(zipfd,(char *)inbuf,INBUFSIZ))<=0) return(51);\
X   inptr=inbuf+(int)inbuf_offset; incnt-=(int)inbuf_offset;`7D else\
X   `7Bincnt+=(inptr-inbuf)-(int)inbuf_offset; inptr=inbuf+(int)inbuf_offset;
V`7D`7D
X
X/*
X *  Seek to the block boundary of the block which includes abs_offset,
X *  then read block into input buffer and set pointers appropriately.
X *  If block is already in the buffer, just set the pointers.  This macro
X *  is used by process_end_central_dir (unzip.c) and do_string (misc.c).
X *  A slightly modified version is embedded within extract_or_test_files
X *  (unzip.c).  ReadByte and readbuf (file_io.c) are compatible.
X *
X *  macro LSEEK(abs_offset)
X *      ULONG   abs_offset;
X *  `7B
X *      longint   request = abs_offset + extra_bytes;
X *      longint   inbuf_offset = request % INBUFSIZ;
X *      longint   bufstart = request - inbuf_offset;
X *
X *      if (request < 0) `7B
X *          fprintf(stderr, SeekMsg, ReportMsg);
X *          return(3);             /-* 3:  severe error in zipfile *-/
X *      `7D else if (bufstart != cur_zipfile_bufstart) `7B
X *          cur_zipfile_bufstart = lseek(zipfd, bufstart, SEEK_SET);
X *          if ((incnt = read(zipfd,inbuf,INBUFSIZ)) <= 0)
X *              return(51);        /-* 51:  unexpected EOF *-/
X *          inptr = inbuf + (int)inbuf_offset;
X *          incnt -= (int)inbuf_offset;
X *      `7D else `7B
X *          incnt += (inptr-inbuf) - (int)inbuf_offset;
X *          inptr = inbuf + (int)inbuf_offset;
X *      `7D
X *  `7D
X *
X */
X
X
X#define SKIP_(length) if(length&&((error=do_string(length,SKIP))!=0))\
X  `7Berror_in_archive=error; if(error>1) return error;`7D
X
X/*
X *  Skip a variable-length field, and report any errors.  Used in zipinfo.c
X *  and unzip.c in several functions.
X *
X *  macro SKIP_(length)
X *      UWORD   length;
X *  `7B
X *      if (length && ((error = do_string(length, SKIP)) != 0)) `7B
X *          error_in_archive = error;   /-* might be warning *-/
X *          if (error > 1)              /-* fatal *-/
X *              return (error);
X *      `7D
X *  `7D
X *
X */
X
X
X#define OUTB(intc) `7B*outptr++=(byte)(intc); if (++outcnt==OUTBUFSIZ)\
X  FlushOutput();`7D
X
X/*
X *  macro OUTB(intc)
X *  `7B
X *      *outptr++ = (byte)(intc);
X *      if (++outcnt == OUTBUFSIZ)
X *          FlushOutput();
X *  `7D
X *
X */
X
X
X#define READBIT(nbits,zdest) `7Bif(nbits>bits_left) FillBitBuffer();\
X  zdest=(int)((UWORD)bitbuf&mask_bits`5Bnbits`5D);bitbuf>>=nbits;bits_left-=
Vnbits;`7D
X
X/*
X * macro READBIT(nbits,zdest)
X *  `7B
X *      if (nbits > bits_left)
X *          FillBitBuffer();
X *      zdest = (int)((UWORD)bitbuf & mask_bits`5Bnbits`5D);
X *      bitbuf >>= nbits;
X *      bits_left -= nbits;
X *  `7D
X *
X */
X
X
X#define PEEKBIT(nbits) (nbits>bits_left? (FillBitBuffer(),\
X  (UWORD)bitbuf & mask_bits`5Bnbits`5D) : (UWORD)bitbuf & mask_bits`5Bnbits`
V5D)
X
X
X#define NUKE_CRs(buf,len) `7Bregister int i,j; for (i=j=0; j<len;\
X  (buf)`5Bi++`5D=(buf)`5Bj++`5D) if ((buf)`5Bj`5D=='\r') ++j; len=i;`7D
X
X/*
X *  Remove all the ASCII carriage returns from buffer buf (length len),
X *  shortening as necessary (note that len gets modified in the process,
X *  so it CANNOT be an expression).  This macro is intended to be used
X *  BEFORE A_TO_N(); hence the check for CR instead of '\r'.  NOTE:  The
X *  if-test gets performed one time too many, but it doesn't matter.
X *
X *  macro NUKE_CRs(buf,len)
X *  `7B
X *      register int   i, j;
X *
X *      for (i = j = 0;  j < len;  (buf)`5Bi++`5D = (buf)`5Bj++`5D)
X *          if ((buf)`5Bj`5D == CR)
X *              ++j;
X *      len = i;
X *  `7D
X *
X */
X
X
X#define TOLOWER(str1,str2) `7Bchar *ps1,*ps2; ps1=(str1)-1; ps2=(str2);\
X  while(*++ps1) *ps2++=(char)(isupper((int)(*ps1))?tolower((int)(*ps1)):*ps1
V);\
X  *ps2='\0';`7D
X
X/*
X *  Copy the zero-terminated string in str1 into str2, converting any
X *  uppercase letters to lowercase as we go.  str2 gets zero-terminated
X *  as well, of course.  str1 and str2 may be the same character array.
X *
X *  macro TOLOWER( str1, str2 )
X *  `7B
X *      char  *ps1, *ps2;
X *
X *      ps1 = (str1) - 1;
X *      ps2 = (str2);
X *      while (*++ps1)
X *          *ps2++ = (char)(isupper((int)(*ps1))? tolower((int)(*ps1)) : *ps
V1);
X *      *ps2='\0';
X *  `7D
X *
X *  NOTES:  This macro makes no assumptions about the characteristics of
X *    the tolower() function or macro (beyond its existence), nor does it
X *    make assumptions about the structure of the character set (i.e., it
X *    should work on EBCDIC machines, too).  The fact that either or both
X *    of isupper() and tolower() may be macros has been taken into account;
X *    watch out for "side effects" (in the C sense) when modifying this
X *    macro.
X */
X
X
X#ifndef ascii_to_native
X#  define ascii_to_native(c)   (c)
X#  define A_TO_N(str1)
X#else
X#  ifndef NATIVE
X#    define NATIVE     "native chars"
X#  endif
X#  define A_TO_N(str1) `7Bregister unsigned char *ps1;\
X     for (ps1=str1; *ps1; ps1++) *ps1=ascii_to_native(*ps1);`7D
X#endif
X
X/*
X *  Translate the zero-terminated string in str1 from ASCII to the native
X *  character set. The translation is performed in-place and uses the
X *  ascii_to_native macro to translate each character.
X *
X *  macro A_TO_N( str1 )
X *  `7B
X *      register unsigned char *ps1;
X *
X *      for (ps1 = str1;  *ps1;  ++ps1)
X *          *ps1 = ascii_to_native(*ps1);
X *  `7D
X *
X *  NOTE:  Using the ascii_to_native macro means that is it the only part of
X *    unzip which knows which translation table (if any) is actually in use
X *    to produce the native character set.  This makes adding new character
X *    set translation tables easy, insofar as all that is needed is an
X *    appropriate ascii_to_native macro definition and the translation
X *    table itself.  Currently, the only non-ASCII native character set
X *    implemented is EBCDIC, but this may not always be so.
X */
X
X
X
X
X
X/*************/
X/*  Globals  */
X/*************/
X
X   extern int       aflag;
X/* extern int       bflag;   reserved */
X   extern int       cflag;
X   extern int       fflag;
X   extern int       jflag;
X   extern int       overwrite_none;
X   extern int       overwrite_all;
X   extern int       force_flag;
X   extern int       quietflg;
X#ifdef DOS_OS2
X   extern int       sflag;
X#endif
X   extern int       tflag;
X   extern int       uflag;
X   extern int       V_flag;
X#ifdef VMS
X   extern int       secinf;
X#endif
X#ifdef MACOS
X   extern int       hfsflag;
X#endif
X   extern int       process_all_files;
X   extern longint   csize;
X   extern longint   ucsize;
X   extern char      *fnames`5B`5D;
X   extern char      **fnv;
X   extern char      sig`5B`5D;
X   extern char      answerbuf`5B`5D;
X   extern min_info  *pInfo;
X   extern char      *key;
X   extern ULONG     keys`5B`5D;
X
X#ifdef MACOS
X   union work `7B
X     struct `7B
X       short *Prefix_of;        /* (8193 * sizeof(short)) */
X       byte *Suffix_of;
X       byte *Stack;
X     `7D shrink;
X     byte *Slide;
X   `7D;
X#else
X   union work `7B
X     struct `7B
X       short Prefix_of`5BHSIZE + 2`5D;      /* (8194 * sizeof(short)) */
X       byte Suffix_of`5BHSIZE + 2`5D;       /* also s-f length_nodes (smalle
Vr) */
X       byte Stack`5BHSIZE + 2`5D;           /* also s-f distance_nodes (smal
Vler) */
X     `7D shrink;
X     byte Slide`5BWSIZE`5D;
X   `7D;
X#endif
X   extern union work area;
X
X#  define prefix_of area.shrink.Prefix_of
X#  define suffix_of area.shrink.Suffix_of
X#  define stack area.shrink.Stack
X#  define slide area.Slide
X
X   extern ULONG     crc32val;
X   extern UWORD     mask_bits`5B`5D;
X
X   extern byte      *inbuf;
X   extern byte      *inptr;
X   extern int       incnt;
X   extern ULONG     bitbuf;
X   extern int       bits_left;
X   extern boolean   zipeof;
X   extern int       zipfd;
X#ifdef MSWIN
X   extern char      *zipfn;
X#else
X   extern char      zipfn`5B`5D;
X#endif
X   extern longint   extra_bytes;
X   extern longint   cur_zipfile_bufstart;
X   extern byte      *extra_field;
X   extern char      local_hdr_sig`5B`5D;
X   extern char      central_hdr_sig`5B`5D;
X   extern char      end_central_sig`5B`5D;
X   extern local_file_hdr  lrec;
X   extern cdir_file_hdr   crec;
X   extern ecdir_rec       ecrec;
X   extern struct stat     statbuf;
X
X   extern byte      *outbuf;
X   extern byte      *outptr;
X#ifdef MSWIN
X   extern byte __far *outout;
X   extern char     *filename;
X#else
X   extern byte      *outout;
X   extern char      filename`5B`5D;
X#endif
X   extern longint   outpos;
X   extern int       outcnt;
X   extern int       outfd;
X   extern int       mem_mode;
X   extern int       disk_full;
X
X   extern char      *EndSigMsg;
X   extern char      *CentSigMsg;
X   extern char      *SeekMsg;
X   extern char      *ReportMsg;
X
X#ifdef DECLARE_ERRNO
X   extern int       errno;
X#endif
X
X#ifdef EBCDIC
X   extern byte      ebcdic`5B`5D;
X#endif
X
X#ifdef MACOS
X   extern short     gnVRefNum;
X   extern long      glDirID;
X   extern OSType    gostCreator;
X   extern OSType    gostType;
X   extern boolean   fMacZipped;
X   extern boolean   macflag;
X   extern short     giCursor;
X   extern CursHandle rghCursor`5B`5D;
X#endif
$ CALL UNPACK [.UNZIP50]UNZIP.H;1 2002099974
$ create 'f'
X.!
X.!  File:`09UNZIP.RNH
X.!
X.!  Author:`09Hunter Goatley
X.!
X.!  Date:`09October 23, 1991
X.!
X.!  Description:
X.!
X.!`09RUNOFF source file for portable UNZIP on-line help for VMS.
X.!`09Adapted from UNZIP.MAN, distributed with UNZIP.
X.!
X.!`09To build:`09$ RUNOFF UNZIP.RNH
X.!`09`09`09$ LIBR/HELP/INSERT libr UNZIP
X.!
X.!  Modification history:
X.!
X.!`0901-001`09`09Hunter Goatley`09`0923-OCT-1991 09:21
X.!`09`09Genesis.
X.!`0901-002`09`09Cave Newt`09`0916-MAR-1992 22:37
X.!`09`09Update for UnZip 4.2.
X.!`0901-003`09`09Igor Mandrichenko`0923-MAY-1992 22:14
X.!`09`09Add -X option to command syntax.
X.!`0901-004`09`09Cave Newt`09`0924-MAY-1992 13:30
X.!`09`09Add UNZIP_OPTS environment variable help.
X.!
X.noflags
X.lm4 .rm72
X.indent -4
X1 UNZIP
X.br
XUnZip is used to extract files compressed and packaged by Zip (see HELP ZIP
Xfor information on ZIP).
X.sk
XFor a brief help on Zip and Unzip, run each without specifying any
Xparameters on the command line.
X.sk
XUNZIP will list, test, or extract from a ZIP archive.  ZIP archives are comm
Vonly
Xfound on MS-DOS systems; a VMS version of ZIP can also be found here.
X.sk
XArchive member extraction is implied by the absence of the -c, -p, -t, -l, -
Vv or
X-z options.  All archive members are processed unless a filespec is provided
V to
Xspecify a subset of the archive members.  The filespec is similar to an egre
Vp
Xexpression, and may contain:
X.sk
X.literal
X     *       matches a sequence of 0 or more characters
X     ?       matches exactly 1 character
X     \nnn    matches the character having octal code nnn
X     `5B...`5D   matches any single character found inside the brackets;
X             ranges are specified by a beginning character,
X             a hyphen, and an ending character.  If a '!' follows
X             the left bracket, then the range of characters
X             matched is complemented with respect to the ASCII
X             character set.
X.end literal
X.sk
XFormat:
X.sk;.lm+1;.literal
XUNZIP `5B-cflptuvxz`5BajnoqUVX`5D`5D file`5B.zip`5D `5Bfilespec...`5D
X.end literal;.lm-1
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Parameters
X.sk;.indent -4
Xfile`5B.zip`5D
X.sk
XFile specification for the ZIP archive.  The suffix .ZIP is applied if the
Xspecified file does not exist.  Note that self-extracting ZIP files are
Xsupported; just specify the .EXE suffix yourself.
X.sk;.indent -4
X`5Bfilespec`5D
X.sk
XAn optional list of archive members to be processed.  Expressions may be
Xused to match multiple members.  Expressions should be enclosed in double-qu
Votes
Xto prevent interpretation by DCL.  Multiple filenames should be separated by
Xblanks.
X.!--------------------------------------------------------------------------
V----
X.indent -4
X2 Options
X.br
XThe default action of UnZip is to extract all zipfile entries.  The followin
Vg
Xoptions and modifiers can be provided:
X.sk;.literal
X   -c   extract files to SYS$OUTPUT (terminal)
X   -f   freshen existing files (replace if newer); create none
X   -l   list archive files (short format)
X   -p   extract files to SYS$OUTPUT; no informational messages
X   -t   test archive files
X   -u   update existing files; create new ones if needed
X   -v   list archive files (verbose format)
X   -x   extract files in archive (default)
X   -z   display only the archive comment
X.end literal;.sk;.literal
X MODIFIERS
X   -a   convert to VMS textfile format (only use for TEXT files!)
X   -j   junk paths (don't recreate archive's directory structure)
X   -n   never overwrite existing files; don't prompt
X   -o   OK to overwrite files without prompting
X   -q   perform operations quietly (-qq => even quieter)
X   -U   leave filenames uppercase if created under MS-DOS, VMS, etc.
X   -V   retain (VMS) file version numbers
X   -X   restore owner/protection info (may require privileges)
X.end literal;.sk
X! `5Bthis should probably be a separate section`5D:
XIn addition, default options may be specified via the UNZIP_OPTS logical.
XFor example, the following will cause UnZip to restore owner/protection
Xinformation and perform all operations at quiet-level 1 by default:
X.sk;.literal
X    define UNZIP_OPTS "-qX"
X.end literal;.sk
XNote that the quotation marks are required to preserve lowercase options.
XTo negate a default option on the command line, add one or more minus`20
Xsigns before the option letter, in addition to the leading switch character
X`60-':
X.sk;.literal
X    unzip --ql zipfile
X.end literal
Xor
X.literal
X    unzip -l-q zipfile
X.end literal;.sk
XAt present it is not possible to decrement an option below zero--that is,
Xmore than a few minuses have no effect.
X.sk
XUNZIP_OPTS may be defined as a symbol rather than a logical, but if both
Xare defined, the logical is used.
X.!--------------------------------------------------------------------------
V---
X.indent -4
X2 Authors
X.br
XSamuel H. Smith, Usenet contributors, and Info-ZIP.
X.sk
XVMS on-line help ported from UNZIP.MAN by Hunter Goatley.
$ CALL UNPACK [.UNZIP50]UNZIP.RNH;1 1141060954
$ create 'f'
X/*************************************************************************
X *                                                                       *
X * Copyright (C) 1992 Igor Mandrichenko.                                 *
X * Permission is granted to any individual or institution to use, copy,  *
X * or redistribute this software so long as all of the original files    *
X * are included unmodified, that it is not sold for profit, and that     *
X * this copyright notice is retained.                                    *
X *                                                                       *
X *************************************************************************/
X
X/*
X *    vms.c  by Igor Mandrichenko
X *    version 1.2-1
X *
X *    This module contains routines to extract VMS file attributes
X *    from extra field and create file with these attributes.  This
X *    source is mainly based on sources of file_io.c from UNZIP 4.1
X *    by Info-ZIP.  `5BInfo-ZIP note:  very little of this code is from
X *    file_io.c; it has virtually been written from the ground up.
X *    Of the few lines which are from the older code, most are mine
X *    (G. Roelofs) and I make no claims upon them.  On the contrary,
X *    my/our thanks to Igor for his contributions!`5D
X */
X
X/*
X *      Revision history:
X *      1.0-1   Mandrichenko    16-feb-1992
X *              Recognize -c option
X *      1.0-2   Mandrichenko    17-feb-1992
X *              Do not use ASYnchroneous mode.
X *      1.0-3   Mandrichenko    2-mar-1992
X *              Make code more standard
X *              Use lrec instead of crec -- unzip4.2p does not provide
X *              crec now.
X *      1.1     Mandrichenko    5-mar-1992
X *              Make use of asynchronous output.
X *              Be ready to extract RMS blocks of invalid size (because diff
X *              VMS version used to compress).
X *      1.1-1   Mandrichenko    11-mar-1992
X *              Use internal file attributes saved in pInfo to decide
X *              if the file is text.  `5BGRR:  temporarily disabled, since
X *              no way to override and force binary extraction`5D
X *      1.1-2   Mandrichenko    13-mar-1992
X *              Do not restore owner/protection info if -X not specified.
X *      1.1-3   Mandrichenko    30-may-1992
X *              Set revision date/time to creation date/time if none specifi
Ved
X *              Take quiet flag into account.
X *      1.1-4   Cave Newt       14-jun-1992
X *              Check zipfile for variable-length format (unzip and zipinfo)
V.
X *`091.2`09Mandrichenko`0921-jun-1992
X *`09`09Use deflation/inflation for compression of extra blocks
X *`09`09Free all allocated space
X *`091.2-1`09Mandrichenko`0923-jun-1992
X *`09`09Interactively select an action when file exists
X */
X
X#ifdef VMS`09`09`09/*      VMS only !      */
X
X#ifndef SYI$_VERSION
X#define SYI$_VERSION 4096`09/* VMS 5.4 definition */
X#endif
X
X#ifndef VAXC
X`09`09`09`09/* This definition may be missed */
Xstruct XAB `7B
X    unsigned char xab$b_cod;
X    unsigned char xab$b_bln;
X    short int xabdef$$_fill_1;
X    char *xab$l_nxt;
X`7D;
X
X#endif
X
X#include "unzip.h"
X#include <ctype.h>
X#include <descrip.h>
X#include <syidef.h>
X
X#define ERR(s) !((s) & 1)
X
X#define BUFS512 8192*2`09`09/* Must be a multiple of 512 */
X
X/*
X*   Local static storage
X*/
Xstatic struct FAB fileblk;
Xstatic struct XABDAT dattim;
Xstatic struct XABRDT rdt;
Xstatic struct RAB rab;
X
Xstatic struct FAB *outfab = 0;
Xstatic struct RAB *outrab = 0;
Xstatic struct XABFHC *xabfhc = 0;
Xstatic struct XABDAT *xabdat = 0;
Xstatic struct XABRDT *xabrdt = 0;
Xstatic struct XABPRO *xabpro = 0;
Xstatic struct XABKEY *xabkey = 0;
Xstatic struct XABALL *xaball = 0;
Xstruct XAB *first_xab = 0L, *last_xab = 0L;
X
Xstatic char query = 0;
Xstatic int text_file = 0;
X
Xstatic char locbuf`5BBUFS512`5D;
Xstatic int loccnt = 0;
Xstatic char *locptr;
X
Xstatic int WriteBuffer();
Xstatic int _flush_blocks();
Xstatic int _flush_records();
Xstatic byte *extract_block();
Xstatic void message();
Xstatic int get_vms_version();
Xstatic void free_up();
Xstatic int replace();
X
Xstruct bufdsc
X`7B
X    struct bufdsc *next;
X    byte *buf;
X    int bufcnt;
X`7D;
X
Xstatic struct bufdsc b1, b2, *curbuf;
Xstatic byte buf1`5BBUFS512`5D, buf2`5BBUFS512`5D;
X
X
Xint check_format()`09`09/* return non-0 if format is variable-length */
X`7B
X    int rtype;
X    struct FAB fab;
X
X    fab = cc$rms_fab;
X    fab.fab$l_fna = zipfn;
X    fab.fab$b_fns = strlen(zipfn);
X    sys$open(&fab);
X    rtype = fab.fab$b_rfm;
X    sys$close(&fab);
X
X    if (rtype == FAB$C_VAR `7C`7C rtype == FAB$C_VFC)
X    `7B
X`09fprintf(stderr,
X`09`09"\n     Error:  zipfile is in variable-length record format.  Please\n
V\
X     run \"bilf l %s\" to convert the zipfile to stream-LF\n\
X     record format.  (Bilf.exe, bilf.c and make_bilf.com are included\n\
X     in the VMS UnZip source distribution.)\n\n", zipfn);
X`09return 2;`09`09/* 2:  error in zipfile */
X    `7D
X
X    return 0;
X`7D
X
X
X#ifndef ZIPINFO
X
Xint create_output_file()
X`7B`09`09`09`09/* return non-0 if sys$create failed */
X    int ierr, yr, mo, dy, hh, mm, ss;
X    char timbuf`5B24`5D;`09`09/* length = first entry in "stupid" + 1 */
X    int attr_given = 0;`09`09/* =1 if VMS attributes are present in
X`09`09`09`09*     extra_field */
X
X    rab = cc$rms_rab;`09`09/* fill FAB & RAB with default values */
X    fileblk = cc$rms_fab;
X
X    text_file =/* pInfo->text `7C`7C */aflag `7C`7C cflag;
X
X    if (attr_given = find_vms_attrs())
X    `7B
X`09text_file = 0;
X`09if (cflag)
X`09`7B
X`09    printf("Cannot put VMS file %s to stdout.\n",
X`09`09   filename);
X`09    free_up();
X`09    return 50;
X`09`7D
X    `7D
X
X    if (!attr_given)
X    `7B
X`09outfab = &fileblk;
X`09outfab->fab$l_xab = 0L;
X`09if (text_file)
X`09`7B
X`09    outfab->fab$b_rfm = FAB$C_VAR;`09/* variable length records */
X`09    outfab->fab$b_rat = FAB$M_CR;`09/* carriage-return carriage ctrl */
X`09`7D
X`09else
X`09`7B
X`09    outfab->fab$b_rfm = FAB$C_STMLF;`09/* stream-LF record format */
X`09    outfab->fab$b_rat = FAB$M_CR;`09/* carriage-return carriage ctrl */
X`09`7D
X    `7D
X
X    if (!cflag)
X`09outfab->fab$l_fna = filename;
X    else
X`09outfab->fab$l_fna = "sys$output:";
X
X    outfab->fab$b_fns = strlen(outfab->fab$l_fna);
X
X    if ((!attr_given) `7C`7C xabdat == 0 `7C`7C xabrdt == 0)`09/* Use date/t
Vime info
X`09`09`09`09`09`09`09 *  from zipfile if
X`09`09`09`09`09`09`09 *  no attributes given
X`09`09`09`09`09`09`09 */
X    `7B
X`09static char *month`5B`5D =
X`09    `7B"JAN", "FEB", "MAR", "APR", "MAY", "JUN",
X`09     "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"`7D;
X
X`09/*  fixed-length string descriptor: */
X`09struct dsc$descriptor stupid =
X`09    `7B23, DSC$K_DTYPE_T, DSC$K_CLASS_S, timbuf`7D;
X
X`09yr = ((lrec.last_mod_file_date >> 9) & 0x7f) + 1980;
X`09mo = ((lrec.last_mod_file_date >> 5) & 0x0f) - 1;
X`09dy = (lrec.last_mod_file_date & 0x1f);
X`09hh = (lrec.last_mod_file_time >> 11) & 0x1f;
X`09mm = (lrec.last_mod_file_time >> 5) & 0x3f;
X`09ss = (lrec.last_mod_file_time & 0x1f) * 2;
X
X`09dattim = cc$rms_xabdat;`09/* fill XABs with default values */
X`09rdt = cc$rms_xabrdt;
X`09sprintf(timbuf, "%02d-%3s-%04d %02d:%02d:%02d.00", dy, month`5Bmo`5D, yr,
X`09`09hh, mm, ss);
X`09sys$bintim(&stupid, &dattim.xab$q_cdt);
X`09memcpy(&rdt.xab$q_rdt, &dattim.xab$q_cdt, sizeof(rdt.xab$q_rdt));
X
X`09if ((!attr_given) `7C`7C xabdat == 0L)
X`09`7B
X`09    dattim.xab$l_nxt = outfab->fab$l_xab;
X`09    outfab->fab$l_xab = &dattim;
X`09`7D
X    `7D
X
X    outfab->fab$w_ifi = 0;`09/* Clear IFI. It may be nonzero after ZIP */
X
X    ierr = sys$create(outfab);
X    if (ierr == RMS$_FEX)
X`09ierr = replace();
X
X    if (ierr == 0)`09`09/* Canceled */
X`09return free_up(), 1;
X
X    if (ERR(ierr))
X    `7B
X`09char buf`5B256`5D;
X
X`09sprintf(buf, "`5B Cannot create output file %s `5D\n", filename);
X`09message(buf, ierr);
X`09message("", outfab->fab$l_stv);
X`09free_up();
X`09return (1);
X    `7D
X
X    if (!text_file && !cflag)`09/* Do not reopen text files and stdout
X`09`09`09`09*  Just open them in right mode         */
X    `7B
X`09/*
X`09*       Reopen file for Block I/O with no XABs.
X`09*/
X`09if ((ierr = sys$close(outfab)) != RMS$_NORMAL)
X`09`7B
X#ifdef DEBUG
X`09    message("`5B create_output_file: sys$close failed `5D\n", ierr);
X`09    message("", outfab->fab$l_stv);
X#endif
X`09    fprintf(stderr, "Can't create output file:  %s\n", filename);
X`09    free_up();
X`09    return (1);
X`09`7D
X
X
X`09outfab->fab$b_fac = FAB$M_BIO `7C FAB$M_PUT;`09/* Get ready for block
X`09`09`09`09`09`09`09 * output */
X`09outfab->fab$l_xab = 0L;`09/* Unlink all XABs */
X
X`09if ((ierr = sys$open(outfab)) != RMS$_NORMAL)
X`09`7B
X`09    char buf`5B256`5D;
X
X`09    sprintf(buf, "`5B Cannot open output file %s `5D\n", filename);
X`09    message(buf, ierr);
X`09    message("", outfab->fab$l_stv);
X`09    free_up();
X`09    return (1);
X`09`7D
X    `7D
X
X    outrab = &rab;
X    rab.rab$l_fab = outfab;
X    if (!text_file) rab.rab$l_rop `7C= RAB$M_BIO;
X    if (!text_file) rab.rab$l_rop `7C= RAB$M_ASY;
X    rab.rab$b_rac = RAB$C_SEQ;
X
X    if ((ierr = sys$connect(outrab)) != RMS$_NORMAL)
X    `7B
X#ifdef DEBUG
X`09message("create_output_file: sys$connect failed.\n", ierr);
X`09message("", outfab->fab$l_stv);
X#endif
X`09fprintf(stderr, "Can't create output file:  %s\n", filename);
X`09free_up();
X`09return (1);
X    `7D
X
X    locptr = &locbuf`5B0`5D;
X    loccnt = 0;
X
X    b1.buf = &buf1`5B0`5D;
X    b1.bufcnt = 0;
X    b1.next = &b2;
X    b2.buf = &buf2`5B0`5D;
X    b2.bufcnt = 0;
X    b2.next = &b1;
X    curbuf = &b1;
X
X    return (0);
X`7D
X
Xstatic int replace()
X`7B`09`09`09`09/*
X`09`09`09`09*`09File exists. Inquire user about futher action.
X`09`09`09`09*/
X    char answ`5B10`5D;
X    struct NAM nam;
X    int ierr;
X
X    if (query == 0)
X    `7B
X`09do
X`09`7B
X`09    fprintf(stderr,
X`09`09    "Replace %s : `5Bo`5Dverwrite, new `5Bv`5Dersion or `5Bc`5Dancel (
VO,V,C - all) ? ",
X`09`09    filename);
X`09    fflush(stderr);
X`09`7D while (fgets(answ, 9, stderr) == NULL && !isalpha(answ`5B0`5D)
X`09`09 && tolower(answ`5B0`5D) != 'o'
X`09`09 && tolower(answ`5B0`5D) != 'v'
X`09`09 && tolower(answ`5B0`5D) != 'c');
X
X`09if (isupper(answ`5B0`5D))
X`09    query = answ`5B0`5D = tolower(answ`5B0`5D);
X    `7D
X    else
X`09answ`5B0`5D = query;
X
X    switch (answ`5B0`5D)
X    `7B
X`09case 'c':
X`09    ierr = 0;
X`09    break;
X`09case 'v':
X`09    nam = cc$rms_nam;
X`09    nam.nam$l_rsa = filename;
+-+-+-+-+-+-+-+-  END  OF PART 12 +-+-+-+-+-+-+-+-
Technical Details
Message-ID: <8009655@MVB.SAIC.COM>
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!rutgers!network.ucsd.edu!mvb.saic.com!vmsnet-sources

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!rutgers!network.ucsd.edu!mvb.saic.com!vmsnet-sources
From: goathunter@wkuvx1.bitnet
Newsgroups: vmsnet.sources
Subject: Zip v1.9 & UnZip v5.0, part 12/22
Message-ID: <8009655@MVB.SAIC.COM>
Date: 1 Sep 92 22:52:17 GMT
Organization: Western Kentucky University, Bowling Green, KY
Lines: 1456
Approved: Mark.Berryman@Mvb.Saic.Com