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

📄 extrafld.c

📁 给出了 zip 压缩算法的完整实现过程。
💻 C
📖 第 1 页 / 共 3 页
字号:
    return ef;}/** Build the new mac local extra field header.* All native data are in Intel (=little-endian) format*/unsigned make_extrafield_MAC3(char *ef){    char *ef_m3_begin = ef;    char *temp_Pathname;    char tmp_buffer[NAME_MAX];    unsigned char comment[257];    unsigned short FLength = 0;    unsigned short CLength = 0;    short   tempFork;    OSErr       err;    Assert_it(ef, "make_extrafield_MAC3","")    if (MacZip.isMacStatValid == false)    {        fprintf(stderr,                "Internal Logic Error: [%d/%s] MacStat is out of sync !",                __LINE__, __FILE__);        exit(-1);    }    /* Start Macintosh Finder FInfo structure except Type/Creator       (see make_EF_Head_MAC3()) 8 Bytes overall */                                             /* file Finder Flags: 2 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags >> 8);                                    /* Finders Icon position of a file*/                                   /* V/Y-Position:                2 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.v);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.v >> 8);                                   /* H/X-Position:                2 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.h);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.h >> 8);                               /* fdFldr Folder containing file    2 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFldr);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFldr >> 8);                /* End Macintosh Finder FInfo structure */                                                    /*    8 Bytes so far ... */                /* Start Macintosh Finder FXInfo structure  16 Bytes overall */                                                    /* Icon ID:    2 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdIconID);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdIconID >> 8);                                                        /* unused: 6 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdUnused[0]);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdUnused[0] >> 8);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdUnused[1]);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdUnused[1] >> 8);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdUnused[2]);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdUnused[2] >> 8);                                                   /* Script flag: 1 Byte */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdScript);                                                /* More flag bits: 1 Byte */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdXFlags);                                                /* Comment ID      2 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdComment);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdComment >> 8);                                                   /* Home Dir ID: 4 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdPutAway);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdPutAway >> 8);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdPutAway >> 16);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlXFndrInfo.fdPutAway >> 24);                /* End Macintosh Finder FXInfo structure */                                                    /*   24 Bytes so far ... */                                            /* file version number 1 Byte */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFVersNum);                                        /* directory access rights 1 Byte */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioACUser);                                                 /* Creation-time  4 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat  >> 8);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat >> 16);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlCrDat >> 24);                                             /* Modification-time  4 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat >> 8);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat >> 16);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlMdDat >> 24);                                                   /* Backup-time  4 Bytes */    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlBkDat);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlBkDat >> 8);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlBkDat >> 16);    *ef++ = (char)(MacZip.fpb.hFileInfo.ioFlBkDat >> 24);                                                    /*   38 Bytes so far ... */#ifdef USE_EF_UT_TIME    if (MacZip.HaveGMToffset) {                                              /* GMT-Offset times  12 Bytes */        *ef++ = (char)(MacZip.Cr_UTCoffs);        *ef++ = (char)(MacZip.Cr_UTCoffs >> 8);        *ef++ = (char)(MacZip.Cr_UTCoffs >> 16);        *ef++ = (char)(MacZip.Cr_UTCoffs >> 24);        *ef++ = (char)(MacZip.Md_UTCoffs);        *ef++ = (char)(MacZip.Md_UTCoffs >> 8);        *ef++ = (char)(MacZip.Md_UTCoffs >> 16);        *ef++ = (char)(MacZip.Md_UTCoffs >> 24);        *ef++ = (char)(MacZip.Bk_UTCoffs);        *ef++ = (char)(MacZip.Bk_UTCoffs >> 8);        *ef++ = (char)(MacZip.Bk_UTCoffs >> 16);        *ef++ = (char)(MacZip.Bk_UTCoffs >> 24);    }                                                    /*   50 Bytes so far ... */#endif                                  /* Text Encoding Base (charset)  2 Bytes */    *ef++ = (char)(MacZip.CurrTextEncodingBase);    *ef++ = (char)(MacZip.CurrTextEncodingBase >> 8);                                                    /*   52 Bytes so far ... */    /* MacZip.CurrentFork will be changed, so we have to save it  */    tempFork = MacZip.CurrentFork;    if (!MacZip.StoreFullPath)  {        temp_Pathname = StripPartialDir(tmp_buffer, MacZip.SearchDir,                                        MacZip.FullPath);    } else {        temp_Pathname = MacZip.FullPath;    }    MacZip.CurrentFork = tempFork;    FLength = strlen(temp_Pathname) + 1;    memcpy( ef, temp_Pathname, (size_t)FLength );    ef += FLength;          /* make room for the string -  variable length */    err = FSpLocationFromFullPath(strlen(MacZip.FullPath), MacZip.FullPath,                                  &MacZip.fileSpec);    printerr("FSpLocationFromFullPath:", err, err,             __LINE__, __FILE__, tmp_buffer);    err = FSpDTGetComment(&MacZip.fileSpec, comment);    printerr("FSpDTGetComment:", (err != -5012) && (err != 0), err,             __LINE__, __FILE__, "");    PToCCpy(comment,tmp_buffer);    CLength = strlen(tmp_buffer) + 1;    memcpy( ef, tmp_buffer, (size_t)CLength );    ef += CLength;          /* make room for the string -  variable length */    if (verbose) printf("\n comment: [%s]", tmp_buffer);    return (unsigned)(ef - ef_m3_begin);}/** Print all native data of the new mac local extra field.* It's for debugging purposes and disabled by default.*/static void PrintFileInfo(void){DateTimeRec  MacTime;printf("\n\n---------------------------------------------"\       "----------------------------------");printf("\n FullPath Name =                   [%s]",  MacZip.FullPath);printf("\n File Attributes =                  %s  0x%x  %d",          sBit2Str(MacZip.fpb.hFileInfo.ioFlAttrib),          MacZip.fpb.hFileInfo.ioFlAttrib,          MacZip.fpb.hFileInfo.ioFlAttrib);printf("\n Enclosing Folder ID# =             0x%x  %d",          MacZip.fpb.hFileInfo.ioFlParID,          MacZip.fpb.hFileInfo.ioFlParID);if (!MacZip.isDirectory){printf("\n File Type =                        [%c%c%c%c]  0x%lx",    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 24,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 16,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 8,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType);printf("\n File Creator =                     [%c%c%c%c]  0x%lx",    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 24,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 16,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 8,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator);printf("\n Data Fork :" );printf("\n    Actual (Logical) Length =       %d  0x%x ",              MacZip.fpb.hFileInfo.ioFlLgLen,              MacZip.fpb.hFileInfo.ioFlLgLen);printf("\n    Allocated (Physical) Length =   %d  0x%x",              MacZip.fpb.hFileInfo.ioFlPyLen,              MacZip.fpb.hFileInfo.ioFlPyLen);printf("\n Resource Fork :" );printf("\n    Actual (Logical) Length =       %d  0x%x",              MacZip.fpb.hFileInfo.ioFlRLgLen,              MacZip.fpb.hFileInfo.ioFlRLgLen );printf("\n    Allocated (Physical) Length =   %d  0x%x",              MacZip.fpb.hFileInfo.ioFlRPyLen,              MacZip.fpb.hFileInfo.ioFlRPyLen );}printf("\n Dates :               ");SecondsToDate (MacZip.CreatDate, &MacTime);printf("\n    Created  =                       %4d/%2d/%2d %2d:%2d:%2d  ",    MacTime.year,    MacTime.month,    MacTime.day,    MacTime.hour,    MacTime.minute,    MacTime.second);SecondsToDate (MacZip.BackDate, &MacTime);printf("\n    Backup   =                       %4d/%2d/%2d %2d:%2d:%2d  ",    MacTime.year,    MacTime.month,    MacTime.day,    MacTime.hour,    MacTime.minute,    MacTime.second);SecondsToDate (MacZip.ModDate, &MacTime);printf("\n    Modified =                       %4d/%2d/%2d %2d:%2d:%2d  ",    MacTime.year,    MacTime.month,    MacTime.day,    MacTime.hour,    MacTime.minute,    MacTime.second);if (!MacZip.isDirectory){printf("\n Finder Flags :                     %s  0x%x  %d",          sBit2Str(MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags),          MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags,          MacZip.fpb.hFileInfo.ioFlFndrInfo.fdFlags);printf("\n Finder Icon Position =          X: %d  0x%x ",          MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.h,          MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.h);printf("\n                                  Y: %d  0x%x ",          MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.v,          MacZip.fpb.hFileInfo.ioFlFndrInfo.fdLocation.v);}else{printf("\n Finder Flags :                     %s  0x%x  %d",          sBit2Str(MacZip.fpb.dirInfo.ioDrUsrWds.frFlags),          MacZip.fpb.dirInfo.ioDrUsrWds.frFlags,          MacZip.fpb.dirInfo.ioDrUsrWds.frFlags);printf("\n Finder Icon Position =          X: %d  0x%x ",          MacZip.fpb.dirInfo.ioDrUsrWds.frLocation.h,          MacZip.fpb.dirInfo.ioDrUsrWds.frLocation.h);printf("\n                                  Y: %d  0x%x ",          MacZip.fpb.dirInfo.ioDrUsrWds.frLocation.v,          MacZip.fpb.dirInfo.ioDrUsrWds.frLocation.v);}printf("\n----------------------------------------------------"\        "---------------------------\n");}/** If the switch '-v' is used, print some more info.*/static void print_extra_info(void){char Fork[20];if (MacZip.CurrentFork == DataFork) sstrcpy(Fork,"<DataFork>");else  sstrcpy(Fork,"<ResourceFork>");printf("\n%16s [%c%c%c%c]  [%c%c%c%c]",Fork,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 24,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 16,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType >> 8,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdType,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 24,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 16,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator >> 8,    MacZip.fpb.hFileInfo.ioFlFndrInfo.fdCreator);}

⌨️ 快捷键说明

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