home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip511.zip / zipinfo.c < prev    next >
C/C++ Source or Header  |  1994-07-22  |  64KB  |  1,611 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   zipinfo.c
  4.  
  5.   This file contains all of the zipfile-listing routines for UnZip, inclu-
  6.   ding the bulk of what used to be the separate program ZipInfo.  All of
  7.   the ZipInfo routines are by Greg Roelofs; list_files is by the usual mish-
  8.   mash of Info-ZIP contributors (see the listing in CONTRIBS).
  9.  
  10.   Contains:  zi_opts()
  11.              zi_end_central()
  12.              zipinfo()
  13.              zi_long()
  14.              zi_short()
  15.              zi_time()
  16.              list_files()
  17.              ratio()
  18.              fnprint()
  19.  
  20.   ---------------------------------------------------------------------------*/
  21.  
  22.  
  23. #include "unzip.h"
  24.  
  25. static char unkn[16];
  26.  
  27. static int ratio OF((ulg uc, ulg c));
  28. static void fnprint OF((void));
  29.  
  30.  
  31. /********************************************/
  32. /*  Strings used in zipinfo.c (UnZip half)  */
  33. /********************************************/
  34.  
  35. /* also referenced in UpdateListBox() in updatelb.c (Windows version) */
  36. char Far HeadersS[] = " Length    Date    Time    Name";
  37. char Far HeadersS1[] = " ------    ----    ----    ----";
  38. char Far HeadersL[] = " Length  Method   Size  Ratio   Date    Time   CRC-32     Name";
  39. char Far HeadersL1[] = " ------  ------   ----  -----   ----    ----   ------     ----";
  40. char Far *Headers[][2] = { {HeadersS, HeadersS1}, {HeadersL, HeadersL1} };
  41.  
  42. static char Far CaseConversion[] = "%s (\"^\" ==> case\n%s   conversion)\n";
  43. static char Far CompFactorStr[] = "%c%d%%";
  44. static char Far CompMethodUnknown[] = "Unk:%03d";
  45. #ifdef MSWIN
  46.    static char Far LongHdrStats[] =
  47.      "%7lu  %-7s%7lu %4s  %02u-%02u-%02u  %02u:%02u  %08lx  %c%s";
  48.    static char Far LongFileHeader[] =
  49.      "%7lu         %7lu %4s                              %-7u";
  50.    static char Far ShortHdrStats[] = "%7lu  %02u-%02u-%02u  %02u:%02u  %c%s";
  51.    static char Far ShortFileHeader[] = "%7lu                    %-7u";
  52. #else /* !MSWIN */
  53.    static char Far LongHdrStats[] =
  54.      "%7lu  %-7s%7lu %4s  %02u-%02u-%02u  %02u:%02u  %08lx  %c";
  55.    static char Far ShortHdrStats[] = "%7lu  %02u-%02u-%02u  %02u:%02u  %c";
  56.    static char Far LongFileHeader[] =
  57.      " ------          ------  ---                         \
  58.      -------\n%7lu         %7lu %4s                              %-7u\n";
  59.    static char Far ShortFileHeader[] =
  60.      " ------                    -------\n%7lu                    %-7u\n";
  61. #endif /* ?MSWIN */
  62.  
  63.  
  64.  
  65. #ifndef NO_ZIPINFO  /* strings use up too much space in small-memory systems */
  66.  
  67. /* Define OS-specific attributes for use on ALL platforms--the S_xxxx
  68.  * versions of these are defined differently (or not defined) by different
  69.  * compilers and operating systems. */
  70.  
  71. #define UNX_IFMT       0170000     /* Unix file type mask */
  72. #define UNX_IFDIR      0040000     /* Unix directory */
  73. #define UNX_IFREG      0100000     /* Unix regular file */
  74. #define UNX_IFSOCK     0140000     /* Unix socket (BSD, not SysV or Amiga) */
  75. #define UNX_IFLNK      0120000     /* Unix symbolic link (not SysV, Amiga) */
  76. #define UNX_IFBLK      0060000     /* Unix block special       (not Amiga) */
  77. #define UNX_IFCHR      0020000     /* Unix character special   (not Amiga) */
  78. #define UNX_IFIFO      0010000     /* Unix fifo    (BCC, not MSC or Amiga) */
  79. #define UNX_ISUID      04000       /* Unix set user id on execution */
  80. #define UNX_ISGID      02000       /* Unix set group id on execution */
  81. #define UNX_ISVTX      01000       /* Unix directory permissions control */
  82. #define UNX_ENFMT      UNX_ISGID   /* Unix record locking enforcement flag */
  83. #define UNX_IRWXU      00700       /* Unix read, write, execute: owner */
  84. #define UNX_IRUSR      00400       /* Unix read permission: owner */
  85. #define UNX_IWUSR      00200       /* Unix write permission: owner */
  86. #define UNX_IXUSR      00100       /* Unix execute permission: owner */
  87. #define UNX_IRWXG      00070       /* Unix read, write, execute: group */
  88. #define UNX_IRGRP      00040       /* Unix read permission: group */
  89. #define UNX_IWGRP      00020       /* Unix write permission: group */
  90. #define UNX_IXGRP      00010       /* Unix execute permission: group */
  91. #define UNX_IRWXO      00007       /* Unix read, write, execute: other */
  92. #define UNX_IROTH      00004       /* Unix read permission: other */
  93. #define UNX_IWOTH      00002       /* Unix write permission: other */
  94. #define UNX_IXOTH      00001       /* Unix execute permission: other */
  95.  
  96. #define VMS_IRUSR      UNX_IRUSR   /* VMS read/owner */
  97. #define VMS_IWUSR      UNX_IWUSR   /* VMS write/owner */
  98. #define VMS_IXUSR      UNX_IXUSR   /* VMS execute/owner */
  99. #define VMS_IRGRP      UNX_IRGRP   /* VMS read/group */
  100. #define VMS_IWGRP      UNX_IWGRP   /* VMS write/group */
  101. #define VMS_IXGRP      UNX_IXGRP   /* VMS execute/group */
  102. #define VMS_IROTH      UNX_IROTH   /* VMS read/other */
  103. #define VMS_IWOTH      UNX_IWOTH   /* VMS write/other */
  104. #define VMS_IXOTH      UNX_IXOTH   /* VMS execute/other */
  105.  
  106. #define AMI_IFMT       06000       /* Amiga file type mask */
  107. #define AMI_IFDIR      04000       /* Amiga directory */
  108. #define AMI_IFREG      02000       /* Amiga regular file */
  109. #define AMI_IHIDDEN    00200       /* to be supported in AmigaDOS 3.x */
  110. #define AMI_ISCRIPT    00100       /* executable script (text command file) */
  111. #define AMI_IPURE      00040       /* allow loading into resident memory */
  112. #define AMI_IARCHIVE   00020       /* not modified since bit was last set */
  113. #define AMI_IREAD      00010       /* can be opened for reading */
  114. #define AMI_IWRITE     00004       /* can be opened for writing */
  115. #define AMI_IEXECUTE   00002       /* executable image, a loadable runfile */
  116. #define AMI_IDELETE    00001       /* can be deleted */
  117.  
  118. /* extra-field ID values: */
  119. #define EF_AV        0x0007   /* PKWARE authenticity verification */
  120. #define EF_OS2       0x0009   /* OS/2 extended attributes */
  121. #define EF_PKVMS     0x000c   /* PKWARE's VMS ID */
  122. #define EF_IZVMS     0x4d49   /* Info-ZIP's VMS ID ("IM") */
  123. #define EF_ASIUNIX   0x756e   /* ASi/PKWARE's Unix ID ("IM") */
  124. #define EF_SPARK     0x4341   /* David Pilling's Acorn/SparkFS ID ("AC") */
  125.  
  126. #define LFLAG  3   /* short "ls -l" type listing */
  127.  
  128. static int   zi_long   OF((void));
  129. static int   zi_short  OF((void));
  130. static char *zi_time   OF((ush *datez, ush *timez));
  131.  
  132.  
  133. /**********************************************/
  134. /*  Strings used in zipinfo.c (ZipInfo half)  */
  135. /**********************************************/
  136.  
  137. static char Far LongHeader[] = "Archive:  %s   %ld bytes   %d file%s\n";
  138. static char Far ShortHeader[] = "Archive:  %s   %ld   %d\n";
  139. static char Far EndCentDirRec[] = "\nEnd-of-central-directory record:\n";
  140. static char Far LineSeparators[] = "-------------------------------\n\n";
  141. static char Far ActOffsetCentDir[] = "\
  142.   Actual offset of end-of-central-dir record:   %9ld (%.8lXh)\n\
  143.   Expected offset of end-of-central-dir record: %9ld (%.8lXh)\n\
  144.   (based on the length of the central directory and its expected offset)\n\n";
  145. static char Far SinglePartArchive[] = "\
  146.   This zipfile constitutes the sole disk of a single-part archive; its\n\
  147.   central directory contains %u %s.  The central directory is %lu\n\
  148.   (%.8lXh) bytes long, and its (expected) offset in bytes from the\n\
  149.   beginning of the zipfile is %lu (%.8lXh).\n\n";
  150. static char Far MultiPartArchive[] = "\
  151.   This zipfile constitutes disk %u of a multi-part archive.  The central\n\
  152.   directory starts on disk %u; %u of its entries %s contained within\n\
  153.   this zipfile, out of a total of %u %s.  The entire central\n\
  154.   directory is %lu (%.8lXh) bytes long, and its offset in bytes from\n\
  155.   the beginning of the zipfile in which it begins is %lu (%.8lXh).\n\n";
  156. static char Far NoZipfileComment[] = "  There is no zipfile comment.\n";
  157. static char Far ZipfileCommentDesc[] =
  158.   "  The zipfile comment is %u bytes long and contains the following text:\n\n";
  159. static char Far ZipfileCommBegin[] =
  160.  "======================== zipfile comment begins ==========================\n";
  161. static char Far ZipfileCommEnd[] =
  162.  "========================= zipfile comment ends ===========================\n";
  163. static char Far ZipfileCommTrunc2[] = "\n  The zipfile comment is truncated.\n";
  164. static char Far ZipfileCommTruncMsg[] =
  165.   "\ncaution:  zipfile comment truncated\n";
  166.  
  167. #ifdef T20_VMS
  168.    static char Far CentralDirEntry[] = "\nCentral directory entry #%d:\n";
  169. #else
  170.    static char Far CentralDirEntry[] = "%s\nCentral directory entry #%d:\n";
  171. #endif
  172.  
  173. static char Far CentralDirLines[] = "---------------------------\n\n";
  174. static char Far ZipfileStats[] = 
  175.   "%d file%s, %lu bytes uncompressed, %lu bytes compressed:  %s%d.%d%%\n";
  176.  
  177. /* zi_long() strings */
  178. static char Far OS_FAT[] = "MS-DOS, OS/2 or NT FAT";
  179. static char Far OS_Amiga[] = "Amiga";
  180. static char Far OS_VAXVMS[] = "VAX VMS";
  181. static char Far OS_Unix[] = "Unix";
  182. static char Far OS_VMCMS[] = "VM/CMS";
  183. static char Far OS_AtariST[] = "Atari ST";
  184. static char Far OS_HPFS[] = "OS/2 or NT HPFS";
  185. static char Far OS_Macintosh[] = "Macintosh";
  186. static char Far OS_ZSystem[] = "Z-System";
  187. static char Far OS_CPM[] = "CP/M";
  188. static char Far OS_TOPS20[] = "TOPS-20";
  189. static char Far OS_NTFS[] = "NT NTFS";
  190. static char Far OS_QDOS[] = "QDOS (maybe)";
  191. static char Far OS_Acorn[] = "Acorn RISCOS";
  192.  
  193. static char Far MthdNone[] = "none (stored)";
  194. static char Far MthdShrunk[] = "shrunk";
  195. static char Far MthdRedF1[] = "reduced (factor 1)";
  196. static char Far MthdRedF2[] = "reduced (factor 2)";
  197. static char Far MthdRedF3[] = "reduced (factor 3)";
  198. static char Far MthdRedF4[] = "reduced (factor 4)";
  199. static char Far MthdImplode[] = "imploded";
  200. static char Far MthdToken[] = "tokenized";
  201. static char Far MthdDeflate[] = "deflated";
  202.  
  203. static char Far Unknown[] = "unknown (%d)";
  204.  
  205. static char Far HostOS[] =
  206.   "\n  host operating system (created on):               %s\n";
  207. static char Far EncodeSWVer[] =
  208.   "  version of encoding software:                     %d.%d\n";
  209. static char Far MinOSCompReq[] =
  210.   "  minimum operating system compatibility required:  %s\n";
  211. static char Far MinSWVerReq[] =
  212.   "  minimum software version required to extract:     %d.%d\n";
  213. static char Far CompressMethod[] =
  214.   "  compression method:                               %s\n";
  215. static char Far SlideWindowSizeImplode[] =
  216.   "  size of sliding dictionary (implosion):           %cK\n";
  217. static char Far ShannonFanoTrees[] =
  218.   "  number of Shannon-Fano trees (implosion):         %c\n";
  219. static char Far CompressSubtype[] =
  220.   "  compression sub-type (deflation):                 %s\n";
  221. static char Far FileSecurity[] =
  222.   "  file security status:                             %sencrypted\n";
  223. static char Far ExtendedLocalHdr[] =
  224.   "  extended local header:                            %s\n";
  225. static char Far FileModDate[] =
  226.   "  file last modified on:                            %s\n";
  227. static char Far CRC32Value[] =
  228.   "  32-bit CRC value (hex):                           %.8lx\n";
  229. static char Far CompressedFileSize[] =
  230.   "  compressed size:                                  %lu bytes\n";
  231. static char Far UncompressedFileSize[] =
  232.   "  uncompressed size:                                %lu bytes\n";
  233. static char Far FilenameLength[] =
  234.   "  length of filename:                               %u characters\n";
  235. static char Far ExtraFieldLength[] =
  236.   "  length of extra field:                            %u bytes\n";
  237. static char Far FileCommentLength[] =
  238.   "  length of file comment:                           %u characters\n";
  239. static char Far FileDiskNum[] =
  240.   "  disk number on which file begins:                 disk %u\n";
  241. static char Far ApparentFileType[] =
  242.   "  apparent file type:                               %s\n";
  243. static char Far VMSFileAttributes[] =
  244.   "  VMS file attributes (%06o octal):               %s\n";
  245. static char Far AmigaFileAttributes[] =
  246.   "  Amiga file attributes (%06o octal):             %s\n";
  247. static char Far UnixFileAttributes[] =
  248.   "  Unix file attributes (%06o octal):              %s\n";
  249. static char Far NonMSDOSFileAttributes[] =
  250.   "  non-MSDOS external file attributes:               %06lX hex\n";
  251. static char Far MSDOSFileAttributes[] =
  252.   "  MS-DOS file attributes (%02X hex):                  none\n";
  253. static char Far MSDOSFileAttributesRO[] =
  254.   "  MS-DOS file attributes (%02X hex):                  read-only\n";
  255. static char Far MSDOSFileAttributesAlpha[] =
  256.   "  MS-DOS file attributes (%02X hex):                  %s%s%s%s%s%s\n";
  257. static char Far LocalHeaderOffset[] =
  258.   "  offset of local header from start of archive:     %lu (%.8lXh) bytes\n";
  259. static char Far ExtraFieldType[] = "\n\
  260.   The central-directory extra field has ID 0x%04x (%s) and has %u\n\
  261.   data bytes";
  262. static char Far OS2EAs[] = "\
  263. .  The local extra field has %lu bytes of OS/2 extended\n\
  264.   attributes (may not match OS/2 \"dir\" amount due to storage method).";
  265. static char Far First16[] = ".  The first 16 are%s";
  266. static char Far ColonIndent[] = ":\n     ";
  267. static char Far efFormat[] = " %02x";
  268. static char Far efAV[] = "PKWARE AV";
  269. static char Far efOS2[] = "OS/2";
  270. static char Far efPKVMS[] = "PKWARE VMS";
  271. static char Far efIZVMS[] = "Info-ZIP VMS";
  272. static char Far efASiUnix[] = "ASi Unix";
  273. /* static char Far efIZUnix[] = "Info-ZIP Unix"; */
  274. static char Far efSpark[] = "Acorn SparkFS";
  275. static char Far efUnknown[] = "unknown";
  276. static char Far NoFileComment[] = "\n  There is no file comment.\n";
  277. static char Far FileCommBegin[] = "\n\
  278. ------------------------- file comment begins ----------------------------\n";
  279. static char Far FileCommEnd[] = "\
  280. -------------------------- file comment ends -----------------------------\n";
  281. static char Far JanMonth[] = "Jan";
  282. static char Far FebMonth[] = "Feb";
  283. static char Far MarMonth[] = "Mar";
  284. static char Far AprMonth[] = "Apr";
  285. static char Far MayMonth[] = "May";
  286. static char Far JunMonth[] = "Jun";
  287. static char Far JulMonth[] = "Jul";
  288. static char Far AugMonth[] = "Aug";
  289. static char Far SepMonth[] = "Sep";
  290. static char Far OctMonth[] = "Oct";
  291. static char Far NovMonth[] = "Nov";
  292. static char Far DecMonth[] = "Dec";
  293. static char Far BogusFmt[] = "%03d";
  294. static char Far DMYHMTime[] = "%2u-%s-%02u %02u:%02u";
  295. static char Far YMDHMSTime[] = "%u %s %u %02u:%02u:%02u";
  296. static char Far DecimalTime[] = "%02u%02u%02u.%02u%02u%02u";
  297.  
  298.  
  299.  
  300.  
  301.  
  302. /************************/
  303. /*  Function zi_opts()  */
  304. /************************/
  305.  
  306. int zi_opts(pargc, pargv)
  307.     int *pargc;
  308.     char ***pargv;
  309. {
  310.     char   **argv, *s;
  311.     int    argc, c, error=FALSE, negative=0;
  312.     int    hflag_slmv=TRUE, hflag_2=FALSE;  /* diff options => diff defaults */
  313.     int    tflag_slm=TRUE, tflag_2v=FALSE;
  314.     int    explicit_h=FALSE, explicit_t=FALSE;
  315.  
  316.  
  317. #ifdef MACOS
  318.     lflag = LFLAG;   /* reset default on each call */
  319. #endif
  320.     argc = *pargc;
  321.     argv = *pargv;
  322.  
  323.     while (--argc > 0 && (*++argv)[0] == '-') {
  324.         s = argv[0] + 1;
  325.         while ((c = *s++) != 0) {    /* "!= 0":  prevent Turbo C warning */
  326.             switch (c) {
  327.                 case '-':
  328.                     ++negative;
  329.                     break;
  330.                 case '1':      /* shortest listing:  JUST filenames */
  331.                     if (negative)
  332.                         lflag = -2, negative = 0;
  333.                     else
  334.                         lflag = 1;
  335.                     break;
  336.                 case '2':      /* just filenames, plus headers if specified */
  337.                     if (negative)
  338.                         lflag = -2, negative = 0;
  339.                     else
  340.                         lflag = 2;
  341.                     break;
  342.                 case 'h':      /* header line */
  343.                     if (negative)
  344.                         hflag_2 = hflag_slmv = FALSE, negative = 0;
  345.                     else {
  346.                         hflag_2 = hflag_slmv = explicit_h = TRUE;
  347.                         if (lflag == -1)
  348.                             lflag = 0;
  349.                     }
  350.                     break;
  351.                 case 'l':      /* longer form of "ls -l" type listing */
  352.                     if (negative)
  353.                         lflag = -2, negative = 0;
  354.                     else
  355.                         lflag = 5;
  356.                     break;
  357.                 case 'm':      /* medium form of "ls -l" type listing */
  358.                     if (negative)
  359.                         lflag = -2, negative = 0;
  360.                     else
  361.                         lflag = 4;
  362.                     break;
  363.                 case 's':      /* default:  shorter "ls -l" type listing */
  364.                     if (negative)
  365.                         lflag = -2, negative = 0;
  366.                     else
  367.                         lflag = 3;
  368.                     break;
  369.                 case 't':      /* totals line */
  370.                     if (negative)
  371.                         tflag_2v = tflag_slm = FALSE, negative = 0;
  372.                     else {
  373.                         tflag_2v = tflag_slm = explicit_t = TRUE;
  374.                         if (lflag == -1)
  375.                             lflag = 0;
  376.                     }
  377.                     break;
  378.                 case ('T'):    /* use (sortable) decimal time format */
  379.                     if (negative)
  380.                         T_flag = FALSE, negative = 0;
  381.                     else
  382.                         T_flag = TRUE;
  383.                     break;
  384.                 case 'v':      /* turbo-verbose listing */
  385.                     if (negative)
  386.                         lflag = -2, negative = 0;
  387.                     else
  388.                         lflag = 10;
  389.                     break;
  390.                 case 'z':      /* print zipfile comment */
  391.                     if (negative)
  392.                         zflag = negative = 0;
  393.                     else
  394.                         zflag = 1;
  395.                     break;
  396.                 case 'Z':      /* ZipInfo mode:  ignore */
  397.                     break;
  398.                 default:
  399.                     error = TRUE;
  400.                     break;
  401.             }
  402.         }
  403.     }
  404.     if ((argc-- == 0) || error) {
  405.         *pargc = argc;
  406.         *pargv = argv;
  407.         return usage(error);
  408.     }
  409.  
  410.     /* if no listing options given (or all negated), or if only -h/-t given
  411.      * with individual files specified, use default listing format */
  412.     if ((lflag < 0) || ((argc > 0) && (lflag == 0)))
  413.         lflag = LFLAG;
  414.  
  415.     /* set header and totals flags to default or specified values */
  416.     switch (lflag) {
  417.         case 0:   /* 0:  can only occur if either -t or -h explicitly given; */
  418.         case 2:   /*  therefore set both flags equal to normally false value */
  419.             hflag = hflag_2;
  420.             tflag = tflag_2v;
  421.             break;
  422.         case 1:   /* only filenames, *always* */
  423.             hflag = FALSE;
  424.             tflag = FALSE;
  425.             zflag = FALSE;
  426.             break;
  427.         case 3:
  428.         case 4:
  429.         case 5:
  430.             hflag = ((argc > 0) && !explicit_h)? FALSE : hflag_slmv;
  431.             tflag = ((argc > 0) && !explicit_t)? FALSE : tflag_slm;
  432.             break;
  433.         case 10:
  434.             hflag = hflag_slmv;
  435.             tflag = tflag_2v;
  436.             break;
  437.     }
  438.  
  439.     *pargc = argc;
  440.     *pargv = argv;
  441.     return 0;
  442.  
  443. } /* end function zi_opts() */
  444.  
  445.  
  446.  
  447.  
  448.  
  449. /*******************************/
  450. /*  Function zi_end_central()  */
  451. /*******************************/
  452.  
  453. int zi_end_central()   /* return PK-type error code */
  454. {
  455.     int  error = PK_COOL;
  456.  
  457.  
  458. /*---------------------------------------------------------------------------
  459.     Print out various interesting things about the zipfile.
  460.   ---------------------------------------------------------------------------*/
  461.  
  462.     /* header fits on one line, for anything up to 10GB and 10000 files: */
  463.     if (hflag)
  464.         PRINTF(((int)strlen(zipfn) < 39)?
  465.           LoadFarString(LongHeader) :
  466.           LoadFarString(ShortHeader), zipfn, (long)ziplen,
  467.           ecrec.total_entries_central_dir,
  468.           (ecrec.total_entries_central_dir==1)? "":"s");
  469.  
  470.     /* verbose format */
  471.     if (lflag > 9) {
  472.         PRINTF(LoadFarString(EndCentDirRec));
  473.         PRINTF(LoadFarString(LineSeparators));
  474.  
  475.         PRINTF(LoadFarString(ActOffsetCentDir),
  476.           (long)real_ecrec_offset, (long)real_ecrec_offset,
  477.           (long)expect_ecrec_offset, (long)expect_ecrec_offset);
  478.  
  479.         if (ecrec.number_this_disk == 0) {
  480.             PRINTF(LoadFarString(SinglePartArchive),
  481.               ecrec.total_entries_central_dir,
  482.               (ecrec.total_entries_central_dir == 1)? "entry" : "entries",
  483.               ecrec.size_central_directory, ecrec.size_central_directory,
  484.               ecrec.offset_start_central_directory,
  485.               ecrec.offset_start_central_directory);
  486.         } else {
  487.             PRINTF(LoadFarString(MultiPartArchive),
  488.               ecrec.number_this_disk,
  489.               ecrec.num_disk_with_start_central_dir,
  490.               ecrec.num_entries_centrl_dir_ths_disk,
  491.               (ecrec.num_entries_centrl_dir_ths_disk == 1)? "is" : "are",
  492.               ecrec.total_entries_central_dir,
  493.               (ecrec.total_entries_central_dir == 1) ? "entry" : "entries",
  494.               ecrec.size_central_directory, ecrec.size_central_directory,
  495.               ecrec.offset_start_central_directory,
  496.               ecrec.offset_start_central_directory);
  497.         }
  498.  
  499.     /*-----------------------------------------------------------------------
  500.         Get the zipfile comment, if any, and print it out.  (Comment may be
  501.         up to 64KB long.  May the fleas of a thousand camels infest the arm-
  502.         pits of anyone who actually takes advantage of this fact.)
  503.       -----------------------------------------------------------------------*/
  504.  
  505.         if (!ecrec.zipfile_comment_length)
  506.             PRINTF(LoadFarString(NoZipfileComment));
  507.         else {
  508.             PRINTF(LoadFarString(ZipfileCommentDesc),
  509.               ecrec.zipfile_comment_length );
  510.             PRINTF(LoadFarString(ZipfileCommBegin));
  511.             if (do_string(ecrec.zipfile_comment_length, DISPLAY))
  512.                 error = PK_WARN;
  513.             PRINTF(LoadFarString(ZipfileCommEnd));
  514.             if (error)
  515.                 PRINTF(LoadFarString(ZipfileCommTrunc2));
  516.         } /* endif (comment exists) */
  517.  
  518.     /* non-verbose mode:  print zipfile comment only if requested */
  519.     } else if (zflag && ecrec.zipfile_comment_length) {
  520.         if (do_string(ecrec.zipfile_comment_length,DISPLAY)) {
  521.             FPRINTF(stderr, LoadFarString(ZipfileCommTruncMsg));
  522.             error = PK_WARN;
  523.         }
  524.     } /* endif (verbose) */
  525.  
  526.     return error;
  527.  
  528. } /* end function zi_end_central() */
  529.  
  530.  
  531.  
  532.  
  533.  
  534. /************************/
  535. /*  Function zipinfo()  */
  536. /************************/
  537.  
  538. int zipinfo()   /* return PK-type error code */
  539. {
  540.     int   j, do_this_file=FALSE, error, error_in_archive=PK_COOL;
  541.     int   *fn_matched=NULL, *xn_matched=NULL;
  542.     ush   members=0;
  543.     ulg   tot_csize=0L, tot_ucsize=0L;
  544.  
  545.  
  546. /*---------------------------------------------------------------------------
  547.     Malloc space for check on unmatched filespecs (no big deal if one or both
  548.     are NULL).
  549.   ---------------------------------------------------------------------------*/
  550.  
  551.     if (filespecs > 0  &&
  552.         (fn_matched=(int *)malloc(filespecs*sizeof(int))) != NULL)
  553.         for (j = 0;  j < filespecs;  ++j)
  554.             fn_matched[j] = FALSE;
  555.  
  556.     if (xfilespecs > 0  &&
  557.         (xn_matched=(int *)malloc(xfilespecs*sizeof(int))) != NULL)
  558.         for (j = 0;  j < xfilespecs;  ++j)
  559.             xn_matched[j] = FALSE;
  560.  
  561. /*---------------------------------------------------------------------------
  562.     Set file pointer to start of central directory, then loop through cen-
  563.     tral directory entries.  Check that directory-entry signature bytes are
  564.     actually there (just a precaution), then process the entry.  We know
  565.     the entire central directory is on this disk:  we wouldn't have any of
  566.     this information unless the end-of-central-directory record was on this
  567.     disk, and we wouldn't have gotten to this routine unless this is also
  568.     the disk on which the central directory starts.  In practice, this had
  569.     better be the *only* disk in the archive, but maybe someday we'll add
  570.     multi-disk support.
  571.   ---------------------------------------------------------------------------*/
  572.  
  573.     pInfo->lcflag = 0;    /* used in do_string():  never TRUE in zipinfo mode */
  574.     pInfo->textmode = 0;  /* so one can read on screen (but is it ever used?) */
  575.  
  576.     for (j = 0;  j < (int)ecrec.total_entries_central_dir;  ++j) {
  577.         if (readbuf(sig, 4) == 0)
  578.             return PK_EOF;
  579.         if (strncmp(sig, central_hdr_sig, 4)) {  /* just to make sure */
  580.             FPRINTF(stderr, LoadFarString(CentSigMsg), j);  /* sig not found */
  581.             return PK_BADERR;
  582.         }
  583.         if ((error = get_cdir_ent()) != PK_COOL)
  584.             return error;       /* only PK_EOF defined */
  585.  
  586.         /* do Amigas (AMIGA_) also have volume labels? */
  587.         if (IS_VOLID(crec.external_file_attributes) &&
  588.             (pInfo->hostnum == FS_FAT_ || pInfo->hostnum == FS_HPFS_ ||
  589.              pInfo->hostnum == FS_NTFS_ || pInfo->hostnum == ATARI_))
  590.             pInfo->vollabel = TRUE;
  591.         else
  592.             pInfo->vollabel = FALSE;
  593.  
  594.         if ((error = do_string(crec.filename_length, FILENAME)) != PK_COOL) {
  595.           error_in_archive = error;   /* might be warning */
  596.           if (error > PK_WARN)        /* fatal */
  597.               return error;
  598.         }
  599.  
  600.         if (!process_all_files) {    /* check if specified on command line */
  601.             char  **pfn = pfnames-1;
  602.  
  603.             do_this_file = FALSE;
  604.             while (*++pfn)
  605.                 if (match(filename, *pfn, 0)) {
  606.                     do_this_file = TRUE;
  607.                     if (fn_matched)
  608.                         fn_matched[pfn-pfnames] = TRUE;
  609.                     break;       /* found match, so stop looping */
  610.                 }
  611.             if (do_this_file) {  /* check if this is an excluded file */
  612.                 char  **pxn = pxnames-1;
  613.  
  614.                 while (*++pxn)
  615.                     if (match(filename, *pxn, 0)) {
  616.                         do_this_file = FALSE;
  617.                         if (xn_matched)
  618.                             xn_matched[pxn-pxnames] = TRUE;
  619.                         break;
  620.                     }
  621.             }
  622.         }
  623.  
  624.     /*-----------------------------------------------------------------------
  625.         If current file was specified on command line, or if no names were
  626.         specified, do the listing for this file.  Otherwise, get rid of the
  627.         file comment and go back for the next file.
  628.       -----------------------------------------------------------------------*/
  629.  
  630.         if (process_all_files || do_this_file) {
  631.  
  632.             switch (lflag) {
  633.                 case 1:
  634.                 case 2:
  635.                     fnprint();
  636.                     SKIP_(crec.extra_field_length)
  637.                     SKIP_(crec.file_comment_length)
  638.                     break;
  639.  
  640.                 case 3:
  641.                 case 4:
  642.                 case 5:
  643.                     if ((error = zi_short()) != PK_COOL) {
  644.                         error_in_archive = error;   /* might be warning */
  645.                         if (error > PK_WARN)        /* fatal */
  646.                             return error;
  647.                     }
  648.                     break;
  649.  
  650.                 case 10:
  651. #ifdef T20_VMS  /* GRR:  add cbreak-style "more" */
  652.                     PRINTF(LoadFarString(CentralDirEntry), j);
  653. #else
  654.                     /* formfeed/CR for piping to "more": */
  655.                     PRINTF(LoadFarString(CentralDirEntry), "\014", j);
  656. #endif
  657.                     PRINTF(LoadFarString(CentralDirLines));
  658.  
  659.                     if ((error = zi_long()) != PK_COOL) {
  660.                         error_in_archive = error;   /* might be warning */
  661.                         if (error > PK_WARN)        /* fatal */
  662.                             return error;
  663.                     }
  664.                     break;
  665.  
  666.                 default:
  667.                     SKIP_(crec.extra_field_length)
  668.                     SKIP_(crec.file_comment_length)
  669.                     break;
  670.  
  671.             } /* end switch (lflag) */
  672.  
  673.             tot_csize += crec.csize;
  674.             tot_ucsize += crec.ucsize;
  675.             if (crec.general_purpose_bit_flag & 1)
  676.                 tot_csize -= 12;   /* don't count encryption header */
  677.             ++members;
  678.  
  679.         } else {   /* not listing */
  680.             SKIP_(crec.extra_field_length)
  681.             SKIP_(crec.file_comment_length)
  682.  
  683.         } /* end if (list member?) */
  684.  
  685.     } /* end for-loop (j: member files) */
  686.  
  687. /*---------------------------------------------------------------------------
  688.     Double check that we're back at the end-of-central-directory record.
  689.   ---------------------------------------------------------------------------*/
  690.  
  691.     if (readbuf(sig, 4) == 0)  /* disk error? */
  692.         return PK_EOF;
  693.     if (strncmp(sig, end_central_sig, 4)) {     /* just to make sure again */
  694.         FPRINTF(stderr, LoadFarString(EndSigMsg));  /* didn't find sig */
  695.         error_in_archive = PK_WARN;
  696.     }
  697.  
  698. /*---------------------------------------------------------------------------
  699.     Check that we actually found requested files; if so, print totals.
  700.   ---------------------------------------------------------------------------*/
  701.  
  702.     if (tflag) {
  703.         char *sgn = "";
  704.         int cfactor = ratio(tot_ucsize, tot_csize);
  705.  
  706.         if (cfactor < 0) {
  707.             sgn = "-";
  708.             cfactor = -cfactor;
  709.         }
  710.         PRINTF(LoadFarString(ZipfileStats),
  711.           members, (members==1)? "":"s", tot_ucsize, tot_csize, sgn, cfactor/10,
  712.           cfactor%10);
  713.     }
  714.  
  715. /*---------------------------------------------------------------------------
  716.     Check for unmatched filespecs on command line and print warning if any
  717.     found.
  718.   ---------------------------------------------------------------------------*/
  719.  
  720.     if (fn_matched) {
  721.         for (j = 0;  j < filespecs;  ++j)
  722.             if (!fn_matched[j])
  723.                 FPRINTF(stderr, LoadFarString(FilenameNotMatched),
  724.                   pfnames[j]);
  725.         free(fn_matched);
  726.     }
  727.     if (xn_matched) {
  728.         for (j = 0;  j < xfilespecs;  ++j)
  729.             if (!xn_matched[j])
  730.                 FPRINTF(stderr, LoadFarString(ExclFilenameNotMatched),
  731.                   pxnames[j]);
  732.         free(xn_matched);
  733.     }
  734.     if (members == 0 && error_in_archive <= PK_WARN)
  735.         error_in_archive = PK_FIND;
  736.  
  737.     return error_in_archive;
  738.  
  739. } /* end function zipinfo() */
  740.  
  741.  
  742.  
  743.  
  744.  
  745. #define OS_unkn unkn
  746.  
  747. /************************/
  748. /*  Function zi_long()  */
  749. /************************/
  750.  
  751. static int zi_long()   /* return PK-type error code */
  752. {
  753.     int  error, error_in_archive=PK_COOL;
  754.     ush  hostnum, hostver, extnum, extver, methnum, xattr;
  755.     char workspace[12], attribs[22];
  756.     static char meth_unkn[16];
  757.     static char Far *os[NUM_HOSTS+1] = {
  758.         OS_FAT, OS_Amiga, OS_VAXVMS, OS_Unix, OS_VMCMS, OS_AtariST, OS_HPFS,
  759.         OS_Macintosh, OS_ZSystem, OS_CPM, OS_TOPS20, OS_NTFS, OS_QDOS,
  760.         OS_Acorn, OS_unkn
  761.     };
  762.     static char Far *method[NUM_METHODS+1] = {
  763.         MthdNone, MthdShrunk, MthdRedF1, MthdRedF2, MthdRedF3, MthdRedF4,
  764.         MthdImplode, MthdToken, MthdDeflate, meth_unkn
  765.     };
  766.     static char *dtype[4] = {"normal", "maximum", "fast", "superfast"};
  767.  
  768.  
  769. /*---------------------------------------------------------------------------
  770.     Print out various interesting things about the compressed file.
  771.   ---------------------------------------------------------------------------*/
  772.  
  773.     hostnum = MIN(crec.version_made_by[1], NUM_HOSTS);
  774.     hostver = crec.version_made_by[0];
  775.     extnum = MIN(crec.version_needed_to_extract[1], NUM_HOSTS);
  776.     extver = crec.version_needed_to_extract[0];
  777.     methnum = MIN(crec.compression_method, NUM_METHODS);
  778.  
  779.     if (hostnum == NUM_HOSTS)
  780.         sprintf(OS_unkn, LoadFarString(Unknown), (int)crec.version_made_by[1]);
  781.     if (methnum == NUM_METHODS)
  782.         sprintf(meth_unkn, LoadFarString(Unknown), crec.compression_method);
  783.  
  784.     putchar(' ');  putchar(' ');  fnprint();
  785.  
  786.     PRINTF(LoadFarString(HostOS), LoadFarStringSmall(os[hostnum]));
  787.     PRINTF(LoadFarString(EncodeSWVer), hostver/10, hostver%10);
  788.     PRINTF(LoadFarString(MinOSCompReq), LoadFarStringSmall(os[extnum]));
  789.     PRINTF(LoadFarString(MinSWVerReq), extver/10, extver%10);
  790.     PRINTF(LoadFarString(CompressMethod), LoadFarStringSmall(method[methnum]));
  791.     if (methnum == IMPLODED) {
  792.         PRINTF(LoadFarString(SlideWindowSizeImplode),
  793.           (crec.general_purpose_bit_flag & 2)? '8' : '4');
  794.         PRINTF(LoadFarString(ShannonFanoTrees),
  795.           (crec.general_purpose_bit_flag & 4)? '3' : '2');
  796.     } else if (methnum == DEFLATED) {
  797.         ush  dnum=(crec.general_purpose_bit_flag>>1) & 3;
  798.         PRINTF(LoadFarString(CompressSubtype), dtype[dnum]);
  799.     }
  800.     PRINTF(LoadFarString(FileSecurity),
  801.       (crec.general_purpose_bit_flag & 1)? "" : "not ");
  802.     PRINTF(LoadFarString(ExtendedLocalHdr),
  803.       (crec.general_purpose_bit_flag & 8)? "yes" : "no");
  804.     /* print upper 3 bits for amusement? */
  805.     PRINTF(LoadFarString(FileModDate),
  806.       zi_time(&crec.last_mod_file_date, &crec.last_mod_file_time));
  807.     PRINTF(LoadFarString(CRC32Value), crec.crc32);
  808.     PRINTF(LoadFarString(CompressedFileSize), crec.csize);
  809.     PRINTF(LoadFarString(UncompressedFileSize), crec.ucsize);
  810.     PRINTF(LoadFarString(FilenameLength), crec.filename_length);
  811.     PRINTF(LoadFarString(ExtraFieldLength), crec.extra_field_length);
  812.     PRINTF(LoadFarString(FileCommentLength), crec.file_comment_length);
  813.     PRINTF(LoadFarString(FileDiskNum), crec.disk_number_start);
  814.     PRINTF(LoadFarString(ApparentFileType),
  815.       (crec.internal_file_attributes & 1)? "text" : "binary");
  816. /*
  817.     PRINTF("  external file attributes (hex):                   %.8lx\n",
  818.       crec.external_file_attributes);
  819.  */
  820.     xattr = (ush)((crec.external_file_attributes >> 16) & 0xFFFF);
  821.     if (hostnum == VMS_) {
  822.         char   *p=attribs, *q=attribs+1;
  823.         int    i, j, k;
  824.  
  825.         for (k = 0;  k < 12;  ++k)
  826.             workspace[k] = 0;
  827.         if (xattr & VMS_IRUSR)
  828.             workspace[0] = 'R';
  829.         if (xattr & VMS_IWUSR) {
  830.             workspace[1] = 'W';
  831.             workspace[3] = 'D';
  832.         }
  833.         if (xattr & VMS_IXUSR)
  834.             workspace[2] = 'E';
  835.         if (xattr & VMS_IRGRP)
  836.             workspace[4] = 'R';
  837.         if (xattr & VMS_IWGRP) {
  838.             workspace[5] = 'W';
  839.             workspace[7] = 'D';
  840.         }
  841.         if (xattr & VMS_IXGRP)
  842.             workspace[6] = 'E';
  843.         if (xattr & VMS_IROTH)
  844.             workspace[8] = 'R';
  845.         if (xattr & VMS_IWOTH) {
  846.             workspace[9] = 'W';
  847.             workspace[11] = 'D';
  848.         }
  849.         if (xattr & VMS_IXOTH)
  850.             workspace[10] = 'E';
  851.  
  852.         *p++ = '(';
  853.         for (k = j = 0;  j < 3;  ++j) {    /* loop over groups of permissions */
  854.             for (i = 0;  i < 4;  ++i, ++k)  /* loop over perms within a group */
  855.                 if (workspace[k])
  856.                     *p++ = workspace[k];
  857.             *p++ = ',';                       /* group separator */
  858.             if (j == 0)
  859.                 while ((*p++ = *q++) != ','); /* system, owner perms are same */
  860.         }
  861.         *p-- = 0;
  862.         *p = ')';   /* overwrite last comma */
  863.         PRINTF(LoadFarString(VMSFileAttributes), xattr, attribs);
  864.  
  865.     } else if (hostnum == AMIGA_) {
  866.         switch (xattr & AMI_IFMT) {
  867.             case AMI_IFDIR:  attribs[0] = 'd';  break;
  868.             case AMI_IFREG:  attribs[0] = '-';  break;
  869.             default:         attribs[0] = '?';  break;
  870.         }
  871.         attribs[1] = (xattr & AMI_IHIDDEN)?   'h' : '-';
  872.         attribs[2] = (xattr & AMI_ISCRIPT)?   's' : '-';
  873.         attribs[3] = (xattr & AMI_IPURE)?     'p' : '-';
  874.         attribs[4] = (xattr & AMI_IARCHIVE)?  'a' : '-';
  875.         attribs[5] = (xattr & AMI_IREAD)?     'r' : '-';
  876.         attribs[6] = (xattr & AMI_IWRITE)?    'w' : '-';
  877.         attribs[7] = (xattr & AMI_IEXECUTE)?  'e' : '-';
  878.         attribs[8] = (xattr & AMI_IDELETE)?   'd' : '-';
  879.         attribs[9] = 0;   /* better dlm the string */
  880.         PRINTF(LoadFarString(AmigaFileAttributes), xattr, attribs);
  881.  
  882.     } else if ((hostnum != FS_FAT_) && (hostnum != FS_HPFS_) &&
  883.                (hostnum != FS_NTFS_) && (hostnum != ATARI_) &&
  884.                (hostnum != ACORN_))
  885.     {                                 /* assume Unix-like */
  886.         switch (xattr & UNX_IFMT) {
  887.             case UNX_IFDIR:   attribs[0] = 'd';  break;
  888.             case UNX_IFREG:   attribs[0] = '-';  break;
  889.             case UNX_IFLNK:   attribs[0] = 'l';  break;
  890.             case UNX_IFBLK:   attribs[0] = 'b';  break;
  891.             case UNX_IFCHR:   attribs[0] = 'c';  break;
  892.             case UNX_IFIFO:   attribs[0] = 'p';  break;
  893.             case UNX_IFSOCK:  attribs[0] = 's';  break;
  894.             default:          attribs[0] = '?';  break;
  895.         }
  896.         attribs[1] = (xattr & UNX_IRUSR)? 'r' : '-';
  897.         attribs[4] = (xattr & UNX_IRGRP)? 'r' : '-';
  898.         attribs[7] = (xattr & UNX_IROTH)? 'r' : '-';
  899.  
  900.         attribs[2] = (xattr & UNX_IWUSR)? 'w' : '-';
  901.         attribs[5] = (xattr & UNX_IWGRP)? 'w' : '-';
  902.         attribs[8] = (xattr & UNX_IWOTH)? 'w' : '-';
  903.  
  904.         if (xattr & UNX_IXUSR)
  905.             attribs[3] = (xattr & UNX_ISUID)? 's' : 'x';
  906.         else
  907.             attribs[3] = (xattr & UNX_ISUID)? 'S' : '-';   /* S = undefined */
  908.         if (xattr & UNX_IXGRP)
  909.             attribs[6] = (xattr & UNX_ISGID)? 's' : 'x';   /* == UNX_ENFMT */
  910.         else
  911.             attribs[6] = (xattr & UNX_ISGID)? 'l' : '-';
  912.         if (xattr & UNX_IXOTH)
  913.             attribs[9] = (xattr & UNX_ISVTX)? 't' : 'x';   /* "sticky bit" */
  914.         else
  915.             attribs[9] = (xattr & UNX_ISVTX)? 'T' : '-';   /* T = undefined */
  916.         attribs[10] = 0;
  917.  
  918.         PRINTF(LoadFarString(UnixFileAttributes), xattr, attribs);
  919.  
  920.     } else {
  921.         PRINTF(LoadFarString(NonMSDOSFileAttributes),
  922.             crec.external_file_attributes >> 8);
  923.  
  924.     } /* endif (hostnum: external attributes format) */
  925.  
  926.     if ((xattr=(ush)(crec.external_file_attributes & 0xFF)) == 0)
  927.         PRINTF(LoadFarString(MSDOSFileAttributes), xattr);
  928.     else if (xattr == 1)
  929.         PRINTF(LoadFarString(MSDOSFileAttributesRO), xattr);
  930.     else
  931.         PRINTF(LoadFarString(MSDOSFileAttributesAlpha),
  932.           xattr, (xattr&1)?"rdo ":"", (xattr&2)?"hid ":"", (xattr&4)?"sys ":"",
  933.           (xattr&8)?"lab ":"", (xattr&16)?"dir ":"", (xattr&32)?"arc":"");
  934.     PRINTF(LoadFarString(LocalHeaderOffset),
  935.       crec.relative_offset_local_header, crec.relative_offset_local_header);
  936.  
  937. /*---------------------------------------------------------------------------
  938.     Skip the extra field, if any, and print the file comment, if any (the
  939.     filename has already been printed, above).  That finishes up this file
  940.     entry...
  941.   ---------------------------------------------------------------------------*/
  942.  
  943.     if (crec.extra_field_length > 0) {
  944.         ush ef_id, ef_datalen;
  945.  
  946.         if ((error = do_string(crec.extra_field_length, EXTRA_FIELD)) != 0) {
  947.             error_in_archive = error;
  948.             if (error > PK_WARN)   /* fatal:  can't continue */
  949.                 return error;
  950.         }
  951.         if (extra_field == (uch *)NULL)
  952.             return PK_ERR;   /* not consistent with crec length */
  953.         ef_id = makeword(extra_field);
  954.         ef_datalen = makeword(&extra_field[2]);
  955.         switch (ef_id) {
  956.             case EF_AV:
  957.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  958.                   LoadFarStringSmall(efAV), ef_datalen);
  959.                 break;
  960.             case EF_OS2:
  961.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  962.                   LoadFarStringSmall(efOS2), ef_datalen);
  963. /* GRR:  should check that ef_datalen really 4 and not 2 before doing this: */
  964.                 PRINTF(LoadFarString(OS2EAs), makelong(&extra_field[4]));
  965.                 break;
  966.             case EF_PKVMS:
  967.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  968.                   LoadFarStringSmall(efPKVMS), ef_datalen);
  969.                 break;
  970.             case EF_IZVMS:
  971.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  972.                   LoadFarStringSmall(efIZVMS), ef_datalen);
  973.                 break;
  974.             case EF_ASIUNIX:
  975.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  976.                   LoadFarStringSmall(efASiUnix), ef_datalen);
  977.                 break;
  978.             case EF_SPARK:
  979.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  980.                   LoadFarStringSmall(efSpark), ef_datalen);
  981.                 break;
  982.             default:
  983.                 PRINTF(LoadFarString(ExtraFieldType), ef_id,
  984.                   LoadFarStringSmall(efUnknown), ef_datalen);
  985.                 break;
  986.         }
  987.         if (ef_id != EF_OS2) {
  988.             ush i, n;
  989.  
  990.             if (ef_datalen <= 16) {
  991.                 PRINTF(LoadFarString(ColonIndent));
  992. /* GRR:  should double-check that datalen <= crec.extra_field_length - 4 */
  993.                 n = ef_datalen;
  994.             } else {
  995.                 PRINTF(LoadFarString(First16),
  996.                   LoadFarStringSmall(ColonIndent));
  997.                 n = 16;
  998.             }
  999.             for (i = 0;  i < n;  ++i)
  1000.                 PRINTF(LoadFarString(efFormat), extra_field[i+4]);
  1001.         }
  1002.         PRINTF("\n");
  1003.     }
  1004.  
  1005.     if (!crec.file_comment_length)
  1006.         PRINTF(LoadFarString(NoFileComment));
  1007.     else {
  1008.         PRINTF(LoadFarString(FileCommBegin));
  1009.         if ((error = do_string(crec.file_comment_length, DISPLAY)) != PK_COOL) {
  1010.           error_in_archive = error;   /* might be warning */
  1011.           if (error > PK_WARN)   /* fatal */
  1012.               return error;
  1013.         }
  1014.         PRINTF(LoadFarString(FileCommEnd));
  1015.     }
  1016.  
  1017.     return error_in_archive;
  1018.  
  1019. } /* end function zi_long() */
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025. /*************************/
  1026. /*  Function zi_short()  */
  1027. /*************************/
  1028.  
  1029. static int zi_short()   /* return PK-type error code */
  1030. {
  1031.     int         k, error, error_in_archive=PK_COOL;
  1032.     ush         methnum, hostnum, hostver, xattr;
  1033.     char        *p, workspace[12], attribs[16];
  1034.     static char impl[5]="i#:#", defl[5]="def#";
  1035.     static char dtype[5]="NXFS";  /* normal, maximum, fast, superfast */
  1036.     static char *os[NUM_HOSTS+1] = {
  1037.         "fat", "ami", "vms", "unx", "cms", "atr", "hpf", "mac", "zzz",
  1038.         "cpm", "t20", "ntf", "qds", "aco", "???"
  1039.     };
  1040.     static char *method[NUM_METHODS+1] = {
  1041.         "stor", "shrk", "re:1", "re:2", "re:3", "re:4", impl, "tokn",
  1042.         defl, unkn
  1043.     };
  1044.  
  1045.  
  1046. /*---------------------------------------------------------------------------
  1047.     Print out various interesting things about the compressed file.
  1048.   ---------------------------------------------------------------------------*/
  1049.  
  1050.     methnum = MIN(crec.compression_method, NUM_METHODS);
  1051.     hostnum = MIN(crec.version_made_by[1], NUM_HOSTS);
  1052.     hostver = crec.version_made_by[0];
  1053. /*
  1054.     extnum = MIN(crec.version_needed_to_extract[1], NUM_HOSTS);
  1055.     extver = crec.version_needed_to_extract[0];
  1056.  */
  1057.  
  1058.     if (methnum == IMPLODED) {
  1059.         impl[1] = (char) ((crec.general_purpose_bit_flag & 2)? '8' : '4');
  1060.         impl[3] = (char) ((crec.general_purpose_bit_flag & 4)? '3' : '2');
  1061.     } else if (methnum == DEFLATED) {
  1062.         ush  dnum=(crec.general_purpose_bit_flag>>1) & 3;
  1063.         defl[3] = dtype[dnum];
  1064.     } else if (methnum == NUM_METHODS) {   /* unknown */
  1065.         sprintf(unkn, "u%03d", crec.compression_method);
  1066.     }
  1067.  
  1068.     for (k = 0;  k < 15;  ++k)
  1069.         attribs[k] = ' ';
  1070.     attribs[15] = 0;
  1071.  
  1072.     xattr = (ush)((crec.external_file_attributes >> 16) & 0xFFFF);
  1073.     switch (hostnum) {
  1074.         case VMS_:
  1075.             {   int    i, j;
  1076.  
  1077.                 for (k = 0;  k < 12;  ++k)
  1078.                     workspace[k] = 0;
  1079.                 if (xattr & VMS_IRUSR)
  1080.                     workspace[0] = 'R';
  1081.                 if (xattr & VMS_IWUSR) {
  1082.                     workspace[1] = 'W';
  1083.                     workspace[3] = 'D';
  1084.                 }
  1085.                 if (xattr & VMS_IXUSR)
  1086.                     workspace[2] = 'E';
  1087.                 if (xattr & VMS_IRGRP)
  1088.                     workspace[4] = 'R';
  1089.                 if (xattr & VMS_IWGRP) {
  1090.                     workspace[5] = 'W';
  1091.                     workspace[7] = 'D';
  1092.                 }
  1093.                 if (xattr & VMS_IXGRP)
  1094.                   workspace[6] = 'E';
  1095.                 if (xattr & VMS_IROTH)
  1096.                     workspace[8] = 'R';
  1097.                 if (xattr & VMS_IWOTH) {
  1098.                     workspace[9] = 'W';
  1099.                     workspace[11] = 'D';
  1100.                 }
  1101.                 if (xattr & VMS_IXOTH)
  1102.                     workspace[10] = 'E';
  1103.  
  1104.                 p = attribs;
  1105.                 for (k = j = 0;  j < 3;  ++j) {     /* groups of permissions */
  1106.                     for (i = 0;  i < 4;  ++i, ++k)  /* perms within a group */
  1107.                         if (workspace[k])
  1108.                             *p++ = workspace[k];
  1109.                     *p++ = ',';                     /* group separator */
  1110.                 }
  1111.                 *--p = ' ';   /* overwrite last comma */
  1112.                 if ((p - attribs) < 12)
  1113.                     sprintf(&attribs[12], "%d.%d", hostver/10, hostver%10);
  1114.             }
  1115.             break;
  1116.  
  1117.         case FS_FAT_:
  1118.         case FS_HPFS_:
  1119.         case FS_NTFS_:
  1120.         case ATARI_:
  1121.         case ACORN_:
  1122.             xattr = (ush)(crec.external_file_attributes & 0xFF);
  1123.             sprintf(attribs, ".r.-...     %d.%d", hostver/10, hostver%10);
  1124.             attribs[2] = (xattr & 0x01)? '-' : 'w';
  1125.             attribs[5] = (xattr & 0x02)? 'h' : '-';
  1126.             attribs[6] = (xattr & 0x04)? 's' : '-';
  1127.             attribs[4] = (xattr & 0x20)? 'a' : '-';
  1128.             if (xattr & 0x10) {
  1129.                 attribs[0] = 'd';
  1130.                 attribs[3] = 'x';
  1131.             } else
  1132.                 attribs[0] = '-';
  1133.             if (IS_VOLID(xattr))
  1134.                 attribs[0] = 'V';
  1135.             else if ((p = strrchr(filename, '.')) != (char *)NULL) {
  1136.                 ++p;
  1137.                 if (STRNICMP(p, "com", 3) == 0 || STRNICMP(p, "exe", 3) == 0 ||
  1138.                     STRNICMP(p, "btm", 3) == 0 || STRNICMP(p, "cmd", 3) == 0 ||
  1139.                     STRNICMP(p, "bat", 3) == 0)
  1140.                     attribs[3] = 'x';
  1141.             }
  1142.             break;
  1143.  
  1144.         case AMIGA_:
  1145.             switch (xattr & AMI_IFMT) {
  1146.                 case AMI_IFDIR:  attribs[0] = 'd';  break;
  1147.                 case AMI_IFREG:  attribs[0] = '-';  break;
  1148.                 default:         attribs[0] = '?';  break;
  1149.             }
  1150.             attribs[1] = (xattr & AMI_IHIDDEN)?   'h' : '-';
  1151.             attribs[2] = (xattr & AMI_ISCRIPT)?   's' : '-';
  1152.             attribs[3] = (xattr & AMI_IPURE)?     'p' : '-';
  1153.             attribs[4] = (xattr & AMI_IARCHIVE)?  'a' : '-';
  1154.             attribs[5] = (xattr & AMI_IREAD)?     'r' : '-';
  1155.             attribs[6] = (xattr & AMI_IWRITE)?    'w' : '-';
  1156.             attribs[7] = (xattr & AMI_IEXECUTE)?  'e' : '-';
  1157.             attribs[8] = (xattr & AMI_IDELETE)?   'd' : '-';
  1158.             sprintf(&attribs[12], "%d.%d", hostver/10, hostver%10);
  1159.             break;
  1160.  
  1161.         default:   /* assume Unix-like */
  1162.             switch (xattr & UNX_IFMT) {
  1163.                 case UNX_IFDIR:   attribs[0] = 'd';  break;
  1164.                 case UNX_IFREG:   attribs[0] = '-';  break;
  1165.                 case UNX_IFLNK:   attribs[0] = 'l';  break;
  1166.                 case UNX_IFBLK:   attribs[0] = 'b';  break;
  1167.                 case UNX_IFCHR:   attribs[0] = 'c';  break;
  1168.                 case UNX_IFIFO:   attribs[0] = 'p';  break;
  1169.                 case UNX_IFSOCK:  attribs[0] = 's';  break;
  1170.                 default:          attribs[0] = '?';  break;
  1171.             }
  1172.             attribs[1] = (xattr & UNX_IRUSR)? 'r' : '-';
  1173.             attribs[4] = (xattr & UNX_IRGRP)? 'r' : '-';
  1174.             attribs[7] = (xattr & UNX_IROTH)? 'r' : '-';
  1175.             attribs[2] = (xattr & UNX_IWUSR)? 'w' : '-';
  1176.             attribs[5] = (xattr & UNX_IWGRP)? 'w' : '-';
  1177.             attribs[8] = (xattr & UNX_IWOTH)? 'w' : '-';
  1178.  
  1179.             if (xattr & UNX_IXUSR)
  1180.                 attribs[3] = (xattr & UNX_ISUID)? 's' : 'x';
  1181.             else
  1182.                 attribs[3] = (xattr & UNX_ISUID)? 'S' : '-';  /* S==undefined */
  1183.             if (xattr & UNX_IXGRP)
  1184.                 attribs[6] = (xattr & UNX_ISGID)? 's' : 'x';  /* == UNX_ENFMT */
  1185.             else
  1186.                 /* attribs[6] = (xattr & UNX_ISGID)? 'l' : '-';  real 4.3BSD */
  1187.                 attribs[6] = (xattr & UNX_ISGID)? 'S' : '-';  /* SunOS 4.1.x */
  1188.             if (xattr & UNX_IXOTH)
  1189.                 attribs[9] = (xattr & UNX_ISVTX)? 't' : 'x';  /* "sticky bit" */
  1190.             else
  1191.                 attribs[9] = (xattr & UNX_ISVTX)? 'T' : '-';  /* T==undefined */
  1192.  
  1193.             sprintf(&attribs[12], "%d.%d", hostver/10, hostver%10);
  1194.             break;
  1195.  
  1196.     } /* end switch (hostnum: external attributes format) */
  1197.  
  1198.     PRINTF("%s %s %7lu %c%c", attribs, os[hostnum], crec.ucsize,
  1199.       (crec.general_purpose_bit_flag & 1)?
  1200.       ((crec.internal_file_attributes & 1)? 'T' : 'B') :   /* encrypted */
  1201.       ((crec.internal_file_attributes & 1)? 't' : 'b'),    /* plaintext */
  1202.       (crec.general_purpose_bit_flag & 8)? (crec.extra_field_length? 'X' : 'l')
  1203.                                         : (crec.extra_field_length? 'x' : '-'));
  1204.     if (lflag == 4) {
  1205.         ulg csiz = crec.csize;
  1206.  
  1207.         if (crec.general_purpose_bit_flag & 1)
  1208.             csiz -= 12;    /* if encrypted, don't count encryption header */
  1209.         PRINTF("%3d%%", (ratio(crec.ucsize,csiz) + 5)/10);
  1210.     } else if (lflag == 5)
  1211.         PRINTF(" %7lu", crec.csize);
  1212.  
  1213.     PRINTF(" %s %s ", method[methnum],
  1214.       zi_time(&crec.last_mod_file_date, &crec.last_mod_file_time));
  1215.     fnprint();
  1216.  
  1217. /*---------------------------------------------------------------------------
  1218.     Skip the extra field and/or the file comment, if any (the filename has
  1219.     already been printed, above).  That finishes up this file entry...
  1220.   ---------------------------------------------------------------------------*/
  1221.  
  1222.     SKIP_(crec.extra_field_length)
  1223.     SKIP_(crec.file_comment_length)
  1224.  
  1225.     return error_in_archive;
  1226.  
  1227. } /* end function zi_short() */
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233. /************************/
  1234. /*  Function zi_time()  */
  1235. /************************/
  1236.  
  1237. static char *zi_time(datez, timez)
  1238.     ush *datez, *timez;
  1239. {
  1240.     ush yr, mo, dy, hh, mm, ss;
  1241.     static char d_t_str[21], bogus[4];
  1242.     static char Far *month[13] = {
  1243.         bogus, JanMonth, FebMonth, MarMonth, AprMonth, MayMonth, JunMonth,
  1244.         JulMonth, AugMonth, SepMonth, OctMonth, NovMonth, DecMonth
  1245.     };
  1246.  
  1247.  
  1248.  
  1249. /*---------------------------------------------------------------------------
  1250.     Convert the file-modification date and time info to a string of the form
  1251.     "1991 Feb 23 17:15:00" or "23-Feb-91 17:15," depending on value of lflag.
  1252.   ---------------------------------------------------------------------------*/
  1253.  
  1254.     yr = ((*datez >> 9) & 0x7f) + 80;
  1255.     mo = ((*datez >> 5) & 0x0f);
  1256.     dy = *datez & 0x1f;
  1257.  
  1258.     hh = (*timez >> 11) & 0x1f;
  1259.     mm = (*timez >> 5) & 0x3f;
  1260.     ss = (*timez & 0x1f) * 2;
  1261.  
  1262.     if (mo == 0 || mo > 12) {
  1263.         sprintf(bogus, LoadFarString(BogusFmt), mo);
  1264.         mo = 0;
  1265.     }
  1266.  
  1267.     if (lflag > 9)  /* verbose listing format */
  1268.         sprintf(d_t_str, LoadFarString(YMDHMSTime), yr+1900,
  1269.             LoadFarStringSmall(month[mo]), dy, hh, mm, ss);
  1270.     else if (T_flag)
  1271.         sprintf(d_t_str, LoadFarString(DecimalTime), yr%100, mo, dy, hh, mm,
  1272.           ss);
  1273.     else   /* was:  if ((lflag >= 3) && (lflag <= 5)) */
  1274.         sprintf(d_t_str, LoadFarString(DMYHMTime), dy,
  1275.             LoadFarStringSmall(month[mo]), yr%100, hh, mm);
  1276.  
  1277.     return d_t_str;
  1278.  
  1279. } /* end function zi_time() */
  1280.  
  1281. #endif /* !NO_ZIPINFO */
  1282.  
  1283.  
  1284.  
  1285.  
  1286.  
  1287. /*************************/
  1288. /* Function list_files() */
  1289. /*************************/
  1290.  
  1291. int list_files()    /* return PK-type error code */
  1292. {
  1293.     char sgn, cfactorstr[10];
  1294.     int do_this_file=FALSE, cfactor, error, error_in_archive=PK_COOL;
  1295.     int longhdr=(vflag>1), date_format, methnum;
  1296.     ush j, yr, mo, dy, hh, mm, members=0;
  1297.     ulg csiz, tot_csize=0L, tot_ucsize=0L;
  1298. #ifdef OS2
  1299.     ulg ea_size, tot_easize=0L, tot_eafiles=0L;
  1300. #endif
  1301. #ifdef MSWIN
  1302.     PSTR psLBEntry;  /* list box entry */
  1303. #endif
  1304.     min_info info;
  1305.     static char defl[]="Defl:#", dtype[]="NXFS";   /* see zi_short() */
  1306.     static char *method[NUM_METHODS+1] =
  1307.         {"Stored", "Shrunk", "Reduce1", "Reduce2", "Reduce3", "Reduce4",
  1308.          "Implode", "Token", defl, unkn};
  1309.  
  1310.  
  1311.  
  1312. /*---------------------------------------------------------------------------
  1313.     Unlike extract_or_test_files(), this routine confines itself to the cen-
  1314.     tral directory.  Thus its structure is somewhat simpler, since we can do
  1315.     just a single loop through the entire directory, listing files as we go.
  1316.  
  1317.     So to start off, print the heading line and then begin main loop through
  1318.     the central directory.  The results will look vaguely like the following:
  1319.  
  1320.   Length  Method   Size  Ratio   Date    Time   CRC-32     Name ("^" ==> case
  1321.   ------  ------   ----  -----   ----    ----   ------     ----   conversion)
  1322.    44004  Implode  13041  71%  11-02-89  19:34  8b4207f7   Makefile.UNIX
  1323.     3438  Shrunk    2209  36%  09-15-90  14:07  a2394fd8  ^dos-file.ext
  1324.   ---------------------------------------------------------------------------*/
  1325.  
  1326.     pInfo = &info;
  1327.     date_format = DATE_FORMAT;
  1328.  
  1329. #ifndef MSWIN
  1330.     if (qflag < 2)
  1331.         if (L_flag)
  1332.             PRINTF(LoadFarString(CaseConversion),
  1333.               LoadFarStringSmall(Headers[longhdr][0]),
  1334.               LoadFarStringSmall2(Headers[longhdr][1]));
  1335.         else
  1336.             PRINTF("%s\n%s\n", LoadFarString(Headers[longhdr][0]),
  1337.                    LoadFarStringSmall(Headers[longhdr][1]));
  1338. #endif /* !MSWIN */
  1339.  
  1340.     for (j = 0; j < ecrec.total_entries_central_dir; ++j) {
  1341.  
  1342.         if (readbuf(sig, 4) == 0)
  1343.             return PK_EOF;
  1344.         if (strncmp(sig, central_hdr_sig, 4)) {  /* just to make sure */
  1345.             FPRINTF(stderr, LoadFarString(CentSigMsg), j);   /* sig not found */
  1346.             FPRINTF(stderr, LoadFarString(ReportMsg));  /* check binary xfers */
  1347.             return PK_BADERR;
  1348.         }
  1349.         /* process_cdir_file_hdr() sets pInfo->lcflag: */
  1350.         if ((error = process_cdir_file_hdr()) != PK_COOL)
  1351.             return error;       /* only PK_EOF defined */
  1352.  
  1353.         /*
  1354.          * We could DISPLAY the filename instead of storing (and possibly trun-
  1355.          * cating, in the case of a very long name) and printing it, but that
  1356.          * has the disadvantage of not allowing case conversion--and it's nice
  1357.          * to be able to see in the listing precisely how you have to type each
  1358.          * filename in order for unzip to consider it a match.  Speaking of
  1359.          * which, if member names were specified on the command line, check in
  1360.          * with match() to see if the current file is one of them, and make a
  1361.          * note of it if it is.
  1362.          */
  1363.  
  1364.         if ((error = do_string(crec.filename_length, FILENAME)) != PK_COOL) {
  1365.             error_in_archive = error;             /*  ^--(uses pInfo->lcflag) */
  1366.             if (error > PK_WARN)   /* fatal:  can't continue */
  1367.                 return error;
  1368.         }
  1369.         if (extra_field != (uch *)NULL) {
  1370.             free(extra_field);
  1371.             extra_field = (uch *)NULL;
  1372.         }
  1373.         if ((error = do_string(crec.extra_field_length, EXTRA_FIELD)) != 0) {
  1374.             error_in_archive = error;  
  1375.             if (error > PK_WARN)      /* fatal */
  1376.                 return error;
  1377.         }
  1378.         if (!process_all_files) {   /* check if specified on command line */
  1379.             char **pfn = pfnames-1;
  1380.  
  1381.             do_this_file = FALSE;
  1382.             while (*++pfn)
  1383.                 if (match(filename, *pfn, C_flag)) {
  1384.                     do_this_file = TRUE;
  1385.                     break;       /* found match, so stop looping */
  1386.                 }
  1387.             if (do_this_file) {  /* check if this is an excluded file */
  1388.                 char **pxn = pxnames-1;
  1389.  
  1390.                 while (*++pxn)
  1391.                     if (match(filename, *pxn, C_flag)) {
  1392.                         do_this_file = FALSE;  /* ^-- ignore case in match */
  1393.                         break;
  1394.                     }
  1395.             }
  1396.         }
  1397.         /*
  1398.          * If current file was specified on command line, or if no names were
  1399.          * specified, do the listing for this file.  Otherwise, get rid of the
  1400.          * file comment and go back for the next file.
  1401.          */
  1402.  
  1403.         if (process_all_files || do_this_file) {
  1404.  
  1405.             yr = (((crec.last_mod_file_date >> 9) & 0x7f) + 80) % (unsigned)100;
  1406.             mo = (crec.last_mod_file_date >> 5) & 0x0f;
  1407.             dy = crec.last_mod_file_date & 0x1f;
  1408.  
  1409.             /* permute date so it displays according to national convention */
  1410.             switch (date_format) {
  1411.                 case DF_YMD:
  1412.                     hh = mo; mo = yr; yr = dy; dy = hh;
  1413.                     break;
  1414.                 case DF_DMY:
  1415.                     hh = mo; mo = dy; dy = hh;
  1416.             }
  1417.             hh = (crec.last_mod_file_time >> 11) & 0x1f;
  1418.             mm = (crec.last_mod_file_time >> 5) & 0x3f;
  1419.  
  1420.             csiz = crec.csize;
  1421.             if (crec.general_purpose_bit_flag & 1)
  1422.                 csiz -= 12;   /* if encrypted, don't count encryption header */
  1423.             if ((cfactor = ratio(crec.ucsize, csiz)) < 0) {
  1424.                 sgn = '-';
  1425.                 cfactor = (-cfactor + 5) / 10;
  1426.             } else {
  1427.                 sgn = ' ';
  1428.                 cfactor = (cfactor + 5) / 10;
  1429.             }
  1430.             sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, cfactor);
  1431.  
  1432.             methnum = MIN(crec.compression_method, NUM_METHODS);
  1433.             if (methnum == DEFLATED)
  1434.                 defl[5] = dtype[(crec.general_purpose_bit_flag>>1) & 3];
  1435.             else if (methnum == NUM_METHODS)
  1436.                 sprintf(unkn, LoadFarString(CompMethodUnknown),
  1437.                     crec.compression_method);
  1438.  
  1439. #if 0       /* GRR/Euro:  add this? */
  1440. #if defined(DOS_NT_OS2) || defined(UNIX)
  1441.             for (p = filename;  *p;  ++p)
  1442.                 if (!isprint(*p))
  1443.                     *p = '?';  /* change non-printable chars to '?' */
  1444. #endif /* DOS_NT_OS2 || UNIX */
  1445. #endif /* 0 */
  1446.  
  1447. #ifdef MSWIN
  1448. #ifdef NEED_EARLY_REDRAW
  1449.             /* turn on listbox redrawing just before adding last line */
  1450.             if (j == (ecrec.total_entries_central_dir-1))
  1451.                 (void)SendMessage(hWndList, WM_SETREDRAW, TRUE, 0L);
  1452. #endif /* NEED_EARLY_REDRAW */
  1453.             psLBEntry =
  1454.               (PSTR)LocalAlloc(LMEM_FIXED, FILNAMSIZ+LONG_FORM_FNAME_INX);
  1455.             /* GRR:  does OemToAnsi filter out escape and CR characters? */
  1456.             OemToAnsi(filename, filename);  /* translate to ANSI */
  1457.             if (longhdr) {
  1458.                 wsprintf(psLBEntry, LoadFarString(LongHdrStats),
  1459.                   crec.ucsize, (LPSTR)method[methnum], csiz, cfactorstr,
  1460.                   mo, dy, yr, hh, mm, crec.crc32, (pInfo->lcflag?'^':' '),
  1461.                   (LPSTR)filename);
  1462.                 SendMessage(hWndList, LB_ADDSTRING, 0,
  1463.                   (LONG)(LPSTR)psLBEntry);
  1464.             } else {
  1465.                 wsprintf(psLBEntry, LoadFarString(ShortHdrStats),
  1466.                   crec.ucsize, mo, dy, yr, hh, mm, (pInfo->lcflag?'^':' '),
  1467.                   (LPSTR)filename);
  1468.                 SendMessage(hWndList, LB_ADDSTRING, 0,
  1469.                   (LONG)(LPSTR)psLBEntry);
  1470.             }
  1471.             LocalFree((HANDLE)psLBEntry);
  1472. #else /* !MSWIN */
  1473.             if (longhdr)
  1474.                 PRINTF(LoadFarString(LongHdrStats),
  1475.                   crec.ucsize, method[methnum], csiz, cfactorstr, mo, dy, yr,
  1476.                   hh, mm, crec.crc32, (pInfo->lcflag?'^':' '));
  1477.             else
  1478.                 PRINTF(LoadFarString(ShortHdrStats), crec.ucsize,
  1479.                   mo, dy, yr, hh, mm, (pInfo->lcflag?'^':' '));
  1480.             fnprint();
  1481. #endif /* ?MSWIN */
  1482.  
  1483.             error = do_string(crec.file_comment_length, QCOND? DISPLAY : SKIP);
  1484.             if (error) {
  1485.                 error_in_archive = error;  /* might be just warning */
  1486.                 if (error > PK_WARN)       /* fatal */
  1487.                     return error;
  1488.             }
  1489.             tot_ucsize += crec.ucsize;
  1490.             tot_csize += csiz;
  1491.             ++members;
  1492. #ifdef OS2
  1493.             if ((ea_size = SizeOfEAs(extra_field)) != 0) {
  1494.                 tot_easize += ea_size;
  1495.                 tot_eafiles++;
  1496.             }
  1497. #endif
  1498.         } else {        /* not listing this file */
  1499.             SKIP_(crec.file_comment_length)
  1500.         }
  1501.     } /* end for-loop (j: files in central directory) */
  1502.  
  1503. /*---------------------------------------------------------------------------
  1504.     Print footer line and totals (compressed size, uncompressed size, number
  1505.     of members in zipfile).
  1506.   ---------------------------------------------------------------------------*/
  1507.  
  1508.     if (qflag < 2) {
  1509.         if ((cfactor = ratio(tot_ucsize, tot_csize)) < 0) {
  1510.             sgn = '-';
  1511.             cfactor = (-cfactor + 5) / 10;
  1512.         } else {
  1513.             sgn = ' ';
  1514.             cfactor = (cfactor + 5) / 10;
  1515.         }
  1516.         sprintf(cfactorstr, LoadFarString(CompFactorStr), sgn, cfactor);
  1517. #ifdef MSWIN
  1518.         /* Display just the totals since the dashed lines get displayed
  1519.          * in UpdateListBox(). Get just enough space to display total. */
  1520.         if (longhdr)
  1521.             wsprintf(lpumb->szTotalsLine,LoadFarString(LongFileHeader), 
  1522.               tot_ucsize, tot_csize, cfactorstr, members);
  1523.         else
  1524.             wsprintf(lpumb->szTotalsLine, LoadFarString(ShortFileHeader), 
  1525.               tot_ucsize, members);
  1526. #else /* !MSWIN */
  1527.         if (longhdr)
  1528.             PRINTF(LoadFarString(LongFileHeader), tot_ucsize, tot_csize, cfactorstr, members);
  1529.         else
  1530.             PRINTF(LoadFarString(ShortFileHeader), tot_ucsize, members);
  1531. #endif /* ?MSWIN */
  1532. #ifdef OS2
  1533.         if (tot_eafiles && tot_easize)
  1534.             PRINTF("\n%ld file%s %ld bytes of EA's attached.\n", tot_eafiles, 
  1535.               tot_eafiles == 1 ? " has" : "s have a total of", tot_easize);
  1536. #endif
  1537.     }
  1538. /*---------------------------------------------------------------------------
  1539.     Double check that we're back at the end-of-central-directory record.
  1540.   ---------------------------------------------------------------------------*/
  1541.  
  1542.     if (readbuf(sig, 4) == 0)
  1543.         return PK_EOF;
  1544.     if (strncmp(sig, end_central_sig, 4)) {     /* just to make sure again */
  1545.         FPRINTF(stderr, LoadFarString(EndSigMsg));  /* didn't find sig */
  1546.         error_in_archive = PK_WARN;
  1547.     }
  1548.     if (members == 0 && error_in_archive <= PK_WARN)
  1549.         error_in_archive = PK_FIND;
  1550.  
  1551.     return error_in_archive;
  1552.  
  1553. } /* end function list_files() */
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559. /********************/
  1560. /* Function ratio() */
  1561. /********************/
  1562.  
  1563. static int ratio(uc, c)
  1564.     ulg uc, c;
  1565. {
  1566.     ulg denom;
  1567.  
  1568.     if (uc == 0)
  1569.         return 0;
  1570.     if (uc > 2000000L) {    /* risk signed overflow if multiply numerator */
  1571.         denom = uc / 1000L;
  1572.         return ((uc >= c) ?
  1573.             (int) ((uc-c + (denom>>1)) / denom) :
  1574.           -((int) ((c-uc + (denom>>1)) / denom)));
  1575.     } else {             /* ^^^^^^^^ rounding */
  1576.         denom = uc;
  1577.         return ((uc >= c) ?
  1578.             (int) ((1000L*(uc-c) + (denom>>1)) / denom) :
  1579.           -((int) ((1000L*(c-uc) + (denom>>1)) / denom)));
  1580.     }                            /* ^^^^^^^^ rounding */
  1581. }
  1582.  
  1583.  
  1584.  
  1585.  
  1586.  
  1587. /************************/
  1588. /*  Function fnprint()  */
  1589. /************************/
  1590.  
  1591. static void fnprint()    /* print filename (after filtering) and newline */
  1592. {
  1593.     register uch *p = (uch *)filename-1;
  1594.     register uch *q = (uch *)slide;
  1595.  
  1596. #ifdef NATIVE
  1597.     PRINTF("%s", filename);   /* GRR:  can ANSI be used with EBCDIC? */
  1598. #else /* ASCII */
  1599.     while (*++p) {
  1600.         if (*p < 32) {        /* ASCII control character */
  1601.             *q++ = '^';
  1602.             *q++ = *p + 64;
  1603.         } else
  1604.             *q++ = *p;
  1605.     }                    /* filename better not be longer than slide[] ... */
  1606.     *q = '\0';
  1607.     PRINTF("%s\n", slide);
  1608. #endif /* ?NATIVE */
  1609.  
  1610. } /* end function fnprint() */
  1611.