Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "c.h"
00025
00026 #undef setlocale
00027
00028 struct locale_map
00029 {
00030 const char *locale_name_part;
00031 const char *replacement;
00032 };
00033
00034 static const struct locale_map locale_map_list[] = {
00035
00036
00037
00038
00039
00040
00041
00042
00043 {"Hong Kong S.A.R.", "HKG"},
00044 {"U.A.E.", "ARE"},
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 {"Chinese (Traditional)_Macau S.A.R..950", "ZHM"},
00060 {"Chinese_Macau S.A.R..950", "ZHM"},
00061 {"Chinese (Traditional)_Macao S.A.R..950", "ZHM"},
00062 {"Chinese_Macao S.A.R..950", "ZHM"}
00063 };
00064
00065 char *
00066 pgwin32_setlocale(int category, const char *locale)
00067 {
00068 char *result;
00069 char *alias;
00070 int i;
00071
00072 if (locale == NULL)
00073 return setlocale(category, locale);
00074
00075
00076 alias = NULL;
00077 for (i = 0; i < lengthof(locale_map_list); i++)
00078 {
00079 const char *needle = locale_map_list[i].locale_name_part;
00080 const char *replacement = locale_map_list[i].replacement;
00081 char *match;
00082
00083 match = strstr(locale, needle);
00084 if (match != NULL)
00085 {
00086
00087 int matchpos = match - locale;
00088 int replacementlen = strlen(replacement);
00089 char *rest = match + strlen(needle);
00090 int restlen = strlen(rest);
00091
00092 alias = malloc(matchpos + replacementlen + restlen + 1);
00093 if (!alias)
00094 return NULL;
00095
00096 memcpy(&alias[0], &locale[0], matchpos);
00097 memcpy(&alias[matchpos], replacement, replacementlen);
00098 memcpy(&alias[matchpos + replacementlen], rest, restlen + 1);
00099
00100
00101 break;
00102 }
00103 }
00104
00105
00106 if (alias)
00107 {
00108 result = setlocale(category, alias);
00109 free(alias);
00110 }
00111 else
00112 result = setlocale(category, locale);
00113
00114 return result;
00115 }