1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
*
* Copyright (C) 1999-2016, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
* file name: icuinfo.cpp
* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
* created on: 2009-2010
* created by: Steven R. Loomis
*
* This program shows some basic info about the current ICU.
*/
#include <stdio.h>
#include <stdlib.h>
#include "unicode/utypes.h"
#include "unicode/putil.h"
#include "unicode/uclean.h"
#include "udbgutil.h"
#include "unewdata.h"
#include "cmemory.h"
#include "cstring.h"
#include "uoptions.h"
#include "toolutil.h"
#include "icuplugimp.h"
#include <unicode/uloc.h>
#include <unicode/ucnv.h>
#include "unicode/ucal.h"
#include <unicode/ulocdata.h>
#include "putilimp.h"
#include "unicode/uchar.h"
static UOption options[]={
/*0*/ UOPTION_HELP_H,
/*1*/ UOPTION_HELP_QUESTION_MARK,
/*2*/ UOPTION_ICUDATADIR,
/*3*/ UOPTION_VERBOSE,
/*4*/ UOPTION_DEF("list-plugins", 'L', UOPT_NO_ARG), // may be a no-op if disabled
/*5*/ UOPTION_DEF("milisecond-time", 'm', UOPT_NO_ARG),
/*6*/ UOPTION_DEF("cleanup", 'K', UOPT_NO_ARG),
/*7*/ UOPTION_DEF("xml", 'x', UOPT_REQUIRES_ARG),
};
static UErrorCode initStatus = U_ZERO_ERROR;
static UBool icuInitted = false;
static void do_init() {
if(!icuInitted) {
u_init(&initStatus);
icuInitted = true;
}
}
static void do_cleanup() {
if (icuInitted) {
u_cleanup();
icuInitted = false;
}
}
void cmd_millis()
{
printf("Milliseconds since Epoch: %.0f\n", uprv_getUTCtime());
}
void cmd_version(UBool /* noLoad */, UErrorCode &errorCode)
{
do_init();
udbg_writeIcuInfo(stdout); /* print the XML format */
union {
uint8_t byte;
uint16_t word;
} u;
u.word=0x0100;
if(U_IS_BIG_ENDIAN==u.byte) {
//printf("U_IS_BIG_ENDIAN: %d\n", U_IS_BIG_ENDIAN);
} else {
fprintf(stderr, " error: U_IS_BIG_ENDIAN=%d != %d=actual 'is big endian'\n",
U_IS_BIG_ENDIAN, u.byte);
errorCode=U_INTERNAL_PROGRAM_ERROR;
}
#if defined(_MSC_VER)
// Ignore warning 4127, conditional expression is constant. This is intentional below.
#pragma warning(push)
#pragma warning(disable: 4127)
#endif
if(U_SIZEOF_WCHAR_T==sizeof(wchar_t)) {
//printf("U_SIZEOF_WCHAR_T: %d\n", U_SIZEOF_WCHAR_T);
} else {
fprintf(stderr, " error: U_SIZEOF_WCHAR_T=%d != %d=sizeof(wchar_t)\n",
U_SIZEOF_WCHAR_T, static_cast<int>(sizeof(wchar_t)));
errorCode=U_INTERNAL_PROGRAM_ERROR;
}
int charsetFamily;
if('A'==0x41) {
charsetFamily=U_ASCII_FAMILY;
} else if('A'==0xc1) {
charsetFamily=U_EBCDIC_FAMILY;
} else {
charsetFamily=-1; // unknown
}
if(U_CHARSET_FAMILY==charsetFamily) {
//printf("U_CHARSET_FAMILY: %d\n", U_CHARSET_FAMILY);
} else {
fprintf(stderr, " error: U_CHARSET_FAMILY=%d != %d=actual charset family\n",
U_CHARSET_FAMILY, charsetFamily);
errorCode=U_INTERNAL_PROGRAM_ERROR;
}
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
printf("\n\nICU Initialization returned: %s\n", u_errorName(initStatus));
#if UCONFIG_ENABLE_PLUGINS
#if U_ENABLE_DYLOAD
const char *pluginFile = uplug_getPluginFile();
printf("Plugin file is: %s\n", (pluginFile&&*pluginFile)?pluginFile:"(not set. try setting ICU_PLUGINS to a directory.)");
#else
fprintf(stderr, "Dynamic Loading: is disabled. No plugins will be loaded at start-up.\n");
#endif
#else
fprintf(stderr, "Plugins are disabled.\n");
#endif
}
void cmd_cleanup()
{
u_cleanup();
fprintf(stdout, "ICU u_cleanup() called.\n");
}
void cmd_listplugins() {
#if UCONFIG_ENABLE_PLUGINS
int32_t i;
UPlugData *plug;
do_init();
printf("ICU Initialized: u_init() returned %s\n", u_errorName(initStatus));
printf("Plugins: \n");
printf( "# %6s %s \n",
"Level",
"Name" );
printf( " %10s:%-10s\n",
"Library",
"Symbol"
);
printf( " config| (configuration string)\n");
printf( " >>> Error | Explanation \n");
printf( "-----------------------------------\n");
for(i=0;(plug=uplug_getPlugInternal(i))!=nullptr;i++) {
UErrorCode libStatus = U_ZERO_ERROR;
const char *name = uplug_getPlugName(plug);
const char *sym = uplug_getSymbolName(plug);
const char *lib = uplug_getLibraryName(plug, &libStatus);
const char *config = uplug_getConfiguration(plug);
UErrorCode loadStatus = uplug_getPlugLoadStatus(plug);
const char *message = nullptr;
printf("\n#%d %-6s %s \n",
i+1,
udbg_enumName(UDBG_UPlugLevel,(int32_t)uplug_getPlugLevel(plug)),
name!=nullptr?(*name?name:"this plugin did not call uplug_setPlugName()"):"(null)"
);
printf(" plugin| %10s:%-10s\n",
(U_SUCCESS(libStatus)?(lib!=nullptr?lib:"(null)"):u_errorName(libStatus)),
sym!=nullptr?sym:"(null)"
);
if(config!=nullptr&&*config) {
printf(" config| %s\n", config);
}
switch(loadStatus) {
case U_PLUGIN_CHANGED_LEVEL_WARNING:
message = "Note: This plugin changed the system level (by allocating memory or calling something which does). Later plugins may not load.";
break;
case U_PLUGIN_DIDNT_SET_LEVEL:
message = "Error: This plugin did not call uplug_setPlugLevel during QUERY.";
break;
case U_PLUGIN_TOO_HIGH:
message = "Error: This plugin couldn't load because the system level was too high. Try loading this plugin earlier.";
break;
case U_ZERO_ERROR:
message = nullptr; /* no message */
break;
default:
if(U_FAILURE(loadStatus)) {
message = "error loading:";
} else {
message = "warning during load:";
}
}
if(message!=nullptr) {
printf("\\\\\\ status| %s\n"
"/// %s\n", u_errorName(loadStatus), message);
}
}
if(i==0) {
printf("No plugins loaded.\n");
}
#endif
}
extern int
main(int argc, char* argv[]) {
UErrorCode errorCode = U_ZERO_ERROR;
UBool didSomething = false;
/* preset then read command line options */
argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options);
/* error handling, printing usage message */
if(argc<0) {
fprintf(stderr,
"error in command line argument \"%s\"\n",
argv[-argc]);
}
if( options[0].doesOccur || options[1].doesOccur) {
fprintf(stderr, "%s: Output information about the current ICU\n", argv[0]);
fprintf(stderr, "Options:\n"
" -h or --help - Print this help message.\n"
" -m or --millisecond-time - Print the current UTC time in milliseconds.\n"
" -d <dir> or --icudatadir <dir> - Set the ICU Data Directory\n"
" -v - Print version and configuration information about ICU\n"
#if UCONFIG_ENABLE_PLUGINS
" -L or --list-plugins - List and diagnose issues with ICU Plugins\n"
#endif
" -K or --cleanup - Call u_cleanup() before exiting (will attempt to unload plugins)\n"
"\n"
"If no arguments are given, the tool will print ICU version and configuration information.\n"
);
fprintf(stderr, "International Components for Unicode %s\n%s\n", U_ICU_VERSION, U_COPYRIGHT_STRING );
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
}
if(options[2].doesOccur) {
u_setDataDirectory(options[2].value);
}
if(options[5].doesOccur) {
cmd_millis();
didSomething=true;
}
if(options[4].doesOccur) {
cmd_listplugins();
didSomething = true;
}
if(options[3].doesOccur) {
cmd_version(false, errorCode);
didSomething = true;
}
if(options[7].doesOccur) { /* 2nd part of version: cleanup */
FILE *out = fopen(options[7].value, "w");
if(out==nullptr) {
fprintf(stderr,"ERR: can't write to XML file %s\n", options[7].value);
return 1;
}
/* todo: API for writing DTD? */
fprintf(out, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
udbg_writeIcuInfo(out);
fclose(out);
didSomething = true;
}
if(options[6].doesOccur) { /* 2nd part of version: cleanup */
cmd_cleanup();
didSomething = true;
}
if(!didSomething) {
cmd_version(false, errorCode); /* at least print the version # */
}
do_cleanup();
return U_FAILURE(errorCode);
}
|