📄 macos.c
字号:
GetCompletePath(CompletePath, path, &spec, &err); printerr("GetCompletePath", (err != -43) && (err != -120) && (err != 0), err, __LINE__, __FILE__, path); err = FSpGetDirectoryID(&spec, &dirID, &isDirectory); printerr("macmkdir FSpGetDirectoryID ", (err != -43) && (err != 0), err, __LINE__, __FILE__, path); if (err != -43) /* -43 = file/directory not found */ return 0; else { HParamBlockRec hpbr; hpbr.fileParam.ioCompletion = NULL; hpbr.fileParam.ioNamePtr = spec.name; hpbr.fileParam.ioVRefNum = spec.vRefNum; hpbr.fileParam.ioDirID = spec.parID; err = PBDirCreateSync(&hpbr); printerr("macmkdir PBDirCreateSync ", err, err, __LINE__, __FILE__, CompletePath); if (MacZipMode != UnKnown_EF) { err_rc = SetFinderInfo(&spec, &newExtraField); printerr("macmkdir SetFinderInfo ", err_rc, err_rc, __LINE__, __FILE__, CompletePath); } } return (int)err;} /* macmkdir *//**********************//* Function macopen() *//**********************/short macopen(char *sz, short nFlags){ OSErr err; char chPerms = (!nFlags) ? fsRdPerm : fsRdWrPerm; short nFRefNum; static char CompletePath[NAME_MAX]; /* we only need the filespec of the zipfile; filespec of the other files (to be extracted) will be determined by open_outfile() */ if (firstcall_of_macopen) { GetCompletePath(CompletePath, sz, &CurrentFile, &err); printerr("GetCompletePath", (err != -43) && (err != 0), err, __LINE__, __FILE__, sz); /* we are working only with pathnames, this can cause big problems * on a Mac ... */ if (CheckMountedVolumes(CompletePath) > 1) DoWarnUserDupVol(CompletePath); firstcall_of_macopen = false; } if (nFlags > 1) { err = HOpenRF(CurrentFile.vRefNum, CurrentFile.parID, CurrentFile.name, chPerms, &nFRefNum); printerr("HOpenRF", (err != -43) && (err != 0) && (err != -54), err, __LINE__, __FILE__, sz); } else { err = HOpen(CurrentFile.vRefNum, CurrentFile.parID, CurrentFile.name, chPerms, &nFRefNum); printerr("HOpen", (err != -43) && (err != 0), err, __LINE__, __FILE__, sz); } if ( err || (nFRefNum == 1) ) return -1; else { if ( nFlags ) SetEOF( nFRefNum, 0 ); return nFRefNum; }}/***********************//* Function maccreat() *//***********************/short maccreat(char *sz){ OSErr err; char scriptTag = newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript; sz = sz; /* Set fdScript in FXInfo * The negative script constants (smSystemScript, smCurrentScript, * and smAllScripts) don't make sense on disk. So only use scriptTag * if scriptTag >= smRoman (smRoman is 0). * fdScript is valid if high bit is set (see IM-6, page 9-38) */ scriptTag = (scriptTag >= smRoman) ? ((char)scriptTag | (char)0x80) : (smRoman); newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript = scriptTag; err = FSpCreate(&CurrentFile, newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdCreator, newExtraField.fpb.hFileInfo.ioFlFndrInfo.fdType, newExtraField.fpb.hFileInfo.ioFlXFndrInfo.fdScript); err = printerr("FSpCreate maccreat ", (err != -48) && (err != 0), err, __LINE__, __FILE__, G.filename); if (err == noErr) return noErr; else return -1;}/**********************//* Function macread() *//**********************/short macread(short nFRefNum, char *pb, unsigned cb){ long lcb = cb; (void)FSRead( nFRefNum, &lcb, pb ); return (short)lcb;}/***********************//* Function macwrite() *//***********************/long macwrite(short nFRefNum, char *pb, unsigned cb){ long lcb = cb; OSErr err; FILE *stream; if ( (nFRefNum == 1) || (nFRefNum == 2) ) { stream = (nFRefNum == 1 ? stdout : stderr); pb[cb] = '\0'; /* terminate C-string */ /* assumes writable buffer (e.g., slide[]) */ /* with room for one more char at end of buf */ MakeMacOS_String( pb, ' ', ' ', ' ', ' '); lcb = fprintf(stream, pb); } else err = FSWrite( nFRefNum, &lcb, pb ); if (err != 0) { errno = ERANGE; return -1; } return (long)lcb;}/***********************//* Function macclose() *//***********************/short macclose(short nFRefNum){OSErr err;err = FSClose( nFRefNum );printerr("macclose FSClose ",err,err, __LINE__,__FILE__,G.filename);return err;}/***********************//* Function maclseek() *//***********************/long maclseek(short nFRefNum, long lib, short nMode){ ParamBlockRec pbr; if (nMode == SEEK_SET) nMode = fsFromStart; else if (nMode == SEEK_CUR) nMode = fsFromMark; else if (nMode == SEEK_END) nMode = fsFromLEOF; pbr.ioParam.ioRefNum = nFRefNum; pbr.ioParam.ioPosMode = nMode; pbr.ioParam.ioPosOffset = lib; (void)PBSetFPosSync(&pbr); return pbr.ioParam.ioPosOffset;}/***********************************//* Function FindNewExtractFolder() *//***********************************/char *FindNewExtractFolder(char *ExtractPath){char buffer[NAME_MAX];short count = 0, length = strlen(ExtractPath) - 2;OSErr err;FSSpec Spec;long theDirID;Boolean isDirectory;for (count = 0; count < 99; count++) { memset(buffer,0,sizeof(buffer)); ExtractPath[length] = 0; sprintf(buffer,"%s%d",ExtractPath,count); GetCompletePath(ExtractPath, buffer, &Spec,&err); err = FSpGetDirectoryID(&Spec, &theDirID, &isDirectory); if (err == -43) return ExtractPath; }return ExtractPath; /* can't find unique path, defaults to Extract-Folder */}/* The following functions are dealing with the extra-field handling, only. *//****************************//* Function SetFinderInfo() *//****************************/static OSErr SetFinderInfo(FSSpec *spec, MACINFO *mi){ OSErr err; CInfoPBRec fpb; fpb.hFileInfo.ioNamePtr = (StringPtr) &(spec->name); fpb.hFileInfo.ioVRefNum = spec->vRefNum; fpb.hFileInfo.ioDirID = spec->parID; fpb.hFileInfo.ioFDirIndex = 0; err = PBGetCatInfo(&fpb, false); printerr("PBGetCatInfo SetFinderInfo ", err, err, __LINE__, __FILE__, G.filename); if ((MacZipMode == JohnnyLee_EF) || (MacZipMode == NewZipMode_EF)) { if (!UseUT_ExtraField) { fpb.hFileInfo.ioFlCrDat = mi->fpb.hFileInfo.ioFlCrDat; fpb.hFileInfo.ioFlMdDat = mi->fpb.hFileInfo.ioFlMdDat; } fpb.hFileInfo.ioFlFndrInfo = mi->fpb.hFileInfo.ioFlFndrInfo; } if (MacZipMode == NewZipMode_EF) { if (uO.E_flag) PrintMacExtraInfo(); fpb.hFileInfo.ioFlXFndrInfo = mi->fpb.hFileInfo.ioFlXFndrInfo; fpb.hFileInfo.ioFVersNum = mi->fpb.hFileInfo.ioFVersNum; fpb.hFileInfo.ioACUser = mi->fpb.hFileInfo.ioACUser; if (!UseUT_ExtraField) { fpb.hFileInfo.ioFlBkDat = mi->fpb.hFileInfo.ioFlBkDat;#ifdef USE_EF_UT_TIME if (#ifdef IZ_CHECK_TZ G.tz_is_valid &&#endif !(mi->flags & EB_M3_FL_NOUTC)) {#ifdef DEBUG_TIME { printf("\nSetFinderInfo: Mac modif: %lu local -> UTOffset: %d before AdjustForTZmoveMac\n", fpb.hFileInfo.ioFlCrDat, mi->Cr_UTCoffs); }#endif /* DEBUG_TIME */ fpb.hFileInfo.ioFlCrDat = AdjustForTZmoveMac(fpb.hFileInfo.ioFlCrDat, mi->Cr_UTCoffs); fpb.hFileInfo.ioFlMdDat = AdjustForTZmoveMac(fpb.hFileInfo.ioFlMdDat, mi->Md_UTCoffs); fpb.hFileInfo.ioFlBkDat = AdjustForTZmoveMac(fpb.hFileInfo.ioFlBkDat, mi->Bk_UTCoffs);#ifdef DEBUG_TIME { printf("SetFinderInfo: Mac modif: %lu local -> UTOffset: %d after AdjustForTZmoveMac\n", fpb.hFileInfo.ioFlCrDat, mi->Cr_UTCoffs); }#endif /* DEBUG_TIME */ }#endif /* USE_EF_UT_TIME */ } if (mi->FinderComment) { C2PStr(mi->FinderComment); err = FSpDTSetComment(spec, (unsigned char *) mi->FinderComment); printerr("FSpDTSetComment:",err , err, __LINE__, __FILE__, mi->FullPath); } } /* Restore ioDirID field in pb which was changed by PBGetCatInfo */ fpb.hFileInfo.ioDirID = spec->parID; err = PBSetCatInfo(&fpb, false); return err;} /* SetFinderInfo() *//*** Scan the extra fields in extra_field, and look for a MacOS EF; return a** pointer to that EF, or NULL if it's not there.*/static uch *scanMacOSexfield(uch *ef_ptr, unsigned ef_len, short *MacZipMode){ while (ef_ptr != NULL && ef_len >= EB_HEADSIZE) { unsigned eb_id = makeword(EB_ID + ef_ptr); unsigned eb_len = makeword(EB_LEN + ef_ptr); if (eb_len > (ef_len - EB_HEADSIZE)) { Trace((stderr, "scanMacOSexfield: block length %u > rest ef_size %u\n", eb_len, ef_len - EB_HEADSIZE)); break; } if (isMacOSexfield(eb_id, eb_len, MacZipMode)) { return ef_ptr; } ef_ptr += (eb_len + EB_HEADSIZE); ef_len -= (eb_len + EB_HEADSIZE); } return NULL;}static Boolean isMacOSexfield(unsigned id, unsigned size, short *MacZipMode){ switch (id) { case EF_ZIPIT: case EF_ZIPIT2: { /* we do not support ZipIt's format completly */ Info(slide, 0x221, ((char *)slide, "warning: found %s ZipIt extra field (size %u) -> "\ "file is probably not usable!!\n", (id == EF_ZIPIT2 ? "short": "long", size))); IgnoreEF_Macfilename = true; return false; } case EF_MAC3: { *MacZipMode = NewZipMode_EF; IgnoreEF_Macfilename = false; return true; } case EF_JLMAC: { *MacZipMode = JohnnyLee_EF; IgnoreEF_Macfilename = true; return true; } default: { *MacZipMode = UnKnown_EF; IgnoreEF_Macfilename = true; return false; } } return false;}/*** Return a unsigned long from a four-byte sequence** in big endian format*/ulg makePPClong(ZCONST uch *sig){ return (((ulg)sig[0]) << 24) + (((ulg)sig[1]) << 16) + (((ulg)sig[2]) << 8) + ((ulg)sig[3]);}/*** Return a unsigned short from a two-byte sequence** in big endian format*/ush makePPCword(ZCONST uch *b){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -