A tool to display MS-Windows locale information
リビジョン | 56ea875e915359fb82af7cc890c2ee97ad4de2b4 (tree) |
---|---|
日時 | 2019-03-03 20:18:07 |
作者 | Keith Marshall <keith@user...> |
コミッター | Keith Marshall |
Check GetLocaleInfoEx() API availability.
* locale-info.c (main): Rename it to...
(query_locale_info): ...this; call it conditionally, from...
(main): ...a subsequent reimplementation of this, provided that...
[(dll = GetModuleHandle ("kernel32.dll"))]: ...first this, and then...
[GetProcAddress (dll, "GetLocaleInfoEx")]: ...this is non-NULL.
@@ -69,15 +69,15 @@ | ||
69 | 69 | #define _GNU_SOURCE |
70 | 70 | #define _WIN32_WINNT _WIN32_WINNT_VISTA |
71 | 71 | |
72 | -#ifndef ALT_BUFSIZ | |
73 | -#define ALT_BUFSIZ BUFSIZ | |
74 | -#endif | |
72 | +static const char *error = "Error ***"; | |
73 | +#define errprintf(fmt, ...) fprintf(stderr, "%s " fmt, error, ##__VA_ARGS__) | |
75 | 74 | |
76 | 75 | #include <stdio.h> |
76 | +#include <winbase.h> | |
77 | 77 | #include <stdlib.h> |
78 | + | |
78 | 79 | #include <limits.h> |
79 | 80 | #include <unistd.h> |
80 | -#include <winbase.h> | |
81 | 81 | #include <winnls.h> |
82 | 82 | #include <locale.h> |
83 | 83 |
@@ -85,6 +85,10 @@ | ||
85 | 85 | WINAPI int GetCalendarInfoEx (LPCWSTR, CALID, LPCWSTR, CALTYPE, LPWSTR, int, LPDWORD); |
86 | 86 | WINAPI int GetLocaleInfoEx (LPCWSTR, int, LPWSTR, int); |
87 | 87 | |
88 | +#ifndef ALT_BUFSIZ | |
89 | +#define ALT_BUFSIZ BUFSIZ | |
90 | +#endif | |
91 | + | |
88 | 92 | static wchar_t *locale = L"en-GB"; |
89 | 93 | static union { unsigned int i; wchar_t s[ALT_BUFSIZ]; } buf; |
90 | 94 | static CALID calendar; |
@@ -152,7 +156,7 @@ static int build_locale_string( wchar_t delim, int offset, int category ) | ||
152 | 156 | } |
153 | 157 | #endif |
154 | 158 | |
155 | -int main( int argc, char **argv ) | |
159 | +int query_locale_info( int argc, char **argv ) | |
156 | 160 | { |
157 | 161 | unsigned int base = 0, span = UINT_MAX >> 4; |
158 | 162 | int opt; void (*action)(unsigned int) = get_locale_info; |
@@ -238,7 +242,7 @@ int main( int argc, char **argv ) | ||
238 | 242 | opt = build_locale_string( L'_', opt, LOCALE_SENGCOUNTRY ); |
239 | 243 | build_locale_string( L'.', opt, LOCALE_IDEFAULTANSICODEPAGE ); |
240 | 244 | if( _wsetlocale( LC_ALL, buf.s ) == NULL ) |
241 | - { fprintf( stderr, "Failed to set CRT locale to '%S'\n", buf.s ); | |
245 | + { errprintf( "failed to set CRT locale to '%S'\n", buf.s ); | |
242 | 246 | return EXIT_FAILURE; |
243 | 247 | } |
244 | 248 | # endif |
@@ -253,7 +257,7 @@ int main( int argc, char **argv ) | ||
253 | 257 | ); |
254 | 258 | if( calendar == 2 ) calendar = buf.i; |
255 | 259 | else |
256 | - { fprintf( stderr, "Cannot establish calendar for locale '%S'\n", locale ); | |
260 | + { errprintf( "cannot establish calendar for locale '%S'\n", locale ); | |
257 | 261 | return EXIT_FAILURE; |
258 | 262 | } |
259 | 263 | } |
@@ -268,4 +272,20 @@ int main( int argc, char **argv ) | ||
268 | 272 | return EXIT_SUCCESS; |
269 | 273 | } |
270 | 274 | |
275 | +int main( int argc, char **argv ) | |
276 | +{ | |
277 | + HMODULE ref; const char *api = "kernel32.dll"; | |
278 | + if( (ref = GetModuleHandleA( api )) != NULL ) | |
279 | + { | |
280 | + if( GetProcAddress( ref, api = "GetLocaleInfoEx" ) == NULL ) | |
281 | + { | |
282 | + errprintf( "function '%s' is unsupported on this host\n", api ); | |
283 | + errprintf( "Windows-Vista (or later) is required\n" ); | |
284 | + } | |
285 | + else return query_locale_info( argc, argv ); | |
286 | + } | |
287 | + else errprintf( "'%s' was not mapped within this process\n", api ); | |
288 | + return EXIT_FAILURE; | |
289 | +} | |
290 | + | |
271 | 291 | /* $RCSfile$: end of file */ |