summaryrefslogtreecommitdiffstats
path: root/scilab
diff options
context:
space:
mode:
authorAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-11-10 08:28:27 +0100
committerAntoine ELIAS <antoine.elias@scilab-enterprises.com>2016-11-10 08:28:27 +0100
commit120e12f8b2c85db5b513e9f4ef1c9c4fc58fedb4 (patch)
tree795dd819156870160cc4a23721531093701386f4 /scilab
parent2ded3117215ff751fbd27fe4708313e7258431df (diff)
downloadscilab-120e12f8b2c85db5b513e9f4ef1c9c4fc58fedb4.zip
scilab-120e12f8b2c85db5b513e9f4ef1c9c4fc58fedb4.tar.gz
utf: localization 3
Change-Id: Ia30f4bc59865462241137dc2c2ef5ccffa1cb0f7
Diffstat (limited to 'scilab')
-rw-r--r--scilab/modules/localization/includes/charEncoding.h2
-rw-r--r--scilab/modules/localization/sci_gateway/c/sci_gettext.c10
-rw-r--r--scilab/modules/localization/sci_gateway/cpp/sci_setdefaultlanguage.cpp4
-rw-r--r--scilab/modules/localization/sci_gateway/cpp/sci_setlanguage.cpp8
-rw-r--r--scilab/modules/localization/src/c/InitializeLocalization.c2
-rw-r--r--scilab/modules/localization/src/c/charEncoding.c30
-rw-r--r--scilab/modules/localization/src/c/setgetlanguage.c6
-rw-r--r--scilab/modules/localization/src/localization.vcxproj.filters6
-rw-r--r--scilab/modules/localization/src/localization_export.def1
9 files changed, 51 insertions, 18 deletions
diff --git a/scilab/modules/localization/includes/charEncoding.h b/scilab/modules/localization/includes/charEncoding.h
index b4a90b8..8f4b180 100644
--- a/scilab/modules/localization/includes/charEncoding.h
+++ b/scilab/modules/localization/includes/charEncoding.h
@@ -61,6 +61,8 @@ extern "C" {
61 */ 61 */
62 char *wide_string_to_UTF8(const wchar_t *_wide); 62 char *wide_string_to_UTF8(const wchar_t *_wide);
63 63
64 int get_codepoint_count(const char* _UTFStr);
65
64 /*file management with UTF filename*/ 66 /*file management with UTF filename*/
65#ifdef _MSC_VER 67#ifdef _MSC_VER
66 int wcstat(char* filename, struct _stat *st); 68 int wcstat(char* filename, struct _stat *st);
diff --git a/scilab/modules/localization/sci_gateway/c/sci_gettext.c b/scilab/modules/localization/sci_gateway/c/sci_gettext.c
index 897485a..e2b2ddf 100644
--- a/scilab/modules/localization/sci_gateway/c/sci_gettext.c
+++ b/scilab/modules/localization/sci_gateway/c/sci_gettext.c
@@ -101,7 +101,7 @@ int sci_gettext(char *fname, void* pvApiCtx)
101 { 101 {
102 if (strcmp(StringsToTranslate[i], "") == 0) 102 if (strcmp(StringsToTranslate[i], "") == 0)
103 { 103 {
104 TranslatedStrings[i] = strdup(""); 104 TranslatedStrings[i] = os_strdup("");
105 } 105 }
106 else 106 else
107 { 107 {
@@ -191,7 +191,7 @@ static char *convertString_dgettext(const char *domain, const char *pStr)
191 } 191 }
192 192
193 revertStrsub = TRUE; 193 revertStrsub = TRUE;
194 tmpStr = strdup(tmpStr1); 194 tmpStr = os_strdup(tmpStr1);
195 if (tmpStr1) 195 if (tmpStr1)
196 { 196 {
197 FREE(tmpStr1); 197 FREE(tmpStr1);
@@ -201,10 +201,10 @@ static char *convertString_dgettext(const char *domain, const char *pStr)
201 else 201 else
202 { 202 {
203 revertStrsub = FALSE; 203 revertStrsub = FALSE;
204 tmpStr = strdup(pStr); 204 tmpStr = os_strdup(pStr);
205 } 205 }
206 206
207 TranslatedString = strdup(dgettext(domain, tmpStr)); 207 TranslatedString = os_strdup(dgettext(domain, tmpStr));
208 if (tmpStr) 208 if (tmpStr)
209 { 209 {
210 FREE(tmpStr); 210 FREE(tmpStr);
@@ -260,7 +260,7 @@ static char *convertString_dgettext(const char *domain, const char *pStr)
260 TranslatedString = NULL; 260 TranslatedString = NULL;
261 } 261 }
262 262
263 TranslatedString = strdup(tmpStr2); 263 TranslatedString = os_strdup(tmpStr2);
264 264
265 if (tmpStr2) 265 if (tmpStr2)
266 { 266 {
diff --git a/scilab/modules/localization/sci_gateway/cpp/sci_setdefaultlanguage.cpp b/scilab/modules/localization/sci_gateway/cpp/sci_setdefaultlanguage.cpp
index 2e2edbd..cc8e380 100644
--- a/scilab/modules/localization/sci_gateway/cpp/sci_setdefaultlanguage.cpp
+++ b/scilab/modules/localization/sci_gateway/cpp/sci_setdefaultlanguage.cpp
@@ -76,7 +76,7 @@ types::Function::ReturnValue sci_setdefaultlanguage(types::typed_list &in, int _
76 */ 76 */
77 if (getWarningMode()) 77 if (getWarningMode())
78 { 78 {
79 sciprint(_("%ls: This feature is only supported on Windows.\n"), L"setdefaultlanguage"); 79 sciprint(_("%s: This feature is only supported on Windows.\n"), "setdefaultlanguage");
80 } 80 }
81 81
82 types::Bool* pbOut = new types::Bool(FALSE); 82 types::Bool* pbOut = new types::Bool(FALSE);
@@ -95,7 +95,7 @@ types::Function::ReturnValue sci_setdefaultlanguage(types::typed_list &in, int _
95 { 95 {
96 if (getWarningMode()) 96 if (getWarningMode())
97 { 97 {
98 sciprint(_("Unsupported language '%ls'.\n"), newlang); 98 sciprint(_("Unsupported language '%s'.\n"), newlang);
99 } 99 }
100 out.push_back(new types::Bool(FALSE)); 100 out.push_back(new types::Bool(FALSE));
101 101
diff --git a/scilab/modules/localization/sci_gateway/cpp/sci_setlanguage.cpp b/scilab/modules/localization/sci_gateway/cpp/sci_setlanguage.cpp
index 25bfda4..7820976 100644
--- a/scilab/modules/localization/sci_gateway/cpp/sci_setlanguage.cpp
+++ b/scilab/modules/localization/sci_gateway/cpp/sci_setlanguage.cpp
@@ -55,11 +55,11 @@ types::Function::ReturnValue sci_setlanguage(types::typed_list &in, int _piRetCo
55 { 55 {
56 if (newlanguage == NULL) 56 if (newlanguage == NULL)
57 { 57 {
58 sciprint(_("%ls: Unsupported language '%ls'.\n"), L"setlanguage", param); 58 sciprint(_("%s: Unsupported language '%s'.\n"), "setlanguage", param);
59 } 59 }
60 else 60 else
61 { 61 {
62 sciprint(_("%ls: Unsupported language '%ls'.\n"), L"setlanguage", newlanguage); 62 sciprint(_("%s: Unsupported language '%s'.\n"), "setlanguage", newlanguage);
63 } 63 }
64 } 64 }
65 65
@@ -91,8 +91,8 @@ types::Function::ReturnValue sci_setlanguage(types::typed_list &in, int _piRetCo
91 { 91 {
92 if (getWarningMode()) 92 if (getWarningMode())
93 { 93 {
94 sciprint(_("Unsupported language '%ls'.\n"), param); 94 sciprint(_("Unsupported language '%s'.\n"), param);
95 sciprint(_("Switching to default language : '%ls'.\n"), SCILABDEFAULTLANGUAGE); 95 sciprint(_("Switching to default language : '%s'.\n"), SCILABDEFAULTLANGUAGE);
96 } 96 }
97 setlanguage(SCILABDEFAULTLANGUAGE); 97 setlanguage(SCILABDEFAULTLANGUAGE);
98 out.push_back(new types::Bool(FALSE)); 98 out.push_back(new types::Bool(FALSE));
diff --git a/scilab/modules/localization/src/c/InitializeLocalization.c b/scilab/modules/localization/src/c/InitializeLocalization.c
index f0c4006..49eb9d1 100644
--- a/scilab/modules/localization/src/c/InitializeLocalization.c
+++ b/scilab/modules/localization/src/c/InitializeLocalization.c
@@ -80,7 +80,7 @@ BOOL InitializeLocalization(void)
80 textdomain(NAMELOCALIZATIONDOMAIN); 80 textdomain(NAMELOCALIZATIONDOMAIN);
81 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8"); 81 bind_textdomain_codeset (NAMELOCALIZATIONDOMAIN, "UTF-8");
82#ifndef _MSC_VER 82#ifndef _MSC_VER
83 setlanguage(L""); 83 setlanguage("");
84#else 84#else
85 /* We look if registry value LANGUAGE exists */ 85 /* We look if registry value LANGUAGE exists */
86 /* If not exists the "" means that we will try to use the language of the system.*/ 86 /* If not exists the "" means that we will try to use the language of the system.*/
diff --git a/scilab/modules/localization/src/c/charEncoding.c b/scilab/modules/localization/src/c/charEncoding.c
index cb98a3b..f5dbddb 100644
--- a/scilab/modules/localization/src/c/charEncoding.c
+++ b/scilab/modules/localization/src/c/charEncoding.c
@@ -106,8 +106,38 @@ int wcstat(char* filename, struct _stat *st)
106 FREE(wfilename); 106 FREE(wfilename);
107 return stat_result; 107 return stat_result;
108} 108}
109
110int get_codepoint_count(const char* _UTFStr)
111{
112 DWORD dwFlags = 0;
113 UINT codePage = CP_ACP;
114
115 if (_UTFStr == NULL)
116 {
117 return 0;
118 }
119
120 if (IsValidUTF8(_UTFStr))
121 {
122 codePage = CP_UTF8;
123 }
124
125 return MultiByteToWideChar(codePage, dwFlags, _UTFStr, -1, NULL, 0) - 1; //MultiByteToWideChar return size including any terminating null character.
126}
127
109/*--------------------------------------------------------------------------*/ 128/*--------------------------------------------------------------------------*/
110#else 129#else
130int get_codepoint_count(const char* _UTFStr)
131{
132 mbstate_t ps;
133 if (_UTFStr == NULL)
134 {
135 return 0;
136 }
137
138 memset (&ps, 0x00, sizeof(ps));
139 return mbsrtowcs(NULL, &_UTFStr, 0, &ps);
140}
111/*--------------------------------------------------------------------------*/ 141/*--------------------------------------------------------------------------*/
112#ifdef __APPLE__ // Mac OS X 142#ifdef __APPLE__ // Mac OS X
113/*--------------------------------------------------------------------------*/ 143/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/localization/src/c/setgetlanguage.c b/scilab/modules/localization/src/c/setgetlanguage.c
index 918fe41..63e013f 100644
--- a/scilab/modules/localization/src/c/setgetlanguage.c
+++ b/scilab/modules/localization/src/c/setgetlanguage.c
@@ -134,7 +134,7 @@ BOOL setlanguage(const char* lang)
134 if (pstRet == NULL) 134 if (pstRet == NULL)
135 { 135 {
136 fprintf(stderr, 136 fprintf(stderr,
137 "Warning: Localization issue. Failed to change the LC_CTYPE locale category. Does not support the locale '%ls' %ls %s.\nDid you install the system locales?\n", 137 "Warning: Localization issue. Failed to change the LC_CTYPE locale category. Does not support the locale '%s' %s %s.\nDid you install the system locales?\n",
138 lang, ret, setlocale(LC_CTYPE, NULL)); 138 lang, ret, setlocale(LC_CTYPE, NULL));
139 } 139 }
140 140
@@ -160,7 +160,7 @@ BOOL setlanguage(const char* lang)
160 if (ret == NULL) 160 if (ret == NULL)
161 { 161 {
162#ifndef _MSC_VER 162#ifndef _MSC_VER
163 fprintf(stderr, "Warning: Localization issue. Does not support the locale '%ls'\nReturned: NULL\nCurrent system locale: %s\nDid you install the system locales?\n", lang, 163 fprintf(stderr, "Warning: Localization issue. Does not support the locale '%s'\nReturned: NULL\nCurrent system locale: %s\nDid you install the system locales?\n", lang,
164 setlocale(LC_MESSAGES, NULL)); 164 setlocale(LC_MESSAGES, NULL));
165#else 165#else
166 fprintf(stderr, "Warning: Localization issue. Cannot detect user locale.\n"); 166 fprintf(stderr, "Warning: Localization issue. Cannot detect user locale.\n");
@@ -382,7 +382,7 @@ BOOL exportLocaleToSystem(const char* locale)
382#ifdef _MSC_VER 382#ifdef _MSC_VER
383 fprintf(stderr, "Localization: Have not been able to find a suitable locale. Remains to default %s.\n", "LC_CTYPE"); 383 fprintf(stderr, "Localization: Have not been able to find a suitable locale. Remains to default %s.\n", "LC_CTYPE");
384#else 384#else
385 fprintf(stderr, "Localization: Have not been able to find a suitable locale. Remains to default %ls.\n", EXPORTENVLOCALESTR); 385 fprintf(stderr, "Localization: Have not been able to find a suitable locale. Remains to default %s.\n", EXPORTENVLOCALESTR);
386#endif 386#endif
387 return FALSE; 387 return FALSE;
388 } 388 }
diff --git a/scilab/modules/localization/src/localization.vcxproj.filters b/scilab/modules/localization/src/localization.vcxproj.filters
index 1f77961..8b13d0a 100644
--- a/scilab/modules/localization/src/localization.vcxproj.filters
+++ b/scilab/modules/localization/src/localization.vcxproj.filters
@@ -49,9 +49,6 @@
49 </None> 49 </None>
50 </ItemGroup> 50 </ItemGroup>
51 <ItemGroup> 51 <ItemGroup>
52 <ClCompile Include="c\charEncoding.c">
53 <Filter>Source Files</Filter>
54 </ClCompile>
55 <ClCompile Include="c\DllmainLocalization.c"> 52 <ClCompile Include="c\DllmainLocalization.c">
56 <Filter>Source Files</Filter> 53 <Filter>Source Files</Filter>
57 </ClCompile> 54 </ClCompile>
@@ -88,6 +85,9 @@
88 <ClCompile Include="cpp\UTF8.cpp"> 85 <ClCompile Include="cpp\UTF8.cpp">
89 <Filter>Source Files</Filter> 86 <Filter>Source Files</Filter>
90 </ClCompile> 87 </ClCompile>
88 <ClCompile Include="c\charEncoding.c">
89 <Filter>Source Files</Filter>
90 </ClCompile>
91 </ItemGroup> 91 </ItemGroup>
92 <ItemGroup> 92 <ItemGroup>
93 <ClInclude Include="..\includes\charEncoding.h"> 93 <ClInclude Include="..\includes\charEncoding.h">
diff --git a/scilab/modules/localization/src/localization_export.def b/scilab/modules/localization/src/localization_export.def
index dcc7554..55085d5 100644
--- a/scilab/modules/localization/src/localization_export.def
+++ b/scilab/modules/localization/src/localization_export.def
@@ -8,6 +8,7 @@ EXPORTS
8InitializeLocalization 8InitializeLocalization
9to_wide_string 9to_wide_string
10wide_string_to_UTF8 10wide_string_to_UTF8
11get_codepoint_count
11wcstat 12wcstat
12setlanguage 13setlanguage
13getlanguage 14getlanguage