2 *******************************************************************************
4 * Copyright (C) 1999-2012, 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
),
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
));
113 const char *pluginFile
= uplug_getPluginFile();
114 printf("Plugin file is: %s\n", (pluginFile
&&*pluginFile
)?pluginFile
:"(not set. try setting ICU_PLUGINS to a directory.)");
116 fprintf(stderr
, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n");
123 fprintf(stderr
,"ICU u_cleanup() called.\n");
127 void cmd_listplugins() {
132 printf("ICU Initialized: u_init() returned %s\n", u_errorName(initStatus
));
134 printf("Plugins: \n");
135 printf( "# %6s %s \n",
138 printf( " %10s:%-10s\n",
144 printf( " config| (configuration string)\n");
145 printf( " >>> Error | Explanation \n");
146 printf( "-----------------------------------\n");
148 for(i
=0;(plug
=uplug_getPlugInternal(i
))!=NULL
;i
++) {
149 UErrorCode libStatus
= U_ZERO_ERROR
;
150 const char *name
= uplug_getPlugName(plug
);
151 const char *sym
= uplug_getSymbolName(plug
);
152 const char *lib
= uplug_getLibraryName(plug
, &libStatus
);
153 const char *config
= uplug_getConfiguration(plug
);
154 UErrorCode loadStatus
= uplug_getPlugLoadStatus(plug
);
155 const char *message
= NULL
;
157 printf("\n#%d %-6s %s \n",
159 udbg_enumName(UDBG_UPlugLevel
,(int32_t)uplug_getPlugLevel(plug
)),
160 name
!=NULL
?(*name
?name
:"this plugin did not call uplug_setPlugName()"):"(null)"
162 printf(" plugin| %10s:%-10s\n",
163 (U_SUCCESS(libStatus
)?(lib
!=NULL
?lib
:"(null)"):u_errorName(libStatus
)),
164 sym
!=NULL
?sym
:"(null)"
167 if(config
!=NULL
&&*config
) {
168 printf(" config| %s\n", config
);
172 case U_PLUGIN_CHANGED_LEVEL_WARNING
:
173 message
= "Note: This plugin changed the system level (by allocating memory or calling something which does). Later plugins may not load.";
176 case U_PLUGIN_DIDNT_SET_LEVEL
:
177 message
= "Error: This plugin did not call uplug_setPlugLevel during QUERY.";
180 case U_PLUGIN_TOO_HIGH
:
181 message
= "Error: This plugin couldn't load because the system level was too high. Try loading this plugin earlier.";
185 message
= NULL
; /* no message */
188 if(U_FAILURE(loadStatus
)) {
189 message
= "error loading:";
191 message
= "warning during load:";
196 printf("\\\\\\ status| %s\n"
197 "/// %s\n", u_errorName(loadStatus
), message
);
202 printf("No plugins loaded.\n");
210 main(int argc
, char* argv
[]) {
211 UErrorCode errorCode
= U_ZERO_ERROR
;
212 UBool didSomething
= FALSE
;
214 /* preset then read command line options */
215 argc
=u_parseArgs(argc
, argv
, sizeof(options
)/sizeof(options
[0]), options
);
217 /* error handling, printing usage message */
220 "error in command line argument \"%s\"\n",
223 if( options
[0].doesOccur
|| options
[1].doesOccur
) {
224 fprintf(stderr
, "%s: Output information about the current ICU\n", argv
[0]);
225 fprintf(stderr
, "Options:\n"
226 " -h or --help - Print this help message.\n"
227 " -m or --millisecond-time - Print the current UTC time in milliseconds.\n"
228 " -d <dir> or --icudatadir <dir> - Set the ICU Data Directory\n"
229 " -v - Print version and configuration information about ICU\n"
230 " -L or --list-plugins - List and diagnose issues with ICU Plugins\n"
231 " -K or --cleanup - Call u_cleanup() before exitting (will attempt to unload plugins)\n"
233 "If no arguments are given, the tool will print ICU version and configuration information.\n"
235 fprintf(stderr
, "International Components for Unicode %s\n%s\n", U_ICU_VERSION
, U_COPYRIGHT_STRING
);
236 return argc
<0 ? U_ILLEGAL_ARGUMENT_ERROR
: U_ZERO_ERROR
;
239 if(options
[2].doesOccur
) {
240 u_setDataDirectory(options
[2].value
);
243 if(options
[5].doesOccur
) {
247 if(options
[4].doesOccur
) {
252 if(options
[3].doesOccur
) {
253 cmd_version(FALSE
, errorCode
);
257 if(options
[7].doesOccur
) { /* 2nd part of version: cleanup */
258 FILE *out
= fopen(options
[7].value
, "w");
260 fprintf(stderr
,"ERR: can't write to XML file %s\n", options
[7].value
);
263 /* todo: API for writing DTD? */
264 fprintf(out
, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
265 udbg_writeIcuInfo(out
);
270 if(options
[6].doesOccur
) { /* 2nd part of version: cleanup */
276 cmd_version(FALSE
, errorCode
); /* at least print the version # */
279 return U_FAILURE(errorCode
);