From: Bernard D. <bde...@or...> - 2015-10-05 15:01:32
|
Thanks ! I’ll experiment and test in the next days. Le 5 oct. 2015 à 15:46, Jonathan Guyer <jg...@hi...> a écrit : > Absolutely no objection > > ----- Original Message ----- >> From: "Bernard Desgraupes" <bde...@or...> >> To: "Lars Hellström" <Lar...@re...> >> Cc: "Alpha TCL Developers List" <alp...@li...> >> Sent: Monday, October 5, 2015 8:45:24 AM >> Subject: Re: Alphatk resurrection >> >> >> Le 4 oct. 2015 à 16:07, Lars Hellström >> <Lar...@re...> a écrit : >> >>> Bernard Desgraupes skrev 2015-09-25 22.35: >>>> >>>> I can only answer this last one. In AlphaX, I have installed >>>> coercion handlers between 'alis' and ‘utxt’ types, which is why >>>> your instruction succeeded. >>>> >>>> static pascal OSErr Alpha_UtxtToAlisCoerceProc(const AEDesc >>>> *fromDesc, DescType toType, long handlerRefCon, AEDesc *toDesc); >>>> static pascal OSErr Alpha_AlisToUtxtCoerceProc(const AEDesc >>>> *fromDesc, DescType toType, long handlerRefCon, AEDesc *toDesc); >>> >>> I presume one would have to provide implementations for these as >>> well, not just the prototypes? >>> >>> And they should probably be built into TclAE, rather than just >>> AlphaX. [Sigh.] TclAE really needs a new release proper. >> >> >> Here is the complete code below. >> I agree that this should be part of TclAE (mutatis mutandis). I’ll >> look into this if Jon does has no objection. >> >> cheers, >> Bernard >> >> static AECoerceDescUPP sUtxtToAlisCoerceUPP; >> static AECoerceDescUPP sAlisToUtxtCoerceUPP; >> >> >> >> OSErr Alpha_InstallCoercionHandlers(void) { >> OSErr error = noErr; >> >> sUtxtToAlisCoerceUPP = >> NewAECoerceDescUPP(Alpha_UtxtToAlisCoerceProc); >> assert(sUtxtToAlisCoerceUPP != NULL); >> >> sAlisToUtxtCoerceUPP = >> NewAECoerceDescUPP(Alpha_AlisToUtxtCoerceProc); >> assert(sAlisToUtxtCoerceUPP != NULL); >> >> error = AEInstallCoercionHandler('utxt', 'alis', >> (AECoercionHandlerUPP) sUtxtToAlisCoerceUPP, 0, true, false); >> error = AEInstallCoercionHandler('alis', 'utxt', >> (AECoercionHandlerUPP) sAlisToUtxtCoerceUPP, 0, true, false); >> return error; >> } >> >> >> >> static pascal OSErr Alpha_UtxtToAlisCoerceProc(const AEDesc >> *fromDesc, DescType toType, long handlerRefCon, AEDesc *toDesc) >> { >> OSErr error, result = errAECoercionFail; >> Size theSize; >> Handle theHandle = NULL; >> AliasHandle aliasHandle = NULL; >> CFStringRef theString = NULL; >> CFURLRef theUrl = NULL; >> FSRef theFSRef; >> >> if (fromDesc->descriptorType == 'utxt') { >> theSize = AEGetDescDataSize(fromDesc); >> theHandle = NewHandle(theSize); >> >> if (theHandle != NULL) { >> error = AEGetDescData(fromDesc, *theHandle, theSize); >> if (error == noErr) { >> // Create CFStringRef >> theString = CFStringCreateWithCharacters(kCFAllocatorDefault, >> (const UniChar *) *theHandle, theSize/2); >> >> if (theString != NULL) { >> // CFStringRef to CFURLRef >> theUrl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, >> theString, kCFURLPOSIXPathStyle, false); >> CFRelease(theString); >> >> if (theUrl != NULL) { >> // CFURLRef to FSRef >> if ( CFURLGetFSRef(theUrl, &theFSRef) ) { >> // FSRef to alias >> error = FSNewAlias(NULL, &theFSRef, &aliasHandle); >> >> if (aliasHandle != NULL) { >> error = AECreateDesc('alis', *aliasHandle, GetHandleSize( >> (Handle) aliasHandle), toDesc); >> result = error; >> DisposeHandle( (Handle) aliasHandle); >> } >> } >> CFRelease(theUrl); >> } >> } >> } >> DisposeHandle(theHandle); >> } >> } >> >> return result; >> } >> >> >> static pascal OSErr Alpha_AlisToUtxtCoerceProc(const AEDesc >> *fromDesc, DescType toType, long handlerRefCon, AEDesc *toDesc) >> { >> OSErr error, result = errAECoercionFail; >> Size theSize; >> Handle theHandle = NULL; >> CFStringRef theString = NULL; >> CFURLRef theUrl = NULL; >> FSRef theFSRef; >> Boolean hasChanged; >> UniCharPtr uniStringPtr; >> CFIndex len; >> >> if (fromDesc->descriptorType == 'alis') { >> theSize = AEGetDescDataSize(fromDesc); >> theHandle = NewHandle(theSize); >> >> if (theHandle != NULL) { >> error = AEGetDescData(fromDesc, *theHandle, theSize); >> if (error == noErr) { >> // alias to FSRef >> error = FSResolveAlias(NULL, (AliasHandle) theHandle, &theFSRef, >> &hasChanged); >> if (error == noErr) { >> // FSRef to CFURLRef >> theUrl = CFURLCreateFromFSRef(kCFAllocatorDefault, &theFSRef); >> if (theUrl != NULL) { >> // CFURLRef to CFStringRef >> theString = file_CopyPathFromURL(theUrl); >> CFRelease(theUrl); >> if (theString != NULL) { >> len = CFStringGetLength(theString); >> uniStringPtr = (UniCharPtr) >> CFStringGetCharactersPtr(theString); >> if (uniStringPtr != NULL) { >> error = AECreateDesc('utxt', uniStringPtr, len * >> sizeof(UniChar), toDesc); >> } else { >> uniStringPtr = (UniCharPtr) ckalloc(len * sizeof(UniChar)); >> CFStringGetCharacters(theString, CFRangeMake(0, len), >> uniStringPtr); >> error = AECreateDesc('utxt', uniStringPtr, len * >> sizeof(UniChar), toDesc); >> ckfree((char*) uniStringPtr); >> } >> result = error; >> CFRelease(theString); >> } >> } >> } >> } >> DisposeHandle(theHandle); >> } >> } >> >> return result; >> } >> >> >> >> And the function file_CopyPathFromURL() is just an utility function >> in AlphaX defined like this : >> CFStringRef >> file_CopyPathFromURL(CFURLRef inUrl) >> { >> CFStringRef theStr = NULL; >> CFMutableStringRef thePath = NULL; >> >> if (inUrl != NULL) { >> theStr = CFURLCopyFileSystemPath(inUrl, kCFURLPOSIXPathStyle); >> if (theStr != NULL) { >> thePath = CFStringNormalize(theStr, kCFStringNormalizationFormC); >> CFRelease(theStr); >> } >> } >> >> return (CFStringRef) thePath; >> } >> >> >> >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> AlphaTcl-developers mailing list >> Alp...@li... >> http://lists.sourceforge.net/lists/listinfo/alphatcl-developers >> > > ------------------------------------------------------------------------------ > _______________________________________________ > AlphaTcl-developers mailing list > Alp...@li... > http://lists.sourceforge.net/lists/listinfo/alphatcl-developers |