X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flocalcharset.c;h=66099d5e315bfbddc1118042a4a9eb9b3ac61b90;hb=0df2580e13bb5523b7f5569e9bec1fda9c812677;hp=2b1564e2fd8d00b71cd112d2e26d3da6bd37d560;hpb=120198bc782d3d46c3f7247200ef8cb3e102b991;p=gnulib.git diff --git a/lib/localcharset.c b/lib/localcharset.c index 2b1564e2f..66099d5e3 100644 --- a/lib/localcharset.c +++ b/lib/localcharset.c @@ -1,21 +1,20 @@ /* Determine a canonical name for the current locale's character encoding. - Copyright (C) 2000-2002 Free Software Foundation, Inc. + Copyright (C) 2000-2004 Free Software Foundation, Inc. - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published - by the Free Software Foundation; either version 2, or (at your option) + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU Library General Public - License along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. */ + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Written by Bruno Haible . */ @@ -23,6 +22,9 @@ # include #endif +/* Specification. */ +#include "localcharset.h" + #if HAVE_STDDEF_H # include #endif @@ -64,8 +66,14 @@ # include #endif -#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__ - /* Win32, OS/2, DOS */ +#if ENABLE_RELOCATABLE +# include "relocatable.h" +#else +# define relocate(pathname) (pathname) +#endif + +#if defined _WIN32 || defined __WIN32__ || defined __CYGWIN__ || defined __EMX__ || defined __DJGPP__ + /* Win32, Cygwin, OS/2, DOS */ # define ISSLASH(C) ((C) == '/' || (C) == '\\') #endif @@ -77,16 +85,11 @@ # define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) #endif -#ifdef HAVE_GETC_UNLOCKED +#if HAVE_DECL_GETC_UNLOCKED # undef getc # define getc getc_unlocked #endif -#ifdef __cplusplus -/* When compiling with "gcc -x c++", produce a function with C linkage. */ -extern "C" const char * locale_charset (void); -#endif - /* The following static variable is declared 'volatile' to avoid a possible multithread problem in the function get_charset_aliases. If we are running in a threaded environment, and if two threads initialize @@ -110,9 +113,9 @@ get_charset_aliases () cp = charset_aliases; if (cp == NULL) { -#if !defined WIN32 +#if !(defined VMS || defined WIN32) FILE *fp; - const char *dir = LIBDIR; + const char *dir = relocate (LIBDIR); const char *base = "charset.alias"; char *file_name; @@ -137,15 +140,17 @@ get_charset_aliases () else { /* Parse the file's contents. */ - int c; - char buf1[50+1]; - char buf2[50+1]; char *res_ptr = NULL; size_t res_size = 0; - size_t l1, l2; for (;;) { + int c; + char buf1[50+1]; + char buf2[50+1]; + size_t l1, l2; + char *old_res_ptr; + c = getc (fp); if (c == EOF) break; @@ -166,6 +171,7 @@ get_charset_aliases () break; l1 = strlen (buf1); l2 = strlen (buf2); + old_res_ptr = res_ptr; if (res_size == 0) { res_size = l1 + 1 + l2 + 1; @@ -180,6 +186,8 @@ get_charset_aliases () { /* Out of memory. */ res_size = 0; + if (old_res_ptr != NULL) + free (old_res_ptr); break; } strcpy (res_ptr + res_size - (l2 + 1) - (l1 + 1), buf1); @@ -200,11 +208,36 @@ get_charset_aliases () #else +# if defined VMS + /* To avoid the troubles of an extra file charset.alias_vms in the + sources of many GNU packages, simply inline the aliases here. */ + /* The list of encodings is taken from the OpenVMS 7.3-1 documentation + "Compaq C Run-Time Library Reference Manual for OpenVMS systems" + section 10.7 "Handling Different Character Sets". */ + cp = "ISO8859-1" "\0" "ISO-8859-1" "\0" + "ISO8859-2" "\0" "ISO-8859-2" "\0" + "ISO8859-5" "\0" "ISO-8859-5" "\0" + "ISO8859-7" "\0" "ISO-8859-7" "\0" + "ISO8859-8" "\0" "ISO-8859-8" "\0" + "ISO8859-9" "\0" "ISO-8859-9" "\0" + /* Japanese */ + "eucJP" "\0" "EUC-JP" "\0" + "SJIS" "\0" "SHIFT_JIS" "\0" + "DECKANJI" "\0" "DEC-KANJI" "\0" + "SDECKANJI" "\0" "EUC-JP" "\0" + /* Chinese */ + "eucTW" "\0" "EUC-TW" "\0" + "DECHANYU" "\0" "DEC-HANYU" "\0" + "DECHANZI" "\0" "GB2312" "\0" + /* Korean */ + "DECKOREAN" "\0" "EUC-KR" "\0"; +# endif + +# if defined WIN32 /* To avoid the troubles of installing a separate file in the same directory as the DLL and of retrieving the DLL's directory at runtime, simply inline the aliases here. */ -# if defined WIN32 cp = "CP936" "\0" "GBK" "\0" "CP1361" "\0" "JOHAB" "\0" "CP20127" "\0" "ASCII" "\0"