• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A tool to display MS-Windows locale information


Commit MetaInfo

修订版56ea875e915359fb82af7cc890c2ee97ad4de2b4 (tree)
时间2019-03-03 20:18:07
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

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.

更改概述

差异

--- a/locale-info.c
+++ b/locale-info.c
@@ -69,15 +69,15 @@
6969 #define _GNU_SOURCE
7070 #define _WIN32_WINNT _WIN32_WINNT_VISTA
7171
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__)
7574
7675 #include <stdio.h>
76+#include <winbase.h>
7777 #include <stdlib.h>
78+
7879 #include <limits.h>
7980 #include <unistd.h>
80-#include <winbase.h>
8181 #include <winnls.h>
8282 #include <locale.h>
8383
@@ -85,6 +85,10 @@
8585 WINAPI int GetCalendarInfoEx (LPCWSTR, CALID, LPCWSTR, CALTYPE, LPWSTR, int, LPDWORD);
8686 WINAPI int GetLocaleInfoEx (LPCWSTR, int, LPWSTR, int);
8787
88+#ifndef ALT_BUFSIZ
89+#define ALT_BUFSIZ BUFSIZ
90+#endif
91+
8892 static wchar_t *locale = L"en-GB";
8993 static union { unsigned int i; wchar_t s[ALT_BUFSIZ]; } buf;
9094 static CALID calendar;
@@ -152,7 +156,7 @@ static int build_locale_string( wchar_t delim, int offset, int category )
152156 }
153157 #endif
154158
155-int main( int argc, char **argv )
159+int query_locale_info( int argc, char **argv )
156160 {
157161 unsigned int base = 0, span = UINT_MAX >> 4;
158162 int opt; void (*action)(unsigned int) = get_locale_info;
@@ -238,7 +242,7 @@ int main( int argc, char **argv )
238242 opt = build_locale_string( L'_', opt, LOCALE_SENGCOUNTRY );
239243 build_locale_string( L'.', opt, LOCALE_IDEFAULTANSICODEPAGE );
240244 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 );
242246 return EXIT_FAILURE;
243247 }
244248 # endif
@@ -253,7 +257,7 @@ int main( int argc, char **argv )
253257 );
254258 if( calendar == 2 ) calendar = buf.i;
255259 else
256- { fprintf( stderr, "Cannot establish calendar for locale '%S'\n", locale );
260+ { errprintf( "cannot establish calendar for locale '%S'\n", locale );
257261 return EXIT_FAILURE;
258262 }
259263 }
@@ -268,4 +272,20 @@ int main( int argc, char **argv )
268272 return EXIT_SUCCESS;
269273 }
270274
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+
271291 /* $RCSfile$: end of file */