diff options
Diffstat (limited to 'Build/source/libs/icu-xetex/tools/genrb/parse.c')
-rw-r--r-- | Build/source/libs/icu-xetex/tools/genrb/parse.c | 140 |
1 files changed, 118 insertions, 22 deletions
diff --git a/Build/source/libs/icu-xetex/tools/genrb/parse.c b/Build/source/libs/icu-xetex/tools/genrb/parse.c index 1de849fe68a..b4aa2caf0e1 100644 --- a/Build/source/libs/icu-xetex/tools/genrb/parse.c +++ b/Build/source/libs/icu-xetex/tools/genrb/parse.c @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 1998-2005, International Business Machines +* Copyright (C) 1998-2006, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -83,6 +83,8 @@ static UCHARBUF *buffer; static struct SRBRoot *bundle; static const char *inputdir; static uint32_t inputdirLength; +static const char *outputdir; +static uint32_t outputdirLength; static UBool gMakeBinaryCollation = TRUE; @@ -203,14 +205,14 @@ expect(enum ETokenType expectedToken, struct UString **tokenValue, struct UStrin enum ETokenType token = getToken(tokenValue, comment, &line, status); - if (U_FAILURE(*status)) + if (linenumber != NULL) { - return; + *linenumber = line; } - if (linenumber != NULL) + if (U_FAILURE(*status)) { - *linenumber = line; + return; } if (token != expectedToken) @@ -473,8 +475,71 @@ parseTransliterator(char *tag, uint32_t startline, const struct UString* comment return result; } +static struct SResource* dependencyArray = NULL; static struct SResource * +parseDependency(char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) +{ + struct SResource *result = NULL; + struct SResource *elem = NULL; + struct UString *tokenValue; + uint32_t line; + char filename[256] = { '\0' }; + char cs[128] = { '\0' }; + + expect(TOK_STRING, &tokenValue, NULL, &line, status); + + if(isVerbose()){ + printf(" %s at line %i \n", (tag == NULL) ? "(null)" : tag, (int)startline); + } + + if (U_FAILURE(*status)) + { + return NULL; + } + /* make the filename including the directory */ + if (outputdir != NULL) + { + uprv_strcat(filename, outputdir); + + if (outputdir[outputdirLength - 1] != U_FILE_SEP_CHAR) + { + uprv_strcat(filename, U_FILE_SEP_STRING); + } + } + + u_UCharsToChars(tokenValue->fChars, cs, tokenValue->fLength); + + if (U_FAILURE(*status)) + { + return NULL; + } + uprv_strcat(filename, cs); + if(!T_FileStream_file_exists(filename)){ + if(isStrict()){ + error(line, "The dependency file %s does not exist. Please make sure it exists.\n",filename); + }else{ + warning(line, "The dependency file %s does not exist. Please make sure it exists.\n",filename); + } + } + if(dependencyArray==NULL){ + dependencyArray = array_open(bundle, "%%DEPENDENCY", NULL, status); + } + if(tag!=NULL){ + result = string_open(bundle, tag, tokenValue->fChars, tokenValue->fLength, comment, status); + } + elem = string_open(bundle, NULL, tokenValue->fChars, tokenValue->fLength, comment, status); + + array_add(dependencyArray, elem, status); + + if (U_FAILURE(*status)) + { + return NULL; + } + expect(TOK_CLOSE_BRACE, NULL, NULL, NULL, status); + return result; +} +static struct SResource * parseString(char *tag, uint32_t startline, const struct UString* comment, UErrorCode *status) { struct UString *tokenValue; @@ -1474,6 +1539,7 @@ U_STRING_DECL(k_type_string, "string", 6); U_STRING_DECL(k_type_binary, "binary", 6); U_STRING_DECL(k_type_bin, "bin", 3); U_STRING_DECL(k_type_table, "table", 5); +U_STRING_DECL(k_type_table_no_fallback, "table(nofallback)", 17); U_STRING_DECL(k_type_int, "int", 3); U_STRING_DECL(k_type_integer, "integer", 7); U_STRING_DECL(k_type_array, "array", 5); @@ -1487,6 +1553,7 @@ U_STRING_DECL(k_type_reserved, "reserved", 8); U_STRING_DECL(k_type_plugin_uca_rules, "process(uca_rules)", 18); U_STRING_DECL(k_type_plugin_collation, "process(collation)", 18); U_STRING_DECL(k_type_plugin_transliterator, "process(transliterator)", 23); +U_STRING_DECL(k_type_plugin_dependency, "process(dependency)", 19); typedef enum EResourceType { @@ -1494,6 +1561,7 @@ typedef enum EResourceType RT_STRING, RT_BINARY, RT_TABLE, + RT_TABLE_NO_FALLBACK, RT_INTEGER, RT_ARRAY, RT_ALIAS, @@ -1503,6 +1571,7 @@ typedef enum EResourceType RT_PROCESS_UCA_RULES, RT_PROCESS_COLLATION, RT_PROCESS_TRANSLITERATOR, + RT_PROCESS_DEPENDENCY, RT_RESERVED } EResourceType; @@ -1515,6 +1584,7 @@ static struct { {"string", k_type_string, parseString}, {"binary", k_type_binary, parseBinary}, {"table", k_type_table, parseTable}, + {"table(nofallback)", k_type_table_no_fallback, NULL}, /* parseFunction will never be called */ {"integer", k_type_integer, parseInteger}, {"array", k_type_array, parseArray}, {"alias", k_type_alias, parseAlias}, @@ -1522,8 +1592,9 @@ static struct { {"import", k_type_import, parseImport}, {"include", k_type_include, parseInclude}, {"process(uca_rules)", k_type_plugin_uca_rules, parseUCARules}, - {"process(collation)", k_type_plugin_collation, NULL}, + {"process(collation)", k_type_plugin_collation, NULL /* not implemented yet */}, {"process(transliterator)", k_type_plugin_transliterator, parseTransliterator}, + {"process(dependency)", k_type_plugin_dependency, parseDependency}, {"reserved", NULL, NULL} }; @@ -1535,6 +1606,7 @@ void initParser(UBool makeBinaryCollation) U_STRING_INIT(k_type_binary, "binary", 6); U_STRING_INIT(k_type_bin, "bin", 3); U_STRING_INIT(k_type_table, "table", 5); + U_STRING_INIT(k_type_table_no_fallback, "table(nofallback)", 17); U_STRING_INIT(k_type_int, "int", 3); U_STRING_INIT(k_type_integer, "integer", 7); U_STRING_INIT(k_type_array, "array", 5); @@ -1547,6 +1619,8 @@ void initParser(UBool makeBinaryCollation) U_STRING_INIT(k_type_plugin_uca_rules, "process(uca_rules)", 18); U_STRING_INIT(k_type_plugin_collation, "process(collation)", 18); U_STRING_INIT(k_type_plugin_transliterator, "process(transliterator)", 23); + U_STRING_INIT(k_type_plugin_dependency, "process(dependency)", 19); + for (i = 0; i < MAX_LOOKAHEAD + 1; i++) { ustr_init(&lookahead[i].value); @@ -1554,6 +1628,10 @@ void initParser(UBool makeBinaryCollation) gMakeBinaryCollation = makeBinaryCollation; } +static U_INLINE UBool isTable(enum EResourceType type) { + return (UBool)(type==RT_TABLE || type==RT_TABLE_NO_FALLBACK); +} + static enum EResourceType parseResourceType(UErrorCode *status) { @@ -1572,7 +1650,8 @@ parseResourceType(UErrorCode *status) *status = U_ZERO_ERROR; /* Search for normal types */ - for (result = RT_UNKNOWN+1; result < RT_RESERVED; result++) { + result=RT_UNKNOWN; + while (++result < RT_RESERVED) { if (u_strcmp(tokenValue->fChars, gResourceTypes[result].nameUChars) == 0) { break; } @@ -1595,6 +1674,7 @@ parseResourceType(UErrorCode *status) return result; } +/* parse a non-top-level resource */ static struct SResource * parseResource(char *tag, const struct UString *comment, UErrorCode *status) { @@ -1706,6 +1786,10 @@ parseResource(char *tag, const struct UString *comment, UErrorCode *status) } /* printf("Type guessed as %s\n", resourceNames[resType]); */ + } else if(resType == RT_TABLE_NO_FALLBACK) { + *status = U_INVALID_FORMAT_ERROR; + error(startline, "error: %s resource type not valid except on top bundle level", gResourceTypes[resType].nameChars); + return NULL; } /* We should now know what we need to parse next, so call the appropriate parser @@ -1722,8 +1806,9 @@ parseResource(char *tag, const struct UString *comment, UErrorCode *status) return NULL; } +/* parse the top-level resource */ struct SRBRoot * -parse(UCHARBUF *buf, const char *currentInputDir, UErrorCode *status) +parse(UCHARBUF *buf, const char *inputDir, const char *outputDir, UErrorCode *status) { struct UString *tokenValue; struct UString comment; @@ -1734,8 +1819,10 @@ parse(UCHARBUF *buf, const char *currentInputDir, UErrorCode *status) initLookahead(buf, status); - inputdir = currentInputDir; + inputdir = inputDir; inputdirLength = (inputdir != NULL) ? (uint32_t)uprv_strlen(inputdir) : 0; + outputdir = outputDir; + outputdirLength = (outputdir != NULL) ? (uint32_t)uprv_strlen(outputdir) : 0; ustr_init(&comment); expect(TOK_STRING, &tokenValue, &comment, NULL, status); @@ -1753,21 +1840,11 @@ parse(UCHARBUF *buf, const char *currentInputDir, UErrorCode *status) /* expect(TOK_OPEN_BRACE, NULL, &line, status); */ /* The following code is to make Empty bundle work no matter with :table specifer or not */ token = getToken(NULL, NULL, &line, status); - - if(token==TOK_COLON) - { + if(token==TOK_COLON) { *status=U_ZERO_ERROR; - } - else - { - *status=U_PARSE_ERROR; - } - - if(U_SUCCESS(*status)){ - bundleType=parseResourceType(status); - if(bundleType==RT_TABLE) + if(isTable(bundleType)) { expect(TOK_OPEN_BRACE, NULL, NULL, &line, status); } @@ -1779,12 +1856,17 @@ parse(UCHARBUF *buf, const char *currentInputDir, UErrorCode *status) } else { + /* not a colon */ if(token==TOK_OPEN_BRACE) { *status=U_ZERO_ERROR; + bundleType=RT_TABLE; } else { + /* neither colon nor open brace */ + *status=U_PARSE_ERROR; + bundleType=RT_UNKNOWN; error(line, "parse error, did not find open-brace '{' or colon ':', stopped with %s", u_errorName(*status)); } } @@ -1796,11 +1878,25 @@ parse(UCHARBUF *buf, const char *currentInputDir, UErrorCode *status) return NULL; } + if(bundleType==RT_TABLE_NO_FALLBACK) { + /* + * Parse a top-level table with the table(nofallback) declaration. + * This is the same as a regular table, but also sets the + * URES_ATT_NO_FALLBACK flag in indexes[URES_INDEX_ATTRIBUTES] . + */ + bundle->noFallback=TRUE; + } + /* top-level tables need not handle special table names like "collations" */ realParseTable(bundle->fRoot, NULL, line, status); - + + if(dependencyArray!=NULL){ + table_add(bundle->fRoot, dependencyArray, 0, status); + dependencyArray = NULL; + } if (U_FAILURE(*status)) { bundle_close(bundle, status); + array_close(dependencyArray, status); return NULL; } |