|
From: <set...@us...> - 2006-05-02 20:32:46
|
Revision: 1340 Author: sethdill Date: 2006-05-02 13:32:33 -0700 (Tue, 02 May 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1340&view=rev Log Message: ----------- Merged trunk changes r1333:1339 into the Conversant branch. (Common directory only.) Modified Paths: -------------- Frontier/branches/Conversant/Common/headers/conversantverbs.h Frontier/branches/Conversant/Common/resources/Mac/conversantverbs.r Frontier/branches/Conversant/Common/resources/Mac/lang.r Frontier/branches/Conversant/Common/resources/Win32/WinLand.rc Frontier/branches/Conversant/Common/source/conversantverbs.c Frontier/branches/Conversant/Common/source/strings.c Modified: Frontier/branches/Conversant/Common/headers/conversantverbs.h =================================================================== --- Frontier/branches/Conversant/Common/headers/conversantverbs.h 2006-05-02 20:17:16 UTC (rev 1339) +++ Frontier/branches/Conversant/Common/headers/conversantverbs.h 2006-05-02 20:32:33 UTC (rev 1340) @@ -73,6 +73,8 @@ typedef enum tyconversanttoken { /* verbs that are processed by conversantverbs.c */ compilestringfunc, + + tabletostringfunc, cconversantverbs Modified: Frontier/branches/Conversant/Common/resources/Mac/conversantverbs.r =================================================================== --- Frontier/branches/Conversant/Common/resources/Mac/conversantverbs.r 2006-05-02 20:17:16 UTC (rev 1339) +++ Frontier/branches/Conversant/Common/resources/Mac/conversantverbs.r 2006-05-02 20:32:33 UTC (rev 1340) @@ -30,7 +30,8 @@ { "conv", false, { - "compilestring" + "compilestring", + "tabletostring" } } }; Modified: Frontier/branches/Conversant/Common/resources/Mac/lang.r =================================================================== --- Frontier/branches/Conversant/Common/resources/Mac/lang.r 2006-05-02 20:17:16 UTC (rev 1339) +++ Frontier/branches/Conversant/Common/resources/Mac/lang.r 2006-05-02 20:32:33 UTC (rev 1340) @@ -1029,9 +1029,21 @@ }; resource 'STR#' (263, "String Errors", purgeable) { - { /* array StringArray: 1 elements */ + { /* array StringArray: 7 elements */ /* [1] */ - "Internal error running \xD2string.^0\xD3." + "Internal error running \xD2string.^0\xD3.", + /* [2] */ + "Can't convert character set because of an unknown error.", + /* [3] - Mac OSStatus: kTextUnsupportedEncodingErr */ + "Can't convert character set because \xD2^0\xD3 is not supported.", + /* [4] - Mac OSStatus: kTextMalformedInputErr */ + "Can't convert character set because the text contains a sequence that is not legal in the specified character set (^0).", + /* [5] - Mac OSStatus: kTextUndefinedElementErr */ + "Can't convert character set because the text contains a code point that is undefined in the specified character set (^0).", + /* [6] - Mac OSStatus: kTECNoConversionPathErr */ + "Can't convert character set because there is no way to convert from \xD2^0\xD3 to \xD2^1\xD3.", + /* [7] - Mac OSStatus: kTECPartialCharErr */ + "Can't convert character set because the text ends in the middle of a multibyte character." } }; Modified: Frontier/branches/Conversant/Common/resources/Win32/WinLand.rc =================================================================== --- Frontier/branches/Conversant/Common/resources/Win32/WinLand.rc 2006-05-02 20:17:16 UTC (rev 1339) +++ Frontier/branches/Conversant/Common/resources/Win32/WinLand.rc 2006-05-02 20:32:33 UTC (rev 1340) @@ -1638,6 +1638,12 @@ 1 File_Errors DISCARDABLE BEGIN "Internal error running \042file.^0\042.\0" END 1 String_Errors DISCARDABLE BEGIN "Internal error running \042string.^0\042.\0" END + 2 String_Errors DISCARDABLE BEGIN "Can't convert character set because of an unknown error.\0" END + 3 String_Errors DISCARDABLE BEGIN "Can't convert character set because \042^0\042 is not supported.\0" END + 4 String_Errors DISCARDABLE BEGIN "Can't convert character set because the text contains a sequence that is not legal in the specified character set (^0).\0" END + 5 String_Errors DISCARDABLE BEGIN "Can't convert character set because the text contains a code point that is undefined in the specified character set (^0).\0" END + 6 String_Errors DISCARDABLE BEGIN "Can't convert character set because there is no way to convert from \042^0\042 to \042^1\042.\0" END + 7 String_Errors DISCARDABLE BEGIN "Can't convert character set because the text ends in the middle of a multibyte character.\0" END 1 WP_Verb_Errors DISCARDABLE BEGIN "Can't do \042wp.^0\042 because the target window is not in edit mode, or does not contain editable text.\0" END 2 WP_Verb_Errors DISCARDABLE BEGIN "The address of a wptext object was expected here.\0" END Modified: Frontier/branches/Conversant/Common/source/conversantverbs.c =================================================================== --- Frontier/branches/Conversant/Common/source/conversantverbs.c 2006-05-02 20:17:16 UTC (rev 1339) +++ Frontier/branches/Conversant/Common/source/conversantverbs.c 2006-05-02 20:32:33 UTC (rev 1340) @@ -966,6 +966,135 @@ return CONV_NOTYPE; } +/** + * Get the size of the value, but coerce val to a string if necessary + * This is essentially a wrapper for langgetvalsize +**/ +static boolean conv_getValueStringLength( tyvaluerecord * pVal, long * pLen ) +{ + if ( (*pVal).valuetype != stringvaluetype ) + { + if ( ! copyvaluerecord( *pVal, pVal ) || ! coercetostring( pVal ) ) + return ( false ); + } + + langgetvalsize( *pVal, pLen ); + + return ( true ); +} + + +#if 0 +/** + * Add up the lengths of all of the strings in the table +**/ +static unsigned long conv_getTableStringLength( ptrhashtable pTable ) +{ + hdlhashnode nomad; /* trip-trip-tripping merrily through the strings */ + tyvaluerecord val; /* the value record associated with the table cell */ + unsigned long lenResult, /* the final length of the string */ + lenItem; /* the length of one string in the table */ + + lenResult = lenItem = 0; + + nomad = (*pTable).hfirstsort; + + while ( nomad != NULL ) + { + val = (**nomad).val; + + lenItem = conv_getValueStringLength( &val ); + + lenResult += lenItem; + + nomad = (**nomad).sortedlink; + } + + return ( lenResult ); +} +#endif + + +/** + * walk through a table, concatenating evertyhing into the result string +**/ +static boolean conv_concatenateTableStrings( ptrhashtable pTable, Handle * hOutString ) +{ + handlestream hs; /* this is how we handle writing to the string */ + hdlhashnode nomad; /* trip-trip-tripping merrily through the strings */ + tyvaluerecord * pVal; /* the value record associated with the table cell */ + long ix; /* position in the handle */ + + newemptyhandle( hOutString ); + + openhandlestream( *hOutString, &hs ); + + nomad = (*pTable).hfirstsort; + + ix = 0; + + while ( nomad != NULL ) + { + pVal = &(**nomad).val; + + if ( ! conv_getValueStringLength( pVal, &ix ) ) + return ( false ); + + if ( ! writehandlestreamhandle( &hs, (*pVal).data.stringvalue ) ) + { + closehandlestream( &hs ); + return ( false ); + } + + /* + if ( ! enlargehandle( *hOutString, ix, (ptrvoid) (*((*pVal).data.stringvalue)) ) ) + return ( false ); + */ + + nomad = (**nomad).sortedlink; + } + + closehandlestream( &hs ); + + return ( true ); +} + + +static boolean conv_tabletostringverb( hdltreenode hp1, tyvaluerecord *v, bigstring bserror ) +{ + Handle hresult; /* the resulting string, after concatenating the whole thing */ + + convaddress adr; /* address of the table we're traversing */ + hdlhashtable htbl; /* the table of strings we're concatenating */ + + /* + get the address of the table we're going to traverse + */ + flnextparamislast = true; + + if ( !getvarparam( hp1, 1, &adr.ht, adr.bs ) ) + return ( false ); + + /* + conver the address to an hdlhashtable + */ + if ( ! findnamedtable( adr.ht, adr.bs, &htbl ) ) + return ( false ); + + /* + build the string from the table + */ + if ( ! conv_concatenateTableStrings( *htbl, & hresult ) ) + return ( false ); + + /* + set the result + */ + setheapvalue( hresult, stringvaluetype, v ); + + return ( true ); +} + static boolean conv_compilestringverb( hdltreenode hp1, tyvaluerecord *v, bigstring bserror ) { Handle s; /* the string being parsed */ @@ -1063,8 +1192,17 @@ switch (token) { case compilestringfunc: /* 2004/12/31 smd */ - return ( conv_compilestringverb( hp1, v, bserror ) ); + if ( conv_compilestringverb( hp1, v, bserror ) ) + return ( true ); + else + goto error; + case tabletostringfunc: /* 2006-04-24 smd */ + if ( conv_tabletostringverb( hp1, v, bserror ) ) + return ( true ); + else + goto error; + default: errornum = notimplementederror; Modified: Frontier/branches/Conversant/Common/source/strings.c =================================================================== --- Frontier/branches/Conversant/Common/source/strings.c 2006-05-02 20:17:16 UTC (rev 1339) +++ Frontier/branches/Conversant/Common/source/strings.c 2006-05-02 20:32:33 UTC (rev 1340) @@ -48,7 +48,25 @@ #define ctparseparams 4 #define hextoint(ch) (isdigit(ch)? (ch - '0') : (getlower (ch) - 'a' + 10)) + +#define stringerrorlist 263 +/* + constants related to text-conversion functions +*/ +#define cs_utf8 BIGSTRING( "\xA5" "utf-8" ) +#define cs_utf16 BIGSTRING( "\x06" "utf-16" ) +#define cs_iso88591 BIGSTRING( "\xA0" "iso-8859-1" ) +#define cs_macintosh BIGSTRING( "\x09" "macintosh" ) + +#ifdef WIN95VERSION + #define kTextUnsupportedEncodingErr -8738 + #define kTextMalformedInputErr -8739 + #define kTextUndefinedElementErr -8740 + #define kTECNoConversionPathErr -8749 + #define kTECPartialCharErr -8753 +#endif + byte zerostring [] = "\0"; /*use this to conserve constant space*/ unsigned char lowercasetable[256]; @@ -62,12 +80,12 @@ /* declarations */ -static boolean converttextencoding( Handle, Handle, const long, const long ); +static boolean converttextencoding( Handle, Handle, const long, const long, long * ); static boolean getTextEncodingID( bigstring, long * ); #ifdef WIN95VERSION - static HRESULT UnicodeToAnsi(Handle, Handle, unsigned long); - static HRESULT AnsiToUnicode(Handle, Handle, unsigned long); + static boolean UnicodeToAnsi(Handle, Handle, unsigned long, long *); + static boolean AnsiToUnicode(Handle, Handle, unsigned long, long *); #endif @@ -1686,14 +1704,28 @@ #ifdef WIN95VERSION boolean copyWideToPString( const wchar_t * inString, bigstring bs ) { - HRESULT err; + DWORD err; size_t lenOut; - err = wcstombs_s( &lenOut, bs, 255, inString, _TRUNCATE ); - - if ( FAILED( err ) ) - return (false); + lenOut = WideCharToMultiByte( 1252, 0,(wchar_t *) inString, -1, bs, + 255, NULL, NULL); + if ( lenOut == 0 ) + { + err = GetLastError(); + + switch ( err ) + { + case ERROR_INSUFFICIENT_BUFFER: /* these are the err codes it can return */ + case ERROR_INVALID_FLAGS: /* I'm just not yet sure how to handle them */ + case ERROR_INVALID_PARAMETER: + return ( false ); + + case S_OK: + break; + } + } + convertcstring( bs ); return (true); @@ -1702,19 +1734,35 @@ boolean copyPStringToWide( bigstring bs, long * lenResult, wchar_t * outString ) { HRESULT err; - size_t lenOut; + size_t lenIn; + bigstring bsCString; - convertpstring( bs ); + lenIn = (size_t) bs[ 0 ]; + + copystring( bs, bsCString ); + convertpstring( bsCString ); - err = mbstowcs_s( &lenOut, outString, 255, (const char *) bs, _TRUNCATE ); + *lenResult = (long) MultiByteToWideChar( 1252, 0, bsCString, lenIn, (LPWSTR) outString, 255 ); - if ( SUCCEEDED( err ) ) + if ( *lenResult == 0 ) { - *lenResult = (long) lenOut; - return (true); + err = GetLastError(); + + switch ( err ) + { + case ERROR_INSUFFICIENT_BUFFER: /* these are the err codes it can return */ + case ERROR_INVALID_FLAGS: /* I'm just not yet sure how to handle them */ + case ERROR_INVALID_PARAMETER: + return ( false ); + + case S_OK: + break; + } } - else - return (false); + + outString[ *lenResult ] = L'\0'; /* the API doesn't seem to do this consistently */ + + return ( true ); } #endif @@ -2305,11 +2353,46 @@ return (pushchar (':', bs)); } /*assurelastchariscolon*/ + + + +static short getTextEncodingErrorNumFromOSCode( long osStatusCode ) +{ + switch ( osStatusCode ) + { + case kTextUnsupportedEncodingErr: + return 3; + case kTextMalformedInputErr: + return 4; + case kTextUndefinedElementErr: + return 5; + case kTECNoConversionPathErr: + return 6; + case kTECPartialCharErr: + return 7; + + default: + return 2; + } +} + +static void setTextEncodingConversionError( const bigstring encIn, const bigstring encOut, long osStatusCode ) +{ + short errStringNum = getTextEncodingErrorNumFromOSCode( osStatusCode ); + bigstring rezErrorMessage, bsErrorMessage; + if ( ! getstringlist( stringerrorlist, errStringNum, rezErrorMessage ) ) + getstringlist( stringerrorlist, 1, rezErrorMessage ); + + parsedialogstring( rezErrorMessage, (ptrstring) encIn, (ptrstring) encOut, nil, nil, bsErrorMessage ); + + langerrormessage( bsErrorMessage ); +} + #ifdef WIN95VERSION -static HRESULT UnicodeToAnsi(Handle h, Handle hresult, unsigned long encoding) +static boolean UnicodeToAnsi( Handle h, Handle hresult, unsigned long encoding, long * errCode ) { /* 7.0b42 PBS: convert from Unicode to Ansi. Borrowed from Microsoft sample code. @@ -2325,45 +2408,57 @@ sethandlesize (hresult, cbAnsi); // Convert to ANSI. - lentext = WideCharToMultiByte( encoding, 0,(wchar_t *) *h, -1, *hresult, - cbAnsi, NULL, NULL); - + lentext = WideCharToMultiByte( encoding, 0, (wchar_t *) *h, -1, *hresult, cbAnsi, NULL, NULL); + + if ( lentext == 0 ) // report error + { + * errCode = GetLastError(); + + return ( false ); + } + + *errCode = S_OK; + sethandlesize (hresult, lentext - 1); - return NOERROR; + return ( true ); } -static HRESULT AnsiToUnicode (Handle h, Handle hresult, unsigned long encoding) +static boolean AnsiToUnicode( Handle h, Handle hresult, unsigned long encoding, long * errCode ) { - /* 7.0b42 PBS: convert from ANSI to Unicode. Borrowed from Microsoft sample code. */ ULONG cbUni, cCharacters; long lentext; - // unsigned long ix; cCharacters = gethandlesize (h); // Determine number of bytes to be allocated for ANSI string. An // ANSI string can have at most 2 bytes per character (for Double // Byte Character Strings.) - cbUni = cCharacters*4; + cbUni = cCharacters * 4; sethandlesize (hresult, cbUni); // Convert to ANSI. lentext = MultiByteToWideChar (encoding, 0, *h, cCharacters, (wchar_t *) *hresult, cbUni); - - if ( lentext > 0 ) /* FIXME: what should we do if lentext is 0, which is an error condition? */ + + if ( lentext == 0 ) { - sethandlesize( hresult, ( lentext + 1 ) * 2 ); - ((wchar_t *)(*hresult))[lentext] = L'\0'; + * errCode = GetLastError(); + + return ( false ); } + + * errCode = S_OK; + + sethandlesize( hresult, ( lentext + 1 ) * 2 ); + ((wchar_t *)(*hresult))[lentext] = L'\0'; - return NOERROR; + return ( true ); } #endif /*end Windows character conversion routines*/ @@ -2371,63 +2466,76 @@ /* convert an "internet name" for an encoding into a platform-specific id for the character set */ -static boolean getTextEncodingID( bigstring bsEncodingName, long * encodingId ) { +static boolean getTextEncodingID( bigstring bsEncodingName, long * encodingId ) +{ + #ifdef MACVERSION -#ifdef MACVERSION + OSStatus err; + TextEncoding oneEncoding; + + err = TECGetTextEncodingFromInternetName( &oneEncoding, bsEncodingName ); + + if ( err != noErr ) + { + setTextEncodingConversionError( bsEncodingName, BIGSTRING( "" ), (long) err ); + + return ( false ); + } + + *encodingId = (long) oneEncoding; + + #endif - OSStatus err; - TextEncoding oneEncoding; - - err = TECGetTextEncodingFromInternetName( &oneEncoding, bsEncodingName ); - - if ( err != noErr ) - return (false); - - *encodingId = (long) oneEncoding; - -#endif + #ifdef WIN95VERSION -#ifdef WIN95VERSION + HRESULT err; + IMultiLanguage2 * pMultiLanguage; + MIMECSETINFO setInfo; + wchar_t ianaName[ 512 ]; + long lenIanaName; - HRESULT err; - IMultiLanguage2 * pMultiLanguage; - MIMECSETINFO setInfo; - wchar_t ianaName[ 512 ]; - long lenIanaName; + lowertext( (ptrbyte) (bsEncodingName + 1), (long) bsEncodingName[ 0 ] ); - lowertext( (ptrbyte) (bsEncodingName + 1), (long) bsEncodingName[ 0 ] ); + if ( equalstrings( bsEncodingName, BIGSTRING ("\x06" "utf-16") ) ) + { + *encodingId = 1200; + + return (true); + } - if ( equalstrings( bsEncodingName, BIGSTRING ("\x06" "utf-16") ) ) - { - *encodingId = 0; - return (true); - } + initCOM(); - initCOM(); + err = CoCreateInstance( + &CLSID_CMultiLanguage, + NULL, + CLSCTX_INPROC_SERVER, + &IID_IMultiLanguage2, + (void **) &pMultiLanguage ); - err = CoCreateInstance( - &CLSID_CMultiLanguage, - NULL, - CLSCTX_INPROC_SERVER, - &IID_IMultiLanguage2, - (void **) &pMultiLanguage ); + if ( FAILED( err ) ) + { + setTextEncodingConversionError( bsEncodingName, BIGSTRING( "" ), err ); + + return ( false ); + } - if ( FAILED( err ) ) - return (false); + copyPStringToWide( bsEncodingName, &lenIanaName, ianaName ); - copyPStringToWide( bsEncodingName, &lenIanaName, ianaName ); + err = pMultiLanguage->lpVtbl->GetCharsetInfo( pMultiLanguage, ianaName, &setInfo ); + if ( FAILED( err ) ) + { + setTextEncodingConversionError( bsEncodingName, BIGSTRING( "" ), kTextUnsupportedEncodingErr ); + + pMultiLanguage->lpVtbl->Release( pMultiLanguage ); + + return ( false ); + } - // pSetInfo = (PMIMECSETINFO)CoTaskMemAlloc( sizeof(MIMECSETINFO) ); + *encodingId = (long)(setInfo.uiInternetEncoding); - err = pMultiLanguage->lpVtbl->GetCharsetInfo( pMultiLanguage, ianaName, &setInfo ); - if ( FAILED( err ) ) - return (false); + pMultiLanguage->lpVtbl->Release( pMultiLanguage ); - *encodingId = (long)(setInfo.uiInternetEncoding); - - pMultiLanguage->lpVtbl->Release( pMultiLanguage ); - -#endif + #endif return (true); } @@ -2441,7 +2549,15 @@ long encodingId; if ( ! getTextEncodingID( bsEncodingName, &encodingId ) ) + { + /* + if the encoding isn't recognized then getTextEncodingId set an error + we need to clear that error + */ + langerrorclear(); + return (false); + } #ifdef MACVERSION @@ -2452,14 +2568,14 @@ #ifdef WIN95VERSION - // we use 0 to refer to UTF-16 on Windows, as it's the default character set and has no code page + // we use 0 to refer to UTF-16 on Windows, as it's the default character set and seems to have no code page return (true); #endif } -static boolean converttextencoding( Handle h, Handle hresult, const long inputcharset, const long outputcharset) { - +static boolean converttextencoding( Handle h, Handle hresult, const long inputcharset, const long outputcharset, long * OSStatusCode ) +{ #ifdef MACVERSION /*Mac character conversion common routine*/ TECObjectRef converter; @@ -2472,7 +2588,8 @@ status = TECCreateConverter (&converter, inputcharset, outputcharset); if ( status != noErr ) { TECDisposeConverter (converter); - return (false); + *OSStatusCode = (long) status; + return ( false ); } sizeoutputbuffer = lentext * 4; @@ -2508,11 +2625,14 @@ lentext = gethandlesize (h) - pullBytes; - status = TECConvertText (converter, (ConstTextPtr)(*h + pullBytes), lentext, &ctorigbytes, (TextPtr)(*hresult), sizeoutputbuffer, &ctoutputbytes); + status = TECConvertText( converter, (ConstTextPtr)(*h + pullBytes), lentext, &ctorigbytes, (TextPtr)(*hresult), sizeoutputbuffer, &ctoutputbytes ); - if (status != noErr) { + if ( status != noErr ) + { TECDisposeConverter (converter); - return (false); + + *OSStatusCode = (long) status; + return ( false ); } TECFlushText (converter, (TextPtr)(*hresult), sizeoutputbuffer, &ctflushedbytes); @@ -2528,47 +2648,49 @@ #ifdef WIN95VERSION long lentext; + boolean flResult; + lentext = gethandlesize (h); + switch ( inputcharset ) { - case 0: /* unicode with BOM, not handled as a code page. I Hatesk Windows. */ - lentext = gethandlesize (h); + case 1200: + case 0: /* utf-16le, a.k.a. "unicode" on windows, not handled as a code page. */ sethandlesize (h,lentext + 2); (*h) [lentext] = '\0'; (*h) [lentext + 1] = '\0'; - if (UnicodeToAnsi (h, hresult, outputcharset)) - return (false); + flResult = UnicodeToAnsi( h, hresult, outputcharset, OSStatusCode ); - if ((*h) [0] == '\xFF') + if ( flResult && ( (*h) [0] == '\xFF') ) pullfromhandle (hresult,0, 1, NULL); /* Pop off the BOM */ - return (true); + break; default: { - lentext = gethandlesize (h); switch ( outputcharset ) { - case 0: /* unicode with BOM, not handled as a code page. I Sitll Hatesk Windows (and rrrabbits) */ + case 1200: + case 0: /* utf-16le, a.k.a. "unicode" on windows, not handled as a code page */ - return (!AnsiToUnicode (h, hresult, inputcharset)); + flResult = AnsiToUnicode( h, hresult, inputcharset, OSStatusCode ); + + break; default: { Handle htemp; - boolean flResult = true; newemptyhandle (&htemp); sethandlesize (h, lentext + 1); (*h) [lentext] = '\0'; - if (AnsiToUnicode (h, htemp, inputcharset)) - flResult = false; + flResult = AnsiToUnicode (h, htemp, inputcharset, OSStatusCode ); - if (flResult && ! UnicodeToAnsi (htemp, hresult, outputcharset)) { - + if ( flResult && UnicodeToAnsi( htemp, hresult, outputcharset, OSStatusCode ) ) { + if ((*hresult) [0] == '\xFF') pullfromhandle (hresult, 0, 1, NULL); /* pop BOM ? */ @@ -2578,8 +2700,6 @@ disposehandle (htemp); - return (flResult); - } /* case default */ } /* switch outputcharset */ @@ -2587,6 +2707,8 @@ } /* case default */ } /* switch inputcharset */ + + return ( flResult ); #endif } /*converttextencoding*/ @@ -2594,37 +2716,40 @@ boolean convertCharset( Handle hString, Handle hresult, bigstring charsetIn, bigstring charsetOut ) { -#ifdef MACVERSION + long err; - TextEncoding teInputSet, teOutputSet; + #ifdef MACVERSION + + TextEncoding teInputSet, teOutputSet; -#endif + #endif -#ifdef WIN95VERSION + #ifdef WIN95VERSION - long teInputSet, teOutputSet; + long teInputSet, teOutputSet; - initCOM(); + initCOM(); -#endif - + #endif + if ( ! getTextEncodingID( charsetIn, (long *) &teInputSet ) ) - { - // FIXME: generate error, encoding not available return (false); - } if ( ! getTextEncodingID( charsetOut, (long *) &teOutputSet ) ) + return (false); + + if ( ! converttextencoding( hString, hresult, (long) teInputSet, (long) teOutputSet, &err ) ) { - // FIXME: generate error, encoding not available - return (false); + setTextEncodingConversionError( charsetIn, charsetOut, err ); + + return ( false ); } - return ( converttextencoding( hString, hresult, (long) teInputSet, (long) teOutputSet ) ); + return ( true ); } -boolean utf16toansi (Handle h, Handle hresult) { +boolean utf16toansi( Handle h, Handle hresult ) { /* 7.0b42 PBS: convert from UTF-16 to iso-8859-1 character sets. @@ -2632,6 +2757,7 @@ #ifdef WIN95VERSION + long err; long lentext = gethandlesize (h); sethandlesize (h, lentext + 2); @@ -2640,7 +2766,9 @@ (*h) [lentext + 1] = '\0'; - UnicodeToAnsi (h, hresult, CP_ACP); + if ( ! UnicodeToAnsi (h, hresult, CP_ACP, &err) ) + + goto error; if ((*h) [0] == '\xFF') @@ -2649,13 +2777,24 @@ #endif #ifdef MACVERSION - - if (!converttextencoding (h, hresult, kTextEncodingUnicodeDefault, kTextEncodingWindowsLatin1)) - return (false); + + long err; + + if ( !converttextencoding( h, hresult, kTextEncodingUnicodeDefault, kTextEncodingWindowsLatin1, &err ) ) + + goto error; #endif return (true); + + + error: + + setTextEncodingConversionError( cs_utf16, cs_iso88591, (long) err ); + + return ( false ); + } /*utf16toansi*/ @@ -2664,7 +2803,9 @@ /* 70b42 PBS: convert from UTF-8 to ANSI. */ - + + long err; + #ifdef WIN95VERSION long lentext = gethandlesize (h); @@ -2677,9 +2818,19 @@ (*h) [lentext] = '\0'; - AnsiToUnicode (h, htemp, CP_UTF8); /*Convert to UTF-16*/ + if ( ! AnsiToUnicode (h, htemp, CP_UTF8, &err ) ) /*Convert to UTF-16*/ + { + setTextEncodingConversionError( cs_utf8, cs_utf16, err ); + + return ( false ); + } - UnicodeToAnsi (htemp, hresult, CP_ACP); /*Convert from UTF-16 to ANSI*/ + if ( ! UnicodeToAnsi( htemp, hresult, CP_ACP, &err ) ) /*Convert from UTF-16 to ANSI*/ + { + setTextEncodingConversionError( cs_utf16, cs_iso88591, err); + + return ( false ); + } if ((*htemp) [0] == '\xFF') @@ -2691,12 +2842,17 @@ #ifdef MACVERSION - if (!converttextencoding (h, hresult, kCFStringEncodingUTF8, kTextEncodingWindowsLatin1)) + if ( !converttextencoding( h, hresult, kCFStringEncodingUTF8, kTextEncodingWindowsLatin1, &err ) ) + { + setTextEncodingConversionError( cs_utf8, cs_iso88591, err ); + return (false); + } #endif return (true); + } /*utf8toansi*/ @@ -2706,6 +2862,8 @@ 7.0b42 PBS: convert from ANSI to UTF-8. */ + long err; + #ifdef WIN95VERSION Handle htemp; @@ -2717,10 +2875,20 @@ newemptyhandle (&htemp); - AnsiToUnicode (h, htemp, CP_ACP); /*convert to UTF-16*/ + if ( ! AnsiToUnicode( h, htemp, CP_ACP, &err ) ) /*convert to UTF-16*/ + { + setTextEncodingConversionError( cs_iso88591, cs_utf16, err ); + + return ( false ); + } + + if ( ! UnicodeToAnsi( htemp, hresult, CP_UTF8, &err ) ) /*convert from UTF-16 to UTF-8*/ + { + setTextEncodingConversionError( cs_utf16, cs_utf8, err ); + + return ( false ); + } - UnicodeToAnsi (htemp, hresult, CP_UTF8); /*convert from UTF-16 to UTF-8*/ - disposehandle (htemp); lentext = gethandlesize (hresult); @@ -2729,8 +2897,12 @@ #ifdef MACVERSION - if (!converttextencoding (h, hresult, kTextEncodingWindowsLatin1, kCFStringEncodingUTF8)) - return (false); + if ( !converttextencoding( h, hresult, kTextEncodingWindowsLatin1, kCFStringEncodingUTF8, &err ) ) + { + setTextEncodingConversionError( cs_iso88591, cs_utf8, err ); + + return ( false ); + } #endif @@ -2743,7 +2915,9 @@ /* 7.0b42 PBS: convert from ANSI to UTF-16. */ - + + long err; + #ifdef WIN95VERSION long lentext = gethandlesize (h); @@ -2752,14 +2926,23 @@ (*h) [lentext] = '\0'; - AnsiToUnicode (h, hresult, CP_ACP); + if ( ! AnsiToUnicode( h, hresult, CP_ACP, &err ) ) + { + setTextEncodingConversionError( cs_iso88591, cs_utf16, err ); + + return ( false ); + } #endif #ifdef MACVERSION - if (!converttextencoding (h, hresult, kTextEncodingWindowsLatin1, kTextEncodingUnicodeDefault)) - return (false); + if ( !converttextencoding( h, hresult, kTextEncodingWindowsLatin1, kTextEncodingUnicodeDefault, &err ) ) + { + setTextEncodingConversionError( cs_iso88591, cs_utf16, err ); + + return ( false ); + } #endif @@ -2814,45 +2997,35 @@ } /*pullsuffix*/ -void initstrings (void) { - - register short i; - - for (i = 0; i < 256; i++) - lowercasetable[i] = tolower (i); - - clearbytes (&parseparams, longsizeof (parseparams)); - - for (i = 1; i <= ctdirections; i++) { - - bigstring bs; - - getstringlist (directionlistnumber, i, bs); - - newheapstring (bs, &dirstrings [i - 1]); - } /*for*/ - } /*initstrings*/ - - boolean macromantoutf8 (Handle h, Handle hresult) { /* 2006-02-24 creedon: convert from Mac Roman character set to UTF-8, cribbed from ansitoutf8 */ + long err; + long encIn, encOut; + #ifdef WIN95VERSION - - if (!converttextencoding (h, hresult, 10000, CP_UTF8)) - return (false); - + + encIn = CP_UTF8; + encOut = 10000; + #endif #ifdef MACVERSION + + encIn = kCFStringEncodingUTF8; + encOut = kTextEncodingMacRoman; - if (!converttextencoding (h, hresult, kTextEncodingMacRoman, kCFStringEncodingUTF8)) - return (false); + #endif - #endif + if ( !converttextencoding( h, hresult, encIn, encOut, &err ) ) + { + setTextEncodingConversionError( cs_utf8, cs_macintosh, err ); + + return ( false ); + } return (true); } /* macromantoutf8 */ @@ -2863,21 +3036,51 @@ /* 2006-02-26 creedon: convert from UTF-8 character set to Mac Roman, cribbed from utf8toansi */ - + + long err; + long encIn, encOut; + #ifdef WIN95VERSION - - if (!converttextencoding (h, hresult, CP_UTF8, 10000)) - return (false); - + + encIn = CP_UTF8; + encOut = 10000; + #endif #ifdef MACVERSION - if (!converttextencoding (h, hresult, kCFStringEncodingUTF8, kTextEncodingMacRoman)) - return (false); + encIn = kCFStringEncodingUTF8; + encOut = kTextEncodingMacRoman; #endif - + + if ( !converttextencoding( h, hresult, encIn, encOut, &err ) ) + { + setTextEncodingConversionError( cs_utf8, cs_macintosh, err ); + + return ( false ); + } + return (true); } /* utf8tomacroman */ + + +void initstrings (void) { + + register short i; + + for (i = 0; i < 256; i++) + lowercasetable[i] = tolower (i); + + clearbytes (&parseparams, longsizeof (parseparams)); + + for (i = 1; i <= ctdirections; i++) { + + bigstring bs; + + getstringlist (directionlistnumber, i, bs); + + newheapstring (bs, &dirstrings [i - 1]); + } /*for*/ + } /*initstrings*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |