|
From: <cre...@us...> - 2006-08-12 02:58:01
|
Revision: 1480 Author: creecode Date: 2006-08-11 19:57:56 -0700 (Fri, 11 Aug 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1480&view=rev Log Message: ----------- fix bugs mainly related to Mac Roman characters in the range 128 - 255 and filespecs < http://sourceforge.net/tracker/index.php?func=detail&aid=1536162&group_id=120666&atid=687798 >. note: I think I have found a bug in the Finder related to naming files with the not equal character, which doesn't manifest if the files are named with Frontier, TextEdit, Script Editor, etc. Modified Paths: -------------- Frontier/branches/FSRef_Migration/Common/headers/file.h Frontier/branches/FSRef_Migration/Common/source/file.c Frontier/branches/FSRef_Migration/Common/source/fileops.c Frontier/branches/FSRef_Migration/Common/source/filepath.c Modified: Frontier/branches/FSRef_Migration/Common/headers/file.h =================================================================== --- Frontier/branches/FSRef_Migration/Common/headers/file.h 2006-08-12 00:21:41 UTC (rev 1479) +++ Frontier/branches/FSRef_Migration/Common/headers/file.h 2006-08-12 02:57:56 UTC (rev 1480) @@ -441,6 +441,30 @@ extern boolean getmacfileinfocipbr ( const FSSpecPtr, CInfoPBRec * ); +/* 2006-08-11 creedon: cribbed from MoreFilesX.c and modded to work with Str255 */ + +OSErr +HFSNameGetUnicodeName255 ( + ConstStr255Param hfsName, + TextEncoding textEncodingHint, + HFSUniStr255 *unicodeName); + +/* + The HFSNameGetUnicodeName function converts a Pascal Str255 string to an + Unicode HFSUniStr255 string using the same routines as the File Manager. + + hfsName --> The Pascal string to convert. + textEncodingHint --> The text encoding hint used for the conversion. + You can pass kTextEncodingUnknown to use the + "default" textEncodingHint. + unicodeName <-- The Unicode string. + + __________ + + Also see: HFSNameGetUnicodeName in MoreFilesX.c + +*/ + #endif Modified: Frontier/branches/FSRef_Migration/Common/source/file.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/file.c 2006-08-12 00:21:41 UTC (rev 1479) +++ Frontier/branches/FSRef_Migration/Common/source/file.c 2006-08-12 02:57:56 UTC (rev 1480) @@ -923,15 +923,19 @@ boolean CFStringRefToStr255 ( CFStringRef input, StringPtr output ) { // - // 2006-07-06 creedon: created, cribbed from < http://developer.apple.com/carbon/tipsandtricks.html#CFStringFromUnicode > + // 2006-08-08 creedon: created, cribbed from < http://developer.apple.com/carbon/tipsandtricks.html#CFStringFromUnicode > // - - output [ 0 ] = CFStringGetBytes ( input, CFRangeMake ( 0, MIN ( CFStringGetLength ( input ), 255 ) ), - kTextEncodingMacRoman, '^', false, &( output [ 1 ] ), 255, NULL ); - + + CFIndex usedBufLen; + + CFStringGetBytes ( input, CFRangeMake ( 0, MIN ( CFStringGetLength ( input ), 255 ) ), + kCFStringEncodingMacRoman, '^', false, &( output [ 1 ] ), 255, &usedBufLen ); + + output [ 0 ] = usedBufLen; + if ( output [ 0 ] == 0 ) return ( false ); - + return ( true ); } // CFStringRefToStr255 @@ -1003,11 +1007,11 @@ boolean CFStringRefToHFSUniStr255 ( CFStringRef input, HFSUniStr255 *output ) { // - // 2006-07-06 creedon: created, cribbed from < http://developer.apple.com/carbon/tipsandtricks.html#CFStringFromUnicode > + // 2006-08-11 creedon: created, cribbed from < http://developer.apple.com/carbon/tipsandtricks.html#CFStringFromUnicode > // - + ( *output ).length = CFStringGetBytes ( input, CFRangeMake (0, MIN ( CFStringGetLength ( input ), 255 ) ), - kCFStringEncodingUnicode, 0, false, ( UInt8 * ) ( *output).unicode, 255, NULL ); + kCFStringEncodingUnicode, 0, false, ( UInt8 * ) ( *output ).unicode, 255, NULL ); if ( ( *output ).length == 0 ) return ( false ); @@ -1016,5 +1020,88 @@ } // CFStringRefToHFSUniStr255 + +/* 2006-08-11 creedon: cribbed from MoreFilesX.c and modded to work with Str255 */ + +/* macro for casting away const when you really have to */ +#define CONST_CAST(type, const_var) (*(type*)((void *)&(const_var))) + +OSErr +HFSNameGetUnicodeName255 ( + ConstStr255Param hfsName, + TextEncoding textEncodingHint, + HFSUniStr255 *unicodeName) +{ + ByteCount unicodeByteLength; + OSStatus result; + UnicodeMapping uMapping; + TextToUnicodeInfo tuInfo; + ByteCount pascalCharsRead; + + /* check parameters */ + require_action(NULL != unicodeName, BadParameter, result = paramErr); + + /* make sure output is valid in case we get errors or there's nothing to convert */ + unicodeName->length = 0; + + if ( 0 == StrLength(CONST_CAST(StringPtr, hfsName)) ) + { + result = noErr; + } + else + { + /* if textEncodingHint is kTextEncodingUnknown, get a "default" textEncodingHint */ + if ( kTextEncodingUnknown == textEncodingHint ) + { + ScriptCode script; + RegionCode region; + + script = GetScriptManagerVariable(smSysScript); + region = GetScriptManagerVariable(smRegionCode); + result = UpgradeScriptInfoToTextEncoding(script, kTextLanguageDontCare, region, + NULL, &textEncodingHint); + if ( paramErr == result ) + { + /* ok, ignore the region and try again */ + result = UpgradeScriptInfoToTextEncoding(script, kTextLanguageDontCare, + kTextRegionDontCare, NULL, &textEncodingHint); + } + if ( noErr != result ) + { + /* ok... try something */ + textEncodingHint = kTextEncodingMacRoman; + } + } + + uMapping.unicodeEncoding = CreateTextEncoding(kTextEncodingUnicodeDefault, + kUnicodeCanonicalDecompVariant, kUnicode16BitFormat); + uMapping.otherEncoding = GetTextEncodingBase(textEncodingHint); + uMapping.mappingVersion = kUnicodeUseHFSPlusMapping; + + result = CreateTextToUnicodeInfo(&uMapping, &tuInfo); + require_noerr(result, CreateTextToUnicodeInfo); + + result = ConvertFromTextToUnicode(tuInfo, hfsName[0], &hfsName[1], + 0, /* no control flag bits */ + 0, NULL, 0, NULL, /* offsetCounts & offsetArrays */ + sizeof(unicodeName->unicode), /* output buffer size in bytes */ + &pascalCharsRead, &unicodeByteLength, unicodeName->unicode); + require_noerr(result, ConvertFromTextToUnicode); + + /* convert from byte count to char count */ + unicodeName->length = unicodeByteLength / sizeof(UniChar); + +ConvertFromTextToUnicode: + + /* verify the result in debug builds -- there's really not anything you can do if it fails */ + verify_noerr(DisposeTextToUnicodeInfo(&tuInfo)); + } + +CreateTextToUnicodeInfo: +BadParameter: + + return ( result ); +} + #endif Modified: Frontier/branches/FSRef_Migration/Common/source/fileops.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/fileops.c 2006-08-12 00:21:41 UTC (rev 1479) +++ Frontier/branches/FSRef_Migration/Common/source/fileops.c 2006-08-12 02:57:56 UTC (rev 1480) @@ -52,6 +52,7 @@ #include "MoreFilesX.h" #include "FSCopyObject.h" + #include <sys/param.h> // 2006-08-11 creedon #ifdef flcomponent #include "SetUpA5.h" @@ -3618,14 +3619,14 @@ HFSUniStr255 name; OSErr err; - + CFStringRefToHFSUniStr255 ( ( *fsin ).path, &name ); - err = FSMakeFSRefUnicode ( &( *fsin ).fsref, name.length, name.unicode, kTextEncodingUnknown, &fst.fsref ); + err = FSMakeFSRefUnicode ( &( *fsin ).fsref, name.length, name.unicode, kTextEncodingUnknown, &fst.fsref ); // kTextEncodingUnicodeDefault if ( err != noErr ) return ( false ); - + *fsout = fst; #endif // MACVERSION Modified: Frontier/branches/FSRef_Migration/Common/source/filepath.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/filepath.c 2006-08-12 00:21:41 UTC (rev 1479) +++ Frontier/branches/FSRef_Migration/Common/source/filepath.c 2006-08-12 02:57:56 UTC (rev 1480) @@ -38,6 +38,7 @@ #ifdef MACVERSION #include "MoreFilesX.h" // 2006-05-31 creedon + #include <CoreFoundation/CFString.h> // 2006-08-10 creedon #endif // MACVERSION @@ -254,7 +255,7 @@ boolean pathtofilespec ( bigstring bspath, ptrfilespec fs ) { // - // 2006-06-25 creedon: for Mac, FSRef-ized + // 2006-08-11 creedon: for Mac, FSRef-ized // // 5.0d8 dmb: clear fs first thing // @@ -344,13 +345,18 @@ if ( FSCompareFSRefs ( &fsr, &volumesfsref ) != noErr ) { + HFSUniStr255 name; + OSErr err; + filefrompath ( bsfullpath, bs ); ( *fs ).fsref = fsr; - ( *fs ).path = CFStringCreateWithPascalString ( kCFAllocatorDefault, bs, - kCFStringEncodingMacRoman ); + err = HFSNameGetUnicodeName255 ( bs, kTextEncodingUnknown, &name ); + ( *fs ).path = CFStringCreateWithCharacters ( kCFAllocatorDefault, name.unicode, + name.length ); + return ( true ); } // if This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |