⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unzip.c

📁 汇编语言程序的编写虽然有一定的难度,但是它是一门低级的语言,有很强的基础性作用,具有广泛的用途.
💻 C
📖 第 1 页 / 共 4 页
字号:
    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  ---------------------------------------------------------------------------*/    pInfo = &info;    if (quietflg < 2)        if (U_flag)            printf("%s\n%s\n", Headers[which_hdr][0], Headers[which_hdr][1]);        else            printf("%s (\"^\" ==> case\n%s   conversion)\n",               Headers[which_hdr][0], Headers[which_hdr][1]);    for (j = 0; j < ecrec.total_entries_central_dir; ++j) {        if (readbuf(sig, 4) <= 0)            return (51);        /* 51:  unexpected EOF */        if (strncmp(sig, central_hdr_sig, 4)) {  /* just to make sure */            fprintf(stderr, CentSigMsg, j);  /* sig not found */            fprintf(stderr, ReportMsg);   /* check binary transfers */            return (3);         /* 3:  error in zipfile */        }        if ((error = process_cdir_file_hdr()) != 0)  /* (sets pInfo->lcflag) */            return (error);     /* only 51 (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(crec.filename_length, FILENAME)) != 0) {            error_in_archive = error;  /*             ^--(uses pInfo->lcflag) */            if (error > 1)      /* fatal:  can't continue */                return (error);        }        if ((error = do_string(crec.extra_field_length, EXTRA_FIELD)) != 0) {            error_in_archive = error;              if (error > 1)      /* fatal:  can't continue */                return (error);        }        if (!process_all_files) {   /* check if specified on command line */            do_this_file = FALSE;            fnamev = fnv;       /* don't destroy permanent filename ptr */            for (--fnamev; *++fnamev;)                if (match(filename, *fnamev)) {                    do_this_file = TRUE;                    break;      /* found match, so stop looping */                }        }        /*         * 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 (process_all_files || do_this_file) {            yr = (((crec.last_mod_file_date >> 9) & 0x7f) + 80) % (unsigned)100;            mo = (crec.last_mod_file_date >> 5) & 0x0f;            dy = crec.last_mod_file_date & 0x1f;            /* twist date so it displays according to national convention */            switch (dateformat()) {                case DF_YMD:                    hh = mo; mo = yr; yr = dy; dy = hh; break;                case DF_DMY:                    hh = mo; mo = dy; dy = hh;            }            hh = (crec.last_mod_file_time >> 11) & 0x1f;            mm = (crec.last_mod_file_time >> 5) & 0x3f;            csize = (longint) crec.compressed_size;            ucsize = (longint) crec.uncompressed_size;            if (crec.general_purpose_bit_flag & 1)                csize -= 12;    /* if encrypted, don't count encrypt hdr */            ratio = (ucsize == 0) ? 0 :   /* .zip can have 0-length members */                ((ucsize > 2000000) ?     /* risk signed overflow if mult. */                (int) ((ucsize-csize) / (ucsize/1000L)) + 5 :   /* big */                (int) ((1000L*(ucsize-csize)) / ucsize) + 5);   /* small */            switch (which_hdr) {                case 0:   /* short form */                    printf("%7ld  %02u-%02u-%02u  %02u:%02u  %c%s\n",                      ucsize, mo, dy, yr, hh, mm, (pInfo->lcflag?'^':' '),                      filename);                    break;                case 1:   /* verbose */                    printf(              "%7ld  %-7s%7ld %3d%%  %02u-%02u-%02u  %02u:%02u  %08lx  %c%s\n",                      ucsize, method[methnum], csize, ratio/10, mo, dy, yr,                      hh, mm, crec.crc32, (pInfo->lcflag?'^':' '), filename);            }            error = do_string(crec.file_comment_length, (QCOND2? DISPLAY:SKIP));            if (error) {                error_in_archive = error;  /* might be just warning */                if (error > 1)  /* fatal */                    return (error);            }            tot_ucsize += (ULONG) ucsize;            tot_csize += (ULONG) csize;            ++members;        } else {        /* not listing this file */            SKIP_(crec.file_comment_length)        }    }                   /* end for-loop (j: files in central directory) *//*---------------------------------------------------------------------------    Print footer line and totals (compressed size, uncompressed size, number    of members in zipfile).  ---------------------------------------------------------------------------*/    ratio = (tot_ucsize == 0) ?         0 : ((tot_ucsize > 4000000) ?    /* risk unsigned overflow if mult. */        (int) ((tot_ucsize - tot_csize) / (tot_ucsize/1000L)) + 5 :        (int) ((tot_ucsize - tot_csize) * 1000L / tot_ucsize) + 5);    if (quietflg < 2) {        switch (which_hdr) {        case 0:         /* short */            printf("%s\n%7lu                    %-7u\n",                   " ------                    -------",                   tot_ucsize, members);            break;        case 1:         /* verbose */            printf(              "%s\n%7lu         %7lu %3d%%                              %-7u\n",              " ------          ------  ---                              -------",              tot_ucsize, tot_csize, ratio / 10, members);        }    }/*---------------------------------------------------------------------------    Double check that we're back at the end-of-central-directory record.  ---------------------------------------------------------------------------*/    readbuf(sig, 4);    if (strncmp(sig, end_central_sig, 4)) {     /* just to make sure again */        fprintf(stderr, EndSigMsg);  /* didn't find end-of-central-dir sig *//*      fprintf(stderr, ReportMsg);   */        error_in_archive = 1;        /* 1:  warning error */    }    return (error_in_archive);}       /* end function list_files() *//**************************************//*  Function process_cdir_file_hdr()  *//**************************************/int process_cdir_file_hdr()    /* return PK-type error code */{    cdir_byte_hdr byterec;/*---------------------------------------------------------------------------    Read the next central directory entry and do any necessary machine-type    conversions (byte ordering, structure padding compensation--do so by    copying the data from the array into which it was read (byterec) to the    usable struct (crec)).  ---------------------------------------------------------------------------*/    if (readbuf((char *) byterec, CREC_SIZE) <= 0)        return (51);            /* 51:  unexpected EOF */    crec.version_made_by[0] = byterec[C_VERSION_MADE_BY_0];    crec.version_made_by[1] = byterec[C_VERSION_MADE_BY_1];    crec.version_needed_to_extract[0] = byterec[C_VERSION_NEEDED_TO_EXTRACT_0];    crec.version_needed_to_extract[1] = byterec[C_VERSION_NEEDED_TO_EXTRACT_1];    crec.general_purpose_bit_flag =        makeword(&byterec[C_GENERAL_PURPOSE_BIT_FLAG]);    crec.compression_method =        makeword(&byterec[C_COMPRESSION_METHOD]);    crec.last_mod_file_time =        makeword(&byterec[C_LAST_MOD_FILE_TIME]);    crec.last_mod_file_date =        makeword(&byterec[C_LAST_MOD_FILE_DATE]);    crec.crc32 =        makelong(&byterec[C_CRC32]);    crec.compressed_size =        makelong(&byterec[C_COMPRESSED_SIZE]);    crec.uncompressed_size =        makelong(&byterec[C_UNCOMPRESSED_SIZE]);    crec.filename_length =        makeword(&byterec[C_FILENAME_LENGTH]);    crec.extra_field_length =        makeword(&byterec[C_EXTRA_FIELD_LENGTH]);    crec.file_comment_length =        makeword(&byterec[C_FILE_COMMENT_LENGTH]);    crec.disk_number_start =        makeword(&byterec[C_DISK_NUMBER_START]);    crec.internal_file_attributes =        makeword(&byterec[C_INTERNAL_FILE_ATTRIBUTES]);    crec.external_file_attributes =        makelong(&byterec[C_EXTERNAL_FILE_ATTRIBUTES]);  /* LONG, not word! */    crec.relative_offset_local_header =        makelong(&byterec[C_RELATIVE_OFFSET_LOCAL_HEADER]);    pInfo->hostnum = min(crec.version_made_by[1], NUM_HOSTS);/*  extnum = min( crec.version_needed_to_extract[1], NUM_HOSTS ); */    methnum = min(crec.compression_method, NUM_METHODS);    if (methnum == NUM_METHODS)        sprintf(unkn, "Unk:%03d", crec.compression_method);/*---------------------------------------------------------------------------    Set flag for lowercase conversion of filename, depending on which OS the    file is coming from.  This section could be ifdef'd if some people have    come to love DOS uppercase filenames under Unix...but really, guys, get    a life. :)  NOTE THAT ALL SYSTEM NAMES NOW HAVE TRAILING UNDERSCORES!!!    This is to prevent interference with compiler command-line defines such    as -DUNIX, for example, which are then used in "#ifdef UNIX" constructs.  ---------------------------------------------------------------------------*/    pInfo->lcflag = 0;    if (!U_flag)   /* as long as user hasn't specified case-preservation */        switch (pInfo->hostnum) {            case DOS_OS2_FAT_:            case VMS_:            case VM_CMS_:           /* all caps? */            case CPM_:              /* like DOS, right? */        /*  case ATARI_:            ? */        /*  case Z_SYSTEM_:         ? */        /*  case TOPS20_:           (if we had such a thing...) */                pInfo->lcflag = 1;  /* convert filename to lowercase */                break;            default:                /* AMIGA_, UNIX_, (ATARI_), OS2_HPFS_, */                break;              /*   MAC_, (Z_SYSTEM_):  no conversion */        }    return 0;}       /* end function process_cdir_file_hdr() *//***************************************//*  Function process_local_file_hdr()  *//***************************************/int process_local_file_hdr()    /* return PK-type error code */{    local_byte_hdr byterec;/*---------------------------------------------------------------------------    Read the next local file header and do any necessary machine-type con-    versions (byte ordering, structure padding compensation--do so by copy-    ing the data from the array into which it was read (byterec) to the    usable struct (lrec)).  ---------------------------------------------------------------------------*/    if (readbuf((char *) byterec, LREC_SIZE) <= 0)        return (51);            /* 51:  unexpected EOF */    lrec.version_needed_to_extract[0] = byterec[L_VERSION_NEEDED_TO_EXTRACT_0];    lrec.version_needed_to_extract[1] = byterec[L_VERSION_NEEDED_TO_EXTRACT_1];    lrec.general_purpose_bit_flag = makeword(&byterec[L_GENERAL_PURPOSE_BIT_FLAG]);    lrec.compression_method = makeword(&byterec[L_COMPRESSION_METHOD]);    lrec.last_mod_file_time = makeword(&byterec[L_LAST_MOD_FILE_TIME]);    lrec.last_mod_file_date = makeword(&byterec[L_LAST_MOD_FILE_DATE]);    lrec.crc32 = makelong(&byterec[L_CRC32]);    lrec.compressed_size = makelong(&byterec[L_COMPRESSED_SIZE]);    lrec.uncompressed_size = makelong(&byterec[L_UNCOMPRESSED_SIZE]);    lrec.filename_length = makeword(&byterec[L_FILENAME_LENGTH]);    lrec.extra_field_length = makeword(&byterec[L_EXTRA_FIELD_LENGTH]);    csize = (longint) lrec.compressed_size;    ucsize = (longint) lrec.uncompressed_size;    return (0);                 /* 0:  no error */}       /* end function process_local_file_hdr() */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -