|
From: <cre...@us...> - 2006-06-24 02:15:28
|
Revision: 1412 Author: creecode Date: 2006-06-23 19:15:20 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1412&view=rev Log Message: ----------- FSRef-ized code cleanup Modified Paths: -------------- Frontier/branches/FSRef_Migration/Common/headers/resources.h Frontier/branches/FSRef_Migration/Common/headers/shell.h Frontier/branches/FSRef_Migration/Common/source/resources.c Frontier/branches/FSRef_Migration/Common/source/search.c Frontier/branches/FSRef_Migration/Common/source/shell.c Modified: Frontier/branches/FSRef_Migration/Common/headers/resources.h =================================================================== --- Frontier/branches/FSRef_Migration/Common/headers/resources.h 2006-06-24 02:08:06 UTC (rev 1411) +++ Frontier/branches/FSRef_Migration/Common/headers/resources.h 2006-06-24 02:15:20 UTC (rev 1412) @@ -48,7 +48,7 @@ extern boolean closeresourcefile (short); -extern boolean openresourcefile (const tyfilespec *, short *, short); +extern boolean openresourcefile ( const ptrfilespec, short *, short ); extern boolean writeresource (ResType, short, bigstring, long, void *); @@ -66,27 +66,27 @@ extern boolean filewriteresource (short, ResType, short, bigstring, long, void *); -extern boolean saveresource (const tyfilespec *, short, ResType, short, bigstring, long, void *, short); +extern boolean saveresource (const ptrfilespec , short, ResType, short, bigstring, long, void *, short); -extern boolean saveresourcehandle (const tyfilespec *, ResType, short, bigstring, Handle, short); +extern boolean saveresourcehandle (const ptrfilespec, ResType, short, bigstring, Handle, short); -extern boolean loadresource (const tyfilespec *, short, ResType, short, bigstring, long, void *, short); +extern boolean loadresource (const ptrfilespec, short, ResType, short, bigstring, long, void *, short); -extern boolean loadresourcehandle (const tyfilespec *, ResType, short, bigstring, Handle *, short); +extern boolean loadresourcehandle (const ptrfilespec, ResType, short, bigstring, Handle *, short); -extern boolean deleteresource (const tyfilespec *, ResType, short, bigstring, short); +extern boolean deleteresource (const ptrfilespec, ResType, short, bigstring, short); -extern boolean getnumresourcetypes (const tyfilespec *, short *, short); +extern boolean getnumresourcetypes (const ptrfilespec, short *, short); -extern boolean getnthresourcetype (const tyfilespec *, short, ResType *, short); +extern boolean getnthresourcetype (const ptrfilespec, short, ResType *, short); -extern boolean getnumresources (const tyfilespec *, ResType, short *, short); +extern boolean getnumresources (const ptrfilespec, ResType, short *, short); -extern boolean getnthresourcehandle (const tyfilespec *, ResType, short, short *, bigstring, Handle *, short); +extern boolean getnthresourcehandle (const ptrfilespec, ResType, short, short *, bigstring, Handle *, short); -extern boolean getresourceattributes (const tyfilespec *, ResType, short, bigstring, short *, short); +extern boolean getresourceattributes (const ptrfilespec, ResType, short, bigstring, short *, short); -extern boolean setresourceattributes (const tyfilespec *, ResType, short, bigstring, short, short); +extern boolean setresourceattributes (const ptrfilespec, ResType, short, bigstring, short, short); #endif Modified: Frontier/branches/FSRef_Migration/Common/headers/shell.h =================================================================== --- Frontier/branches/FSRef_Migration/Common/headers/shell.h 2006-06-24 02:08:06 UTC (rev 1411) +++ Frontier/branches/FSRef_Migration/Common/headers/shell.h 2006-06-24 02:15:20 UTC (rev 1412) @@ -772,9 +772,9 @@ extern short windowgetvnum (WindowPtr); -extern boolean windowsetfspec (WindowPtr, tyfilespec *); +extern boolean windowsetfspec (WindowPtr, ptrfilespec ); -extern boolean windowgetfspec (WindowPtr, tyfilespec *); +extern boolean windowgetfspec (WindowPtr, ptrfilespec ); extern boolean windowgetpath (WindowPtr, bigstring); Modified: Frontier/branches/FSRef_Migration/Common/source/resources.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/resources.c 2006-06-24 02:08:06 UTC (rev 1411) +++ Frontier/branches/FSRef_Migration/Common/source/resources.c 2006-06-24 02:15:20 UTC (rev 1412) @@ -139,101 +139,76 @@ } /*closeresourcefile*/ -boolean openresourcefile (const tyfilespec *fs, short *rnum, short forktype) { -#ifdef MACVERSION +boolean openresourcefile ( const ptrfilespec fs, short *rnum, short forktype ) { + /* - 2006-01-30 creedon: added check for non-carbon OS and trying to access the data fork of a file, error message + 2006-01-30 creedon: on Mac added check for non-carbon OS and trying to access the data fork of a file, error message - 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile + 2005-09-02 creedon: on Mac added support for fork parameter, see resources.c: openresourcefile and pushresourcefile */ - - short resourcerefnum = -1; -#if TARGET_API_MAC_CARBON == 1 - HFSUniStr255 fork; - FSRef myRef; -#else - if (forktype == datafork) { // if we're not on carbon then trying to use the data fork for resources is an error - langerrormessage ("\x4A" "Can't open the data fork for use with resources on this version of the OS."); - return (false); - } -#endif - SetResLoad (false); + #ifdef MACVERSION -#if TARGET_API_MAC_CARBON == 1 - - FSpMakeFSRef (fs, &myRef); + short resourcerefnum = -1; + HFSUniStr255 fork; + OSErr err; + + SetResLoad (false); - switch (forktype) { - case resourcefork: - FSGetResourceForkName (&fork); - break; + switch (forktype) { + case resourcefork: + FSGetResourceForkName (&fork); + break; - case datafork: - FSGetDataForkName (&fork); - break; - } + case datafork: + FSGetDataForkName (&fork); + break; + } - /* - 2005-09-01 creedon - in my reading about the FSOpenResourceFile function someone mentioned - that it might not deal well with corrupted resources and that dropping back to FSpOpenResFile - seemed to do the trick. i've not done that here but could be tried if the problem is real - and manifests. - */ + /* + 2005-09-01 creedon - in my reading about the FSOpenResourceFile function someone mentioned + that it might not deal well with corrupted resources and that dropping back to FSpOpenResFile + seemed to do the trick. i've not done that here but could be tried if the problem is real + and manifests. + */ + + err = FSOpenResourceFile ( &( *fs ).fsref, fork.length, fork.unicode, fsRdWrPerm, &resourcerefnum ); - FSOpenResourceFile (&myRef, fork.length, fork.unicode, fsRdWrPerm, &resourcerefnum); + SetResLoad (true); -#else + if (ResError () == -39 ) { /*eof error, file has no resource fork, create one*/ - resourcerefnum = FSpOpenResFile (fs, fsRdWrPerm); - -#endif - - SetResLoad (true); - - if (ResError () == -39) { /*eof error, file has no resource fork, create one*/ - -#if ((TARGET_API_MAC_CARBON == 1) && !defined(__MWERKS__)) - - OSErr errcode = FSCreateResourceFork (&myRef, fork.length, fork.unicode, 0); - - if (errcode != noErr) /*failed to create resource fork*/ - goto error; + err = FSCreateResourceFork (&fs -> fsref, fork.length, fork.unicode, 0); - FSOpenResourceFile (&myRef, fork.length, fork.unicode, fsRdWrPerm, &resourcerefnum); -#else - HCreateResFile ((*fs).vRefNum, (*fs).parID, (StringPtr) (*fs).name); - - if (ResError () != noErr) /*failed to create resource fork*/ - goto error; - - resourcerefnum = FSpOpenResFile (fs, fsRdWrPerm); + if (err != noErr) /*failed to create resource fork*/ + goto error; + + FSOpenResourceFile (&fs -> fsref, fork.length, fork.unicode, fsRdWrPerm, &resourcerefnum); + } -#endif - } - - if (resourcerefnum != -1) /*it's open*/ { + if (resourcerefnum != -1) /*it's open*/ { + + UseResFile (resourcerefnum); /*in case it was already open*/ + + *rnum = resourcerefnum; + + return (true); + } - UseResFile (resourcerefnum); /*in case it was already open*/ - - *rnum = resourcerefnum; - - return (true); - } - -error: + error: - setoserrorparam ((ptrstring) (*fs).name); /*in case error message takes a filename parameter*/ + setfserrorparam ( fs ); /*in case error message takes a filename parameter*/ - oserror (ResError ()); + oserror (ResError ()); - closeresourcefile (resourcerefnum); /*checks for -1*/ + closeresourcefile (resourcerefnum); /*checks for -1*/ - *rnum = -1; + *rnum = -1; -#endif // MACVERSION + #endif // MACVERSION + return (false); - } /*openresourcefile*/ + } /* openresourcefile */ #ifdef MACVERSION @@ -541,7 +516,7 @@ #endif #ifdef MACVERSION -boolean saveresource (const tyfilespec *fs, short rnum, ResType type, short id, bigstring bsname, long sizedata, void *pdata, short forktype) { +boolean saveresource (const ptrfilespec fs, short rnum, ResType type, short id, bigstring bsname, long sizedata, void *pdata, short forktype) { /* open the file indicated by fname and vnum, and assign pdata to the resource @@ -586,7 +561,7 @@ #endif #ifdef MACVERSION -boolean saveresourcehandle (const tyfilespec *fs, ResType type, short id, bigstring bsname, Handle h, short forktype) { +boolean saveresourcehandle (const ptrfilespec fs, ResType type, short id, bigstring bsname, Handle h, short forktype) { /* 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile @@ -607,36 +582,23 @@ /* static for push/popresourcefile */ - private short newrnum, oldrnum; +private short newrnum, oldrnum; + #ifdef MACVERSION -static boolean pushresourcefile (const tyfilespec *fs, char permission, short forktype) { - - /* - 2006-01-30 creedon: added check for non-carbon OS and trying to access the data fork of a file, error message - - 2005-09-02 creedon: added support for fork parameter, allows access to resources in data forks - 2.1b8 dmb: call SetResLoad (false) before opening a resource fork to - prevent all preload resources from being loaded into our heap - */ - - register OSErr errcode; -#if TARGET_API_MAC_CARBON == 1 - FSRef myRef; -#else - if (forktype == datafork) { // if we're not on carbon then trying to use the data fork for resources is an error - langerrormessage ("\x4A" "Can't open the data fork for use with resources on this version of the OS."); - return (false); - } -#endif + static boolean pushresourcefile (const ptrfilespec fs, char permission, short forktype) { + + /* + 2006-01-30 creedon: added check for non-carbon OS and trying to access the data fork of a file, error message + + 2005-09-02 creedon: added support for fork parameter, allows access to resources in data forks -#if TARGET_API_MAC_CARBON == 1 - - errcode = FSpMakeFSRef (fs, &myRef); - - if (!errcode) { - + 2.1b8 dmb: call SetResLoad (false) before opening a resource fork to + prevent all preload resources from being loaded into our heap + */ + + register OSErr errcode; HFSUniStr255 fork; switch (forktype) { @@ -648,7 +610,7 @@ FSGetDataForkName (&fork); break; } -#endif + oldrnum = CurResFile (); SetResLoad (false); @@ -660,75 +622,61 @@ and manifests. */ -#if TARGET_API_MAC_CARBON == 1 + errcode = FSOpenResourceFile (&fs -> fsref, fork.length, fork.unicode, permission, &newrnum); - errcode = FSOpenResourceFile (&myRef, fork.length, fork.unicode, permission, &newrnum); -#else - // kw 2005-12-17 - OS9 compliance - newrnum = FSpOpenResFile (fs, permission); - -#endif SetResLoad (true); -#if TARGET_API_MAC_CARBON == 1 if (errcode != -1) /*opened OK*/ return (true); -#else - if (newrnum != -1) /*opened OK*/ - return (true); -#endif + errcode = ResError (); -#if TARGET_API_MAC_CARBON == 1 - } -#endif + if (errcode != eofErr) { /*don't want an alert if there isn't a resource fork*/ + + setfserrorparam ( fs ); /*in case error message takes a filename parameter*/ + + oserror (errcode); + } + + return (false); + } /* pushresourcefile */ - if (errcode != eofErr) { /*don't want an alert if there isn't a resource fork*/ + static boolean pushresourcefilereadonly (const ptrfilespec fs, short forktype) { - setoserrorparam ((ptrstring) (*fs).name); /*in case error message takes a filename parameter*/ + /* + 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile + */ - oserror (errcode); - } - - return (false); - } /*pushresourcefile*/ + return (pushresourcefile (fs, fsRdPerm, forktype)); + } /*pushresourcefilereadonly*/ -static boolean pushresourcefilereadonly (const tyfilespec *fs, short forktype) { - - /* - 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile - */ - - return (pushresourcefile (fs, fsRdPerm, forktype)); - } /*pushresourcefilereadonly*/ + static boolean pushresourcefilereadwrite (const ptrfilespec fs, short forktype) { + + /* + 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile + */ + + return (pushresourcefile (fs, fsRdWrPerm, forktype)); + } /*pushresourcefilereadwrite*/ -static boolean pushresourcefilereadwrite (const tyfilespec *fs, short forktype) { - - /* - 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile - */ - - return (pushresourcefile (fs, fsRdWrPerm, forktype)); - } /*pushresourcefilereadwrite*/ - -static boolean popresourcefile (void) { - - if ((newrnum == oldrnum) || (newrnum == filegetapplicationrnum ())) { /*don't close active resource fork!*/ + static boolean popresourcefile (void) { - UpdateResFile (newrnum); + if ((newrnum == oldrnum) || (newrnum == filegetapplicationrnum ())) { /*don't close active resource fork!*/ + + UpdateResFile (newrnum); + + UseResFile (oldrnum); + } + else + closeresourcefile (newrnum); - UseResFile (oldrnum); - } - else - closeresourcefile (newrnum); - - return (true); - } /*popresourcefile*/ + return (true); + } /*popresourcefile*/ #endif -boolean loadresource (const tyfilespec *fs, short rnum, ResType type, short id, bigstring bsname, long sizedata, void *pdata, short forktype) { +boolean loadresource (const ptrfilespec fs, short rnum, ResType type, short id, bigstring bsname, long sizedata, void *pdata, short forktype) { /* the inverse of saveresource. we load in the indicated type and id from @@ -772,7 +720,7 @@ #ifdef MACVERSION -boolean loadresourcehandle (const tyfilespec *fs, ResType type, short id, bigstring bsname, Handle *hresource, short forktype) { +boolean loadresourcehandle (const ptrfilespec fs, ResType type, short id, bigstring bsname, Handle *hresource, short forktype) { /* load a resource into a handle. @@ -820,7 +768,7 @@ #ifdef MACVERSION -boolean deleteresource (const tyfilespec *fs, ResType type, short id, bigstring bsname, short forkttype) { +boolean deleteresource (const ptrfilespec fs, ResType type, short id, bigstring bsname, short forkttype) { /* delete the resource specified by type, id or bsname @@ -857,7 +805,7 @@ #ifdef MACVERSION -boolean getnumresourcetypes (const tyfilespec *fs, short *cttypes, short forktype) { +boolean getnumresourcetypes (const ptrfilespec fs, short *cttypes, short forktype) { /* 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile @@ -875,7 +823,7 @@ #endif #ifdef MACVERSION -boolean getnthresourcetype (const tyfilespec *fs, short n, ResType *type, short forktype) { +boolean getnthresourcetype (const ptrfilespec fs, short n, ResType *type, short forktype) { /* 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile @@ -893,7 +841,7 @@ #endif #ifdef MACVERSION -boolean getnumresources (const tyfilespec *fs, ResType type, short *ctresources, short forktype) { +boolean getnumresources (const ptrfilespec fs, ResType type, short *ctresources, short forktype) { /* 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile @@ -911,7 +859,7 @@ #endif #ifdef MACVERSION -boolean getnthresourcehandle (const tyfilespec *fs, ResType type, short n, short *id, bigstring bsname, Handle *hresource, short forktype) { +boolean getnthresourcehandle (const ptrfilespec fs, ResType type, short n, short *id, bigstring bsname, Handle *hresource, short forktype) { /* load the nth resource of the given type into a handle. also return the @@ -992,7 +940,7 @@ #ifdef MACVERSION -boolean getresourceattributes (const tyfilespec *fs, ResType type, short id, bigstring bsname, short *resattrs, short forktype) { +boolean getresourceattributes (const ptrfilespec fs, ResType type, short id, bigstring bsname, short *resattrs, short forktype) { /* 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile @@ -1021,7 +969,7 @@ #ifdef MACVERSION -boolean setresourceattributes (const tyfilespec *fs, ResType type, short id, bigstring bsname, short resattrs, short forktype) { +boolean setresourceattributes (const ptrfilespec fs, ResType type, short id, bigstring bsname, short resattrs, short forktype) { /* 2005-09-02 creedon: added support for fork parameter, see resources.c: openresourcefile and pushresourcefile Modified: Frontier/branches/FSRef_Migration/Common/source/search.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/search.c 2006-06-24 02:08:06 UTC (rev 1411) +++ Frontier/branches/FSRef_Migration/Common/source/search.c 2006-06-24 02:15:20 UTC (rev 1412) @@ -47,7 +47,7 @@ boundaries. */ - #ifdef MACVERSION + #ifdef MACVERSION OffsetTable offsets; //Code change by Timothy Paustian Sunday, June 25, 2000 12:50:40 PM Modified: Frontier/branches/FSRef_Migration/Common/source/shell.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/shell.c 2006-06-24 02:08:06 UTC (rev 1411) +++ Frontier/branches/FSRef_Migration/Common/source/shell.c 2006-06-24 02:15:20 UTC (rev 1412) @@ -28,7 +28,7 @@ #include "frontier.h" #include "standard.h" -#ifdef MACVERSION +#ifdef MACVERSION #include <land.h> #include <SetUpA5.h> #include "player.h" /*7.0b4 PBS*/ @@ -1038,11 +1038,6 @@ //#endif #endif - #ifdef flsystem6 - if ((**landgetglobals ()).transport != macsystem7) /*under system 7, we wait for appleevents*/ - shellopeninitialfiles (); - #endif - #ifdef WIN95VERSION shellopeninitialfiles (); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |