Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/msvcrt/locale.c | 156 ++++++++++++++++++++++++++----------------- dlls/msvcrt/msvcrt.h | 1 + 2 files changed, 95 insertions(+), 62 deletions(-)
diff --git a/dlls/msvcrt/locale.c b/dlls/msvcrt/locale.c index 6f2a83cc7c..2a5cc7fc02 100644 --- a/dlls/msvcrt/locale.c +++ b/dlls/msvcrt/locale.c @@ -53,6 +53,74 @@ BOOL initial_locale = TRUE; #define MSVCRT_LEADBYTE 0x8000 #define MSVCRT_C1_DEFINED 0x200
+static MSVCRT_wchar_t C_time_curr_wstr[43][20] = +{ + {'S','u','n',0}, {'M','o','n',0}, {'T','u','e',0}, {'W','e','d',0}, + {'T','h','u',0}, {'F','r','i',0}, {'S','a','t',0}, + {'S','u','n','d','a','y',0}, {'M','o','n','d','a','y',0}, + {'T','u','e','s','d','a','y',0}, {'W','e','d','n','e','s','d','a','y',0}, + {'T','h','u','r','s','d','a','y',0}, {'F','r','i','d','a','y',0}, + {'S','a','t','u','r','d','a','y',0}, + {'J','a','n',0}, {'F','e','b',0}, {'M','a','r',0}, {'A','p','r',0}, + {'M','a','y',0}, {'J','u','n',0}, {'J','u','l',0}, {'A','u','g',0}, + {'S','e','p',0}, {'O','c','t',0}, {'N','o','v',0}, {'D','e','c',0}, + {'J','a','n','u','a','r','y',0}, {'F','e','b','r','u','a','r','y',0}, + {'M','a','r','c','h',0}, {'A','p','r','i','l',0}, {'M','a','y',0}, + {'J','u','n','e',0}, {'J','u','l','y',0}, {'A','u','g','u','s','t',0}, + {'S','e','p','t','e','m','b','e','r',0}, {'O','c','t','o','b','e','r',0}, + {'N','o','v','e','m','b','e','r',0}, {'D','e','c','e','m','b','e','r',0}, + {'A','M',0}, {'P','M',0}, + {'M','M','/','d','d','/','y','y',0}, + {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0}, + {'H','H',':','m','m',':','s','s',0} +}; + +static char C_time_curr_str[43][20] = +{ + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", + "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", + "January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December", + "AM", "PM", "MM/dd/yy", "dddd, MMMM dd, yyyy", "HH:mm:ss" +}; + +static MSVCRT_wchar_t C_time_curr_locname[] = {'e','n','-','U','S',0}; + +MSVCRT___lc_time_data C_time_curr = +{ + {{C_time_curr_str[0], C_time_curr_str[1], C_time_curr_str[2], C_time_curr_str[3], + C_time_curr_str[4], C_time_curr_str[5], C_time_curr_str[6], C_time_curr_str[7], + C_time_curr_str[8], C_time_curr_str[9], C_time_curr_str[10], C_time_curr_str[11], + C_time_curr_str[12], C_time_curr_str[13], C_time_curr_str[14], C_time_curr_str[15], + C_time_curr_str[16], C_time_curr_str[17], C_time_curr_str[18], C_time_curr_str[19], + C_time_curr_str[20], C_time_curr_str[21], C_time_curr_str[22], C_time_curr_str[23], + C_time_curr_str[24], C_time_curr_str[25], C_time_curr_str[26], C_time_curr_str[27], + C_time_curr_str[28], C_time_curr_str[29], C_time_curr_str[30], C_time_curr_str[31], + C_time_curr_str[32], C_time_curr_str[33], C_time_curr_str[34], C_time_curr_str[35], + C_time_curr_str[36], C_time_curr_str[37], C_time_curr_str[38], C_time_curr_str[39], + C_time_curr_str[40], C_time_curr_str[41], C_time_curr_str[42]}}, +#if _MSVCR_VER < 110 + MAKELCID(LANG_ENGLISH, SORT_DEFAULT), +#endif + {0, 0}, + {{C_time_curr_wstr[0], C_time_curr_wstr[1], C_time_curr_wstr[2], C_time_curr_wstr[3], + C_time_curr_wstr[4], C_time_curr_wstr[5], C_time_curr_wstr[6], C_time_curr_wstr[7], + C_time_curr_wstr[8], C_time_curr_wstr[9], C_time_curr_wstr[10], C_time_curr_wstr[11], + C_time_curr_wstr[12], C_time_curr_wstr[13], C_time_curr_wstr[14], C_time_curr_wstr[15], + C_time_curr_wstr[16], C_time_curr_wstr[17], C_time_curr_wstr[18], C_time_curr_wstr[19], + C_time_curr_wstr[20], C_time_curr_wstr[21], C_time_curr_wstr[22], C_time_curr_wstr[23], + C_time_curr_wstr[24], C_time_curr_wstr[25], C_time_curr_wstr[26], C_time_curr_wstr[27], + C_time_curr_wstr[28], C_time_curr_wstr[29], C_time_curr_wstr[30], C_time_curr_wstr[31], + C_time_curr_wstr[32], C_time_curr_wstr[33], C_time_curr_wstr[34], C_time_curr_wstr[35], + C_time_curr_wstr[36], C_time_curr_wstr[37], C_time_curr_wstr[38], C_time_curr_wstr[39], + C_time_curr_wstr[40], C_time_curr_wstr[41], C_time_curr_wstr[42]}}, +#if _MSVCR_VER >= 110 + C_time_curr_locname, +#endif + {} +}; + /* Friendly country strings & language names abbreviations. */ static const char * const _country_synonyms[] = { @@ -829,7 +897,8 @@ void free_locinfo(MSVCRT_pthreadlocinfo locinfo) MSVCRT_free(locinfo->pclmap); MSVCRT_free(locinfo->pcumap);
- MSVCRT_free(locinfo->lc_time_curr); + if(locinfo->lc_time_curr != &C_time_curr) + MSVCRT_free(locinfo->lc_time_curr);
MSVCRT_free(locinfo); } @@ -929,35 +998,21 @@ static MSVCRT___lc_time_data* create_time_data(LCID lcid) LOCALE_SSHORTDATE, LOCALE_SLONGDATE, LOCALE_STIMEFORMAT }; - static const char cloc_short_date[] = "MM/dd/yy"; - static const MSVCRT_wchar_t cloc_short_dateW[] = {'M','M','/','d','d','/','y','y',0}; - static const char cloc_long_date[] = "dddd, MMMM dd, yyyy"; - static const MSVCRT_wchar_t cloc_long_dateW[] = {'d','d','d','d',',',' ','M','M','M','M',' ','d','d',',',' ','y','y','y','y',0}; - static const char cloc_time[] = "HH:mm:ss"; - static const MSVCRT_wchar_t cloc_timeW[] = {'H','H',':','m','m',':','s','s',0};
MSVCRT___lc_time_data *cur; - const DWORD flags = lcid ? 0 : LOCALE_NOUSEROVERRIDE; - const LCID lcid_tmp = lcid ? lcid : MAKELCID(LANG_ENGLISH, SORT_DEFAULT); int i, ret, size;
size = sizeof(MSVCRT___lc_time_data); for(i=0; i<ARRAY_SIZE(time_data); i++) { - if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { - size += sizeof(cloc_short_date) + sizeof(cloc_short_dateW); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { - size += sizeof(cloc_long_date) + sizeof(cloc_long_dateW); - }else { - ret = GetLocaleInfoA(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) - return NULL; - size += ret; + ret = GetLocaleInfoA(lcid, time_data[i], NULL, 0); + if(!ret) + return NULL; + size += ret;
- ret = GetLocaleInfoW(lcid_tmp, time_data[i]|flags, NULL, 0); - if(!ret) - return NULL; - size += ret*sizeof(MSVCRT_wchar_t); - } + ret = GetLocaleInfoW(lcid, time_data[i], NULL, 0); + if(!ret) + return NULL; + size += ret*sizeof(MSVCRT_wchar_t); } #if _MSVCR_VER >= 110 size += LCIDToLocaleName(lcid, NULL, 0, 0)*sizeof(MSVCRT_wchar_t); @@ -970,35 +1025,12 @@ static MSVCRT___lc_time_data* create_time_data(LCID lcid) ret = 0; for(i=0; i<ARRAY_SIZE(time_data); i++) { cur->str.str[i] = &cur->data[ret]; - if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { - memcpy(&cur->data[ret], cloc_short_date, sizeof(cloc_short_date)); - ret += sizeof(cloc_short_date); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { - memcpy(&cur->data[ret], cloc_long_date, sizeof(cloc_long_date)); - ret += sizeof(cloc_long_date); - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid) { - memcpy(&cur->data[ret], cloc_time, sizeof(cloc_time)); - ret += sizeof(cloc_time); - }else { - ret += GetLocaleInfoA(lcid_tmp, time_data[i]|flags, - &cur->data[ret], size-ret); - } + ret += GetLocaleInfoA(lcid, time_data[i], &cur->data[ret], size-ret); } for(i=0; i<ARRAY_SIZE(time_data); i++) { cur->wstr.wstr[i] = (MSVCRT_wchar_t*)&cur->data[ret]; - if(time_data[i]==LOCALE_SSHORTDATE && !lcid) { - memcpy(&cur->data[ret], cloc_short_dateW, sizeof(cloc_short_dateW)); - ret += sizeof(cloc_short_dateW); - }else if(time_data[i]==LOCALE_SLONGDATE && !lcid) { - memcpy(&cur->data[ret], cloc_long_dateW, sizeof(cloc_long_dateW)); - ret += sizeof(cloc_long_dateW); - }else if(time_data[i]==LOCALE_STIMEFORMAT && !lcid) { - memcpy(&cur->data[ret], cloc_timeW, sizeof(cloc_timeW)); - ret += sizeof(cloc_timeW); - }else { - ret += GetLocaleInfoW(lcid_tmp, time_data[i]|flags, - (MSVCRT_wchar_t*)&cur->data[ret], size-ret)*sizeof(MSVCRT_wchar_t); - } + ret += GetLocaleInfoW(lcid, time_data[i], + (MSVCRT_wchar_t*)&cur->data[ret], size-ret)*sizeof(MSVCRT_wchar_t); } #if _MSVCR_VER >= 110 cur->locname = (MSVCRT_wchar_t*)&cur->data[ret]; @@ -1664,26 +1696,26 @@ static MSVCRT_pthreadlocinfo create_locinfo(int category, lcid[MSVCRT_LC_TIME], cp[MSVCRT_LC_TIME])) { locinfo->lc_handle[MSVCRT_LC_TIME] = old_locinfo->lc_handle[MSVCRT_LC_TIME]; locinfo->lc_id[MSVCRT_LC_TIME].wCodePage = old_locinfo->lc_id[MSVCRT_LC_TIME].wCodePage; - } else { - if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) { - if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], - cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) { - free_locinfo(locinfo); - return NULL; - } + } else if(lcid[MSVCRT_LC_TIME] && (category==MSVCRT_LC_ALL || category==MSVCRT_LC_TIME)) { + if(!update_threadlocinfo_category(lcid[MSVCRT_LC_TIME], + cp[MSVCRT_LC_TIME], locinfo, MSVCRT_LC_TIME)) { + free_locinfo(locinfo); + return NULL; + }
- if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) { - free_locinfo(locinfo); - return NULL; - } - } else - locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + if(!set_lc_locale_name(locinfo, MSVCRT_LC_TIME)) { + free_locinfo(locinfo); + return NULL; + }
locinfo->lc_time_curr = create_time_data(lcid[MSVCRT_LC_TIME]); if(!locinfo->lc_time_curr) { free_locinfo(locinfo); return NULL; } + } else { + locinfo->lc_category[MSVCRT_LC_TIME].locale = MSVCRT__strdup("C"); + locinfo->lc_time_curr = &C_time_curr; }
return locinfo; diff --git a/dlls/msvcrt/msvcrt.h b/dlls/msvcrt/msvcrt.h index 4a7e6f4219..cd7def3c27 100644 --- a/dlls/msvcrt/msvcrt.h +++ b/dlls/msvcrt/msvcrt.h @@ -305,6 +305,7 @@ extern thread_data_t *msvcrt_get_thread_data(void) DECLSPEC_HIDDEN;
LCID MSVCRT_locale_to_LCID(const char*, unsigned short*, BOOL*) DECLSPEC_HIDDEN; extern MSVCRT__locale_t MSVCRT_locale DECLSPEC_HIDDEN; +extern MSVCRT___lc_time_data C_time_curr DECLSPEC_HIDDEN; extern unsigned int MSVCRT___lc_codepage; extern int MSVCRT___lc_collate_cp; extern WORD MSVCRT__ctype [257];