1 /***************************************************************************
2 * copyright : (C) 2002 by Hendrik Sattler *
3 * mail : post@hendrik-sattler.de *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 ***************************************************************************/
11
12 #include <stdio.h>
13
14 //own headers
15 #include <charsets.h>
16 #include <helper.h>
17 #include <gtincl.h>
18
19 #if defined(OS2)
20 #define INCL_DOSNLS
21 #include <os2.h>
22 #define DOS_API
23 static char localcp[30];
get_system_charset_raw()24 char* get_system_charset_raw() {
25 int rc;
26 ULONG aulCpList[8] = {0}; /* Code page list */
27 ULONG ulBufSize = 8 * sizeof(ULONG); /* Size of output list */
28 ULONG ulListSize = 0; /* Size of list returned */
29
30 rc = DosQueryCp(ulBufSize,aulCpList,&ulListSize);
31 /* dirty solution, but it work ... */
32 snprintf(localcp,sizeof(localcp)-1,"CP%u",(int)aulCpList[0]);
33 return localcp;
34 }
35
36 #elif defined(WINDOWS_API)
37 #include <windows.h>
38 static char localcp[30];
get_system_charset_raw()39 char* get_system_charset_raw() {
40 snprintf(localcp,sizeof(localcp)-1,"CP%u",GetConsoleCP());
41 return localcp;
42 }
43
44 #else
45 #include <config.h>
46 #ifdef HAVE_LANGINFO_H
47 # include <langinfo.h>
48 #endif
get_system_charset_raw()49 char* get_system_charset_raw() {
50 # ifdef NO_NL_LANGINFO
51 return "ANSI_X3.4-1968";
52 # else //NO_NL_LANGINFO
53 # ifdef HAVE_LIBICONV
54 /* The default implementation uses nl_langinfo(CODESET)
55 * If this gives you problems with your mixture
56 * of libc and libiconv, fix it here.
57 */
58 # endif
59 return nl_langinfo(CODESET);
60 # endif //NO_NL_LANGINFO
61 }
62 #endif
63
64 static char* system_charset;
65
charset_init(char * charset,int announce)66 void charset_init (char* charset, int announce) {
67 //str_dup returns NULL on NULL input
68 system_charset = str_dup(charset);
69 if (announce) {
70 fprintf(stderr,_("Using \"%s\" as system character set."),get_system_charset());
71 fprintf(stderr,"\n");
72 }
73 gettext_set_codeset(get_system_charset());
74 }
75
get_system_charset()76 char* get_system_charset () {
77 if (system_charset != NULL) return system_charset;
78 else return get_system_charset_raw();
79 }
80