From: Rolf K. <lab...@us...> - 2006-03-01 09:55:37
|
Update of /cvsroot/opengtoolkit/lvzip/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30981/c_source Modified Files: macbin.c macbin.h Log Message: More fixes to the MacOSX code base to allow for mac binary support. The actual path conversion routine still does not work correctly and crashes LabVIEW. Index: macbin.c =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** macbin.c 11 Jan 2006 12:13:56 -0000 1.19 --- macbin.c 1 Mar 2006 09:55:33 -0000 1.20 *************** *** 22,26 **** #define kFileChanged (1L<<7) ! static OSErr MakeMacSpec(Path path, FSSpec *fss); static OSErr MakeFSpec(int16 vol, int32 dirID, ConstStr255 path, FSSpec *fss); static MgErr OSErrToLVErr(OSErr err); --- 22,26 ---- #define kFileChanged (1L<<7) ! static MgErr MakeMacSpec(Path path, FSSpec *fss); static OSErr MakeFSpec(int16 vol, int32 dirID, ConstStr255 path, FSSpec *fss); static MgErr OSErrToLVErr(OSErr err); *************** *** 81,85 **** /* Compatibility functions for older LabVIEW libraries */ ! extern McErr ZEXPORT HasResourceFork(PStr path, int32 *hasResFork) { FSSpec theFSSpec; --- 81,85 ---- /* Compatibility functions for older LabVIEW libraries */ ! extern OSErr ZEXPORT HasResourceFork(PStr path, int32 *hasResFork) { FSSpec theFSSpec; *************** *** 101,105 **** } ! extern McErr ZEXPORT LV_EncodeMacbinary(PStr srcPath, PStr dstPath) { FSSpec srcFSSpec; --- 101,105 ---- } ! extern OSErr ZEXPORT LV_EncodeMacbinary(PStr srcPath, PStr dstPath) { FSSpec srcFSSpec; *************** *** 117,121 **** } ! extern McErr ZEXPORT LV_DecodeMacbinary(PStr srcPath, PStr dstPath) { FSSpec srcFSSpec; --- 117,121 ---- } ! extern OSErr ZEXPORT LV_DecodeMacbinary(PStr srcPath, PStr dstPath) { FSSpec srcFSSpec; *************** *** 145,149 **** #if Mac FSSpec theFSSpec; ! OSErr err = noErr; *hasResFork = 0; --- 145,149 ---- #if Mac FSSpec theFSSpec; ! MgErr err = noErr; *hasResFork = 0; *************** *** 159,163 **** } } ! return OSErrToLVErr(err);; #else *hasResFork = 0; --- 159,163 ---- } } ! return err; #else *hasResFork = 0; *************** *** 171,175 **** FSSpec srcFSSpec; FSSpec dstFSSpec; ! OSErr err; err = MakeMacSpec(srcPath, &srcFSSpec); --- 171,175 ---- FSSpec srcFSSpec; FSSpec dstFSSpec; ! MgErr err; err = MakeMacSpec(srcPath, &srcFSSpec); *************** *** 178,184 **** err = MakeMacSpec(dstPath, &dstFSSpec); if (!err) ! err = EncodeMacbinaryFiles(&srcFSSpec, &dstFSSpec); } ! return OSErrToLVErr(err); #else return mgNotSupported; --- 178,184 ---- err = MakeMacSpec(dstPath, &dstFSSpec); if (!err) ! err = OSErrToLVErr(EncodeMacbinaryFiles(&srcFSSpec, &dstFSSpec)); } ! return err; #else return mgNotSupported; *************** *** 191,195 **** FSSpec srcFSSpec; FSSpec dstFSSpec; ! OSErr err; err = MakeMacSpec(srcPath, &srcFSSpec); --- 191,195 ---- FSSpec srcFSSpec; FSSpec dstFSSpec; ! MgErr err; err = MakeMacSpec(srcPath, &srcFSSpec); *************** *** 197,204 **** { err = MakeMacSpec(dstPath, &dstFSSpec); ! if (err) ! err = DecodeMacBinaryFiles(&srcFSSpec, &dstFSSpec); } ! return OSErrToLVErr(err); #else return mgNotSupported; --- 197,204 ---- { err = MakeMacSpec(dstPath, &dstFSSpec); ! if (!err) ! err = OSErrToLVErr(DecodeMacBinaryFiles(&srcFSSpec, &dstFSSpec)); } ! return err; #else return mgNotSupported; *************** *** 208,223 **** extern MgErr ZEXPORT LVPath_OpenResFork(LVRefNum *refnum, Path path, uInt32 openMode, uInt32 denyMode) { #if Mac int16 perm; HParamBlockRec pb; FSSpec fss; - OSErr ret; Boolean hasDeny; *refnum = 0; ! if (ret = MakeMacSpec(path, &fss)) { ! return OSErrToLVErr(ret); } hasDeny = HasFMExtension(&fss, 1L << bHasOpenDeny); --- 208,224 ---- extern MgErr ZEXPORT LVPath_OpenResFork(LVRefNum *refnum, Path path, uInt32 openMode, uInt32 denyMode) { + MgErr err = mgNotSupported; #if Mac int16 perm; HParamBlockRec pb; FSSpec fss; Boolean hasDeny; *refnum = 0; ! if (err = MakeMacSpec(path, &fss)) { ! DbgPrintf("MakeMacSpec: err = %ld", err); ! return err; } hasDeny = HasFMExtension(&fss, 1L << bHasOpenDeny); *************** *** 266,289 **** if (hasDeny) { ! ret = PBHOpenRFDenySync(&pb); } else { pb.ioParam.ioPermssn = perm; ! ret = PBHOpenSync(&pb); } ! if (!ret) { if (openMode == openWriteOnlyTruncate) ! ret = SetEOF(pb.ioParam.ioRefNum, 0L); } ! if (ret) ! return OSErrToLVErr(ret); ! ! return FNewRefNum(path, (File)pb.ioParam.ioRefNum, refnum); ! #endif *refnum = 0; ! return noErr; } --- 267,292 ---- if (hasDeny) { ! err = OSErrToLVErr(PBHOpenRFDenySync(&pb)); } else { pb.ioParam.ioPermssn = perm; ! err = OSErrToLVErr(PBHOpenSync(&pb)); } ! if (!err) { if (openMode == openWriteOnlyTruncate) ! err = OSErrToLVErr(SetEOF(pb.ioParam.ioRefNum, 0L)); } ! else ! DbgPrintf("OpenRF: err = %ld", err); ! ! if (!err) ! err = FNewRefNum(path, (File)pb.ioParam.ioRefNum, refnum); ! #else *refnum = 0; ! #endif ! return err; } *************** *** 297,307 **** DTPBRec dtpb; CInfoPBRec cpb; ! OSErr err; if (!comment || !PStrLen(comment)) return mgArgErr; if (err = MakeMacSpec(path, &fss)) ! return OSErrToLVErr(err); memset(&cpb, 0, sizeof(CInfoPBRec)); --- 300,315 ---- DTPBRec dtpb; CInfoPBRec cpb; ! MgErr err; if (!comment || !PStrLen(comment)) return mgArgErr; + DoDebugger(); + if (err = MakeMacSpec(path, &fss)) ! { ! DbgPrintf("MakeMacSpec: err = %ld", err); ! return err; ! } memset(&cpb, 0, sizeof(CInfoPBRec)); *************** *** 310,315 **** cpb.hFileInfo.ioDirID = fss.parID; ! err = PBGetCatInfoSync(&cpb); ! if (err == noErr) { dtpb.ioCompletion = nil; --- 318,326 ---- cpb.hFileInfo.ioDirID = fss.parID; ! err = OSErrToLVErr(PBGetCatInfoSync(&cpb)); ! if (err) ! DbgPrintf("PBGetCatInfo: err = %ld", err); ! ! if (!err) { dtpb.ioCompletion = nil; *************** *** 317,322 **** dtpb.ioVRefNum = fss.vRefNum; ! err = PBDTGetPath(&dtpb); ! if (err == noErr) { dtpb.ioNamePtr = fss.name; --- 328,335 ---- dtpb.ioVRefNum = fss.vRefNum; ! err = OSErrToLVErr(PBDTGetPath(&dtpb)); ! if (err) ! DbgPrintf("PBGetPath: err = %ld", err); ! if (!err) { dtpb.ioNamePtr = fss.name; *************** *** 354,361 **** } ! err = PBSetCatInfoSync(&cpb); if (!err && comment) { ! err = PBDTSetCommentSync(&dtpb); } } --- 367,376 ---- } ! err = OSErrToLVErr(PBSetCatInfoSync(&cpb)); ! if (err) ! DbgPrintf("PBSetCatInfo: err = %ld", err); if (!err && comment) { ! err = OSErrToLVErr(PBDTSetCommentSync(&dtpb)); } } *************** *** 392,400 **** ConvertLVTime(&fileInfo->cDate, &cpb.hFileInfo.ioFlMdDat, true); } ! err = PBDTGetCommentSync(&dtpb); } } } ! return OSErrToLVErr(err); #else return mgNotSupported; --- 407,415 ---- ConvertLVTime(&fileInfo->cDate, &cpb.hFileInfo.ioFlMdDat, true); } ! err = OSErrToLVErr(PBDTGetCommentSync(&dtpb)); } } } ! return err; #else return mgNotSupported; *************** *** 417,451 **** } ! #if Mac ! static int32 LToPStr(LStrPtr lstr, PStr str) { ! int32 n = LStrLen(lstr); ! if (n > 255) ! n = 255; ! str[0] = n; ! if (n) ! BlockMove(LStrBuf(lstr), PStrBuf(str), n); ! return n; } ! static OSErr MakeMacSpec(Path path, FSSpec *fss) { ! OSErr err; ! LStr256 lStr; Str255 name; Boolean isDir, isAlias; ! lStr.cnt = -1; ! FPathToText(path, (LStrPtr)&lStr); ! if (lStr.cnt > 255) ! return paramErr; ! else { ! FPathToText(path, (LStrPtr)&lStr); ! LToPStr((LStrPtr)&lStr, name); ! err = MakeFSpec(0, 0, name, fss); ! if (err == noErr) ! err = ResolveAliasFileWithMountFlags(fss, true, (Boolean*)&isDir, (Boolean*)&isAlias, 0); } return err; } --- 432,539 ---- } ! #if MacOSX ! static MgErr ConvertToPosixPath(const CStr hfsPath, CStr posixPath, int32 *len) { ! MgErr err = mFullErr; ! CFStringRef fileRef, posixRef = NULL; ! CFURLRef urlRef = NULL; ! Boolean isDir = FALSE; ! uInt32 enc = CFStringGetSystemEncoding(); ! ! if (!len) ! return mgArgErr; ! ! fileRef = CFStringCreateWithCString(NULL, hfsPath, enc); ! if (fileRef) ! { ! urlRef = CFURLCreateWithFileSystemPath(NULL, fileRef, kCFURLHFSPathStyle, isDir); ! CFRelease(fileRef); ! } ! ! if (urlRef) ! { ! posixRef = CFURLCopyFileSystemPath(urlRef, kCFURLPOSIXPathStyle); ! CFRelease(urlRef); ! } ! ! if (posixRef) ! { ! int32 l = CFStringGetLength(posixRef); ! ! err = noErr; ! if (posixPath && *len > l) ! if (!CFStringGetCString(posixRef, posixPath, *len, enc)) ! err = mgArgErr; ! else ! *len = l; ! CFRelease(posixRef); ! } ! return err; } + #endif ! extern MgErr ZEXPORT LVPath_ToText(Path path, CStr str, int32 *len) { ! MgErr err; ! LStrPtr lstr; ! int32 pathLen = -1; ! ! if (!len) ! return mgArgErr; ! ! err = FPathToText(path, (LStrPtr)&pathLen); ! if (!err) ! { ! if (str && *len > pathLen) ! { ! lstr = (LStrPtr)DSNewPClr(pathLen + 1 + sizeof(int32)); ! if (!lstr) ! return mFullErr; ! lstr->cnt = pathLen; ! err = FPathToText(path, lstr); ! if (!err) ! #if MacOSX ! err = ConvertToPosixPath(lstr->str, str, len); ! #else ! StrNCpy(str, lstr->str, *len); ! #endif ! DSDisposePtr((UPtr)lstr); ! } ! #if MacOSX ! else ! err = ConvertToPosixPath(lstr->str, NULL, len); ! #else ! *len = pathLen; ! #endif ! } ! return err; ! } ! ! #if Mac ! static MgErr MakeMacSpec(Path path, FSSpec *fss) ! { ! MgErr err; Str255 name; + int32 len; Boolean isDir, isAlias; ! err = LVPath_ToText(path, NULL, &len); ! if (err) ! DbgPrintf("LVPath_ToText: err = %ld", err); ! ! if (!err && len <= 255) { ! err = LVPath_ToText(path, name, &len); ! if (err) ! DbgPrintf("LVPath_ToText: err = %ld", err); ! err = OSErrToLVErr(MakeFSpec(0, 0, name, fss)); ! if (!err) ! err = OSErrToLVErr(ResolveAliasFileWithMountFlags(fss, true, (Boolean*)&isDir, (Boolean*)&isAlias, 0)); ! else ! DbgPrintf("MakeFSpec: err = %ld", err); ! } + else + err = mgArgErr; return err; } *************** *** 464,468 **** /* root directory by passing a full pathname in MakeFSSpec's */ /* fileName parameter. */ ! if ((err == noErr) && (fss->parID == 0)) { fss->parID = fsRtParID; } --- 552,557 ---- /* root directory by passing a full pathname in MakeFSSpec's */ /* fileName parameter. */ ! if ((err == noErr) && (fss->parID == 0)) ! { fss->parID = fsRtParID; } Index: macbin.h =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.h,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** macbin.h 11 Jan 2006 12:13:57 -0000 1.14 --- macbin.h 1 Mar 2006 09:55:33 -0000 1.15 *************** *** 13,21 **** #if defined(macintosh) || defined(__PPCC__) || defined(THINK_C) || defined(__SC__) || defined(__MWERKS__) || defined(__APPLE_CC__) ! #define Mac 1 #elif defined(__GNUC__) || defined(linux) ! #define Unix 1 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN32_WCE) ! #define Win32 1 #endif --- 13,36 ---- #if defined(macintosh) || defined(__PPCC__) || defined(THINK_C) || defined(__SC__) || defined(__MWERKS__) || defined(__APPLE_CC__) ! #define Mac 1 ! #ifdef __MACH__ ! #define MacOSX 1 ! #endif #elif defined(__GNUC__) || defined(linux) ! #define Unix 1 #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN32_WCE) ! #define Win32 1 ! #endif ! ! #if defined(DEBUG) ! #if Win32 ! #define DoDebugger() {__asm int 3} ! #elif Mac ! #define DoDebugger() Debugger() ! #else ! #define DoDebugger() ! #endif ! #else ! #define DoDebugger() #endif *************** *** 172,175 **** --- 187,197 ---- MgErr FPathToText(Path path, LStrPtr lstr); MgErr FNewRefNum(Path path, File fd, LVRefNum* refnum); + int32 DbgPrintf(CStr fmt, ...); + + UPtr DSNewPClr(int32); + MgErr DSDisposePtr(UPtr); + int32 StrNCpy(CStr t, const CStr s, int32 l); + + #define Min(a, b) ((a) < (b)) ? (a) : (b) /* Our exported functions */ *************** *** 182,185 **** --- 204,208 ---- #endif + extern MgErr ZEXPORT LVPath_ToText OF((Path path, CStr str, int32 *len)); extern MgErr ZEXPORT LVPath_HasResourceFork OF((Path path, int32 *hasResFork)); extern MgErr ZEXPORT LVPath_EncodeMacbinary OF((Path srcFileName, Path dstFileName)); |