ICU-8972 genprops: use ppucd.txt for the age property; some cleanup

X-SVN-Rev: 31141
This commit is contained in:
Markus Scherer 2011-12-17 05:03:26 +00:00
parent de830ac709
commit 21b5ebc902
4 changed files with 48 additions and 99 deletions

View File

@ -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);
};

View File

@ -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<PropsWriter> corePropsWriter(createCorePropsWriter(errorCode));
LocalPointer<PropsWriter> 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;
}

View File

@ -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);

View File

@ -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<<UPROPS_AGE_SHIFT, UPROPS_AGE_MASK, pErrorCode);
if(U_FAILURE(*pErrorCode)) {
fprintf(stderr, "genprops error: unable to set character age: %s\n", u_errorName(*pErrorCode));
exit(*pErrorCode);
}
}
/* ScriptExtensions.txt ----------------------------------------------------- */
static void U_CALLCONV
@ -940,21 +881,42 @@ writeAdditionalData(FILE *f, uint8_t *p, int32_t capacity, int32_t indexes[UPROP
class Props2Writer : public PropsWriter {
public:
Props2Writer() { initAdditionalProperties(); }
virtual ~Props2Writer() { exitAdditionalProperties(); }
virtual void setProps(const UniProps &, const UnicodeSet &newValues, UErrorCode &errorCode);
};
void
Props2Writer::setProps(const UniProps &props, const UnicodeSet &newValues, UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) { return; }
UChar32 start=props.start;
UChar32 end=props.end;
if(start==0 && end==0x10ffff) {
// Also set bits for initialValue and errorValue.
end=UPVEC_MAX_CP;
}
if(newValues.contains(UCHAR_DECOMPOSITION_TYPE)) {
upvec_setValue(pv, props.start, props.end,
upvec_setValue(pv, start, end,
2, (uint32_t)props.getIntProp(UCHAR_DECOMPOSITION_TYPE), UPROPS_DT_MASK,
&errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops error: unable to set decomposition type: %s\n",
u_errorName(errorCode));
exit(errorCode);
}
if(newValues.contains(UCHAR_AGE)) {
if(props.age[0]>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<<UPROPS_AGE_SHIFT, UPROPS_AGE_MASK,
&errorCode);
}
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops error: unable to set values for %04lX..%04lX: %s\n",
(long)start, (long)end, u_errorName(errorCode));
}
}