📄 macos.c
字号:
return (ush)((b[0] << 8) | b[1]);}/*** Print mac extra-field***/static void PrintMacExtraInfo(void){#define MY_FNDRINFO fpb.hFileInfo.ioFlFndrInfo DateTimeRec MacTime; static ZCONST char space[] = " "; static ZCONST char line[] = "------------------------------------"\ "------------------------------"; printf("\n\n%s", line); printf("\nFullPath = [%s]", newExtraField.FullPath); printf("\nFinderComment = [%s]", newExtraField.FinderComment); printf("\nText Encoding Base (Filename) \"%s\" \n", PrintTextEncoding(newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript)); printf("\nExtraField Flags : %s 0x%x %4d", sBit2Str(newExtraField.flags), newExtraField.flags, newExtraField.flags); printf("\n%sExtra Field is %s", space, (newExtraField.flags & EB_M3_FL_UNCMPR ? "Uncompressed" : "Compressed")); printf("\n%sFile Dates are in %u Bit", space, (newExtraField.flags & EB_M3_FL_TIME64 ? 64 : 32)); printf("\n%sFile UTC time adjustments are %ssupported", space, (newExtraField.flags & EB_M3_FL_NOUTC ? "not " : "")); printf("\n%sFile Name is %schanged", space, (newExtraField.flags & EB_M3_FL_NOCHANGE ? "not " : "")); printf("\n%sFile is a %s\n", space, (newExtraField.flags & EB_M3_FL_DATFRK ? "Datafork" : "Resourcefork")); /* not all type / creator codes are printable */ if (isprint((char)(newExtraField.MY_FNDRINFO.fdType >> 24)) && isprint((char)(newExtraField.MY_FNDRINFO.fdType >> 16)) && isprint((char)(newExtraField.MY_FNDRINFO.fdType >> 8)) && isprint((char)newExtraField.MY_FNDRINFO.fdType)) { printf("\nFile Type = [%c%c%c%c] 0x%lx", (char)(newExtraField.MY_FNDRINFO.fdType >> 24), (char)(newExtraField.MY_FNDRINFO.fdType >> 16), (char)(newExtraField.MY_FNDRINFO.fdType >> 8), (char)(newExtraField.MY_FNDRINFO.fdType), newExtraField.MY_FNDRINFO.fdType); } else { printf("\nFile Type = 0x%lx", newExtraField.MY_FNDRINFO.fdType); } if (isprint((char)(newExtraField.MY_FNDRINFO.fdCreator >> 24)) && isprint((char)(newExtraField.MY_FNDRINFO.fdCreator >> 16)) && isprint((char)(newExtraField.MY_FNDRINFO.fdCreator >> 8)) && isprint((char)newExtraField.MY_FNDRINFO.fdCreator)) { printf("\nFile Creator = [%c%c%c%c] 0x%lx", (char)(newExtraField.MY_FNDRINFO.fdCreator >> 24), (char)(newExtraField.MY_FNDRINFO.fdCreator >> 16), (char)(newExtraField.MY_FNDRINFO.fdCreator >> 8), (char)(newExtraField.MY_FNDRINFO.fdCreator), newExtraField.MY_FNDRINFO.fdCreator); } else { printf("\nFile Creator = 0x%lx", newExtraField.MY_FNDRINFO.fdCreator); } printf("\n\nDates (local time of archiving location):"); SecondsToDate(newExtraField.fpb.hFileInfo.ioFlCrDat, &MacTime); printf("\n Created = %4d/%2d/%2d %2d:%2d:%2d ", MacTime.year, MacTime.month, MacTime.day, MacTime.hour, MacTime.minute, MacTime.second); SecondsToDate(newExtraField.fpb.hFileInfo.ioFlMdDat, &MacTime); printf("\n Modified = %4d/%2d/%2d %2d:%2d:%2d ", MacTime.year, MacTime.month, MacTime.day, MacTime.hour, MacTime.minute, MacTime.second); SecondsToDate(newExtraField.fpb.hFileInfo.ioFlBkDat, &MacTime); printf("\n Backup = %4d/%2d/%2d %2d:%2d:%2d ", MacTime.year, MacTime.month, MacTime.day, MacTime.hour, MacTime.minute, MacTime.second); if (!(newExtraField.flags & EB_M3_FL_NOUTC)) { printf("\nGMT Offset of Creation time = %4ld sec %2d h", newExtraField.Cr_UTCoffs, (int)newExtraField.Cr_UTCoffs / (60 * 60)); printf("\nGMT Offset of Modification time = %4ld sec %2d h", newExtraField.Md_UTCoffs, (int)newExtraField.Md_UTCoffs / (60 * 60)); printf("\nGMT Offset of Backup time = %4ld sec %2d h", newExtraField.Bk_UTCoffs, (int)newExtraField.Bk_UTCoffs / (60 * 60)); } printf("\n\nFinder Flags : %s 0x%x %4d", sBit2Str(newExtraField.MY_FNDRINFO.fdFlags), newExtraField.MY_FNDRINFO.fdFlags, newExtraField.MY_FNDRINFO.fdFlags); printf("\nFinder Icon Position = X: %4d", newExtraField.MY_FNDRINFO.fdLocation.h); printf("\n Y: %4d", newExtraField.MY_FNDRINFO.fdLocation.v); printf("\n\nText Encoding Base (System/MacZip) \"%s\"", PrintTextEncoding(newExtraField.TextEncodingBase)); printf("\n%s", line);#undef MY_FNDRINFO}/*** Decode mac extra-field and assign the data to the structure***/static Boolean GetExtraFieldData(short *MacZipMode, MACINFO *mi){uch *ptr;uch *attrbuff = NULL;int retval = PK_OK;Boolean MallocWasUsed = false;ptr = scanMacOSexfield(G.extra_field, G.lrec.extra_field_length, MacZipMode);/* MacOS is no preemptive OS therefore do some (small) event-handling */UserStop();if (uO.J_flag) { *MacZipMode = UnKnown_EF; IgnoreEF_Macfilename = true; return false;}if (ptr != NULL){ /* Collect the data from the extra field buffer. */ mi->header = makeword(ptr); ptr += 2; mi->data = makeword(ptr); ptr += 2; switch (*MacZipMode) { case NewZipMode_EF: { mi->size = makelong(ptr); ptr += 4; mi->flags = makeword(ptr); ptr += 2; /* Type/Creator are always uncompressed */ mi->fpb.hFileInfo.ioFlFndrInfo.fdType = makePPClong(ptr); ptr += 4; mi->fpb.hFileInfo.ioFlFndrInfo.fdCreator = makePPClong(ptr); ptr += 4; if (!(mi->flags & EB_M3_FL_UNCMPR)) { /* compressed extra field is not yet tested, therefore it's currently not used by default */ attrbuff = (uch *)malloc(mi->size); if (attrbuff == NULL) { /* No memory to uncompress attributes */ Info(slide, 0x201, ((char *)slide, "Can't allocate memory to uncompress file "\ "attributes.\n")); *MacZipMode = UnKnown_EF; /* EF-Block is unusable, ignore it */ return false; } else MallocWasUsed = true; retval = memextract(__G__ attrbuff, mi->size, ptr, mi->data - EB_MAC3_HLEN); if (retval != PK_OK) { /* error uncompressing attributes */ Info(slide, 0x201, ((char *)slide, "Error uncompressing file attributes.\n")); free(attrbuff); *MacZipMode = UnKnown_EF; /* EF-Block unusable, ignore it */ return false; } } else { /* file attributes are uncompressed */ attrbuff = ptr; } DecodeMac3ExtraField(attrbuff, mi); if (MallocWasUsed) free(attrbuff); return true; break; } case JohnnyLee_EF: { if (strncmp((char *)ptr, "JLEE", 4) == 0) { /* Johnny Lee's old MacZip e.f. was found */ attrbuff = ptr + 4; DecodeJLEEextraField(attrbuff, mi); return true; } else { /* second signature did not match, ignore EF block */ *MacZipMode = UnKnown_EF; return false; } break; } default: { /* just to make sure */ *MacZipMode = UnKnown_EF; IgnoreEF_Macfilename = true; return false; break; } }} /* if (ptr != NULL) *//* no Mac extra field was found */return false;}/*** Assign the new Mac3 Extra-Field to the structure***/static void DecodeMac3ExtraField(ZCONST uch *buff, MACINFO *mi){ /* extra-field info of the new MacZip implementation */ /* compresssed extra-field starts here (if compressed) */mi->fpb.hFileInfo.ioFlFndrInfo.fdFlags = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlFndrInfo.fdLocation.v = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlFndrInfo.fdLocation.h = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlFndrInfo.fdFldr = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlXFndrInfo.fdIconID = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlXFndrInfo.fdUnused[0] = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlXFndrInfo.fdUnused[1] = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlXFndrInfo.fdUnused[2] = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlXFndrInfo.fdScript = *buff; buff += 1;mi->fpb.hFileInfo.ioFlXFndrInfo.fdXFlags = *buff; buff += 1;mi->fpb.hFileInfo.ioFlXFndrInfo.fdComment = makeword(buff); buff += 2;mi->fpb.hFileInfo.ioFlXFndrInfo.fdPutAway = makelong(buff); buff += 4;mi->fpb.hFileInfo.ioFVersNum = *buff; buff += 1;mi->fpb.hFileInfo.ioACUser = *buff; buff += 1;if (mi->flags & EB_M3_FL_TIME64) { Info(slide, 0x201, ((char *)slide, "Don't support 64 bit Timevalues; get a newer version of MacZip \n")); UseUT_ExtraField = true; buff += 24; /* jump over the date values */} else { UseUT_ExtraField = false; mi->fpb.hFileInfo.ioFlCrDat = makelong(buff); buff += 4; mi->fpb.hFileInfo.ioFlMdDat = makelong(buff); buff += 4; mi->fpb.hFileInfo.ioFlBkDat = makelong(buff); buff += 4;}if (!(mi->flags & EB_M3_FL_NOUTC)) { mi->Cr_UTCoffs = makelong(buff); buff += 4; mi->Md_UTCoffs = makelong(buff); buff += 4; mi->Bk_UTCoffs = makelong(buff); buff += 4;}/* TextEncodingBase type & values *//* (values 0-32 correspond to the Script Codes defined in "Inside Macintosh", Text pages 6-52 and 6-53) */mi->TextEncodingBase = makeword(buff); buff += 2;if (mi->TextEncodingBase >= kTextEncodingUnicodeV1_1) { Info(slide, 0x201, ((char *)slide, "Don't support Unicoded Filenames; get a newer version of MacZip\n")); IgnoreEF_Macfilename = true;}mi->FullPath = (char *)buff; buff += strlen(mi->FullPath) + 1;mi->FinderComment = (char *)buff; buff += strlen(mi->FinderComment) + 1;if (uO.i_flag) IgnoreEF_Macfilename = true;}/*** Assign the new JLEE Extra-Field to the structure***/static void DecodeJLEEextraField(ZCONST uch *buff, MACINFO *mi){ /* extra-field info of Johnny Lee's old MacZip */mi->fpb.hFileInfo.ioFlFndrInfo.fdType = makePPClong(buff); buff += 4;mi->fpb.hFileInfo.ioFlFndrInfo.fdCreator = makePPClong(buff); buff += 4;mi->fpb.hFileInfo.ioFlFndrInfo.fdFlags = makePPCword(buff); buff += 2;mi->fpb.hFileInfo.ioFlFndrInfo.fdLocation.v = makePPCword(buff); buff += 2;mi->fpb.hFileInfo.ioFlFndrInfo.fdLocation.h = makePPCword(buff); buff += 2;mi->fpb.hFileInfo.ioFlFndrInfo.fdFldr = makePPCword(buff); buff += 2;mi->fpb.hFileInfo.ioFlCrDat = makePPClong(buff); buff += 4;mi->fpb.hFileInfo.ioFlMdDat = makePPClong(buff); buff += 4;mi->flags = makePPClong(buff); buff += 4; /* scriptTag isn't stored in Johnny Lee's ef definiton */newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript = smRoman;}/*** Return char* to describe the text encoding***/static char *PrintTextEncoding(short script){char *info;static char buffer[14];/* TextEncodingBase type & values *//* (values 0-32 correspond to the Script Codes defined in Inside Macintosh: Text pages 6-52 and 6-53 */switch (script) { /* Mac OS encodings*/ case kTextEncodingMacRoman: info = "Roman"; break; case kTextEncodingMacJapanese: info = "Japanese"; break; case kTextEncodingMacChineseTrad: info = "ChineseTrad"; break; case kTextEncodingMacKorean: info = "Korean"; break; case kTextEncodingMacArabic: info = "Arabic"; break; case kTextEncodingMacHebrew: info = "Hebrew"; break; case kTextEncodingMacGreek: info = "Greek"; break; case kTextEncodingMacCyrillic: info = "Cyrillic"; break; case kTextEncodingMacDevanagari: info = "Devanagari"; break; case kTextEncodingMacGurmukhi: info = "Gurmukhi"; break; case kTextEncodingMacGujarati: info = "Gujarati"; break; case kTextEncodingMacOriya: info = "Oriya"; break; case kTextEncodingMacBengali: info = "Bengali"; break; case kTextEncodingMacTamil: info = "Tamil"; break; case kTextEncodingMacTelugu: info = "Telugu"; break; case kTextEncodingMacKannada: info = "Kannada"; break; case kTextEncodingMacMalayalam: info = "Malayalam"; break; case kTextEncodingMacSinhalese: info = "Sinhalese"; break; case kTextEncodingMacBurmese: info = "Burmese"; break; case kTextEncodingMacKhmer: info = "Khmer"; break; case kTextEncodingMacThai: info = "Thai"; break; case kTextEncodingMacLaotian: info = "Laotian"; break; case kTextEncodingMacGeorgian: info = "Georgian"; break; case kTextEncodingMacArmenian: info = "Armenian"; break; case kTextEncodingMacChineseSimp: info = "ChineseSimp"; break; case kTextEncodingMacTibetan: info = "Tibetan"; break; case kTextEncodingMacMongolian: info = "Mongolian"; break; case kTextEncodingMacEthiopic: info = "Ethiopic"; break; case kTextEncodingMacCentralEurRoman: info = "CentralEurRoman"; break; case kTextEncodingMacVietnamese: info = "Vietnamese"; break; case kTextEncodingMacExtArabic: info = "ExtArabic"; break; case kTextEncodingUnicodeV1_1: info = "Unicode V 1.1"; break; case kTextEncodingUnicodeV2_0: info = "Unicode V 2.0"; break; default: { sprintf(buffer,"Code: 0x%x",(short) script); info = buffer; break; } }return info;}/*** Init Globals***/void MacGlobalsInit(__GPRO){newExtraField.FullPath = NULL;newExtraField.FinderComment = NULL;firstcall_of_macopen = true;MacZipMode = UnKnown_EF;IgnoreEF_Macfilename = true;}/*** Convert the MacOS-Strings (Filenames/Findercomments) to a most compatible.** These strings will be stored in the public area of the zip-archive.** Every foreign platform (outside macos) will access these strings** for extraction.*/static void MakeMacOS_String(char *MacOS_Str, const char SpcChar1, const char SpcChar2, const char SpcChar3, const char SpcChar4){ char *tmpPtr; register uch curch; for (tmpPtr = MacOS_Str; (curch = *tmpPtr) != '\0'; tmpPtr++) { if (curch == SpcChar1) *tmpPtr = SpcChar2; else if (curch == SpcChar3) *tmpPtr = SpcChar4; else /* default */ if (curch > 127) { *tmpPtr = (char)ISO8859_1_to_MacRoman[curch - 128]; } } /* end for */}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -