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"); }
void Normalizer2DataBuilder::setUnicodeVersion(const char *v) { UVersionInfo nullVersion= { 0, 0, 0, 0 }; UVersionInfo version; u_versionFromString(version, v); if( 0!=memcmp(version, unicodeVersion, U_MAX_VERSION_LENGTH) && 0!=memcmp(nullVersion, unicodeVersion, U_MAX_VERSION_LENGTH) ) { char buffer[U_MAX_VERSION_STRING_LENGTH]; u_versionToString(unicodeVersion, buffer); fprintf(stderr, "gennorm2 error: multiple inconsistent Unicode version numbers %s vs. %s\n", buffer, v); exit(U_ILLEGAL_ARGUMENT_ERROR); } memcpy(unicodeVersion, version, U_MAX_VERSION_LENGTH); }
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 versionString(JNIEnv* env, const UVersionInfo& version) { char versionString[U_MAX_VERSION_STRING_LENGTH]; u_versionToString(const_cast<UVersionInfo&>(version), &versionString[0]); return env->NewStringUTF(versionString); }
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; }
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)); } } }
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 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(); } }
int main(int argc, const char *argv[]) { UErrorCode errorCode = U_ZERO_ERROR; // Get the unsafeBackwardsSet const CollationCacheEntry *rootEntry = CollationRoot::getRootCacheEntry(errorCode); if(U_FAILURE(errorCode)) { fprintf(stderr, "Err: %s getting root cache entry\n", u_errorName(errorCode)); return 1; } const UVersionInfo &version = rootEntry->tailoring->version; const UnicodeSet *unsafeBackwardSet = rootEntry->tailoring->unsafeBackwardSet; char verString[20]; u_versionToString(version, verString); fprintf(stderr, "Generating data for ICU %s, Collation %s\n", U_ICU_VERSION, verString); int32_t rangeCount = unsafeBackwardSet->getRangeCount(); #if SERIALIZE fprintf(stderr, ".. serializing\n"); // UnicodeSet serialization UErrorCode preflightCode = U_ZERO_ERROR; // preflight int32_t serializedCount = unsafeBackwardSet->serialize(NULL,0,preflightCode); if(U_FAILURE(preflightCode) && preflightCode != U_BUFFER_OVERFLOW_ERROR) { fprintf(stderr, "Err: %s preflighting unicode set\n", u_errorName(preflightCode)); return 1; } uint16_t *serializedData = new uint16_t[serializedCount]; // serialize unsafeBackwardSet->serialize(serializedData, serializedCount, errorCode); if(U_FAILURE(errorCode)) { delete [] serializedData; fprintf(stderr, "Err: %s serializing unicodeset\n", u_errorName(errorCode)); return 1; } #endif #if PATTERN fprintf(stderr,".. pattern. (Note: collationdatareader.cpp does not support this form also see #11891)\n"); // attempt to use pattern UnicodeString pattern; UnicodeSet set(*unsafeBackwardSet); set.compact(); set.toPattern(pattern, FALSE); if(U_SUCCESS(errorCode)) { // This fails (bug# ?) - which is why this method was abandoned. // UnicodeSet usA(pattern, errorCode); // fprintf(stderr, "\n%s:%d: err creating set A %s\n", __FILE__, __LINE__, u_errorName(errorCode)); // return 1; } const UChar *buf = pattern.getBuffer(); int32_t needed = pattern.length(); // print { char buf2[2048]; int32_t len2 = pattern.extract(0, pattern.length(), buf2, "utf-8"); buf2[len2]=0; fprintf(stderr,"===\n%s\n===\n", buf2); } const UnicodeString unsafeBackwardPattern(FALSE, buf, needed); if(U_SUCCESS(errorCode)) { //UnicodeSet us(unsafeBackwardPattern, errorCode); // fprintf(stderr, "\n%s:%d: err creating set %s\n", __FILE__, __LINE__, u_errorName(errorCode)); } else { fprintf(stderr, "Uset OK - \n"); } #endif // Generate the output file. printf("// collunsafe.h\n"); printf("// %s\n", U_COPYRIGHT_STRING); printf("\n"); printf("// To be included by collationdatareader.cpp, and generated by gencolusb.\n"); printf("// Machine generated, do not edit.\n"); printf("\n"); printf("#ifndef COLLUNSAFE_H\n" "#define COLLUNSAFE_H\n" "\n" "#include \"unicode/utypes.h\"\n" "\n" "#define COLLUNSAFE_ICU_VERSION \"" U_ICU_VERSION "\"\n"); printf("#define COLLUNSAFE_COLL_VERSION \"%s\"\n", verString); #if PATTERN printf("#define COLLUNSAFE_PATTERN 1\n"); printf("static const int32_t collunsafe_len = %d;\n", needed); printf("static const UChar collunsafe_pattern[collunsafe_len] = {\n"); for(int i=0;i<needed;i++) { if( (i>0) && (i%8 == 0) ) { printf(" // %d\n", i); } printf("0x%04X", buf[i]); // TODO check if(i != (needed-1)) { printf(", "); } } printf(" //%d\n};\n", (needed-1)); #endif #if RANGE fprintf(stderr, "COLLUNSAFE_RANGE - no code support in collationdatareader.cpp for this\n"); printf("#define COLLUNSAFE_RANGE 1\n"); printf("static const int32_t unsafe_rangeCount = %d;\n", rangeCount); printf("static const UChar32 unsafe_ranges[%d] = { \n", rangeCount*2); for(int32_t i=0;i<rangeCount;i++) { printf(" 0x%04X, 0x%04X, // %d\n", unsafeBackwardSet->getRangeStart(i), unsafeBackwardSet->getRangeEnd(i), i); } printf("};\n"); #endif #if SERIALIZE printf("#define COLLUNSAFE_SERIALIZE 1\n"); printf("static const int32_t unsafe_serializedCount = %d;\n", serializedCount); printf("static const uint16_t unsafe_serializedData[%d] = { \n", serializedCount); for(int32_t i=0;i<serializedCount;i++) { if( (i>0) && (i%8 == 0) ) { printf(" // %d\n", i); } printf("0x%04X", serializedData[i]); // TODO check if(i != (serializedCount-1)) { printf(", "); } } printf("};\n"); #endif printf("#endif\n"); fflush(stderr); fflush(stdout); return(U_SUCCESS(errorCode)?0:1); }