static void _print_psl_entries(FILE *fpout, const _psl_vector_t *v, const char *varname) { int it; #ifdef BUILTIN_GENERATOR_LIBICU do { UVersionInfo version_info; char version[U_MAX_VERSION_STRING_LENGTH]; u_getVersion(version_info); u_versionToString(version_info, version); fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libicu/%s) */\n", version); } while (0); #elif defined(BUILTIN_GENERATOR_LIBIDN2) fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libidn2/%s) */\n", idn2_check_version(NULL)); #elif defined(BUILTIN_GENERATOR_LIBIDN) fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libidn/%s) */\n", stringprep_check_version(NULL)); #else fprintf(fpout, "/* automatically generated by psl2c (without punycode support) */\n"); #endif fprintf(fpout, "static _psl_entry_t %s[] = {\n", varname); for (it = 0; it < v->cur; it++) { _psl_entry_t *e = _vector_get(v, it); fprintf(fpout, "\t{ \"%s\", NULL, %hd, %d, %d },\n", e->label_buf, e->length, (int) e->nlabels, (int) e->flags); } fprintf(fpout, "};\n"); }
static void _print_psl_entries_dafsa(FILE *fpout, const _psl_vector_t *v) { FILE *fp; int it; #ifdef BUILTIN_GENERATOR_LIBICU do { UVersionInfo version_info; char version[U_MAX_VERSION_STRING_LENGTH]; u_getVersion(version_info); u_versionToString(version_info, version); fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libicu/%s) */\n", version); } while (0); #elif defined(BUILTIN_GENERATOR_LIBIDN2) fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libidn2/%s) */\n", idn2_check_version(NULL)); #elif defined(BUILTIN_GENERATOR_LIBIDN) fprintf(fpout, "/* automatically generated by psl2c (punycode generated with libidn/%s) */\n", stringprep_check_version(NULL)); #else fprintf(fpout, "/* automatically generated by psl2c (punycode generated internally) */\n"); #endif if ((fp = fopen("in.tmp", "w"))) { for (it = 0; it < v->cur; it++) { _psl_entry_t *e = _vector_get(v, it); unsigned char *s = (unsigned char *)e->label_buf; /* search for non-ASCII label and skip it */ while (*s && *s < 128) s++; if (*s) continue; fprintf(fp, "%s, %X\n", e->label_buf, (int) (e->flags & 0x0F)); } fclose(fp); } if ((it = system(MAKE_DAFSA " in.tmp out.tmp"))) fprintf(stderr, "Failed to execute " MAKE_DAFSA "\n"); if ((fp = fopen("out.tmp", "r"))) { char buf[256]; while (fgets(buf, sizeof(buf), fp)) fputs(buf, fpout); fclose(fp); } unlink("in.tmp"); unlink("out.tmp"); }
extern "C" void test_current(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[][32]) { uint32_t i = 0; int32_t keySize = 0; UVersionInfo uvi; u_getVersion(uvi); fprintf(stderr, "Entered current, version: [%d.%d.%d.%d]\nMoving to sortkeys\n", uvi[0], uvi[1], uvi[2], uvi[3]); for(i = 0; i<size; i++) { keySize = getSortKey_current("ja", data[i], -1, keys[i], 32); fprintf(stderr, "For i=%d, size of sortkey is %d\n", i, keySize); } fprintf(stderr, "Done sortkeys, doing qsort test\n"); initCollator_current("ja"); qsort(data, size, maxlen*sizeof(UChar), compare_current); closeCollator_current(); fprintf(stderr, "Done current!\n"); }
static PyObject * ICUConverter_getICUVersion(ICUConverter *self, PyObject *args) { assert(self != NULL); if (! PyArg_ParseTuple(args, "")) { return NULL; } if (self->pDecoder != NULL) { // typedef uint8_t UVersionInfo[U_MAX_VERSION_LENGTH]; uint8_t versionInfo[U_MAX_VERSION_LENGTH]; BOOST_STATIC_ASSERT(U_MAX_VERSION_LENGTH == 4); u_getVersion(versionInfo); return Py_BuildValue("iiii", (int)versionInfo[0], (int)versionInfo[1], (int)versionInfo[2], (int)versionInfo[3]); } // return None Py_INCREF(Py_None); return Py_None; }
PyMODINIT_FUNC initicu(void) { PyObject* m; UVersionInfo ver, uver; UErrorCode status = U_ZERO_ERROR; char version[U_MAX_VERSION_STRING_LENGTH+1] = {0}, uversion[U_MAX_VERSION_STRING_LENGTH+5] = {0}; if (sizeof(Py_UNICODE) != 2 && sizeof(Py_UNICODE) != 4) { PyErr_SetString(PyExc_RuntimeError, "This module only works on python versions <= 3.2"); return; } u_init(&status); if (U_FAILURE(status)) { PyErr_SetString(PyExc_RuntimeError, u_errorName(status)); return; } u_getVersion(ver); u_versionToString(ver, version); u_getUnicodeVersion(uver); u_versionToString(uver, uversion); if (PyType_Ready(&icu_CollatorType) < 0) return; if (PyType_Ready(&icu_BreakIteratorType) < 0) return; m = Py_InitModule3("icu", icu_methods, "Wrapper for the ICU internationalization library"); Py_INCREF(&icu_CollatorType); Py_INCREF(&icu_BreakIteratorType); PyModule_AddObject(m, "Collator", (PyObject *)&icu_CollatorType); PyModule_AddObject(m, "BreakIterator", (PyObject *)&icu_BreakIteratorType); // uint8_t must be the same size as char PyModule_AddIntConstant(m, "ok", (U_SUCCESS(status) && sizeof(uint8_t) == sizeof(char)) ? 1 : 0); PyModule_AddStringConstant(m, "icu_version", version); PyModule_AddStringConstant(m, "unicode_version", uversion); ADDUCONST(USET_SPAN_NOT_CONTAINED); ADDUCONST(USET_SPAN_CONTAINED); ADDUCONST(USET_SPAN_SIMPLE); ADDUCONST(UCOL_DEFAULT); ADDUCONST(UCOL_PRIMARY); ADDUCONST(UCOL_SECONDARY); ADDUCONST(UCOL_TERTIARY); ADDUCONST(UCOL_DEFAULT_STRENGTH); ADDUCONST(UCOL_QUATERNARY); ADDUCONST(UCOL_IDENTICAL); ADDUCONST(UCOL_OFF); ADDUCONST(UCOL_ON); ADDUCONST(UCOL_SHIFTED); ADDUCONST(UCOL_NON_IGNORABLE); ADDUCONST(UCOL_LOWER_FIRST); ADDUCONST(UCOL_UPPER_FIRST); ADDUCONST(UNORM_NONE); ADDUCONST(UNORM_NFD); ADDUCONST(UNORM_NFKD); ADDUCONST(UNORM_NFC); ADDUCONST(UNORM_DEFAULT); ADDUCONST(UNORM_NFKC); ADDUCONST(UNORM_FCD); ADDUCONST(UPPER_CASE); ADDUCONST(LOWER_CASE); ADDUCONST(TITLE_CASE); ADDUCONST(UBRK_CHARACTER); ADDUCONST(UBRK_WORD); ADDUCONST(UBRK_LINE); ADDUCONST(UBRK_SENTENCE); }
static jstring ICU_getIcuVersion(JNIEnv* env, jclass) { UVersionInfo icuVersion; u_getVersion(icuVersion); return versionString(env, icuVersion); }
int main(int argc, char **argv) { int i,j,cc=0,startpagenum=-1,ecount=0,chkopt=1; const char *envbuff; UVersionInfo icuVersion; char icu_version[U_MAX_VERSION_STRING_LENGTH] = ""; #ifdef WIN32 char **av; int ac; _setmaxstdio(2048); #endif kpse_set_program_name(argv[0], "upmendex"); #ifdef WIN32 file_system_codepage = CP_UTF8; is_cp932_system = 0; if (get_command_line_args_utf8("utf-8", &ac, &av)) { argv = av; argc = ac; } #endif kp_ist.var_name = "INDEXSTYLE"; kp_ist.path = DEFAULT_INDEXSTYLES; /* default path. */ kp_ist.suffix = "ist"; KP_entry_filetype(&kp_ist); kp_dict.var_name = "INDEXDICTIONARY"; kp_dict.path = DEFAULT_INDEXDICTS; /* default path */ kp_dict.suffix = "dict"; KP_entry_filetype(&kp_dict); /* check options */ for (i=1,j=0; i<argc && j<256; i++) { if ((argv[i][0]=='-')&&(strlen(argv[i])>=2)&&chkopt) { switch (argv[i][1]) { case 'c': bcomp=1; break; case 'd': if ((argv[i][2]=='\0')&&(i+1<argc)) { dicfile=xstrdup(argv[++i]); } else { dicfile=xstrdup(&argv[i][2]); } break; case 'f': force=1; break; case 'g': gflg=1; break; case 'i': fsti=1; break; case 'l': lorder=1; break; case 'o': if ((argv[i][2]=='\0')&&(i+1<argc)) { indfile=xstrdup(argv[++i]); } else { indfile=xstrdup(&argv[i][2]); } break; case 'p': if ((argv[i][2]=='\0')&&(i+1<argc)) { i++; if (strcmp(argv[i],"any")==0) fpage=2; else if (strcmp(argv[i],"odd")==0) fpage=3; else if (strcmp(argv[i],"even")==0) fpage=4; else { fpage=1; startpagenum=atoi(argv[i]); } } else { if (strcmp(&argv[i][2],"any")==0) fpage=2; else if (strcmp(&argv[i][2],"odd")==0) fpage=3; else if (strcmp(&argv[i][2],"even")==0) fpage=4; else { fpage=1; startpagenum=atoi(&argv[i][2]); } } break; case 'q': verb=0; break; case 't': if ((argv[i][2]=='\0')&&(i+1<argc)) { logfile=xstrdup(argv[++i]); } else { logfile=xstrdup(&argv[i][2]); } break; case 'r': prange=0; break; case 's': if ((argv[i][2]=='\0')&&(i+1<argc)) { styfile=xstrdup(argv[++i]); } else { styfile=xstrdup(&argv[i][2]); } break; case 'v': debug=1; break; case '-': if (strlen(argv[i])==2) chkopt=0; if (strcmp(argv[i],"--help")!=0) break; default: u_getVersion(icuVersion); u_versionToString(icuVersion, icu_version); fprintf(stderr,"upmendex - index processor, %s (%s).\n",VERSION, TL_VERSION); fprintf(stderr," Copyright 2009 ASCII MEDIA WORKS, 2015-2016 TANAKA Takuji\n"); fprintf(stderr," using ICU version %s\n",icu_version); fprintf(stderr,"usage:\n"); fprintf(stderr,"%% upmendex [-ilqrcgf] [-s sty] [-d dic] [-o ind] [-t log] [-p no] [--] [idx0 idx1 ...]\n"); fprintf(stderr,"options:\n"); fprintf(stderr,"-i use stdin as the input file.\n"); fprintf(stderr,"-l use letter ordering.\n"); fprintf(stderr,"-q quiet mode.\n"); fprintf(stderr,"-r disable implicit page formation.\n"); fprintf(stderr,"-c compress blanks. (ignore leading and trailing blanks.)\n"); fprintf(stderr,"-g make Japanese index head <%s>.\n", AKASATANAutf8); fprintf(stderr,"-f force to output unknown scripts.\n"); fprintf(stderr,"-s sty take sty as style file.\n"); fprintf(stderr,"-d dic take dic as dictionary file.\n"); fprintf(stderr,"-o ind take ind as the output index file.\n"); fprintf(stderr,"-t log take log as the error log file.\n"); fprintf(stderr,"-p no set the starting page number of index.\n"); fprintf(stderr,"idx... input files.\n"); exit(0); break; } } else { cc=strlen(argv[i]); if (cc<4) cc+=4; else if (strcmp(&argv[i][cc-4],".idx")) cc+=4; idxfile[j]=xmalloc(cc+1); strcpy(idxfile[j++],argv[i]); } } idxcount=j+fsti; /* check option errors */ if (idxcount==0) idxcount=fsti=1; if (styfile==NULL) { envbuff=kpse_var_value("INDEXDEFAULTSTYLE"); if (envbuff!=NULL) { styfile=xstrdup(envbuff); } } /* init hangul tumunja table */ u_strcpy(tumunja,GANADA); if (styfile!=NULL) styread(styfile); if (!indfile &&(idxcount-fsti>0)) { indfile=xmalloc(strlen(idxfile[0]+6)); for (i=strlen(idxfile[0]); i>=0; i--) { if (idxfile[0][i]=='.') { strncpy(indfile,idxfile[0],i); sprintf(&indfile[i],".ind"); break; } } if (i==-1) sprintf(indfile,"%s.ind",idxfile[0]); } if (!logfile && (idxcount-fsti > 0)) { logfile=xmalloc(strlen(idxfile[0]+6)); for (i=strlen(idxfile[0]); i>=0; i--) { if (idxfile[0][i]=='.') { strncpy(logfile,idxfile[0],i); sprintf(&logfile[i],".ilg"); break; } } if (i==-1) sprintf(logfile,"%s.ilg",idxfile[0]); } if (logfile && kpse_out_name_ok(logfile)) efp=fopen(logfile,"wb"); if(efp == NULL) { efp=stderr; logfile=xstrdup("stderr"); } set_icu_attributes(); if (strcmp(argv[0],"makeindex")==0) { verb_printf(efp,"This is Not `MAKEINDEX\', But `UPMENDEX\' %s (%s).\n", VERSION, TL_VERSION); } else { verb_printf(efp,"This is upmendex %s (%s).\n", VERSION, TL_VERSION); } /* init kanatable */ initkanatable(); /* read dictionary */ ecount+=dicread(dicfile); switch (letter_head) { case 0: case 1: if (gflg==1) { u_strcpy(atama,akasatana); } else { u_strcpy(atama,aiueo); } break; case 2: if (gflg==1) { u_strcpy(atama,AKASATANA); } else { u_strcpy(atama,AIUEO); } break; default: break; } /* read idx file */ lines=0; ecount=0; ind=xmalloc(sizeof(struct index)); for (i=0; i<idxcount-fsti; i++) { ecount+=idxread(idxfile[i],lines); } if (fsti==1) { ecount+=idxread(NULL,lines); } verb_printf(efp,"%d entries accepted, %d rejected.\n",acc,reject); if (ecount!=0) { verb_printf(efp,"%d errors, written in %s.\n",ecount,logfile); lines=0; } if (lines==0) { verb_printf(efp,"Nothing written in output file.\n"); if (efp!=stderr) fclose(efp); exit(255); } /* sort index */ verb_printf(efp,"Sorting index."); scount=0; wsort(ind,lines); verb_printf(efp,"...done(%d comparisons).\n",scount); /* sort pages */ verb_printf(efp,"Sorting pages."); scount=0; pagesort(ind,lines); verb_printf(efp,"...done(%d comparisons).\n",scount); /* get last page */ if ((fpage>1)&&(idxcount-fsti>0)) cc=lastpage(idxfile[0]); switch (fpage) { case 2: startpagenum=cc+1; break; case 3: if ((cc+1)%2==0) startpagenum=cc+2; else startpagenum=cc+1; break; case 4: if ((cc+1)%2==1) startpagenum=cc+2; else startpagenum=cc+1; break; default: break; } /* write indfile */ verb_printf(efp,"Making index file."); indwrite(indfile,ind,startpagenum); verb_printf(efp,"...done.\n"); if (idxcount-fsti==0) indfile=xstrdup("stdout"); verb_printf(efp,"%d warnings, written in %s.\n",warn,logfile); verb_printf(efp,"Output written in %s.\n",indfile); if (efp!=stderr) fclose(efp); return 0; }
extern "C" jstring Java_libcore_icu_ICU_getIcuVersion(JNIEnv* env, jclass) { UVersionInfo icuVersion; u_getVersion(icuVersion); return versionString(env, icuVersion); }
static void TestVersion(void) { UVersionInfo versionArray = {0x01, 0x00, 0x02, 0x02}; UVersionInfo versionArray2 = {0x01, 0x00, 0x02, 0x02}; char versionString[17]; /* xxx.xxx.xxx.xxx\0 */ UChar versionUString[] = { 0x0031, 0x002E, 0x0030, 0x002E, 0x0032, 0x002E, 0x0038, 0x0000 }; /* 1.0.2.8 */ UBool isModified = FALSE; UVersionInfo version; UErrorCode status = U_ZERO_ERROR; log_verbose("Testing the API u_versionToString().....\n"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 1.0.2.2, Got=%s\n", versionString); } log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n"); u_versionToString(NULL, versionString); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed. with versionArray=NULL. It should just return\n"); } log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n"); u_versionToString(NULL, versionString); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed . It should just return\n"); } log_verbose("Testing the API u_versionToString().....with versionString=NULL\n"); u_versionToString(versionArray, NULL); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed. with versionArray=NULL It should just return\n"); } versionArray[0] = 0x0a; log_verbose("Testing the API u_versionToString().....\n"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "10.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 10.0.2.2, Got=%s\n", versionString); } versionArray[0] = 0xa0; u_versionToString(versionArray, versionString); if(strcmp(versionString, "160.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.0.2.2, Got=%s\n", versionString); } versionArray[0] = 0xa0; versionArray[1] = 0xa0; u_versionToString(versionArray, versionString); if(strcmp(versionString, "160.160.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString); } versionArray[0] = 0x01; versionArray[1] = 0x0a; u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.10.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString); } log_verbose("Testing the API u_versionFromString() ....\n"); u_versionFromString(versionArray, "1.3.5.6"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.3.5.6") != 0){ log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n", versionString); } log_verbose("Testing the API u_versionFromString() where versionArray=NULL....\n"); u_versionFromString(NULL, "1.3.5.6"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.3.5.6") != 0){ log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n", versionString); } log_verbose("Testing the API u_getVersion().....\n"); u_getVersion(versionArray); u_versionToString(versionArray, versionString); if(strcmp(versionString, U_ICU_VERSION) != 0){ log_err("ERROR: u_getVersion() failed. Got=%s, expected %s\n", versionString, U_ICU_VERSION); } /* test unicode */ log_verbose("Testing u_versionFromUString...\n"); u_versionFromString(versionArray,"1.0.2.8"); u_versionFromUString(versionArray2, versionUString); u_versionToString(versionArray2, versionString); if(memcmp(versionArray, versionArray2, sizeof(UVersionInfo))) { log_err("FAIL: u_versionFromUString produced a different result - not 1.0.2.8 but %s [%x.%x.%x.%x]\n", versionString, (int)versionArray2[0], (int)versionArray2[1], (int)versionArray2[2], (int)versionArray2[3]); } else { log_verbose(" from UString: %s\n", versionString); } /* Test the data version API for better code coverage */ u_getDataVersion(version, &status); if (U_FAILURE(status)) { log_data_err("ERROR: Unable to get data version. %s\n", u_errorName(status)); } else { u_isDataOlder(version, &isModified, &status); if (U_FAILURE(status)) { log_err("ERROR: Unable to compare data version. %s\n", u_errorName(status)); } } }
int main(int argc, char* argv[]) { ConvData data; UErrorCode err = U_ZERO_ERROR, localError; char outFileName[UCNV_MAX_FULL_FILE_NAME_LENGTH]; const char* destdir, *arg; size_t destdirlen; char* dot = NULL, *outBasename; char cnvName[UCNV_MAX_FULL_FILE_NAME_LENGTH]; char cnvNameWithPkg[UCNV_MAX_FULL_FILE_NAME_LENGTH]; UVersionInfo icuVersion; UBool printFilename; err = U_ZERO_ERROR; U_MAIN_INIT_ARGS(argc, argv); /* Set up the ICU version number */ u_getVersion(icuVersion); uprv_memcpy(&dataInfo.dataVersion, &icuVersion, sizeof(UVersionInfo)); /* preset then read command line options */ options[OPT_DESTDIR].value=u_getDataDirectory(); argc=u_parseArgs(argc, argv, LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "error in command line argument \"%s\"\n", argv[-argc]); } else if(argc<2) { argc=-1; } if(argc<0 || options[OPT_HELP_H].doesOccur || options[OPT_HELP_QUESTION_MARK].doesOccur) { FILE *stdfile=argc<0 ? stderr : stdout; fprintf(stdfile, "usage: %s [-options] files...\n" "\tread .ucm codepage mapping files and write .cnv files\n" "options:\n" "\t-h or -? or --help this usage text\n" "\t-V or --version show a version message\n" "\t-c or --copyright include a copyright notice\n" "\t-d or --destdir destination directory, followed by the path\n" "\t-v or --verbose Turn on verbose output\n", argv[0]); fprintf(stdfile, "\t --small Generate smaller .cnv files. They will be\n" "\t significantly smaller but may not be compatible with\n" "\t older versions of ICU and will require heap memory\n" "\t allocation when loaded.\n" "\t --ignore-siso-check Use SI/SO other than 0xf/0xe.\n"); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[OPT_VERSION].doesOccur) { printf("makeconv version %hu.%hu, ICU tool to read .ucm codepage mapping files and write .cnv files\n", dataInfo.formatVersion[0], dataInfo.formatVersion[1]); printf("%s\n", U_COPYRIGHT_STRING); exit(0); } /* get the options values */ haveCopyright = options[OPT_COPYRIGHT].doesOccur; destdir = options[OPT_DESTDIR].value; VERBOSE = options[OPT_VERBOSE].doesOccur; SMALL = options[OPT_SMALL].doesOccur; if (options[OPT_IGNORE_SISO_CHECK].doesOccur) { IGNORE_SISO_CHECK = TRUE; } if (destdir != NULL && *destdir != 0) { uprv_strcpy(outFileName, destdir); destdirlen = uprv_strlen(destdir); outBasename = outFileName + destdirlen; if (*(outBasename - 1) != U_FILE_SEP_CHAR) { *outBasename++ = U_FILE_SEP_CHAR; ++destdirlen; } } else { destdirlen = 0; outBasename = outFileName; } #if DEBUG { int i; printf("makeconv: processing %d files...\n", argc - 1); for(i=1; i<argc; ++i) { printf("%s ", argv[i]); } printf("\n"); fflush(stdout); } #endif err = U_ZERO_ERROR; printFilename = (UBool) (argc > 2 || VERBOSE); for (++argv; --argc; ++argv) { arg = getLongPathname(*argv); /* Check for potential buffer overflow */ if(strlen(arg) > UCNV_MAX_FULL_FILE_NAME_LENGTH) { fprintf(stderr, "%s\n", u_errorName(U_BUFFER_OVERFLOW_ERROR)); return U_BUFFER_OVERFLOW_ERROR; } /*produces the right destination path for display*/ if (destdirlen != 0) { const char *basename; /* find the last file sepator */ basename = findBasename(arg); uprv_strcpy(outBasename, basename); } else { uprv_strcpy(outFileName, arg); } /*removes the extension if any is found*/ dot = uprv_strrchr(outBasename, '.'); if (dot) { *dot = '\0'; } /* the basename without extension is the converter name */ uprv_strcpy(cnvName, outBasename); /*Adds the target extension*/ uprv_strcat(outBasename, CONVERTER_FILE_EXTENSION); #if DEBUG printf("makeconv: processing %s ...\n", arg); fflush(stdout); #endif localError = U_ZERO_ERROR; initConvData(&data); createConverter(&data, arg, &localError); if (U_FAILURE(localError)) { /* if an error is found, print out an error msg and keep going */ fprintf(stderr, "Error creating converter for \"%s\" file for \"%s\" (%s)\n", outFileName, arg, u_errorName(localError)); if(U_SUCCESS(err)) { err = localError; } } else { /* Insure the static data name matches the file name */ /* Changed to ignore directory and only compare base name LDH 1/2/08*/ char *p; p = strrchr(cnvName, U_FILE_SEP_CHAR); /* Find last file separator */ if(p == NULL) /* OK, try alternate */ { p = strrchr(cnvName, U_FILE_ALT_SEP_CHAR); if(p == NULL) { p=cnvName; /* If no separators, no problem */ } } else { p++; /* If found separtor, don't include it in compare */ } if(uprv_stricmp(p,data.staticData.name)) { fprintf(stderr, "Warning: %s%s claims to be '%s'\n", cnvName, CONVERTER_FILE_EXTENSION, data.staticData.name); } uprv_strcpy((char*)data.staticData.name, cnvName); if(!uprv_isInvariantString((char*)data.staticData.name, -1)) { fprintf(stderr, "Error: A converter name must contain only invariant characters.\n" "%s is not a valid converter name.\n", data.staticData.name); if(U_SUCCESS(err)) { err = U_INVALID_TABLE_FORMAT; } } uprv_strcpy(cnvNameWithPkg, cnvName); localError = U_ZERO_ERROR; writeConverterData(&data, cnvNameWithPkg, destdir, &localError); if(U_FAILURE(localError)) { /* if an error is found, print out an error msg and keep going*/ fprintf(stderr, "Error writing \"%s\" file for \"%s\" (%s)\n", outFileName, arg, u_errorName(localError)); if(U_SUCCESS(err)) { err = localError; } } else if (printFilename) { puts(outBasename); } } fflush(stdout); fflush(stderr); cleanupConvData(&data); } return err; }
void cmd_version(UBool noLoad) { UVersionInfo icu; char str[200]; printf("<ICUINFO>\n"); printf("International Components for Unicode for C/C++\n"); printf("%s\n", U_COPYRIGHT_STRING); printf("Compiled-Version: %s\n", U_ICU_VERSION); u_getVersion(icu); u_versionToString(icu, str); printf("Runtime-Version: %s\n", str); printf("Compiled-Unicode-Version: %s\n", U_UNICODE_VERSION); u_getUnicodeVersion(icu); u_versionToString(icu, str); printf("Runtime-Unicode-Version: %s\n", U_UNICODE_VERSION); printf("Platform: %s\n", getPlatform()); #if defined(U_BUILD) printf("Build: %s\n", U_BUILD); #if defined(U_HOST) if(strcmp(U_BUILD,U_HOST)) { printf("Host: %s\n", U_HOST); } #endif #endif #if defined(U_CC) printf("C compiler: %s\n", U_CC); #endif #if defined(U_CXX) printf("C++ compiler: %s\n", U_CXX); #endif #if defined(CYGWINMSVC) printf("Cygwin: CYGWINMSVC\n"); #endif printf("ICUDATA: %s\n", U_ICUDATA_NAME); do_init(); printf("Data Directory: %s\n", u_getDataDirectory()); printf("ICU Initialization returned: %s\n", u_errorName(initStatus)); printf( "Default locale: %s\n", uloc_getDefault()); { UErrorCode subStatus = U_ZERO_ERROR; ulocdata_getCLDRVersion(icu, &subStatus); if(U_SUCCESS(subStatus)) { u_versionToString(icu, str); printf("CLDR-Version: %s\n", str); } else { printf("CLDR-Version: %s\n", u_errorName(subStatus)); } } #if !UCONFIG_NO_CONVERSION if(noLoad == FALSE) { printf("Default converter: %s\n", ucnv_getDefaultName()); } #endif #if !UCONFIG_NO_FORMATTING { UChar buf[100]; char buf2[100]; UErrorCode subsubStatus= U_ZERO_ERROR; int32_t len; len = ucal_getDefaultTimeZone(buf, 100, &subsubStatus); if(U_SUCCESS(subsubStatus)&&len>0) { u_UCharsToChars(buf, buf2, len+1); printf("Default TZ: %s\n", buf2); } else { printf("Default TZ: %s\n", u_errorName(subsubStatus)); } } { UErrorCode subStatus = U_ZERO_ERROR; const char *tzVer = ucal_getTZDataVersion(&subStatus); if(U_FAILURE(subStatus)) { tzVer = u_errorName(subStatus); } printf("TZ data version: %s\n", tzVer); } #endif #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 printf("</ICUINFO>\n\n"); }
static void TestICUDataName() { UVersionInfo icuVersion; char expectDataName[20]; unsigned int expectLen = 8; char typeChar = '?'; /* Print out the version # we have .. */ log_verbose("utypes.h says U_ICUDATA_NAME = %s\n", U_ICUDATA_NAME); /* Build up the version # we expect to get */ u_getVersion(icuVersion); switch(U_CHARSET_FAMILY) { case U_ASCII_FAMILY: switch(U_IS_BIG_ENDIAN) { case 1: typeChar = 'b'; break; case 0: typeChar = 'l'; break; default: log_err("Expected 1 or 0 for U_IS_BIG_ENDIAN, got %d!\n", (int)U_IS_BIG_ENDIAN); /* return; */ } break; case U_EBCDIC_FAMILY: typeChar = 'e'; break; } sprintf(expectDataName, "%s%d%d%c", "icudt", (int)icuVersion[0], (int)icuVersion[1], typeChar); log_verbose("Expected: %s\n", expectDataName); if(uprv_strlen(expectDataName) != expectLen) { log_err("*Expected* length is wrong (test err?), should be %d is %d\n", expectLen, uprv_strlen(expectDataName)); } if(uprv_strlen(U_ICUDATA_NAME) != expectLen) { log_err("U_ICUDATA_NAME length should be %d is %d\n", expectLen, uprv_strlen(U_ICUDATA_NAME)); } if(uprv_strcmp(U_ICUDATA_NAME, expectDataName)) { log_err("U_ICUDATA_NAME should be %s but is %s\n", expectDataName, U_ICUDATA_NAME); } /* ICUDATA_NAME comes from the build system on *nix */ #ifdef ICUDATA_NAME if(uprv_strcmp(U_ICUDATA_NAME, ICUDATA_NAME)) { log_err("ICUDATA_NAME and U_ICUDATA_NAME don't match: " "ICUDATA_NAME=%s, U_ICUDATA_NAME=%s. Check configure.in, icudefs.mk.in, utypes.h...\n", ICUDATA_NAME, U_ICUDATA_NAME); } else { log_verbose("ICUDATA_NAME=%s (from icudefs.mk), U_ICUDATA_NAME=%s (from utypes.h)\n", ICUDATA_NAME, U_ICUDATA_NAME); } #endif }
static void TestPUtilAPI(void){ double n1=0.0, y1=0.0, expn1, expy1; double value1 = 0.021; UVersionInfo versionArray = {0x01, 0x00, 0x02, 0x02}; char versionString[17]; /* xxx.xxx.xxx.xxx\0 */ char *str=0; UBool isTrue=FALSE; log_verbose("Testing the API uprv_modf()\n"); y1 = uprv_modf(value1, &n1); expn1=0; expy1=0.021; if(y1 != expy1 || n1 != expn1){ log_err("Error in uprv_modf. Expected IntegralValue=%f, Got=%f, \n Expected FractionalValue=%f, Got=%f\n", expn1, n1, expy1, y1); } if(VERBOSITY){ log_verbose("[float] x = %f n = %f y = %f\n", value1, n1, y1); } log_verbose("Testing the API uprv_fmod()\n"); expn1=uprv_fmod(30.50, 15.00); doAssert(expn1, 0.5, "uprv_fmod(30.50, 15.00) failed."); log_verbose("Testing the API uprv_ceil()\n"); expn1=uprv_ceil(value1); doAssert(expn1, 1, "uprv_ceil(0.021) failed."); log_verbose("Testing the API uprv_floor()\n"); expn1=uprv_floor(value1); doAssert(expn1, 0, "uprv_floor(0.021) failed."); log_verbose("Testing the API uprv_fabs()\n"); expn1=uprv_fabs((2.02-1.345)); doAssert(expn1, 0.675, "uprv_fabs(2.02-1.345) failed."); log_verbose("Testing the API uprv_fmax()\n"); doAssert(uprv_fmax(2.4, 1.2), 2.4, "uprv_fmax(2.4, 1.2) failed."); log_verbose("Testing the API uprv_fmax() with x value= NaN\n"); expn1=uprv_fmax(uprv_getNaN(), 1.2); doAssert(expn1, uprv_getNaN(), "uprv_fmax(uprv_getNaN(), 1.2) failed. when one parameter is NaN"); log_verbose("Testing the API uprv_fmin()\n"); doAssert(uprv_fmin(2.4, 1.2), 1.2, "uprv_fmin(2.4, 1.2) failed."); log_verbose("Testing the API uprv_fmin() with x value= NaN\n"); expn1=uprv_fmin(uprv_getNaN(), 1.2); doAssert(expn1, uprv_getNaN(), "uprv_fmin(uprv_getNaN(), 1.2) failed. when one parameter is NaN"); log_verbose("Testing the API uprv_max()\n"); doAssert(uprv_max(4, 2), 4, "uprv_max(4, 2) failed."); log_verbose("Testing the API uprv_min()\n"); doAssert(uprv_min(-4, 2), -4, "uprv_min(-4, 2) failed."); log_verbose("Testing the API uprv_trunc()\n"); doAssert(uprv_trunc(12.3456), 12, "uprv_trunc(12.3456) failed."); doAssert(uprv_trunc(12.234E2), 1223, "uprv_trunc(12.234E2) failed."); doAssert(uprv_trunc(uprv_getNaN()), uprv_getNaN(), "uprv_trunc(uprv_getNaN()) failed. with parameter=NaN"); doAssert(uprv_trunc(uprv_getInfinity()), uprv_getInfinity(), "uprv_trunc(uprv_getInfinity()) failed. with parameter=Infinity"); log_verbose("Testing the API uprv_pow10()\n"); doAssert(uprv_pow10(4), 10000, "uprv_pow10(4) failed."); log_verbose("Testing the API uprv_log10()\n"); doAssert(uprv_log10(3456), 3, "uprv_log10(3456) failed."); #ifdef OS390 doAssert(uprv_log10(1.0e55), 55, "uprv_log10(1.0e55) failed."); #else doAssert(uprv_log10(1.0e300), 300, "uprv_log10(1.0e300) failed."); #endif log_verbose("Testing the API uprv_isNegativeInfinity()\n"); isTrue=uprv_isNegativeInfinity(uprv_getInfinity() * -1); if(isTrue != TRUE){ log_err("ERROR: uprv_isNegativeInfinity failed.\n"); } log_verbose("Testing the API uprv_isPositiveInfinity()\n"); isTrue=uprv_isPositiveInfinity(uprv_getInfinity()); if(isTrue != TRUE){ log_err("ERROR: uprv_isPositiveInfinity failed.\n"); } log_verbose("Testing the API uprv_isInfinite()\n"); isTrue=uprv_isInfinite(uprv_getInfinity()); if(isTrue != TRUE){ log_err("ERROR: uprv_isInfinite failed.\n"); } #if 0 log_verbose("Testing the API uprv_digitsAfterDecimal()....\n"); doAssert(uprv_digitsAfterDecimal(value1), 3, "uprv_digitsAfterDecimal() failed."); doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E-2), 6, "uprv_digitsAfterDecimal(1.2345E-2) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E2), 2, "uprv_digitsAfterDecimal(1.2345E2) failed."); doAssert(uprv_digitsAfterDecimal(-1.2345E-20), 24, "uprv_digitsAfterDecimal(1.2345E-20) failed."); doAssert(uprv_digitsAfterDecimal(1.2345E20), 0, "uprv_digitsAfterDecimal(1.2345E20) failed."); doAssert(uprv_digitsAfterDecimal(-0.021), 3, "uprv_digitsAfterDecimal(-0.021) failed."); doAssert(uprv_digitsAfterDecimal(23.0), 0, "uprv_digitsAfterDecimal(23.0) failed."); doAssert(uprv_digitsAfterDecimal(0.022223333321), 9, "uprv_digitsAfterDecimal(0.022223333321) failed."); #endif log_verbose("Testing the API u_versionToString().....\n"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 1.0.2.2, Got=%s\n", versionString); } log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n"); u_versionToString(NULL, versionString); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed. with versionArray=NULL. It should just return\n"); } log_verbose("Testing the API u_versionToString().....with versionArray=NULL\n"); u_versionToString(NULL, versionString); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed . It should just return\n"); } log_verbose("Testing the API u_versionToString().....with versionString=NULL\n"); u_versionToString(versionArray, NULL); if(strcmp(versionString, "") != 0){ log_err("ERROR: u_versionToString() failed. with versionArray=NULL It should just return\n"); } versionArray[0] = 0x0a; log_verbose("Testing the API u_versionToString().....\n"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "10.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 10.0.2.2, Got=%s\n", versionString); } versionArray[0] = 0xa0; u_versionToString(versionArray, versionString); if(strcmp(versionString, "160.0.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.0.2.2, Got=%s\n", versionString); } versionArray[0] = 0xa0; versionArray[1] = 0xa0; u_versionToString(versionArray, versionString); if(strcmp(versionString, "160.160.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString); } versionArray[0] = 0x01; versionArray[1] = 0x0a; u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.10.2.2") != 0){ log_err("ERROR: u_versionToString() failed. Expected: 160.160.2.2, Got=%s\n", versionString); } log_verbose("Testing the API u_versionFromString() ....\n"); u_versionFromString(versionArray, "1.3.5.6"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.3.5.6") != 0){ log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n", versionString); } log_verbose("Testing the API u_versionFromString() where versionArray=NULL....\n"); u_versionFromString(NULL, "1.3.5.6"); u_versionToString(versionArray, versionString); if(strcmp(versionString, "1.3.5.6") != 0){ log_err("ERROR: u_getVersion() failed. Expected: 1.3.5.6, Got=%s\n", versionString); } log_verbose("Testing the API u_getVersion().....\n"); u_getVersion(versionArray); u_versionToString(versionArray, versionString); if(strcmp(versionString, U_ICU_VERSION) != 0){ log_err("ERROR: u_getVersion() failed. Got=%s, expected %s\n", versionString, U_ICU_VERSION); } log_verbose("Testing the API u_errorName()...\n"); str=(char*)u_errorName((UErrorCode)0); if(strcmp(str, "U_ZERO_ERROR") != 0){ log_err("ERROR: u_getVersion() failed. Expected: U_ZERO_ERROR Got=%s\n", str); } log_verbose("Testing the API u_errorName()...\n"); str=(char*)u_errorName((UErrorCode)-127); if(strcmp(str, "U_USING_DEFAULT_WARNING") != 0){ log_err("ERROR: u_getVersion() failed. Expected: U_USING_DEFAULT_WARNING Got=%s\n", str); } log_verbose("Testing the API u_errorName().. with BOGUS ERRORCODE...\n"); str=(char*)u_errorName((UErrorCode)200); if(strcmp(str, "[BOGUS UErrorCode]") != 0){ log_err("ERROR: u_getVersion() failed. Expected: [BOGUS UErrorCode] Got=%s\n", str); } { const char* dataDirectory; UChar *udataDir=0; UChar temp[100]; char *charvalue=0; log_verbose("Testing chars to UChars\n"); /* This cannot really work on a japanese system. u_uastrcpy will have different results than */ /* u_charsToUChars when there is a backslash in the string! */ /*dataDirectory=u_getDataDirectory();*/ dataDirectory="directory1"; /*no backslashes*/ udataDir=(UChar*)malloc(sizeof(UChar) * (strlen(dataDirectory) + 1)); u_charsToUChars(dataDirectory, udataDir, (strlen(dataDirectory)+1)); u_uastrcpy(temp, dataDirectory); if(u_strcmp(temp, udataDir) != 0){ log_err("ERROR: u_charsToUChars failed. Expected %s, Got %s\n", austrdup(temp), austrdup(udataDir)); } log_verbose("Testing UChars to chars\n"); charvalue=(char*)malloc(sizeof(char) * (u_strlen(udataDir) + 1)); u_UCharsToChars(udataDir, charvalue, (u_strlen(udataDir)+1)); if(strcmp(charvalue, dataDirectory) != 0){ log_err("ERROR: u_UCharsToChars failed. Expected %s, Got %s\n", charvalue, dataDirectory); } free(charvalue); free(udataDir); } log_verbose("Testing uprv_timezone()....\n"); { int32_t tzoffset = uprv_timezone(); log_verbose("Value returned from uprv_timezone = %d\n", tzoffset); if (tzoffset != 28800) { log_verbose("***** WARNING: If testing in the PST timezone, t_timezone should return 28800! *****"); } if ((tzoffset % 1800 != 0)) { log_err("FAIL: t_timezone may be incorrect. It is not a multiple of 30min."); } tzoffset=uprv_getUTCtime(); } }