mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 12:40:02 +00:00
ICU-2329 check for invariant characters in converter names and aliases; also fix bugs in options handling
X-SVN-Rev: 12589
This commit is contained in:
parent
5061b43683
commit
29ceab3f7b
1 changed files with 40 additions and 24 deletions
|
@ -156,7 +156,7 @@ static uint16_t
|
|||
addConverter(const char *converter);
|
||||
|
||||
static char *
|
||||
allocString(StringBlock *block, uint32_t length);
|
||||
allocString(StringBlock *block, const char *s, int32_t length);
|
||||
|
||||
static uint16_t
|
||||
addToKnownAliases(const char *alias);
|
||||
|
@ -213,7 +213,7 @@ main(int argc, char* argv[]) {
|
|||
U_MAIN_INIT_ARGS(argc, argv);
|
||||
|
||||
/* preset then read command line options */
|
||||
options[3].value=options[4].value=u_getDataDirectory();
|
||||
options[DESTDIR].value=options[SOURCEDIR].value=u_getDataDirectory();
|
||||
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
|
||||
|
||||
/* error handling, printing usage message */
|
||||
|
@ -243,10 +243,12 @@ main(int argc, char* argv[]) {
|
|||
if(argc>=2) {
|
||||
path=argv[1];
|
||||
} else {
|
||||
path=options[4].value;
|
||||
path=options[SOURCEDIR].value;
|
||||
if(path!=NULL && *path!=0) {
|
||||
char *end = pathBuf+uprv_strlen(pathBuf);
|
||||
char *end;
|
||||
|
||||
uprv_strcpy(pathBuf, path);
|
||||
end = uprv_strchr(pathBuf, 0);
|
||||
if(*(end-1)!=U_FILE_SEP_CHAR) {
|
||||
*(end++)=U_FILE_SEP_CHAR;
|
||||
}
|
||||
|
@ -274,8 +276,8 @@ main(int argc, char* argv[]) {
|
|||
T_FileStream_close(in);
|
||||
|
||||
/* create the output file */
|
||||
out=udata_create(options[3].value, DATA_TYPE, U_ICUDATA_NAME "_" DATA_NAME, &dataInfo,
|
||||
options[2].doesOccur ? U_COPYRIGHT_STRING : NULL, &errorCode);
|
||||
out=udata_create(options[DESTDIR].value, DATA_TYPE, U_ICUDATA_NAME "_" DATA_NAME, &dataInfo,
|
||||
options[COPYRIGHT].doesOccur ? U_COPYRIGHT_STRING : NULL, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
fprintf(stderr, "gencnval: unable to open output file - error %s\n", u_errorName(errorCode));
|
||||
exit(errorCode);
|
||||
|
@ -307,7 +309,7 @@ parseFile(FileStream *in) {
|
|||
/* Add the empty tag, which is for untagged aliases */
|
||||
getTagNumber("", 0);
|
||||
getTagNumber(ALL_TAG_STR, 3);
|
||||
allocString(&stringBlock, 1);
|
||||
allocString(&stringBlock, "", 0);
|
||||
|
||||
/* read the list of aliases */
|
||||
while (validParse) {
|
||||
|
@ -410,9 +412,7 @@ parseLine(const char *line) {
|
|||
|
||||
/* store the converter name */
|
||||
length=(uint16_t)(limit-start);
|
||||
converter=allocString(&stringBlock, length+1);
|
||||
uprv_memcpy(converter, line+start, length);
|
||||
converter[length]=0;
|
||||
converter=allocString(&stringBlock, line+start, length);
|
||||
|
||||
/* add the converter to the converter table */
|
||||
cnv=addConverter(converter);
|
||||
|
@ -448,9 +448,7 @@ parseLine(const char *line) {
|
|||
addAlias(alias, ALL_TAG_NUM, cnv, TRUE);
|
||||
}
|
||||
else {
|
||||
alias=allocString(&stringBlock, length+1);
|
||||
uprv_memcpy(alias, line+start, length);
|
||||
alias[length]=0;
|
||||
alias=allocString(&stringBlock, line+start, length);
|
||||
addAlias(alias, ALL_TAG_NUM, cnv, FALSE);
|
||||
}
|
||||
addToKnownAliases(alias);
|
||||
|
@ -526,9 +524,7 @@ getTagNumber(const char *tag, uint16_t tagLen) {
|
|||
}
|
||||
|
||||
/* allocate a new entry in the tag table */
|
||||
atag = allocString(&tagBlock, tagLen + 1);
|
||||
uprv_memcpy(atag, tag, tagLen);
|
||||
atag[tagLen] = 0;
|
||||
atag = allocString(&tagBlock, tag, tagLen);
|
||||
|
||||
if (standardTagsUsed) {
|
||||
fprintf(stderr, "error(line %d): Tag \"%s\" is not declared at the beginning of the alias table.\n",
|
||||
|
@ -557,7 +553,6 @@ static void
|
|||
addOfficialTaggedStandards(char *line, int32_t lineLen) {
|
||||
char *atag;
|
||||
char *tag = strchr(line, '{') + 1;
|
||||
uint16_t tagSize;
|
||||
static const char WHITESPACE[] = " \t";
|
||||
|
||||
if (tagCount > UCNV_NUM_RESERVED_TAGS) {
|
||||
|
@ -570,11 +565,8 @@ addOfficialTaggedStandards(char *line, int32_t lineLen) {
|
|||
while (tag != NULL) {
|
||||
/* printf("Adding original tag \"%s\"\n", tag);*/
|
||||
|
||||
tagSize = strlen(tag) + 1;
|
||||
/* allocate a new entry in the tag table */
|
||||
|
||||
atag = allocString(&tagBlock, tagSize);
|
||||
uprv_memcpy(atag, tag, tagSize);
|
||||
atag = allocString(&tagBlock, tag, -1);
|
||||
|
||||
/* add the tag to the tag table */
|
||||
tags[tagCount++].tag = (uint16_t)((atag - tagStore) >> 1);
|
||||
|
@ -990,16 +982,40 @@ writeAliasTable(UNewDataMemory *out) {
|
|||
}
|
||||
|
||||
static char *
|
||||
allocString(StringBlock *block, uint32_t length) {
|
||||
/* The (length&1) is used to keep the addresses on a 16-bit boundary */
|
||||
uint32_t top=block->top + length + (length&1);
|
||||
allocString(StringBlock *block, const char *s, int32_t length) {
|
||||
uint32_t top;
|
||||
char *p;
|
||||
|
||||
if(length<0) {
|
||||
length=uprv_strlen(s);
|
||||
}
|
||||
|
||||
/*
|
||||
* add 1 for the terminating NUL
|
||||
* and round up (+1 &~1)
|
||||
* to keep the addresses on a 16-bit boundary
|
||||
*/
|
||||
top=block->top + (uint32_t)((length + 1 + 1) & ~1);
|
||||
|
||||
if(top >= block->max) {
|
||||
fprintf(stderr, "error(line %d): out of memory\n", lineNum);
|
||||
exit(U_MEMORY_ALLOCATION_ERROR);
|
||||
}
|
||||
|
||||
/* get the pointer and copy the string */
|
||||
p = block->store + block->top;
|
||||
uprv_memcpy(p, s, length);
|
||||
p[length] = 0; /* NUL-terminate it */
|
||||
if((length & 1) == 0) {
|
||||
p[length + 1] = 0; /* set the padding byte */
|
||||
}
|
||||
|
||||
/* check for invariant characters now that we have a NUL-terminated string for easy output */
|
||||
if(!uprv_isInvariantString(p, length)) {
|
||||
fprintf(stderr, "error(line %d): the name %s contains not just invariant characters\n", lineNum, p);
|
||||
exit(U_INVALID_TABLE_FORMAT);
|
||||
}
|
||||
|
||||
block->top = top;
|
||||
return p;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue