1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 1999-2016, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: icuinfo.cpp
12 * tab size: 8 (not used)
15 * created on: 2009-2010
16 * created by: Steven R. Loomis
18 * This program shows some basic info about the current ICU.
23 #include "unicode/utypes.h"
24 #include "unicode/putil.h"
25 #include "unicode/uclean.h"
32 #include "icuplugimp.h"
33 #include <unicode/uloc.h>
34 #include <unicode/ucnv.h>
35 #include "unicode/ucal.h"
36 #include <unicode/ulocdata.h>
38 #include "unicode/uchar.h"
40 static UOption options
[]={
42 /*1*/ UOPTION_HELP_QUESTION_MARK
,
43 /*2*/ UOPTION_ICUDATADIR
,
44 /*3*/ UOPTION_VERBOSE
,
45 /*4*/ UOPTION_DEF("list-plugins", 'L', UOPT_NO_ARG
), // may be a no-op if disabled
46 /*5*/ UOPTION_DEF("milisecond-time", 'm', UOPT_NO_ARG
),
47 /*6*/ UOPTION_DEF("cleanup", 'K', UOPT_NO_ARG
),
48 /*7*/ UOPTION_DEF("xml", 'x', UOPT_REQUIRES_ARG
),
51 static UErrorCode initStatus
= U_ZERO_ERROR
;
52 static UBool icuInitted
= FALSE
;
54 static void do_init() {
64 printf("Milliseconds since Epoch: %.0f\n", uprv_getUTCtime());
67 void cmd_version(UBool
/* noLoad */, UErrorCode
&errorCode
)
72 udbg_writeIcuInfo(stdout
); /* print the XML format */
79 if(U_IS_BIG_ENDIAN
==u
.byte
) {
80 //printf("U_IS_BIG_ENDIAN: %d\n", U_IS_BIG_ENDIAN);
82 fprintf(stderr
, " error: U_IS_BIG_ENDIAN=%d != %d=actual 'is big endian'\n",
83 U_IS_BIG_ENDIAN
, u
.byte
);
84 errorCode
=U_INTERNAL_PROGRAM_ERROR
;
87 if(U_SIZEOF_WCHAR_T
==sizeof(wchar_t)) {
88 //printf("U_SIZEOF_WCHAR_T: %d\n", U_SIZEOF_WCHAR_T);
90 fprintf(stderr
, " error: U_SIZEOF_WCHAR_T=%d != %d=sizeof(wchar_t)\n",
91 U_SIZEOF_WCHAR_T
, (int)sizeof(wchar_t));
92 errorCode
=U_INTERNAL_PROGRAM_ERROR
;
97 charsetFamily
=U_ASCII_FAMILY
;
98 } else if('A'==0xc1) {
99 charsetFamily
=U_EBCDIC_FAMILY
;
101 charsetFamily
=-1; // unknown
103 if(U_CHARSET_FAMILY
==charsetFamily
) {
104 //printf("U_CHARSET_FAMILY: %d\n", U_CHARSET_FAMILY);
106 fprintf(stderr
, " error: U_CHARSET_FAMILY=%d != %d=actual charset family\n",
107 U_CHARSET_FAMILY
, charsetFamily
);
108 errorCode
=U_INTERNAL_PROGRAM_ERROR
;
111 printf("\n\nICU Initialization returned: %s\n", u_errorName(initStatus
));
114 #if UCONFIG_ENABLE_PLUGINS
116 const char *pluginFile
= uplug_getPluginFile();
117 printf("Plugin file is: %s\n", (pluginFile
&&*pluginFile
)?pluginFile
:"(not set. try setting ICU_PLUGINS to a directory.)");
119 fprintf(stderr
, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n");
122 fprintf(stderr
, "Plugins are disabled.\n");
129 fprintf(stdout
, "ICU u_cleanup() called.\n");
133 void cmd_listplugins() {
134 #if UCONFIG_ENABLE_PLUGINS
139 printf("ICU Initialized: u_init() returned %s\n", u_errorName(initStatus
));
141 printf("Plugins: \n");
142 printf( "# %6s %s \n",
145 printf( " %10s:%-10s\n",
151 printf( " config| (configuration string)\n");
152 printf( " >>> Error | Explanation \n");
153 printf( "-----------------------------------\n");
155 for(i
=0;(plug
=uplug_getPlugInternal(i
))!=NULL
;i
++) {
156 UErrorCode libStatus
= U_ZERO_ERROR
;
157 const char *name
= uplug_getPlugName(plug
);
158 const char *sym
= uplug_getSymbolName(plug
);
159 const char *lib
= uplug_getLibraryName(plug
, &libStatus
);
160 const char *config
= uplug_getConfiguration(plug
);
161 UErrorCode loadStatus
= uplug_getPlugLoadStatus(plug
);
162 const char *message
= NULL
;
164 printf("\n#%d %-6s %s \n",
166 udbg_enumName(UDBG_UPlugLevel
,(int32_t)uplug_getPlugLevel(plug
)),
167 name
!=NULL
?(*name
?name
:"this plugin did not call uplug_setPlugName()"):"(null)"
169 printf(" plugin| %10s:%-10s\n",
170 (U_SUCCESS(libStatus
)?(lib
!=NULL
?lib
:"(null)"):u_errorName(libStatus
)),
171 sym
!=NULL
?sym
:"(null)"
174 if(config
!=NULL
&&*config
) {
175 printf(" config| %s\n", config
);
179 case U_PLUGIN_CHANGED_LEVEL_WARNING
:
180 message
= "Note: This plugin changed the system level (by allocating memory or calling something which does). Later plugins may not load.";
183 case U_PLUGIN_DIDNT_SET_LEVEL
:
184 message
= "Error: This plugin did not call uplug_setPlugLevel during QUERY.";
187 case U_PLUGIN_TOO_HIGH
:
188 message
= "Error: This plugin couldn't load because the system level was too high. Try loading this plugin earlier.";
192 message
= NULL
; /* no message */
195 if(U_FAILURE(loadStatus
)) {
196 message
= "error loading:";
198 message
= "warning during load:";
203 printf("\\\\\\ status| %s\n"
204 "/// %s\n", u_errorName(loadStatus
), message
);
209 printf("No plugins loaded.\n");
217 main(int argc
, char* argv
[]) {
218 UErrorCode errorCode
= U_ZERO_ERROR
;
219 UBool didSomething
= FALSE
;
221 /* preset then read command line options */
222 argc
=u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
224 /* error handling, printing usage message */
227 "error in command line argument \"%s\"\n",
230 if( options
[0].doesOccur
|| options
[1].doesOccur
) {
231 fprintf(stderr
, "%s: Output information about the current ICU\n", argv
[0]);
232 fprintf(stderr
, "Options:\n"
233 " -h or --help - Print this help message.\n"
234 " -m or --millisecond-time - Print the current UTC time in milliseconds.\n"
235 " -d <dir> or --icudatadir <dir> - Set the ICU Data Directory\n"
236 " -v - Print version and configuration information about ICU\n"
237 #if UCONFIG_ENABLE_PLUGINS
238 " -L or --list-plugins - List and diagnose issues with ICU Plugins\n"
240 " -K or --cleanup - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
242 "If no arguments are given, the tool will print ICU version and configuration information.\n"
244 fprintf(stderr
, "International Components for Unicode %s\n%s\n", U_ICU_VERSION
, U_COPYRIGHT_STRING
);
245 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
248 if(options
[2].doesOccur
) {
249 u_setDataDirectory(options
[2].value
);
252 if(options
[5].doesOccur
) {
256 if(options
[4].doesOccur
) {
261 if(options
[3].doesOccur
) {
262 cmd_version(FALSE
, errorCode
);
266 if(options
[7].doesOccur
) { /* 2nd part of version: cleanup */
267 FILE *out
= fopen(options
[7].value
, "w");
269 fprintf(stderr
,"ERR: can't write to XML file %s\n", options
[7].value
);
272 /* todo: API for writing DTD? */
273 fprintf(out
, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
274 udbg_writeIcuInfo(out
);
279 if(options
[6].doesOccur
) { /* 2nd part of version: cleanup */
285 cmd_version(FALSE
, errorCode
); /* at least print the version # */
288 return U_FAILURE(errorCode
);