2 *******************************************************************************
4 * Copyright (C) 1999-2016, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: icuinfo.cpp
10 * tab size: 8 (not used)
13 * created on: 2009-2010
14 * created by: Steven R. Loomis
16 * This program shows some basic info about the current ICU.
21 #include "unicode/utypes.h"
22 #include "unicode/putil.h"
23 #include "unicode/uclean.h"
30 #include "icuplugimp.h"
31 #include <unicode/uloc.h>
32 #include <unicode/ucnv.h>
33 #include "unicode/ucal.h"
34 #include <unicode/ulocdata.h>
36 #include "unicode/uchar.h"
38 static UOption options
[]={
40 /*1*/ UOPTION_HELP_QUESTION_MARK
,
41 /*2*/ UOPTION_ICUDATADIR
,
42 /*3*/ UOPTION_VERBOSE
,
43 /*4*/ UOPTION_DEF("list-plugins", 'L', UOPT_NO_ARG
), // may be a no-op if disabled
44 /*5*/ UOPTION_DEF("milisecond-time", 'm', UOPT_NO_ARG
),
45 /*6*/ UOPTION_DEF("cleanup", 'K', UOPT_NO_ARG
),
46 /*7*/ UOPTION_DEF("xml", 'x', UOPT_REQUIRES_ARG
),
49 static UErrorCode initStatus
= U_ZERO_ERROR
;
50 static UBool icuInitted
= FALSE
;
52 static void do_init() {
62 printf("Milliseconds since Epoch: %.0f\n", uprv_getUTCtime());
65 void cmd_version(UBool
/* noLoad */, UErrorCode
&errorCode
)
70 udbg_writeIcuInfo(stdout
); /* print the XML format */
77 if(U_IS_BIG_ENDIAN
==u
.byte
) {
78 //printf("U_IS_BIG_ENDIAN: %d\n", U_IS_BIG_ENDIAN);
80 fprintf(stderr
, " error: U_IS_BIG_ENDIAN=%d != %d=actual 'is big endian'\n",
81 U_IS_BIG_ENDIAN
, u
.byte
);
82 errorCode
=U_INTERNAL_PROGRAM_ERROR
;
85 if(U_SIZEOF_WCHAR_T
==sizeof(wchar_t)) {
86 //printf("U_SIZEOF_WCHAR_T: %d\n", U_SIZEOF_WCHAR_T);
88 fprintf(stderr
, " error: U_SIZEOF_WCHAR_T=%d != %d=sizeof(wchar_t)\n",
89 U_SIZEOF_WCHAR_T
, (int)sizeof(wchar_t));
90 errorCode
=U_INTERNAL_PROGRAM_ERROR
;
95 charsetFamily
=U_ASCII_FAMILY
;
96 } else if('A'==0xc1) {
97 charsetFamily
=U_EBCDIC_FAMILY
;
99 charsetFamily
=-1; // unknown
101 if(U_CHARSET_FAMILY
==charsetFamily
) {
102 //printf("U_CHARSET_FAMILY: %d\n", U_CHARSET_FAMILY);
104 fprintf(stderr
, " error: U_CHARSET_FAMILY=%d != %d=actual charset family\n",
105 U_CHARSET_FAMILY
, charsetFamily
);
106 errorCode
=U_INTERNAL_PROGRAM_ERROR
;
109 printf("\n\nICU Initialization returned: %s\n", u_errorName(initStatus
));
112 #if UCONFIG_ENABLE_PLUGINS
114 const char *pluginFile
= uplug_getPluginFile();
115 printf("Plugin file is: %s\n", (pluginFile
&&*pluginFile
)?pluginFile
:"(not set. try setting ICU_PLUGINS to a directory.)");
117 fprintf(stderr
, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n");
120 fprintf(stderr
, "Plugins are disabled.\n");
127 fprintf(stdout
, "ICU u_cleanup() called.\n");
131 void cmd_listplugins() {
132 #if UCONFIG_ENABLE_PLUGINS
137 printf("ICU Initialized: u_init() returned %s\n", u_errorName(initStatus
));
139 printf("Plugins: \n");
140 printf( "# %6s %s \n",
143 printf( " %10s:%-10s\n",
149 printf( " config| (configuration string)\n");
150 printf( " >>> Error | Explanation \n");
151 printf( "-----------------------------------\n");
153 for(i
=0;(plug
=uplug_getPlugInternal(i
))!=NULL
;i
++) {
154 UErrorCode libStatus
= U_ZERO_ERROR
;
155 const char *name
= uplug_getPlugName(plug
);
156 const char *sym
= uplug_getSymbolName(plug
);
157 const char *lib
= uplug_getLibraryName(plug
, &libStatus
);
158 const char *config
= uplug_getConfiguration(plug
);
159 UErrorCode loadStatus
= uplug_getPlugLoadStatus(plug
);
160 const char *message
= NULL
;
162 printf("\n#%d %-6s %s \n",
164 udbg_enumName(UDBG_UPlugLevel
,(int32_t)uplug_getPlugLevel(plug
)),
165 name
!=NULL
?(*name
?name
:"this plugin did not call uplug_setPlugName()"):"(null)"
167 printf(" plugin| %10s:%-10s\n",
168 (U_SUCCESS(libStatus
)?(lib
!=NULL
?lib
:"(null)"):u_errorName(libStatus
)),
169 sym
!=NULL
?sym
:"(null)"
172 if(config
!=NULL
&&*config
) {
173 printf(" config| %s\n", config
);
177 case U_PLUGIN_CHANGED_LEVEL_WARNING
:
178 message
= "Note: This plugin changed the system level (by allocating memory or calling something which does). Later plugins may not load.";
181 case U_PLUGIN_DIDNT_SET_LEVEL
:
182 message
= "Error: This plugin did not call uplug_setPlugLevel during QUERY.";
185 case U_PLUGIN_TOO_HIGH
:
186 message
= "Error: This plugin couldn't load because the system level was too high. Try loading this plugin earlier.";
190 message
= NULL
; /* no message */
193 if(U_FAILURE(loadStatus
)) {
194 message
= "error loading:";
196 message
= "warning during load:";
201 printf("\\\\\\ status| %s\n"
202 "/// %s\n", u_errorName(loadStatus
), message
);
207 printf("No plugins loaded.\n");
215 main(int argc
, char* argv
[]) {
216 UErrorCode errorCode
= U_ZERO_ERROR
;
217 UBool didSomething
= FALSE
;
219 /* preset then read command line options */
220 argc
=u_parseArgs(argc
, argv
, UPRV_LENGTHOF(options
), options
);
222 /* error handling, printing usage message */
225 "error in command line argument \"%s\"\n",
228 if( options
[0].doesOccur
|| options
[1].doesOccur
) {
229 fprintf(stderr
, "%s: Output information about the current ICU\n", argv
[0]);
230 fprintf(stderr
, "Options:\n"
231 " -h or --help - Print this help message.\n"
232 " -m or --millisecond-time - Print the current UTC time in milliseconds.\n"
233 " -d <dir> or --icudatadir <dir> - Set the ICU Data Directory\n"
234 " -v - Print version and configuration information about ICU\n"
235 #if UCONFIG_ENABLE_PLUGINS
236 " -L or --list-plugins - List and diagnose issues with ICU Plugins\n"
238 " -K or --cleanup - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
240 "If no arguments are given, the tool will print ICU version and configuration information.\n"
242 fprintf(stderr
, "International Components for Unicode %s\n%s\n", U_ICU_VERSION
, U_COPYRIGHT_STRING
);
243 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
246 if(options
[2].doesOccur
) {
247 u_setDataDirectory(options
[2].value
);
250 if(options
[5].doesOccur
) {
254 if(options
[4].doesOccur
) {
259 if(options
[3].doesOccur
) {
260 cmd_version(FALSE
, errorCode
);
264 if(options
[7].doesOccur
) { /* 2nd part of version: cleanup */
265 FILE *out
= fopen(options
[7].value
, "w");
267 fprintf(stderr
,"ERR: can't write to XML file %s\n", options
[7].value
);
270 /* todo: API for writing DTD? */
271 fprintf(out
, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
272 udbg_writeIcuInfo(out
);
277 if(options
[6].doesOccur
) { /* 2nd part of version: cleanup */
283 cmd_version(FALSE
, errorCode
); /* at least print the version # */
286 return U_FAILURE(errorCode
);