|
From: John M M. <jo...@us...> - 2004-04-23 20:46:20
|
Update of /cvsroot/squeak/squeak/platforms/Mac OS/vm In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2076/squeak/platforms/Mac OS/vm Modified Files: sqMacFileLogic.c Log Message: 3.7.3b4 Update for normalized unicode pathnames Index: sqMacFileLogic.c =================================================================== RCS file: /cvsroot/squeak/squeak/platforms/Mac OS/vm/sqMacFileLogic.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** sqMacFileLogic.c 2 Dec 2003 04:52:22 -0000 1.12 --- sqMacFileLogic.c 23 Apr 2004 20:46:12 -0000 1.13 *************** *** 58,74 **** #if TARGET_API_MAC_CARBON OSErr makeFSSpec(char *pathString, int pathStringLength,FSSpec *spec) { CFURLRef sillyThing; ! CFStringRef filePath; FSRef theFSRef; OSErr err; ! filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *) pathString,pathStringLength,gCurrentVMEncoding,false); ! if (filePath == nil) return -1000; sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); ! if (!CFURLGetFSRef(sillyThing,&theFSRef)) { // name contains multiple aliases or does not exist, so fallback to lookupPath CFRelease(filePath); --- 58,80 ---- #if TARGET_API_MAC_CARBON + void unicode2NativePascalString(ConstStr255Param fromString, StringPtr toString) ; OSErr makeFSSpec(char *pathString, int pathStringLength,FSSpec *spec) { CFURLRef sillyThing; ! CFStringRef tmpStrRef; ! CFMutableStringRef filePath; FSRef theFSRef; OSErr err; ! tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *) pathString, ! pathStringLength, gCurrentVMEncoding, true); ! if (tmpStrRef == nil) return -1000; + filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef); + if (gCurrentVMEncoding == kCFStringEncodingUTF8) + CFStringNormalize(filePath, kCFStringNormalizationFormD); sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); ! if (CFURLGetFSRef(sillyThing,&theFSRef) == false) { // name contains multiple aliases or does not exist, so fallback to lookupPath CFRelease(filePath); *************** *** 91,95 **** /* Fill in the given string with the full path from a root volume to the given file. */ ! int PathToFile(char *pathName, int pathNameMax, FSSpec *where,UInt32 encoding) { CFURLRef sillyThing; --- 97,102 ---- /* Fill in the given string with the full path from a root volume to the given file. */ ! /* From FSSpec to C-string pathName */ ! /* FSSpec -> FSRef -> URL(Unix) -> HPFS+ */ int PathToFile(char *pathName, int pathNameMax, FSSpec *where,UInt32 encoding) { CFURLRef sillyThing; *************** *** 119,124 **** CFRelease(sillyThing); ! CFStringGetCString (filePath,pathName,pathNameMax, encoding); ! CFRelease(filePath); if (retryWithDirectory) { --- 126,137 ---- CFRelease(sillyThing); ! CFMutableStringRef mutableStr= CFStringCreateMutableCopy(NULL, 0, filePath); ! CFRelease(filePath); ! ! // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements ! if (gCurrentVMEncoding == kCFStringEncodingUTF8) ! CFStringNormalize(mutableStr, kCFStringNormalizationFormKC); // pre-combined ! ! CFStringGetCString (mutableStr, pathName,pathNameMax, encoding); if (retryWithDirectory) { *************** *** 143,147 **** if (filePath == nil) return -1; ! sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); if (!CFURLGetFSRef(sillyThing,&theFSRef)) { --- 156,166 ---- if (filePath == nil) return -1; ! CFMutableStringRef str= CFStringCreateMutableCopy(NULL, 0, filePath); ! // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements ! if (gCurrentVMEncoding == kCFStringEncodingUTF8) ! CFStringNormalize(str, kCFStringNormalizationFormKC); // canonical decomposition ! ! sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, str, kCFURLHFSPathStyle,false); ! CFRelease(str); if (!CFURLGetFSRef(sillyThing,&theFSRef)) { *************** *** 212,215 **** --- 231,252 ---- } + /* Some classcical Mac APIs use the encoding based on WorldScript. for example, Japanese language envrironment use + ShiftJIS encoding. So, unicode2NativePascalString, this function converts unicode encoded pascal string to suitable + encoding (came from CFStringGetSystemEncoding()). + */ + void unicode2NativePascalString(ConstStr255Param fromString, StringPtr toString) { + if (fromString != NULL) { + CFStringRef strRef = CFStringCreateWithPascalString(kCFAllocatorDefault, fromString, gCurrentVMEncoding); + if (strRef != NULL) { + CFMutableStringRef mStrRef = CFStringCreateMutableCopy(NULL, 0, strRef); + if (gCurrentVMEncoding == kCFStringEncodingUTF8) + CFStringNormalize(mStrRef, kCFStringNormalizationFormKD); + CFStringGetPascalString (mStrRef, toString, 256, CFStringGetSystemEncoding()); + CFRelease(mStrRef); + CFRelease(strRef); + } + } + } + /* Convert the squeak path to an OS-X path. This path because of alias resolving may point to another directory tree */ *************** *** 221,225 **** Boolean isFolder=false,isAlias=false; CFURLRef sillyThing,appendedSillyThing; ! CFStringRef filePath,lastPartOfPath; *dst = 0x00; --- 258,263 ---- Boolean isFolder=false,isAlias=false; CFURLRef sillyThing,appendedSillyThing; ! CFStringRef lastPartOfPath; ! CFMutableStringRef filePath; *dst = 0x00; *************** *** 243,249 **** if (err != noErr) return; ! filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false); ! if (filePath == nil) return; sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); CFRelease(filePath); --- 281,292 ---- if (err != noErr) return; ! // filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false); ! CFStringRef tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)src,num,gCurrentVMEncoding,false); ! if (tmpStrRef == nil) return; + filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef); + if (gCurrentVMEncoding == kCFStringEncodingUTF8) + CFStringNormalize(filePath, kCFStringNormalizationFormKD); // canonical decomposition + sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false); CFRelease(filePath); *************** *** 264,267 **** --- 307,311 ---- return; } + err = FSpMakeFSRef(&convertFileNameSpec,&theFSRef); #if defined(__MWERKS__) && !defined(__APPLE__) && !defined(__MACH__) *************** *** 742,747 **** theString = CFStringCreateWithCharacters (kCFAllocatorDefault, unicodeName.unicode, (CFIndex) unicodeName.length); ! CFStringGetPascalString(theString,(unsigned char *) name,256, gCurrentVMEncoding); CFRelease(theString); return; } --- 786,797 ---- theString = CFStringCreateWithCharacters (kCFAllocatorDefault, unicodeName.unicode, (CFIndex) unicodeName.length); ! CFMutableStringRef mStr= CFStringCreateMutableCopy(NULL, 0, theString); CFRelease(theString); + // HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements + if (gCurrentVMEncoding == kCFStringEncodingUTF8) + CFStringNormalize(mStr, kCFStringNormalizationFormKC); // canonical decomposition + + CFStringGetPascalString(mStr, (unsigned char *) name,256, gCurrentVMEncoding); + CFRelease(mStr); return; } *************** *** 790,798 **** OSErr FSMakeFSSpecCompat(short vRefNum, long dirID, ConstStr255Param fileName, FSSpec *spec) { OSErr result; /* Let the file system create the FSSpec if it can since it does the job */ /* much more efficiently than I can. */ ! result = FSMakeFSSpec(vRefNum, dirID, fileName, spec); ! /* Fix a bug in Macintosh PC Exchange's MakeFSSpec code where 0 is */ /* returned in the parID field when making an FSSpec to the volume's */ --- 840,853 ---- OSErr FSMakeFSSpecCompat(short vRefNum, long dirID, ConstStr255Param fileName, FSSpec *spec) { OSErr result; + char pascalString[256]; /* Let the file system create the FSSpec if it can since it does the job */ /* much more efficiently than I can. */ ! #if TARGET_API_MAC_CARBON ! unicode2NativePascalString((unsigned char *) fileName, (unsigned char *) pascalString); ! result = FSMakeFSSpec(vRefNum, dirID,(unsigned char *) pascalString, spec); ! #else ! result = FSMakeFSSpec(vRefNum, dirID,(unsigned char *) fileName, spec); ! #endif /* Fix a bug in Macintosh PC Exchange's MakeFSSpec code where 0 is */ /* returned in the parID field when making an FSSpec to the volume's */ |