Screwed by patch ... enable libscihelptools{.la,-disable.la}.
[scilab.git] / scilab / modules / localization / src / c / getLocaleInfo_Windows.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2008 - INRIA - Allan CORNET
4  * Copyright (C) 2008 - Yung-Jang Lee
5  * 
6  * This file must be used under the terms of the CeCILL.
7  * This source file is licensed as described in the file COPYING, which
8  * you should have received as part of this distribution.  The terms
9  * are also available at    
10  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11  *
12  */
13
14 /*--------------------------------------------------------------------------*/
15 #include <windows.h>
16 #include <stdio.h>
17 #include "getLocaleInfo_Windows.h"
18 #include "MALLOC.h"
19 /*--------------------------------------------------------------------------*/
20 char* getLocaleSystemInfo(void)
21 {
22         #define LENGTH_BUFFER 1024
23         char buffer_LOCALE_SISO639LANGNAME[LENGTH_BUFFER];
24         char buffer_LOCALE_SISO3166CTRYNAME[LENGTH_BUFFER];
25         char *localeStr = NULL;
26         int ret = 0;
27         ret = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
28                 LOCALE_SISO639LANGNAME,
29                 &buffer_LOCALE_SISO639LANGNAME[0],
30                 LENGTH_BUFFER);
31         if (ret > 0)
32         {
33                 ret = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT,
34                         LOCALE_SISO3166CTRYNAME,
35                         &buffer_LOCALE_SISO3166CTRYNAME[0],
36                         LENGTH_BUFFER);
37                 if (ret >0)
38                 {
39                         int length_localeStr = (int)(strlen(buffer_LOCALE_SISO639LANGNAME)+
40                                 strlen(buffer_LOCALE_SISO3166CTRYNAME)+
41                                 strlen("_"));
42                         localeStr = (char*)MALLOC(sizeof(char)*(length_localeStr)+1);
43                         if (localeStr)
44                         {
45                                 #ifdef FORMAT_LOCALE
46                                         #undef FORMAT_LOCALE
47                                 #endif
48                                 #define FORMAT_LOCALE "%s_%s"
49                                 sprintf(localeStr,FORMAT_LOCALE,buffer_LOCALE_SISO639LANGNAME,buffer_LOCALE_SISO3166CTRYNAME);
50                         }
51                 }
52         }
53         return localeStr;
54 }
55 /*--------------------------------------------------------------------------*/
56 wchar_t* getLocaleUserInfo(void)
57 {
58         #define LENGTH_BUFFER 1024
59         wchar_t buffer_LOCALE_SISO639LANGNAME[LENGTH_BUFFER];
60         wchar_t buffer_LOCALE_SISO3166CTRYNAME[LENGTH_BUFFER];
61         wchar_t buffer_LOCALE_IDEFAULTANSICODEPAGE[LENGTH_BUFFER]; 
62         wchar_t *localeStr = NULL;
63         int ret = 0;
64         ret = GetLocaleInfo(LOCALE_USER_DEFAULT,
65                                                 LOCALE_SISO639LANGNAME,
66                                                 &buffer_LOCALE_SISO639LANGNAME[0],
67                                                 LENGTH_BUFFER);
68         if (ret > 0)
69         {
70
71                 ret = GetLocaleInfo(LOCALE_USER_DEFAULT,
72                                                         LOCALE_SISO3166CTRYNAME,
73                                                         &buffer_LOCALE_SISO3166CTRYNAME[0],
74                                                         LENGTH_BUFFER);
75                 if (ret >0)
76                 {
77             // BY YJLee get Windows CODE Page Information
78                         int ret = GetLocaleInfo(LOCALE_USER_DEFAULT,
79                                                 LOCALE_IDEFAULTANSICODEPAGE,
80                                                 &buffer_LOCALE_IDEFAULTANSICODEPAGE[0],
81                                                 LENGTH_BUFFER);
82
83                         int length_localeStr = (int)(strlen(buffer_LOCALE_SISO639LANGNAME)+
84                                                                                  strlen(buffer_LOCALE_SISO3166CTRYNAME)+
85                                                                                  strlen(buffer_LOCALE_IDEFAULTANSICODEPAGE)+
86                                                                                  strlen("_.CP") );
87                         localeStr = (char*)MALLOC(sizeof(char)*(length_localeStr)+1);
88                         if (localeStr)
89                         {
90                                 #ifdef FORMAT_LOCALE
91                                         #undef FORMAT_LOCALE
92                                 #endif
93                                 #define FORMAT_LOCALE "%s_%s.CP%s"
94                                 // in lang_contry.CPxxx format
95                                 sprintf(localeStr,FORMAT_LOCALE,
96                                                       buffer_LOCALE_SISO639LANGNAME,
97                                                                   buffer_LOCALE_SISO3166CTRYNAME,
98                                                                   buffer_LOCALE_IDEFAULTANSICODEPAGE
99                                                                   );
100                         }
101                 }
102         }
103         return localeStr;
104 }
105 /*--------------------------------------------------------------------------*/