X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..d5d484b0fbe924d3663b177965538d517ee412c1:/icuSources/tools/genrb/genrb.c diff --git a/icuSources/tools/genrb/genrb.c b/icuSources/tools/genrb/genrb.c index 827e3302..a73febad 100644 --- a/icuSources/tools/genrb/genrb.c +++ b/icuSources/tools/genrb/genrb.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2003, International Business Machines +* Copyright (C) 1998-2006, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -17,17 +17,18 @@ */ #include "genrb.h" +#include "unicode/uclean.h" /* Protos */ static void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir, const char *packageName, UErrorCode *status); -static char *make_res_filename(const char *filename, const char *outputDir, +static char *make_res_filename(const char *filename, const char *outputDir, const char *packageName, UErrorCode *status); /* File suffixes */ #define RES_SUFFIX ".res" #define COL_SUFFIX ".col" -static char theCurrentFileName[4096]; +static char theCurrentFileName[2048]; const char *gCurrentFileName = theCurrentFileName; #ifdef XP_MAC_CONSOLE #include @@ -48,8 +49,7 @@ enum COPYRIGHT, PACKAGE_NAME, BUNDLE_NAME, - WRITE_XML, - TOUCHFILE, + WRITE_XLIFF, STRICT, NO_BINARY_COLLATION, /*added by Jing*/ @@ -70,23 +70,20 @@ UOption options[]={ UOPTION_COPYRIGHT, UOPTION_PACKAGE_NAME, UOPTION_BUNDLE_NAME, - UOPTION_DEF( "write-xml", 'x', UOPT_NO_ARG), - UOPTION_DEF( "touchfile", 't', UOPT_NO_ARG), + UOPTION_DEF( "write-xliff", 'x', UOPT_OPTIONAL_ARG), UOPTION_DEF( "strict", 'k', UOPT_NO_ARG), /* 14 */ UOPTION_DEF( "noBinaryCollation", 'C', UOPT_NO_ARG),/* 15 */ - /*added by Jing*/ UOPTION_DEF( "language", 'l', UOPT_REQUIRES_ARG) }; static UBool write_java = FALSE; -static UBool write_xml = FALSE; -static UBool touchfile = FALSE; +static UBool write_xliff = FALSE; static const char* outputEnc =""; static const char* gPackageName=NULL; static const char* bundleName=NULL; /*added by Jing*/ static const char* language = NULL; - +static const char* xliffOutputFileName = NULL; int main(int argc, char* argv[]) @@ -97,7 +94,7 @@ main(int argc, const char *inputDir = NULL; const char *encoding = ""; int i; - + U_MAIN_INIT_ARGS(argc, argv); argc = u_parseArgs(argc, argv, (int32_t)(sizeof(options)/sizeof(options[0])), options); @@ -145,16 +142,14 @@ main(int argc, "\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n" "\t defaults to ASCII and \\uXXXX format.\n" "\t-p or --package-name For ICU4J: package name for writing the ListResourceBundle for ICU4J,\n" - "\t defaults to com.ibm.icu.impl.data\n" - "\t For ICU4C: Package name on output. Specfiying\n" - "\t 'ICUDATA' defaults to the current ICU4C data name.\n"); + "\t defaults to com.ibm.icu.impl.data\n"); fprintf(stderr, "\t-b or --bundle-name bundle name for writing the ListResourceBundle for ICU4J,\n" "\t defaults to LocaleElements\n" - "\t-x or --write-xml write a XML file for the resource bundle.\n" + "\t-x or --write-xliff write a XLIFF file for the resource bundle. Followed by an optional output file name.\n" "\t-k or --strict use pedantic parsing of syntax\n" /*added by Jing*/ - "\t-l or --language language code compliant with ISO 639.\n"); + "\t-l or --language For XLIFF: language code compliant with ISO 639.\n"); return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } @@ -192,15 +187,6 @@ main(int argc, } } - if(options[TOUCHFILE].doesOccur) { - if(gPackageName == NULL) { - fprintf(stderr, "%s: Don't use touchfile (-t) option with no package.\n", - argv[0]); - return -1; - } - touchfile = TRUE; - } - if(options[ENCODING].doesOccur) { encoding = options[ENCODING].value; } @@ -208,6 +194,18 @@ main(int argc, if(options[ICUDATADIR].doesOccur) { u_setDataDirectory(options[ICUDATADIR].value); } + /* Initialize ICU */ + u_init(&status); + if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) { + /* Note: u_init() will try to open ICU property data. + * failures here are expected when building ICU from scratch. + * ignore them. + */ + fprintf(stderr, "%s: can not initialize ICU. status = %s\n", + argv[0], u_errorName(status)); + exit(1); + } + status = U_ZERO_ERROR; if(options[WRITE_JAVA].doesOccur) { write_java = TRUE; outputEnc = options[WRITE_JAVA].value; @@ -217,8 +215,11 @@ main(int argc, bundleName = options[BUNDLE_NAME].value; } - if(options[WRITE_XML].doesOccur) { - write_xml = TRUE; + if(options[WRITE_XLIFF].doesOccur) { + write_xliff = TRUE; + if(options[WRITE_XLIFF].value != NULL){ + xliffOutputFileName = options[WRITE_XLIFF].value; + } } if(options[NO_BINARY_COLLATION].doesOccur) { @@ -226,7 +227,7 @@ main(int argc, } else { initParser(TRUE); } - + /*added by Jing*/ if(options[LANGUAGE].doesOccur) { language = options[LANGUAGE].value; @@ -236,7 +237,7 @@ main(int argc, for(i = 1; i < argc; ++i) { status = U_ZERO_ERROR; arg = getLongPathname(argv[i]); - + if (inputDir) { uprv_strcpy(theCurrentFileName, inputDir); uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING); @@ -265,10 +266,10 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch char *inputDirBuf = NULL; char outputFileName[256]; - + int32_t dirlen = 0; int32_t filelen = 0; - + if (status==NULL || U_FAILURE(*status)) { return; } @@ -284,12 +285,12 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch openFileName[0] = '\0'; if (filenameBegin != NULL) { /* - * When a filename ../../../data/root.txt is specified, + * When a filename ../../../data/root.txt is specified, * we presume that the input directory is ../../../data * This is very important when the resource file includes * another file, like UCARules.txt or thaidict.brk. */ - int32_t filenameSize = filenameBegin - filename + 1; + int32_t filenameSize = (int32_t)(filenameBegin - filename + 1); inputDirBuf = uprv_strncpy((char *)uprv_malloc(filenameSize), filename, filenameSize); /* test for NULL */ @@ -316,7 +317,7 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch openFileName[0] = '\0'; /* - * append the input dir to openFileName if the first char in + * append the input dir to openFileName if the first char in * filename is not file seperation char and the last char input directory is not '.'. * This is to support : * genrb -s. /home/icu/data @@ -341,16 +342,16 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch } uprv_strcpy(openFileName, inputDir); - + } } uprv_strcat(openFileName, filename); ucbuf = ucbuf_open(openFileName, &cp,getShowWarning(),TRUE, status); - + if(*status == U_FILE_ACCESS_ERROR) { - + fprintf(stderr, "couldn't open file %s\n", openFileName == NULL ? filename : openFileName); goto finish; } @@ -359,11 +360,11 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch goto finish; } /* auto detected popular encodings? */ - if (cp!=NULL) { + if (cp!=NULL && isVerbose()) { printf("autodetected encoding %s\n", cp); } /* Parse the data into an SRBRoot */ - data = parse(ucbuf, inputDir, status); + data = parse(ucbuf, inputDir, outputDir, status); if (data == NULL || U_FAILURE(*status)) { fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename,u_errorName(*status)); @@ -372,45 +373,14 @@ processFile(const char *filename, const char *cp, const char *inputDir, const ch /* Determine the target rb filename */ rbname = make_res_filename(filename, outputDir, packageName, status); - if(touchfile == TRUE) { - FileStream *q; - char msg[1024]; - char *tfname = NULL; - - tfname = make_res_filename(filename, outputDir, NULL, status); - - if(U_FAILURE(*status)) - { - fprintf(stderr, "Error writing touchfile for \"%s\"\n", filename); - *status = U_FILE_ACCESS_ERROR; - } else { - uprv_strcat(tfname, ".res"); - sprintf(msg, "This empty file tells nmake that %s in package %s has been updated.\n", - filename, packageName); - - q = T_FileStream_open(tfname, "w"); - if(q == NULL) - { - fprintf(stderr, "Error writing touchfile \"%s\"\n", tfname); - *status = U_FILE_ACCESS_ERROR; - } - else - { - T_FileStream_write(q, msg, uprv_strlen(msg)); - T_FileStream_close(q); - } - uprv_free(tfname); - } - - } if(U_FAILURE(*status)) { fprintf(stderr, "couldn't make the res fileName for bundle %s. Error:%s\n", filename,u_errorName(*status)); goto finish; } if(write_java== TRUE){ bundle_write_java(data,outputDir,outputEnc, outputFileName, sizeof(outputFileName),packageName,bundleName,status); - }else if(write_xml ==TRUE){ - bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, packageName,status); + }else if(write_xliff ==TRUE){ + bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, xliffOutputFileName,status); }else{ /* Write the data to the file */ bundle_write(data, outputDir, packageName, outputFileName, sizeof(outputFileName), status); @@ -457,7 +427,7 @@ make_res_filename(const char *filename, if(packageName != NULL) { - pkgLen = 1 + uprv_strlen(packageName); + pkgLen = (int32_t)(1 + uprv_strlen(packageName)); } /* setup */