📄 list.c
字号:
/* Copyright (c) 1990-2005 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, all these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html*//*--------------------------------------------------------------------------- list.c This file contains the non-ZipInfo-specific listing routines for UnZip. Contains: list_files() get_time_stamp() [optional feature] ratio() fnprint() ---------------------------------------------------------------------------*/#define UNZIP_INTERNAL#include "unzip.h"#ifdef WINDLL# ifdef POCKET_UNZIP# include "wince/intrface.h"# else# include "windll/windll.h"# endif#endif#ifdef TIMESTAMP static int fn_is_dir OF((__GPRO));#endif#ifndef WINDLL static ZCONST char Far CompFactorStr[] = "%c%d%%"; static ZCONST char Far CompFactor100[] = "100%%";#ifdef OS2_EAS static ZCONST char Far HeadersS[] = " Length EAs ACLs Date Time Name"; static ZCONST char Far HeadersS1[] = " -------- --- ---- ---- ---- ----";#else static ZCONST char Far HeadersS[] = " Length Date Time Name"; static ZCONST char Far HeadersS1[] = " -------- ---- ---- ----";#endif static ZCONST char Far HeadersL[] = " Length Method Size Ratio Date Time CRC-32 Name"; static ZCONST char Far HeadersL1[] = "-------- ------ ------- ----- ---- ---- ------ ----"; static ZCONST char Far *Headers[][2] = { {HeadersS, HeadersS1}, {HeadersL, HeadersL1} }; static ZCONST char Far CaseConversion[] = "%s (\"^\" ==> case\n%s conversion)\n"; static ZCONST char Far LongHdrStats[] = "%8lu %-7s%8lu %4s %02u%c%02u%c%02u %02u:%02u %08lx %c"; static ZCONST char Far LongFileTrailer[] = "-------- ------- --- \ -------\n%8lu %8lu %4s %lu file%s\n";#ifdef OS2_EAS static ZCONST char Far ShortHdrStats[] = "%9lu %6lu %6lu %02u%c%02u%c%02u %02u:%02u %c"; static ZCONST char Far ShortFileTrailer[] = " -------- ----- ----- \ -------\n%9lu %6lu %6lu %lu file%s\n"; static ZCONST char Far OS2ExtAttrTrailer[] = "%lu file%s %lu bytes of OS/2 extended attributes attached.\n"; static ZCONST char Far OS2ACLTrailer[] = "%lu file%s %lu bytes of access control lists attached.\n";#else static ZCONST char Far ShortHdrStats[] = "%9lu %02u%c%02u%c%02u %02u:%02u %c"; static ZCONST char Far ShortFileTrailer[] = " -------- \ -------\n%9lu %lu file%s\n";#endif /* ?OS2_EAS */#endif /* !WINDLL *//*************************//* Function list_files() *//*************************/int list_files(__G) /* return PK-type error code */ __GDEF{ int do_this_file=FALSE, cfactor, error, error_in_archive=PK_COOL;#ifndef WINDLL char sgn, cfactorstr[10]; int longhdr=(uO.vflag>1);#endif int date_format; char dt_sepchar; ulg j, members=0L; unsigned methnum;#ifdef USE_EF_UT_TIME iztimes z_utime; struct tm *t;#endif unsigned yr, mo, dy, hh, mm; ulg csiz, tot_csize=0L, tot_ucsize=0L;#ifdef OS2_EAS ulg ea_size, tot_easize=0L, tot_eafiles=0L; ulg acl_size, tot_aclsize=0L, tot_aclfiles=0L;#endif min_info info; char methbuf[8]; static ZCONST char dtype[]="NXFS"; /* see zi_short() */ static ZCONST char Far method[NUM_METHODS+1][8] = {"Stored", "Shrunk", "Reduce1", "Reduce2", "Reduce3", "Reduce4", "Implode", "Token", "Defl:#", "Def64#", "ImplDCL", "PKres11", "BZip2", "Unk:###"};/*--------------------------------------------------------------------------- Unlike extract_or_test_files(), this routine confines itself to the cen- tral directory. Thus its structure is somewhat simpler, since we can do just a single loop through the entire directory, listing files as we go. So to start off, print the heading line and then begin main loop through the central directory. The results will look vaguely like the following: Length Method Size Ratio Date Time CRC-32 Name ("^" ==> case-------- ------ ------- ----- ---- ---- ------ ---- conversion) 44004 Implode 13041 71% 11-02-89 19:34 8b4207f7 Makefile.UNIX 3438 Shrunk 2209 36% 09-15-90 14:07 a2394fd8 ^dos-file.ext 16717 Defl:X 5252 69% 11-03-97 06:40 1ce0f189 WHERE-------- ------- --- ------- 64159 20502 68% 3 files ---------------------------------------------------------------------------*/ G.pInfo = &info; date_format = DATE_FORMAT; dt_sepchar = DATE_SEPCHAR;#ifndef WINDLL if (uO.qflag < 2) { if (uO.L_flag) Info(slide, 0, ((char *)slide, LoadFarString(CaseConversion), LoadFarStringSmall(Headers[longhdr][0]), LoadFarStringSmall2(Headers[longhdr][1]))); else Info(slide, 0, ((char *)slide, "%s\n%s\n", LoadFarString(Headers[longhdr][0]), LoadFarStringSmall(Headers[longhdr][1]))); }#endif /* !WINDLL */ for (j = 1L;;j++) { if (readbuf(__G__ G.sig, 4) == 0) return PK_EOF; if (strncmp(G.sig, central_hdr_sig, 4)) { /* is it a CentDir entry? */ if (((unsigned)(j - 1) & (unsigned)0xFFFF) == (unsigned)G.ecrec.total_entries_central_dir) { /* "j modulus 64k" matches the reported 16-bit-unsigned * number of directory entries -> probably, the regular * end of the central directory has been reached */ break; } else { Info(slide, 0x401, ((char *)slide, LoadFarString(CentSigMsg), j)); Info(slide, 0x401, ((char *)slide, LoadFarString(ReportMsg))); return PK_BADERR; /* sig not found */ } } /* process_cdir_file_hdr() sets pInfo->hostnum, pInfo->lcflag, ...: */ if ((error = process_cdir_file_hdr(__G)) != PK_COOL) return error; /* only PK_EOF defined */ /* * We could DISPLAY the filename instead of storing (and possibly trun- * cating, in the case of a very long name) and printing it, but that * has the disadvantage of not allowing case conversion--and it's nice * to be able to see in the listing precisely how you have to type each * filename in order for unzip to consider it a match. Speaking of * which, if member names were specified on the command line, check in * with match() to see if the current file is one of them, and make a * note of it if it is. */ if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) != PK_COOL) /* ^--(uses pInfo->lcflag) */ { error_in_archive = error; if (error > PK_WARN) /* fatal: can't continue */ return error; } if (G.extra_field != (uch *)NULL) { free(G.extra_field); G.extra_field = (uch *)NULL; } if ((error = do_string(__G__ G.crec.extra_field_length, EXTRA_FIELD)) != 0) { error_in_archive = error; if (error > PK_WARN) /* fatal */ return error; } if (!G.process_all_files) { /* check if specified on command line */ unsigned i; if (G.filespecs == 0) do_this_file = TRUE; else { /* check if this entry matches an `include' argument */ do_this_file = FALSE; for (i = 0; i < G.filespecs; i++) if (match(G.filename, G.pfnames[i], uO.C_flag WISEP)) { do_this_file = TRUE; break; /* found match, so stop looping */ } } if (do_this_file) { /* check if this is an excluded file */ for (i = 0; i < G.xfilespecs; i++) if (match(G.filename, G.pxnames[i], uO.C_flag WISEP)) { do_this_file = FALSE; /* ^-- ignore case in match */ break; } } } /* * If current file was specified on command line, or if no names were * specified, do the listing for this file. Otherwise, get rid of the * file comment and go back for the next file. */ if (G.process_all_files || do_this_file) {#ifdef OS2DLL /* this is used by UzpFileTree() to allow easy processing of lists * of zip directory contents */ if (G.processExternally) { if ((G.processExternally)(G.filename, &G.crec)) break; ++members; } else {#endif#ifdef OS2_EAS { uch *ef_ptr = G.extra_field; int ef_size, ef_len = G.crec.extra_field_length; ea_size = acl_size = 0; while (ef_len >= EB_HEADSIZE) { ef_size = makeword(&ef_ptr[EB_LEN]); switch (makeword(&ef_ptr[EB_ID])) { case EF_OS2: ea_size = makelong(&ef_ptr[EB_HEADSIZE]); break; case EF_ACL: acl_size = makelong(&ef_ptr[EB_HEADSIZE]); break; } ef_ptr += (ef_size + EB_HEADSIZE); ef_len -= (ef_size + EB_HEADSIZE); } }#endif#ifdef USE_EF_UT_TIME if (G.extra_field &&#ifdef IZ_CHECK_TZ G.tz_is_valid &&#endif (ef_scan_for_izux(G.extra_field, G.crec.extra_field_length, 1, G.crec.last_mod_dos_datetime, &z_utime, NULL) & EB_UT_FL_MTIME)) { TIMET_TO_NATIVE(z_utime.mtime) /* NOP unless MSC 7.0, Mac */ t = localtime(&(z_utime.mtime)); } else t = (struct tm *)NULL; if (t != (struct tm *)NULL) { mo = (unsigned)(t->tm_mon + 1); dy = (unsigned)(t->tm_mday); yr = (unsigned)(t->tm_year % 100); hh = (unsigned)(t->tm_hour); mm = (unsigned)(t->tm_min); } else#endif /* USE_EF_UT_TIME */ { yr = ((((unsigned)(G.crec.last_mod_dos_datetime >> 25) & 0x7f) + 80) % (unsigned)100); mo = ((unsigned)(G.crec.last_mod_dos_datetime >> 21) & 0x0f); dy = ((unsigned)(G.crec.last_mod_dos_datetime >> 16) & 0x1f); hh = (((unsigned)G.crec.last_mod_dos_datetime >> 11) & 0x1f); mm = (((unsigned)G.crec.last_mod_dos_datetime >> 5) & 0x3f); } /* permute date so it displays according to nat'l convention * ('methnum' is not yet set, it is used as temporary buffer) */ switch (date_format) { case DF_YMD: methnum = mo; mo = yr; yr = dy; dy = methnum; break; case DF_DMY: methnum = mo; mo = dy; dy = methnum; } csiz = G.crec.csize; if (G.crec.general_purpose_bit_flag & 1) csiz -= 12; /* if encrypted, don't count encryption header */ if ((cfactor = ratio(G.crec.ucsize, csiz)) < 0) {#ifndef WINDLL sgn = '-';#endif cfactor = (-cfactor + 5) / 10; } else {#ifndef WINDLL sgn = ' ';#endif cfactor = (cfactor + 5) / 10; } methnum = MIN(G.crec.compression_method, NUM_METHODS); zfstrcpy(methbuf, method[methnum]); if (methnum == DEFLATED || methnum == ENHDEFLATED) { methbuf[5] = dtype[(G.crec.general_purpose_bit_flag>>1) & 3]; } else if (methnum >= NUM_METHODS) { sprintf(&methbuf[4], "%03u", G.crec.compression_method); }#if 0 /* GRR/Euro: add this? */#if defined(DOS_FLX_NLM_OS2_W32) || defined(THEOS) || defined(UNIX) for (p = G.filename; *p; ++p) if (!isprint(*p)) *p = '?'; /* change non-printable chars to '?' */#endif /* DOS_FLX_NLM_OS2_W32 || THEOS || UNIX */#endif /* 0 */#ifdef WINDLL /* send data to application for formatting and printing */ (*G.lpUserFunctions->SendApplicationMessage)(G.crec.ucsize, csiz,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -