From 21b5ebc90294a55088fd0a06af03c54f3b14d7b7 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Sat, 17 Dec 2011 05:03:26 +0000 Subject: [PATCH] ICU-8972 genprops: use ppucd.txt for the age property; some cleanup X-SVN-Rev: 31141 --- tools/unicode/c/genprops/corepropswriter.cpp | 16 +-- tools/unicode/c/genprops/genprops.cpp | 14 +-- tools/unicode/c/genprops/genprops.h | 17 +--- tools/unicode/c/genprops/props2writer.cpp | 100 ++++++------------- 4 files changed, 48 insertions(+), 99 deletions(-) diff --git a/tools/unicode/c/genprops/corepropswriter.cpp b/tools/unicode/c/genprops/corepropswriter.cpp index 0341fdf24a..3b6784ca6b 100644 --- a/tools/unicode/c/genprops/corepropswriter.cpp +++ b/tools/unicode/c/genprops/corepropswriter.cpp @@ -251,22 +251,20 @@ static UTrie2 *pTrie=NULL; /* -------------------------------------------------------------------------- */ -U_CFUNC void +static void initStore() { UErrorCode errorCode=U_ZERO_ERROR; pTrie=utrie2_open(0, 0, &errorCode); if(U_FAILURE(errorCode)) { - fprintf(stderr, "error: utrie2_open() failed - %s\n", u_errorName(errorCode)); + fprintf(stderr, "genprops error: corepropswriter utrie2_open() failed - %s\n", + u_errorName(errorCode)); exit(errorCode); } - - initAdditionalProperties(); } -U_CFUNC void +static void exitStore() { utrie2_close(pTrie); - exitAdditionalProperties(); } /* store a character's properties ------------------------------------------- */ @@ -419,7 +417,8 @@ generateData(const char *dataDir, UBool csource) { if(csource) { /* write .c file for hardcoded data */ - FILE *f=usrc_create(dataDir, "uchar_props_data.h"); + FILE *f=usrc_createFromGenerator(dataDir, "uchar_props_data.h", + "icu/tools/src/unicode/c/genprops/corepropswriter.cpp"); if(f!=NULL) { fputs("#ifndef INCLUDED_FROM_UCHAR_C\n" "# error This file must be #included from uchar.c only.\n" @@ -491,6 +490,9 @@ generateData(const char *dataDir, UBool csource) { class CorePropsWriter : public PropsWriter { public: + CorePropsWriter() { initStore(); } + virtual ~CorePropsWriter() { exitStore(); } + virtual void setUnicodeVersion(const UVersionInfo version); virtual void setProps(const UniProps &, const UnicodeSet &newValues, UErrorCode &errorCode); }; diff --git a/tools/unicode/c/genprops/genprops.cpp b/tools/unicode/c/genprops/genprops.cpp index dfe841f8c1..930f9bdaf4 100644 --- a/tools/unicode/c/genprops/genprops.cpp +++ b/tools/unicode/c/genprops/genprops.cpp @@ -50,6 +50,7 @@ U_NAMESPACE_USE UBool beVerbose=FALSE, haveCopyright=TRUE; +PropsWriter::~PropsWriter() {} void PropsWriter::setUnicodeVersion(const UVersionInfo version) {} void PropsWriter::setProps(const UniProps &, const UnicodeSet &, UErrorCode &) {} @@ -142,8 +143,6 @@ main(int argc, char* argv[]) { destDir=options[DESTDIR].value; /* initialize */ - initStore(); - IcuToolErrorCode errorCode("genprops"); LocalPointer corePropsWriter(createCorePropsWriter(errorCode)); LocalPointer props2Writer(createProps2Writer(errorCode)); @@ -163,7 +162,6 @@ main(int argc, char* argv[]) { } PreparsedUCD::LineType lineType; UnicodeSet newValues; - int i=0; while((lineType=ppucd.readLine(errorCode))!=PreparsedUCD::NO_LINE) { if(ppucd.lineHasPropertyValues()) { const UniProps *props=ppucd.getProps(newValues, errorCode); @@ -172,9 +170,13 @@ main(int argc, char* argv[]) { const UVersionInfo &version=ppucd.getUnicodeVersion(); corePropsWriter->setUnicodeVersion(version); } - ++i; + if(errorCode.isFailure()) { + fprintf(stderr, + "genprops: error parsing or setting values from ppucd.txt line %ld - %s\n", + (long)ppucd.getLineNumber(), errorCode.errorName()); + return errorCode.reset(); + } } - printf("*** parsed %d lines from ppucd.txt\n", i); if(argc>=2) { suffix=argv[1]; @@ -207,8 +209,6 @@ main(int argc, char* argv[]) { generateData(destDir, options[CSOURCE].doesOccur); } - exitStore(); - u_cleanup(); return errorCode; } diff --git a/tools/unicode/c/genprops/genprops.h b/tools/unicode/c/genprops/genprops.h index d450606ec6..630dd5e166 100644 --- a/tools/unicode/c/genprops/genprops.h +++ b/tools/unicode/c/genprops/genprops.h @@ -28,6 +28,7 @@ class PropsWriter { public: + virtual ~PropsWriter(); virtual void setUnicodeVersion(const UVersionInfo version); virtual void setProps(const UniProps &props, const UnicodeSet &newValues, UErrorCode &errorCode); // virtual writeCSourceFile(icusrcroot); @@ -51,9 +52,6 @@ U_CFUNC UBool beVerbose, haveCopyright; U_CFUNC const char *const genCategoryNames[]; -/* properties vectors in props2.cpp */ -U_CFUNC UPropsVectors *pv; - /* prototypes */ U_CFUNC void writeUCDFilename(char *basename, const char *filename, const char *suffix); @@ -64,12 +62,6 @@ isToken(const char *token, const char *s); U_CFUNC int32_t getTokenIndex(const char *const tokens[], int32_t countTokens, const char *s); -U_CFUNC void -initStore(void); - -U_CFUNC void -exitStore(void); - U_CFUNC uint32_t makeProps(Props *p); @@ -85,13 +77,6 @@ repeatProps(uint32_t first, uint32_t last, uint32_t props); U_CFUNC void generateData(const char *dataDir, UBool csource); -/* props2.c */ -U_CFUNC void -initAdditionalProperties(void); - -U_CFUNC void -exitAdditionalProperties(void); - U_CFUNC void generateAdditionalProperties(char *filename, const char *suffix, UErrorCode *pErrorCode); diff --git a/tools/unicode/c/genprops/props2writer.cpp b/tools/unicode/c/genprops/props2writer.cpp index b776fcb0c4..c6e498d36a 100644 --- a/tools/unicode/c/genprops/props2writer.cpp +++ b/tools/unicode/c/genprops/props2writer.cpp @@ -38,7 +38,7 @@ U_NAMESPACE_USE /* data --------------------------------------------------------------------- */ static UTrie2 *newTrie; -UPropsVectors *pv; +static UPropsVectors *pv; static UnicodeString *scriptExtensions; @@ -77,11 +77,6 @@ parseTwoFieldFile(char *filename, char *basename, } } -static void U_CALLCONV -ageLineFn(void *context, - char *fields[][2], int32_t fieldCount, - UErrorCode *pErrorCode); - static void U_CALLCONV scriptExtensionsLineFn(void *context, char *fields[][2], int32_t fieldCount, @@ -417,18 +412,19 @@ parseBinariesFile(char *filename, char *basename, const char *suffix, /* -------------------------------------------------------------------------- */ -U_CFUNC void +static void initAdditionalProperties() { UErrorCode errorCode=U_ZERO_ERROR; pv=upvec_open(UPROPS_VECTOR_WORDS, &errorCode); if(U_FAILURE(errorCode)) { - fprintf(stderr, "error: upvec_open() failed - %s\n", u_errorName(errorCode)); + fprintf(stderr, "genprops error: props2writer upvec_open() failed - %s\n", + u_errorName(errorCode)); exit(errorCode); } scriptExtensions=new UnicodeString; } -U_CFUNC void +static void exitAdditionalProperties() { utrie2_close(newTrie); upvec_close(pv); @@ -446,8 +442,6 @@ generateAdditionalProperties(char *filename, const char *suffix, UErrorCode *pEr /* add Han numeric types & values */ parseMultiFieldFile(filename, basename, "DerivedNumericValues", suffix, 2, numericLineFn, pErrorCode); - parseTwoFieldFile(filename, basename, "DerivedAge", suffix, ageLineFn, pErrorCode); - parseSingleEnumFile(filename, basename, suffix, &scriptSingleEnum, pErrorCode); parseTwoFieldFile(filename, basename, "ScriptExtensions", suffix, scriptExtensionsLineFn, pErrorCode); @@ -524,59 +518,6 @@ for(int32_t c=0; c<=0x10ffff; ++c) { } } -/* DerivedAge.txt ----------------------------------------------------------- */ - -static void U_CALLCONV -ageLineFn(void *context, - char *fields[][2], int32_t fieldCount, - UErrorCode *pErrorCode) { - char *s, *numberLimit; - uint32_t value, start, end, version; - - u_parseCodePointRange(fields[0][0], &start, &end, pErrorCode); - if(U_FAILURE(*pErrorCode)) { - fprintf(stderr, "genprops: syntax error in DerivedAge.txt field 0 at %s\n", fields[0][0]); - exit(*pErrorCode); - } - - /* ignore "unassigned" (the default is already set to 0.0) */ - s=(char *)u_skipWhitespace(fields[1][0]); - if(0==uprv_strncmp(s, "unassigned", 10) || 0==uprv_strncmp(s, "Unassigned", 10)) { - return; - } - - /* parse version number */ - value=(uint32_t)uprv_strtoul(s, &numberLimit, 10); - if(s==numberLimit || value==0 || value>15 || (*numberLimit!='.' && *numberLimit!=' ' && *numberLimit!='\t' && *numberLimit!=0)) { - fprintf(stderr, "genprops: syntax error in DerivedAge.txt field 1 at %s\n", fields[1][0]); - *pErrorCode=U_PARSE_ERROR; - exit(U_PARSE_ERROR); - } - version=value<<4; - - /* parse minor version number */ - if(*numberLimit=='.') { - s=(char *)u_skipWhitespace(numberLimit+1); - value=(uint32_t)uprv_strtoul(s, &numberLimit, 10); - if(s==numberLimit || value>15 || (*numberLimit!=' ' && *numberLimit!='\t' && *numberLimit!=0)) { - fprintf(stderr, "genprops: syntax error in DerivedAge.txt field 1 at %s\n", fields[1][0]); - *pErrorCode=U_PARSE_ERROR; - exit(U_PARSE_ERROR); - } - version|=value; - } - - if(start==0 && end==0x10ffff) { - /* Also set bits for initialValue and errorValue. */ - end=UPVEC_MAX_CP; - } - upvec_setValue(pv, start, end, 0, version<15 || props.age[1]>15 || props.age[2]!=0 || props.age[3]!=0) { + char buffer[U_MAX_VERSION_STRING_LENGTH]; + u_versionToString(props.age, buffer); + fprintf(stderr, "genprops error: age %s cannot be encoded\n", buffer); + errorCode=U_ILLEGAL_ARGUMENT_ERROR; + return; } + uint32_t version=(props.age[0]<<4)|props.age[1]; + upvec_setValue(pv, start, end, + 0, version<