|
From: <set...@us...> - 2006-04-22 18:05:00
|
Revision: 1321 Author: sethdill Date: 2006-04-22 11:04:43 -0700 (Sat, 22 Apr 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1321&view=rev Log Message: ----------- Moved initCharsetsTable from strings.c to langstartup.c Added gettextencodingid function (still in flux) to strings.c Converttextencoding no longer modifies parameter h, so the verbs which call it are all able to use getreadonlytextvalue() (performance reasons). (Instead of popping the byte order mark, we just skip it in the call to TECConvertText) Converttextencoding now checks for more errors, and disposes of the converter object (mac only) when an error occurs. Removed calls to diposehandle in string verbs which are now using getreadonlytextvalue(). Bad bug. Removed call to initcharsetstable() from initstrings(), added it to inittablestructure in langstartup.c Modified Paths: -------------- Frontier/trunk/Common/headers/strings.h Frontier/trunk/Common/source/langstartup.c Frontier/trunk/Common/source/strings.c Frontier/trunk/Common/source/stringverbs.c Modified: Frontier/trunk/Common/headers/strings.h =================================================================== --- Frontier/trunk/Common/headers/strings.h 2006-04-22 13:05:46 UTC (rev 1320) +++ Frontier/trunk/Common/headers/strings.h 2006-04-22 18:04:43 UTC (rev 1321) @@ -266,9 +266,9 @@ extern boolean utf8tomacroman (Handle, Handle); /* 2006-02-25 creedon */ +extern boolean gettextencodingid (const Handle, long *); /* 2006-04-20 smd */ + extern boolean converttextencoding (Handle, Handle, long, long); /* 2006-04-14 smd */ -extern boolean initcharsetstable (void); /* 2006-04-20 smd */ - #endif Modified: Frontier/trunk/Common/source/langstartup.c =================================================================== --- Frontier/trunk/Common/source/langstartup.c 2006-04-22 13:05:46 UTC (rev 1320) +++ Frontier/trunk/Common/source/langstartup.c 2006-04-22 18:04:43 UTC (rev 1321) @@ -424,6 +424,103 @@ } /*initenvironment*/ +static boolean initCharsetsTable (hdlhashtable cSetsTable) +{ + tyvaluerecord v; + +#if MACVERSION + OSStatus err; + ItemCount ct, actual_ct, i; + + v.valuetype = longvaluetype; + + err = TECCountAvailableTextEncodings( &ct ); + if ( err != noErr ) { + pophashtable(); + + return (true); // don't kill the whole startup + } + + TextEncoding enc; + TextEncoding availEncodings[ ct ]; + bigstring ianaName; + + err = TECGetAvailableTextEncodings ( availEncodings, ct, &actual_ct ); + if ( err != noErr ) + return (true); // we don't want to kill the whole startup here + + for ( i = 0; i < actual_ct; i++ ) { + enc = availEncodings[ i ]; + // enc = i; + + /* + get the internet "iana" name for the encoding + */ + err = TECGetTextEncodingInternetName( enc, ianaName ); + if ( err != noErr ) + continue; + + /* + now conver the "iana" name back into the canonical encoding value + (more than one encoding will point to the same iana name, + this makes sure that we use the right one) + */ + err = TECGetTextEncodingFromInternetName( &enc, ianaName ); + if ( err != noErr ) + continue; + + langassignlongvalue( cSetsTable, ianaName, (long) enc ); + } +#endif + +#if WIN95VERSION + langassignlongvalue( cSetsTable, "ASCII", 20127 ); + langassignlongvalue( cSetsTable, "US-ASCII" 20127 ); /* alias for ASCII */ + + langassignlongvalue( cSetsTable, "MACINTOSH", 10000 ); + langassignlongvalue( cSetsTable, "MacRoman", 10000 ); /* alias for MACINTOSH */ + + langassignlongvalue( cSetsTable, "iso-8859-1", 28591 ); + langassignlongvalue( cSetsTable, "iso-latin-1", 28591 ); /* alias for iso-8859-1 */ + langassignlongvalue( cSetsTable, "iso-8859-2", 28592 ); + langassignlongvalue( cSetsTable, "iso-8859-3", 28593 ); + langassignlongvalue( cSetsTable, "iso-8859-4", 28594 ); + langassignlongvalue( cSetsTable, "iso-8859-5", 28595 ); + langassignlongvalue( cSetsTable, "iso-8859-6", 28596 ); + langassignlongvalue( cSetsTable, "iso-8859-7", 28597 ); + langassignlongvalue( cSetsTable, "iso-8859-8", 28598 ); + langassignlongvalue( cSetsTable, "iso-8859-9", 28599 ); + langassignlongvalue( cSetsTable, "iso-8859-10", 28592 ); + + langassignlongvalue( cSetsTable, "windows-1250", 1250 ); + langassignlongvalue( cSetsTable, "windows-latin-2", 1250 ); /* code page 1250, Central Europe */ + + langassignlongvalue( cSetsTable, "windows-1251", 1251 ); /* code page 1251, Slavic Cyrillic */ + + langassignlongvalue( cSetsTable, "windows-1252", 1252 ); + langassignlongvalue( cSetsTable, "windows-latin-1", 1252 ); + + langassignlongvalue( cSetsTable, "windows-1253", 1253 ); /* code page 1253 */ + langassignlongvalue( cSetsTable, "windows-1254", 1254 ); /* code page 1254, Turkish */ + langassignlongvalue( cSetsTable, "windows-1255", 1255 ); /* code page 1255 */ + langassignlongvalue( cSetsTable, "windows-1256", 1256 ); /* code page 1256 */ + langassignlongvalue( cSetsTable, "windows-1257", 1257 ); /* code page 1257 */ + langassignlongvalue( cSetsTable, "windows-1258", 1258 ); /* code page 1258 */ + langassignlongvalue( cSetsTable, "windows-1361", 1361 ); /* code page 1361, for Windows NT */ + + langassignlongvalue( cSetsTable, "UTF-7", 65000 ); + langassignlongvalue( cSetsTable, "UTF-8", 65001 ); + + langassignlongvalue( cSetsTable, "UTF-16", 0 ); /* not a real code page. 0 for special case handling in Frontier */ + + langassignlongvalue( cSetsTable, "UTF-16le", 1200 ); + langassignlongvalue( cSetsTable, "UTF-16be", 1201 ); +#endif + + return (true); + } /* initCharsetsTable */ + + boolean inittablestructure (void) { /* @@ -481,6 +578,8 @@ if (!tablenewsystemtable (htable, namecharsetstable, &charsetstable)) goto error; + initCharsetsTable (charsetstable); /* don't die if the charsets can't be initialized */ + pophashtable (); return (true); Modified: Frontier/trunk/Common/source/strings.c =================================================================== --- Frontier/trunk/Common/source/strings.c 2006-04-22 13:05:46 UTC (rev 1320) +++ Frontier/trunk/Common/source/strings.c 2006-04-22 18:04:43 UTC (rev 1321) @@ -2339,6 +2339,34 @@ #endif /*end Windows character conversion routines*/ +/* convert an "internet name" for an encoding into a platform-specific id for the character set */ + +boolean gettextencodingid (const Handle h, long * encodingId) { + +#ifdef MACVERSION + + OSStatus err; + TextEncoding oneEncoding; + bigstring ianaName; + long ct, ix = 0; + + ct = gethandlesize (h); + ianaName [0] = (byte) ct; + loadfromhandle (h, &ix, ct, ianaName + 1); + + err = TECGetTextEncodingFromInternetName( &oneEncoding, ianaName ); + + if ( err != noErr ) + return (false); + + *encodingId = (long) oneEncoding; + +#endif + + return (true); +} + + boolean converttextencoding (Handle h, Handle hresult, long inputcharset, long outputcharset) { #ifdef MACVERSION /*Mac character conversion common routine*/ @@ -2354,7 +2382,11 @@ // (*h) [lentext] = '\0'; - TECCreateConverter (&converter, inputcharset, outputcharset); + status = TECCreateConverter (&converter, inputcharset, outputcharset); + if ( status != noErr ) { + TECDisposeConverter (converter); + return (false); + } sizeoutputbuffer = lentext * 4; @@ -2391,12 +2423,14 @@ // if (((*h) [0] == '\xFF') || ((*h) [0] == '\xEF')) /*pop byte order mark*/ // pullfromhandle (h, 0, 3, NULL); + /* if (pullBytes > 0) pullfromhandle (h, 0, pullBytes, NULL); + */ + + lentext = gethandlesize (h) - pullBytes; - lentext = gethandlesize (h); - - status = TECConvertText (converter, (ConstTextPtr)(*h), lentext, &ctorigbytes, (TextPtr)(*hresult), sizeoutputbuffer, &ctoutputbytes); + status = TECConvertText (converter, (ConstTextPtr)(*h + pullBytes), lentext, &ctorigbytes, (TextPtr)(*hresult), sizeoutputbuffer, &ctoutputbytes); if (status != noErr) { TECDisposeConverter (converter); @@ -2482,100 +2516,7 @@ #endif } /*converttextencoding*/ -boolean initcharsetstable (void) { -#if MACVERSION - OSStatus err; - ItemCount ct, actual_ct, i; - tyvaluerecord v; - - v.valuetype = longvaluetype; - - err = TECCountAvailableTextEncodings( &ct ); - if ( err != noErr ) { - pophashtable(); - - return (true); // don't kill the whole startup - } - - TextEncoding enc; - TextEncoding availEncodings[ ct ]; - bigstring ianaName; - - err = TECGetAvailableTextEncodings ( availEncodings, ct, &actual_ct ); - if ( err != noErr ) { - pophashtable(); - - return (true); // we don't want to kill the whole startup here - } - - for ( i = 0; i < actual_ct; i++ ) { - enc = availEncodings[ i ]; - // enc = i; - - err = TECGetTextEncodingInternetName( enc, ianaName ); - if ( err != noErr ) - continue; - - nullterminate( ianaName ); - - v.data.longvalue = (signed long) enc; - - hashtableassign( charsetstable, ianaName, v ); - } -#endif - -#if WIN95VERSION - pushhashtable (charsetstable); /* global, table is created in langstartup.c : inittablestructure() */ - - addlong( "ASCII", 20127 ); - addlong( "US-ASCII" 20127 ); /* alias for ASCII */ - - addlong( "MACINTOSH", 10000 ); - addlong( "MacRoman", 10000 ); /* alias for MACINTOSH */ - - addlong( "iso-8859-1", 28591 ); - addlong( "iso-latin-1", 28591 ); /* alias for iso-8859-1 */ - addlong( "iso-8859-2", 28592 ); - addlong( "iso-8859-3", 28593 ); - addlong( "iso-8859-4", 28594 ); - addlong( "iso-8859-5", 28595 ); - addlong( "iso-8859-6", 28596 ); - addlong( "iso-8859-7", 28597 ); - addlong( "iso-8859-8", 28598 ); - addlong( "iso-8859-9", 28599 ); - addlong( "iso-8859-10", 28592 ); - - addlong( "windows-1250", 1250 ); - addlong( "windows-latin-2", 1250 ); /* code page 1250, Central Europe */ - - addlong( "windows-1251", 1251 ); /* code page 1251, Slavic Cyrillic */ - - addlong( "windows-1252", 1252 ); - addlong( "windows-latin-1", 1252 ); - - addlong( "windows-1253", 1253 ); /* code page 1253 */ - addlong( "windows-1254", 1254 ); /* code page 1254, Turkish */ - addlong( "windows-1255", 1255 ); /* code page 1255 */ - addlong( "windows-1256", 1256 ); /* code page 1256 */ - addlong( "windows-1257", 1257 ); /* code page 1257 */ - addlong( "windows-1258", 1258 ); /* code page 1258 */ - addlong( "windows-1361", 1361 ); /* code page 1361, for Windows NT */ - - addlong( "UTF-7", 65000 ); - addlong( "UTF-8", 65001 ); - addlong( "UTF-16", 0 ); /* not a real code page. 0 for special case handling in Frontier */ - addlong( "UTF-16le", 1200 ); - addlong( "UTF-16be", 1201 ); - - pophashtable(); -#endif - - return (true); - } /* initcharsetstable */ - - - boolean utf16toansi (Handle h, Handle hresult) { /* Modified: Frontier/trunk/Common/source/stringverbs.c =================================================================== --- Frontier/trunk/Common/source/stringverbs.c 2006-04-22 13:05:46 UTC (rev 1320) +++ Frontier/trunk/Common/source/stringverbs.c 2006-04-22 18:04:43 UTC (rev 1321) @@ -2282,8 +2282,6 @@ if (!macromantoutf8 (h, hresult)) goto error; - disposehandle (h); - return (setheapvalue (hresult, stringvaluetype, v)); } @@ -2301,8 +2299,6 @@ if (!utf8tomacroman (h, hresult)) goto error; - disposehandle (h); - return (setheapvalue (hresult, stringvaluetype, v)); } @@ -2327,11 +2323,11 @@ if (! converttextencoding (h, hresult, charsetIn, charsetOut)) goto error; - disposehandle(h); + // disposehandle(h); return (setheapvalue (hresult, stringvaluetype, v)); } - + default: errornum = notimplementederror; @@ -2358,12 +2354,8 @@ initialize the builtins directly. 2.1b5 dmb: verb initialization is now resource-based - - 2006-04-20 smd: added call to initialize the character sets */ - initcharsetstable(); - return (loadfunctionprocessor (idstringverbs, &stringfunctionvalue)); } /*stringinitverbs*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |