X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/4388f060552cc537e71e957d32f35e9d75a61233..38fbf2fd31f5cd99b500914d6037b1d06b608645:/icuSources/tools/gennorm2/gennorm2.cpp?ds=sidebyside diff --git a/icuSources/tools/gennorm2/gennorm2.cpp b/icuSources/tools/gennorm2/gennorm2.cpp index 597300da..477bfd62 100644 --- a/icuSources/tools/gennorm2/gennorm2.cpp +++ b/icuSources/tools/gennorm2/gennorm2.cpp @@ -1,12 +1,14 @@ +// © 2016 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * -* Copyright (C) 2009-2012, International Business Machines +* Copyright (C) 2009-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* * file name: gennorm2.cpp -* encoding: US-ASCII +* encoding: UTF-8 * tab size: 8 (not used) * indentation:4 * @@ -38,8 +40,6 @@ #include "unewdata.h" #endif -#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) - U_NAMESPACE_BEGIN UBool beVerbose=FALSE, haveCopyright=TRUE; @@ -60,6 +60,7 @@ enum { SOURCEDIR, OUTPUT_FILENAME, UNICODE_VERSION, + WRITE_C_SOURCE, OPT_FAST }; @@ -71,6 +72,7 @@ static UOption options[]={ UOPTION_SOURCEDIR, UOPTION_DEF("output", 'o', UOPT_REQUIRES_ARG), UOPTION_DEF("unicode", 'u', UOPT_REQUIRES_ARG), + UOPTION_DEF("csource", '\1', UOPT_NO_ARG), UOPTION_DEF("fast", '\1', UOPT_NO_ARG) }; @@ -102,7 +104,7 @@ main(int argc, char* argv[]) { "Usage: %s [-options] infiles+ -o outputfilename\n" "\n" "Reads the infiles with normalization data and\n" - "creates a binary file (outputfilename) with the data.\n" + "creates a binary or C source file (outputfilename) with the data.\n" "\n", argv[0]); fprintf(stderr, @@ -113,9 +115,10 @@ main(int argc, char* argv[]) { "\t-u or --unicode Unicode version, followed by the version like 5.2.0\n"); fprintf(stderr, "\t-s or --sourcedir source directory, followed by the path\n" - "\t-o or --output output filename\n"); + "\t-o or --output output filename\n" + "\t --csource writes a C source file with initializers\n"); fprintf(stderr, - "\t --fast optimize the .nrm file for fast normalization,\n" + "\t --fast optimize the data for fast normalization,\n" "\t which might increase its size (Writes fully decomposed\n" "\t regular mappings instead of delta mappings.\n" "\t You should measure the runtime speed to make sure that\n" @@ -141,7 +144,7 @@ main(int argc, char* argv[]) { #else - LocalPointer builder(new Normalizer2DataBuilder(errorCode)); + LocalPointer builder(new Normalizer2DataBuilder(errorCode), errorCode); errorCode.assertSuccess(); if(options[UNICODE_VERSION].doesOccur) { @@ -176,7 +179,11 @@ main(int argc, char* argv[]) { filename.truncate(pathLength); } - builder->writeBinaryFile(options[OUTPUT_FILENAME].value); + if(options[WRITE_C_SOURCE].doesOccur) { + builder->writeCSourceFile(options[OUTPUT_FILENAME].value); + } else { + builder->writeBinaryFile(options[OUTPUT_FILENAME].value); + } return errorCode.get(); @@ -239,7 +246,7 @@ void parseFile(FILE *f, Normalizer2DataBuilder &builder) { } if(*delimiter=='=' || *delimiter=='>') { UChar uchars[Normalizer2Impl::MAPPING_LENGTH_MASK]; - int32_t length=u_parseString(delimiter+1, uchars, LENGTHOF(uchars), NULL, errorCode); + int32_t length=u_parseString(delimiter+1, uchars, UPRV_LENGTHOF(uchars), NULL, errorCode); if(errorCode.isFailure()) { fprintf(stderr, "gennorm2 error: parsing mapping string from %s\n", line); exit(errorCode.reset());