From: Rolf K. <lab...@us...> - 2006-05-23 12:47:40
|
Update of /cvsroot/opengtoolkit/lvzip/c_source In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv7196/c_source Modified Files: macbin.c macbin.h zlibvc.def Log Message: Modifications for Macbin support Index: macbin.c =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** macbin.c 18 May 2006 20:57:47 -0000 1.22 --- macbin.c 23 May 2006 12:47:29 -0000 1.23 *************** *** 80,227 **** } ! /* Compatibility functions for older LabVIEW libraries */ ! extern OSErr ZEXPORT HasResourceFork(PStr path, int32 *hasResFork) ! { ! FSSpec theFSSpec; ! OSErr err = noErr; ! ! *hasResFork = 0; ! ! err = MakeFSpec(0, 0, path, &theFSSpec); ! if (!err) ! { ! int theRefNum = FSpOpenResFile(&theFSSpec, fsRdPerm); ! if (ResError() == noErr) //we've got a resource file ! { ! CloseResFile(theRefNum); ! *hasResFork = 1; ! } ! } ! return err; ! } ! ! extern OSErr ZEXPORT LV_EncodeMacbinary(PStr srcPath, PStr dstPath) ! { ! FSSpec srcFSSpec; ! FSSpec dstFSSpec; ! OSErr err; ! ! err = MakeFSpec(0, 0, srcPath, &srcFSSpec); ! if (!err) ! { ! err = MakeFSpec(0, 0, dstPath, &dstFSSpec); ! if (!err) ! err = EncodeMacbinaryFiles(&srcFSSpec, &dstFSSpec); ! } ! return err; ! } ! ! extern OSErr ZEXPORT LV_DecodeMacbinary(PStr srcPath, PStr dstPath) ! { ! FSSpec srcFSSpec; ! FSSpec dstFSSpec; ! OSErr err; ! ! err = MakeFSpec(0, 0, srcPath, &srcFSSpec); ! if (!err) ! { ! err = MakeFSpec(0, 0, dstPath, &dstFSSpec); ! if (err) ! err = DecodeMacBinaryFiles(&srcFSSpec, &dstFSSpec); ! } ! return err; ! } ! #elif Win32 ! #include "iowin32.h" ! #endif ! ! extern void ZEXPORT DLLVersion(uChar* version) ! { ! sprintf(version, "lvzlib date: %s, time: %s",__DATE__,__TIME__); ! } ! ! extern MgErr ZEXPORT LVPath_HasResourceFork(Path path, int32 *hasResFork) ! { ! #if Mac ! FSSpec theFSSpec; ! MgErr err = noErr; ! ! *hasResFork = 0; ! ! err = MakeMacSpec(path, &theFSSpec); ! if (!err) ! { ! int theRefNum = FSpOpenResFile(&theFSSpec, fsRdPerm); ! if (ResError() == noErr) //we've got a resource file ! { ! CloseResFile(theRefNum); ! *hasResFork = 1; ! } ! } ! return err; ! #else ! *hasResFork = 0; ! return noErr; ! #endif ! } ! ! extern MgErr ZEXPORT LVPath_EncodeMacbinary(Path srcPath, Path dstPath) ! { ! #if Mac ! FSSpec srcFSSpec; ! FSSpec dstFSSpec; ! MgErr err; ! ! err = MakeMacSpec(srcPath, &srcFSSpec); ! if (!err) ! { ! err = MakeMacSpec(dstPath, &dstFSSpec); ! if (!err) ! err = OSErrToLVErr(EncodeMacbinaryFiles(&srcFSSpec, &dstFSSpec)); ! } ! return err; ! #else ! return mgNotSupported; ! #endif ! } ! ! extern MgErr ZEXPORT LVPath_DecodeMacbinary(Path srcPath, Path dstPath) ! { ! #if Mac ! FSSpec srcFSSpec; ! FSSpec dstFSSpec; ! MgErr err; ! ! err = MakeMacSpec(srcPath, &srcFSSpec); ! if (!err) ! { ! err = MakeMacSpec(dstPath, &dstFSSpec); ! if (!err) ! err = OSErrToLVErr(DecodeMacBinaryFiles(&srcFSSpec, &dstFSSpec)); ! } ! return err; ! #else ! return mgNotSupported; ! #endif ! } ! ! 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); switch (openMode) { --- 80,93 ---- } ! static MgErr OpenResourceFork(FSSpec *fss, uInt32 openMode, uInt32 denyMode, int32 *ioRefnum) { int16 perm; HParamBlockRec pb; FSSpec fss; ! Boolean hasDeny = HasFMExtension(fss, 1L << bHasOpenDeny); + if (!ioRefnum) + return mgArgErr; + switch (openMode) { *************** *** 282,301 **** else DbgPrintf("OpenRF: err = %ld", err); ! ! if (!err) ! err = FNewRefNum(path, (File)pb.ioParam.ioRefNum, refnum); ! #else ! *refnum = 0; ! #endif return err; } ! extern MgErr ZEXPORT LVPath_UtilFileInfo(Path path, ! uInt8 write, ! LVFileInfo *fileInfo, ! PStr comment) { - #if Mac - FSSpec fss; DTPBRec dtpb; CInfoPBRec cpb; --- 148,159 ---- else DbgPrintf("OpenRF: err = %ld", err); ! ! *ioRefnum = pb.ioParam.ioRefNum; return err; } ! ! static MgErr UtilFileInfo(FSSpec fss, uInt8 write, LVFileInfo *fileInfo, PStr comment) { DTPBRec dtpb; CInfoPBRec cpb; *************** *** 305,316 **** return mgArgErr; - DoDebugger(); - - if (err = MakeMacSpec(path, &fss)) - { - DbgPrintf("MakeMacSpec: err = %ld", err); - return err; - } - memset(&cpb, 0, sizeof(CInfoPBRec)); cpb.hFileInfo.ioNamePtr = fss.name; --- 163,166 ---- *************** *** 412,415 **** --- 262,496 ---- } return err; + } + #elif Win32 + #include "iowin32.h" + #endif + + extern MgErr ZEXPORT LV_HasResourceFork(PStr path, int32 *hasResFork) + { + #if Mac + FSSpec theFSSpec; + OSErr err = noErr; + + *hasResFork = 0; + + err = MakeFSpec(0, 0, path, &theFSSpec); + if (!err) + { + int theRefNum = FSpOpenResFile(&theFSSpec, fsRdPerm); + if (ResError() == noErr) //we've got a resource file + { + CloseResFile(theRefNum); + *hasResFork = 1; + } + } + return OSErrToLVErr(err); + #else + *hasResFork = 0; + return noErr; + #endif + } + + extern MgErr ZEXPORT LV_OpenResFork(LVRefNum *refnum, PStr path, uInt32 openMode, uInt32 denyMode) + { + MgErr err = mgNotSupported; + #if Mac + FSSpec fss; + int32 ioRefNum; + + *refnum = 0; + + if (err = MakeFSpec(path, &fss)) + { + DbgPrintf("MakeFSpec: err = %ld", err); + return err; + } + + err = OpenResourceFork(&fss, openMode, denyMode, &ioRefNum); + if (!err) + err = FNewRefNum(path, (File)ioRefNum, refnum); + #else + *refnum = 0; + #endif + return err; + } + + extern MgErr ZEXPORT LV_UtilFileInfo(PStr path, + uInt8 write, + LVFileInfo *fileInfo, + PStr comment) + { + if (!comment || !PStrLen(comment)) + return mgArgErr; + + #if Mac + FSSpec fss; + MgErr err; + + if (err = MakeFSpec(path, &fss)) + { + DbgPrintf("MakeMacSpec: err = %ld", err); + return err; + } + + return UtilFileInfo(&fss, write, fileInfo, comment); + #else + return mgNotSupported; + #endif + } + + extern MgErr ZEXPORT LV_EncodeMacbinary(PStr srcPath, PStr dstPath) + { + #if Mac + FSSpec srcFSSpec; + FSSpec dstFSSpec; + OSErr err; + + err = MakeFSpec(0, 0, srcPath, &srcFSSpec); + if (!err) + { + err = MakeFSpec(0, 0, dstPath, &dstFSSpec); + if (!err) + err = EncodeMacbinaryFiles(&srcFSSpec, &dstFSSpec); + } + return OSErrToLVErr(err); + #else + return mgNotSupported; + #endif + } + + extern MgErr ZEXPORT LV_DecodeMacbinary(PStr srcPath, PStr dstPath) + { + #if Mac + FSSpec srcFSSpec; + FSSpec dstFSSpec; + OSErr err; + + err = MakeFSpec(0, 0, srcPath, &srcFSSpec); + if (!err) + { + err = MakeFSpec(0, 0, dstPath, &dstFSSpec); + if (err) + err = DecodeMacBinaryFiles(&srcFSSpec, &dstFSSpec); + } + return OSErrToLVErr(err); + #else + return mgNotSupported; + #endif + } + + extern void ZEXPORT DLLVersion(uChar* version) + { + sprintf(version, "lvzlib date: %s, time: %s",__DATE__,__TIME__); + } + + extern MgErr ZEXPORT LVPath_HasResourceFork(Path path, int32 *hasResFork) + { + #if Mac + FSSpec theFSSpec; + MgErr err = noErr; + + *hasResFork = 0; + + err = MakeMacSpec(path, &theFSSpec); + if (!err) + { + int theRefNum = FSpOpenResFile(&theFSSpec, fsRdPerm); + if (ResError() == noErr) //we've got a resource file + { + CloseResFile(theRefNum); + *hasResFork = 1; + } + } + return err; + #else + *hasResFork = 0; + return noErr; + #endif + } + + extern MgErr ZEXPORT LVPath_EncodeMacbinary(Path srcPath, Path dstPath) + { + #if Mac + FSSpec srcFSSpec; + FSSpec dstFSSpec; + MgErr err; + + err = MakeMacSpec(srcPath, &srcFSSpec); + if (!err) + { + err = MakeMacSpec(dstPath, &dstFSSpec); + if (!err) + err = OSErrToLVErr(EncodeMacbinaryFiles(&srcFSSpec, &dstFSSpec)); + } + return err; + #else + return mgNotSupported; + #endif + } + + extern MgErr ZEXPORT LVPath_DecodeMacbinary(Path srcPath, Path dstPath) + { + #if Mac + FSSpec srcFSSpec; + FSSpec dstFSSpec; + MgErr err; + + err = MakeMacSpec(srcPath, &srcFSSpec); + if (!err) + { + err = MakeMacSpec(dstPath, &dstFSSpec); + if (!err) + err = OSErrToLVErr(DecodeMacBinaryFiles(&srcFSSpec, &dstFSSpec)); + } + return err; + #else + return mgNotSupported; + #endif + } + + extern MgErr ZEXPORT LVPath_OpenResFork(LVRefNum *refnum, Path path, uInt32 openMode, uInt32 denyMode) + { + MgErr err = mgNotSupported; + #if Mac + FSSpec fss; + int32 ioRefNum; + + *refnum = 0; + + if (err = MakeMacSpec(path, &fss)) + { + DbgPrintf("MakeMacSpec: err = %ld", err); + return err; + } + + err = OpenResourceFork(&fss, openMode, denyMode, &ioRefNum); + if (!err) + err = FNewRefNum(path, (File)ioRefNum, refnum); + #else + *refnum = 0; + #endif + return err; + } + + extern MgErr ZEXPORT LVPath_UtilFileInfo(Path path, + uInt8 write, + LVFileInfo *fileInfo, + PStr comment) + { + if (!comment || !PStrLen(comment)) + return mgArgErr; + + #if Mac + FSSpec fss; + MgErr err; + + if (err = MakeMacSpec(path, &fss)) + { + DbgPrintf("MakeMacSpec: err = %ld", err); + return err; + } + + return UtilFileInfo(&fss, write, fileInfo, comment); #else return mgNotSupported; *************** *** 514,517 **** --- 595,599 ---- { MgErr err; + OSErr ret; LStrPtr lstr; Str255 name; *************** *** 525,528 **** --- 607,611 ---- #endif if (!err) + { if (pathLen <= 255) { *************** *** 533,536 **** --- 616,620 ---- lstr->cnt = pathLen; err = FPathToText(path, lstr); + lstr->str[lstr->cnt] = 0; #if DEBUG if (err) *************** *** 540,549 **** { CToPStr(lstr->str, name); ! err = OSErrToLVErr(MakeFSpec(0, 0, name, fss)); if (!err) err = OSErrToLVErr(ResolveAliasFileWithMountFlags(fss, true, (Boolean*)&isDir, (Boolean*)&isAlias, 0)); #if DEBUG else ! DbgPrintf("MakeFSpec: err = %ld", err); #endif } --- 624,635 ---- { CToPStr(lstr->str, name); ! ret = MakeFSpec(0, 0, name, fss); ! err = OSErrToLVErr(ret); if (!err) err = OSErrToLVErr(ResolveAliasFileWithMountFlags(fss, true, (Boolean*)&isDir, (Boolean*)&isAlias, 0)); #if DEBUG else ! DbgPrintf("MakeFSpec: ret = %d, err = %ld", ret, err); ! DbgPrintf("MakeFSpec: len = %ld, len2 = %d, path = %s", lstr->cnt, (int16)name[0], lstr->str); #endif } *************** *** 558,564 **** { OSErr err = FSMakeFSSpec(vol, dirID, path, fss); ! if (err && !(err == fnfErr)) ! return err; ! /* fileNotFound is expected and normal */ /* Workaround adapted from Apple Developer Support sample code in */ --- 644,685 ---- { OSErr err = FSMakeFSSpec(vol, dirID, path, fss); ! ! if (err) ! { ! DbgPrintf("MakeFSpec: err = %ld", err); ! if (fnfErr == err) ! { ! /* fileNotFound is expected and normal. */ ! err = noErr; ! } ! else if (bdNamErr == err) ! { ! /* MacOSX seems to return sometimes bdNamErr for longer absolute ! filenames, so we try to catch that too. */ ! FSSpec fst; ! Str255 temp; ! uChar *p; ! int32 i; ! ! DbgPrintf("MakeMacSpec: trying with subpaths"); ! /* remove the last elt of the path and see if we have success */ ! PStrCpy(temp, path); ! for (i = 0, p = (uChar*)&temp[PStrLen(path)]; p > temp; p--, i++) ! if (*p == ':') break; ! if (p <= temp) ! return err; ! PStrLen(temp) = PStrLen(path) - i; ! err = MakeFSpec(vol, dirID, temp, &fst); ! DbgPrintf("MakeMacSpec: err2 = %ld", err); ! if (!err || (fnfErr == err)) ! { ! PStrLen(p) = i; ! err = FSMakeFSSpec(vol, fst.parID, p, fss); ! DbgPrintf("MakeMacSpec: err3 = %ld", err); ! } ! } ! else ! return err; ! } /* Workaround adapted from Apple Developer Support sample code in */ Index: macbin.h =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/macbin.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** macbin.h 1 Mar 2006 09:55:33 -0000 1.15 --- macbin.h 23 May 2006 12:47:29 -0000 1.16 *************** *** 147,151 **** typedef uChar Str255[256], *PStr, *CStr, *UPtr; ! typedef const uChar ConstStr255[256]; #define PStrBuf(b) (&((PStr)(b))[1]) --- 147,151 ---- typedef uChar Str255[256], *PStr, *CStr, *UPtr; ! typedef const uChar *ConstCStr, *ConstPStr, ConstStr255[256]; #define PStrBuf(b) (&((PStr)(b))[1]) *************** *** 153,156 **** --- 153,159 ---- #define PStrSize(b) (PStrLen(b)+1) /* # of bytes including length */ + int32 CToPStr(ConstCStr src, PStr dest); + int32 PStrCpy(PStr d, ConstPStr s); + typedef struct { int32 cnt; *************** *** 198,206 **** extern void ZEXPORT DLLVersion OF((uChar* Version)); ! #if Mac ! extern McErr ZEXPORT HasResourceFork OF((PStr path, int32 *hasResFork)); ! extern McErr ZEXPORT LV_EncodeMacbinary OF((PStr srcFileName, PStr dstFileName)); ! extern McErr ZEXPORT LV_DecodeMacbinary OF((PStr srcFileName, PStr dstFileName)); ! #endif extern MgErr ZEXPORT LVPath_ToText OF((Path path, CStr str, int32 *len)); --- 201,216 ---- extern void ZEXPORT DLLVersion OF((uChar* Version)); ! extern MgErr ZEXPORT LV_HasResourceFork OF((PStr path, int32 *hasResFork)); ! extern MgErr ZEXPORT LV_EncodeMacbinary OF((PStr srcFileName, PStr dstFileName)); ! extern MgErr ZEXPORT LV_DecodeMacbinary OF((PStr srcFileName, PStr dstFileName)); ! extern MgErr ZEXPORT LV_UtilFileInfo OF((PStr path, ! uInt8 write, ! LVFileInfo *finderInfo, ! PStr comment)); ! ! extern MgErr ZEXPORT LV_OpenResFork OF((LVRefNum *refnum, ! PStr path, ! uInt32 openMode, ! uInt32 denyMode)); extern MgErr ZEXPORT LVPath_ToText OF((Path path, CStr str, int32 *len)); Index: zlibvc.def =================================================================== RCS file: /cvsroot/opengtoolkit/lvzip/c_source/zlibvc.def,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** zlibvc.def 1 Mar 2006 10:17:44 -0000 1.13 --- zlibvc.def 23 May 2006 12:47:29 -0000 1.14 *************** *** 104,105 **** --- 104,110 ---- LVPath_EncodeMacbinary @205 LVPath_DecodeMacbinary @206 + LV_HasResourceFork @210 + LV_OpenResFork @211 + LV_UtilFileInfo @212 + LV_EncodeMacbinary @213 + LV_DecodeMacbinary @214 |