|
From: <cre...@us...> - 2006-09-09 19:24:52
|
Revision: 1500
http://svn.sourceforge.net/frontierkernel/?rev=1500&view=rev
Author: creecode
Date: 2006-09-09 12:24:48 -0700 (Sat, 09 Sep 2006)
Log Message:
-----------
for Mac, in directorytopath, filespectopath, pathtofilespec & setfsfile functions, fix some broken edge use cases
Modified Paths:
--------------
Frontier/branches/FSRef_Migration/Common/source/filepath.c
Modified: Frontier/branches/FSRef_Migration/Common/source/filepath.c
===================================================================
--- Frontier/branches/FSRef_Migration/Common/source/filepath.c 2006-09-09 18:53:51 UTC (rev 1499)
+++ Frontier/branches/FSRef_Migration/Common/source/filepath.c 2006-09-09 19:24:48 UTC (rev 1500)
@@ -51,40 +51,63 @@
static tyfilespec fsdefault; // we maintain our own default directory
-boolean directorytopath ( const ptrfilespec fs, bigstring path ) {
+ boolean directorytopath ( const ptrfilespec fs, bigstring path ) {
- //
- // 2006-06-06 creedon: FSRef-ized
- // another way might be to use FSRefMakePath and then push insert the volume name on it
- //
+ //
+ // 2006-09-09 creedon: FSRef-ized
+ // another way might be to use FSRefMakePath and then push insert the volume name on it
+ //
- CFMutableStringRef ioPath = CFStringCreateMutable ( NULL, 0 );
- FSCatalogInfo catalogInfo;
- FSRef localRef = ( *fs ).fsref;
- HFSUniStr255 names [ 100 ];
- int i, n;
- OSStatus status = noErr;
- UniChar inSepChar = ':';
-
- clearbytes ( &catalogInfo, longsizeof ( catalogInfo ) );
+ OSErr err;
+ OSStatus status;
+
+ /* bail if fs is Volumes directory */ {
+
+ FSRef volumesfsref;
+ OSErr err;
+
+ status = FSPathMakeRef ( "/Volumes", &volumesfsref, NULL );
+
+ err = FSCompareFSRefs ( &( *fs ).fsref , &volumesfsref );
+
+ if ( err == noErr ) {
+
+ setemptystring ( path );
+
+ return ( true );
+
+ }
+
+ } // bail
- for ( n = 0 ; status == noErr && catalogInfo.nodeID != fsRtDirID && n < 100 ; n++ )
- status = FSGetCatalogInfo ( &localRef, kFSCatInfoNodeID, &catalogInfo, &names [ n ], NULL, &localRef );
-
- if ( status != noErr )
- return ( false );
+ CFMutableStringRef ioPath = CFStringCreateMutable ( NULL, 0 );
+ FSCatalogInfo catalogInfo;
+ FSRef localRef = ( *fs ).fsref;
+ HFSUniStr255 names [ 100 ];
+ int i, n;
+ UniChar inSepChar = ':';
- for ( i = n - 1; i >= 0; --i ) {
- CFStringAppendCharacters ( ioPath, names [ i ].unicode, names [ i ].length );
+ err = noErr;
- // if ( i > 0 )
+ clearbytes ( &catalogInfo, longsizeof ( catalogInfo ) );
+
+ for ( n = 0 ; err == noErr && catalogInfo.nodeID != fsRtDirID && n < 100 ; n++ )
+ err = FSGetCatalogInfo ( &localRef, kFSCatInfoNodeID, &catalogInfo, &names [ n ], NULL, &localRef );
+
+ if ( err != noErr )
+ return ( false );
+
+ for ( i = n - 1; i >= 0; --i ) {
+ CFStringAppendCharacters ( ioPath, names [ i ].unicode, names [ i ].length );
+
+ // if ( i > 0 )
+
+ CFStringAppendCharacters ( ioPath, &inSepChar, 1 );
+ }
- CFStringAppendCharacters ( ioPath, &inSepChar, 1 );
- }
-
- return ( CFStringGetPascalString ( ioPath, path, 256, kCFStringEncodingMacRoman ) );
+ return ( CFStringGetPascalString ( ioPath, path, 256, kCFStringEncodingMacRoman ) );
- } // directorytopath
+ } // directorytopath
#endif
@@ -164,7 +187,7 @@
boolean filespectopath (const ptrfilespec fs, bigstring bspath) {
//
- // 2006-06-24 creedon: for Mac, FSRef-ized
+ // 2006-09-09 creedon: for Mac, FSRef-ized
//
// 2.1a7 dmb: if it's a null filespec, return the empty string
//
@@ -178,6 +201,7 @@
#ifdef MACVERSION
+ bigstring bs;
boolean flfolder;
FSCatalogInfo catalogInfo;
tyfilespec fsp, fst = *fs;
@@ -188,26 +212,16 @@
err = FSGetCatalogInfo ( &fst.fsref, kFSCatInfoParentDirID | kFSCatInfoVolume, &catalogInfo, &outName, NULL,
&fsp.fsref );
-
- if ( catalogInfo.parentDirID == fsRtParID ) { // it's a volume
-
- HFSUniStr255ToStr255 ( &outName, bspath );
-
- pushchar ( ':', bspath );
- return ( true );
- }
+ if ( err != noErr )
+ return ( false );
setemptystring ( bspath );
- if ( ! FSRefValid ( &fst.fsref ) ) // need to check for noErr here?
- return (true);
+ if ( catalogInfo.parentDirID != fsRtParID ) // it's not a volume so lets get the directory path
+ if ( ! directorytopath ( &fsp, bspath ) )
+ return ( false );
- if ( ! directorytopath ( &fsp, bspath ) )
- return (false);
-
- bigstring bs;
-
HFSUniStr255ToStr255 ( &outName, bs );
pushstring ( bs, bspath );
@@ -228,7 +242,7 @@
if ( flfolder )
assurelastchariscolon ( bspath );
- return (true);
+ return ( true );
#endif
@@ -255,7 +269,7 @@
boolean pathtofilespec ( bigstring bspath, ptrfilespec fs ) {
//
- // 2006-08-19 creedon: for Mac, FSRef-ized
+ // 2006-09-05 creedon: for Mac, FSRef-ized
//
// 5.0d8 dmb: clear fs first thing
//
@@ -272,12 +286,8 @@
// non-existant files, we don't give up right away.
//
- #ifdef WIN95VERSION
-
- bigstring bsfolder;
+ bigstring bsfolder;
- #endif // WIN95VERSION
-
clearbytes ( fs, sizeof ( *fs ) );
if ( isemptystring ( bspath ) )
@@ -287,6 +297,8 @@
bigstring bs, bspathtmp;
FSRef fsr;
+ HFSUniStr255 name;
+ OSErr err;
OSStatus status;
short ix = 1, ixslashpos = 0, slashpos [ 255 ];
@@ -294,35 +306,34 @@
cleanendoffilename ( bspathtmp );
- /* try as full path */ {
+ if ( scanstring ( ':', bspath, &ix ) && ( ix > 1 ) ) { // full path, includes a colon, not the first character
+
+ bigstring bsfile, bsfullpath;
- bigstring bsfullpath;
-
copystring ( bspathtmp, bsfullpath );
- insertstring ( BIGSTRING ( "\x09" ":Volumes:" ), bsfullpath ); // this is a funky syntax but we don't want to
- // convert to slashes until the last moment, so
- // we can resuse
+ insertstring ( BIGSTRING ( "\x09" ":Volumes:" ), bsfullpath );
- copystring ( bsfullpath, bs);
+ copystring ( bsfullpath, bs );
+
+ /* convert to / delimited path */ {
- while ( scanstring ( '/', bs, &ix ) )
- slashpos [ ixslashpos++ ] = ix++;
+ while ( scanstring ( '/', bs, &ix ) )
+ slashpos [ ixslashpos++ ] = ix++;
+
+ stringreplaceall ( ':', '/', bs );
+
+ while ( ixslashpos > 0 )
+ setstringcharacter ( bs, slashpos [ --ixslashpos ] - 1, ':' );
+ }
- stringreplaceall ( ':', '/', bs );
+ convertpstring ( bs ); // bs is now a c string
- while ( ixslashpos > 0 )
- setstringcharacter ( bs, slashpos [ --ixslashpos ] - 1, ':' );
-
- convertpstring ( bs );
-
status = FSPathMakeRef ( bs, &fsr, NULL );
if ( status == noErr ) {
- HFSUniStr255 name;
-
- status = FSGetCatalogInfo ( &fsr, kFSCatInfoNone, NULL, &name, NULL, &fsr );
+ err = FSGetCatalogInfo ( &fsr, kFSCatInfoNone, NULL, &name, NULL, &fsr );
( *fs ).fsref = fsr;
@@ -330,58 +341,44 @@
return ( true );
- }
+ } // if
- /* emulate behaviour of FSSpec */ {
+ filefrompath ( bsfullpath, bsfile );
+ folderfrompath ( bsfullpath, bsfolder );
+
+ /* convert to / delimited path */ {
+
ix = 1;
ixslashpos = 0;
-
- folderfrompath ( bsfullpath, bs );
-
- while ( scanstring ( '/', bs, &ix ) )
+
+ while ( scanstring ( '/', bsfolder, &ix ) )
slashpos [ ixslashpos++ ] = ix++;
-
- stringreplaceall ( ':', '/', bs );
+ stringreplaceall ( ':', '/', bsfolder );
+
while ( ixslashpos > 0 )
- setstringcharacter ( bs, slashpos [ --ixslashpos ] - 1, ':' );
+ setstringcharacter ( bsfolder, slashpos [ --ixslashpos ] - 1, ':' );
+ }
- convertpstring ( bs );
+ convertpstring ( bsfolder ); // bsfolder is now a c string
+
+ status = FSPathMakeRef ( bsfolder, &fsr, NULL );
+
+ if ( status == noErr ) {
+
+ ( *fs ).fsref = fsr;
- status = FSPathMakeRef ( bs, &fsr, NULL );
+ ( *fs ).path = CFStringCreateWithPascalString ( kCFAllocatorDefault, bsfile,
+ kCFStringEncodingMacRoman );
+
+ return ( true );
- if ( status == noErr ) {
+ } // if
- /* bail if fsr is Volumes directory */ {
-
- FSRef volumesfsref;
-
- status = FSPathMakeRef ( "/Volumes", &volumesfsref, NULL );
-
- if ( FSCompareFSRefs ( &fsr, &volumesfsref ) != noErr ) {
-
- HFSUniStr255 name;
- OSErr err;
-
- filefrompath ( bsfullpath, bs );
-
- ( *fs ).fsref = fsr;
-
- err = HFSNameGetUnicodeName255 ( bs, kTextEncodingUnknown, &name );
-
- ( *fs ).path = CFStringCreateWithCharacters ( kCFAllocatorDefault, name.unicode,
- name.length );
-
- return ( true );
-
- } // if
- } // bail
- } // if
- } // emulate FSSpec
- } // full path
-
- /* try as partial path */ {
+ } // end full path
+
+ else { // partial path
bigstring bspartialpath;
tyfilespec fst;
@@ -390,18 +387,44 @@
if ( bspartialpath [ 1 ] != chpathseparator )
insertchar ( chpathseparator, bspartialpath );
-
+
( void ) extendfilespec ( &fsdefault, &fst );
status = FSRefMakePath ( &fst.fsref, ( UInt8 * ) bs, 256 ); // bs is now a c string
convertcstring ( bs ); // bs is now a bigstring
- insertstring ( bs, bspartialpath );
-
+ /* convert bs to colon delimited path */ {
+
+ ix = 1;
+ ixslashpos = 0;
+
+ while ( scanstring ( ':', bs, &ix ) )
+ slashpos [ ixslashpos++ ] = ix++;
+
+ stringreplaceall ( '/', ':', bs );
+
+ while ( ixslashpos > 0 )
+ setstringcharacter ( bs, slashpos [ --ixslashpos ] - 1, '/' );
+ }
+
+ insertstring ( bs, bspartialpath ); // we now have a full path
+
copystring ( bspartialpath, bs );
- stringreplaceall ( ':', '/', bs );
+ /* convert bs to / delimited path */ {
+
+ ix = 1;
+ ixslashpos = 0;
+
+ while ( scanstring ( '/', bs, &ix ) )
+ slashpos [ ixslashpos++ ] = ix++;
+
+ stringreplaceall ( ':', '/', bs );
+
+ while ( ixslashpos > 0 )
+ setstringcharacter ( bs, slashpos [ --ixslashpos ] - 1, ':' );
+ }
convertpstring ( bs ); // bs is now a c string
@@ -409,9 +432,7 @@
if ( status == noErr ) {
- HFSUniStr255 name;
-
- status = FSGetCatalogInfo ( &fsr, kFSCatInfoNone, NULL, &name, NULL, &fsr );
+ err = FSGetCatalogInfo ( &fsr, kFSCatInfoNone, NULL, &name, NULL, &fsr );
( *fs ).fsref = fsr;
@@ -419,9 +440,48 @@
return ( true );
- }
+ } // if
- }
+ /* try parent of path */ {
+
+ bigstring bsfile;
+
+ filefrompath ( bspartialpath, bsfile );
+
+ folderfrompath ( bspartialpath, bsfolder );
+
+ /* convert to slash delimited path */ {
+
+ ix = 1;
+ ixslashpos = 0;
+
+ while ( scanstring ( '/', bsfolder, &ix ) )
+ slashpos [ ixslashpos++ ] = ix++;
+
+ stringreplaceall ( ':', '/', bsfolder );
+
+ while ( ixslashpos > 0 )
+ setstringcharacter ( bsfolder, slashpos [ --ixslashpos ] - 1, ':' );
+ }
+
+ convertpstring ( bsfolder ); // bsfolder is now a c string
+
+ status = FSPathMakeRef ( bsfolder, &fsr, NULL );
+
+ if ( status == noErr ) {
+
+ ( *fs ).fsref = fsr;
+
+ ( *fs ).path = CFStringCreateWithPascalString ( kCFAllocatorDefault, bsfile,
+ kCFStringEncodingMacRoman );
+
+ return ( true );
+
+ } // if
+
+ } // end try parent of path
+
+ } // end partial path
return ( false );
@@ -452,7 +512,7 @@
boolean setfsfile ( ptrfilespec fs, bigstring bsfile ) {
//
- // 2006-06-25 creedon: for Mac, FSRef-ized
+ // 2006-08-29 creedon: for Mac, FSRef-ized
//
// 2004-10-26 aradke: Since the getmacfileinfo/foldertest gymnastics do not seem to fit any particular purpose and since
// none of our callers seem to rely it since they usually pass in a file rather than a directory, I
@@ -464,16 +524,20 @@
//
#ifdef MACVERSION
+
+ if ( FSRefValid ( &( *fs ).fsref ) && ( *fs ).path == NULL ) {
- HFSUniStr255 name;
- OSErr err;
-
- bigstringToHFSUniStr255 ( bsfile, &name );
-
- err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, NULL, NULL, &( *fs ).fsref );
-
- err = FSMakeFSRefUnicode ( &( *fs ).fsref, name.length, name.unicode, kTextEncodingUnknown, &( *fs ).fsref );
-
+ HFSUniStr255 name;
+ OSErr err = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, NULL, NULL, &( *fs ).fsref );
+
+ bigstringToHFSUniStr255 ( bsfile, &name );
+
+ err = FSMakeFSRefUnicode ( &( *fs ).fsref, name.length, name.unicode, kTextEncodingUnknown, &( *fs ).fsref );
+
+ }
+ else
+ ( *fs ).path = CFStringCreateWithPascalString ( kCFAllocatorDefault, bsfile, kCFStringEncodingMacRoman );
+
return ( true );
#endif
@@ -582,7 +646,7 @@
getapplicationfilespec ( nil, &fsdefault );
- getfilespecparent ( &fsdefault );
+ ( void ) getfilespecparent ( &fsdefault );
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|