1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2000-05-15 18:39:17 +00:00
|
|
|
* Copyright (C) 1998-2000, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File parse.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 05/26/99 stephen Creation.
|
2000-05-15 18:39:17 +00:00
|
|
|
* 02/25/00 weiv Overhaul to write udata
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "uhash.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "read.h"
|
2000-01-28 22:40:27 +00:00
|
|
|
#include "unicode/ustdio.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "ustr.h"
|
2000-05-15 18:39:17 +00:00
|
|
|
#include "reslist.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ustring.h"
|
2000-05-18 21:25:51 +00:00
|
|
|
#include "unicode/ucol.h"
|
|
|
|
|
|
|
|
U_CAPI const UChar * U_EXPORT2 ucol_getDefaultRulesArray(uint32_t *size);
|
|
|
|
|
|
|
|
U_STRING_DECL(k_start_string, "string", 6);
|
|
|
|
U_STRING_DECL(k_start_binary, "binary", 6);
|
|
|
|
U_STRING_DECL(k_start_table, "table", 5);
|
|
|
|
U_STRING_DECL(k_start_int, "int", 3);
|
|
|
|
U_STRING_DECL(k_start_array, "array", 5);
|
|
|
|
U_STRING_DECL(k_start_intvector, "intvector", 9);
|
|
|
|
U_STRING_DECL(k_start_reserved, "reserved", 8);
|
2000-05-22 19:51:21 +00:00
|
|
|
U_STRING_DECL(rootName, "root", 4);
|
2000-05-18 21:25:51 +00:00
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool didInit=FALSE;
|
2000-05-22 19:51:21 +00:00
|
|
|
static UBool didInitRoot=FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Node IDs for the state transition table. */
|
|
|
|
enum ENode {
|
|
|
|
eError,
|
|
|
|
eInitial, /* Next: Locale name */
|
|
|
|
eGotLoc, /* Next: { */
|
|
|
|
eIdle, /* Next: Tag name | } */
|
2000-05-18 21:25:51 +00:00
|
|
|
eGotTag, /* Next: { | : */
|
1999-08-16 21:50:52 +00:00
|
|
|
eNode5, /* Next: Data | Subtag */
|
|
|
|
eNode6, /* Next: } | { | , */
|
|
|
|
eList, /* Next: List data */
|
|
|
|
eNode8, /* Next: , */
|
|
|
|
eTagList, /* Next: Subtag data */
|
|
|
|
eNode10, /* Next: } */
|
|
|
|
eNode11, /* Next: Subtag */
|
|
|
|
eNode12, /* Next: { */
|
|
|
|
e2dArray, /* Next: Data | } */
|
|
|
|
eNode14, /* Next: , | } */
|
|
|
|
eNode15, /* Next: , | } */
|
2000-05-18 21:25:51 +00:00
|
|
|
eNode16, /* Next: { | } */
|
|
|
|
eTypeStart, /* Next: Type name */
|
|
|
|
eGotType /* Next: { */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Action codes for the state transtiion table. */
|
|
|
|
enum EAction {
|
|
|
|
/* Generic actions */
|
|
|
|
eNOP = 0x0100, /* Do nothing */
|
|
|
|
eOpen = 0x0200, /* Open a new locale data block with the data
|
|
|
|
string as the locale name */
|
|
|
|
eClose = 0x0300, /* Close a locale data block */
|
|
|
|
eSetTag = 0x0400, /* Record the last string as the tag name */
|
|
|
|
|
|
|
|
/* Comma-delimited lists */
|
|
|
|
eBegList = 0x1100, /* Start a new string list with the last string
|
|
|
|
as the first element */
|
|
|
|
eEndList = 0x1200, /* Close a string list being built */
|
|
|
|
eListStr = 0x1300, /* Record the last string as a data string and
|
|
|
|
increment the index */
|
|
|
|
eStr = 0x1400, /* Record the last string as a singleton string */
|
|
|
|
|
|
|
|
/* 2-d lists */
|
|
|
|
eBeg2dList = 0x2100, /* Start a new 2d string list with no elements as yet */
|
|
|
|
eEnd2dList = 0x2200, /* Close a 2d string list being built */
|
|
|
|
e2dStr = 0x2300, /* Record the last string as a 2d string */
|
|
|
|
eNewRow = 0x2400, /* Start a new row */
|
|
|
|
|
|
|
|
/* Tagged lists */
|
|
|
|
eBegTagged = 0x3100, /* Start a new tagged list with the last
|
|
|
|
string as the first subtag */
|
|
|
|
eEndTagged = 0x3200, /* Close a tagged list being build */
|
|
|
|
eSubtag = 0x3300, /* Record the last string as the subtag */
|
2000-05-18 21:25:51 +00:00
|
|
|
eTaggedStr = 0x3400, /* Record the last string as a tagged string */
|
|
|
|
|
|
|
|
/* Type support */
|
|
|
|
eBegType = 0x4100, /* Start getting a type */
|
|
|
|
eSetType = 0x4200 /* Record and init type */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* A struct which encapsulates a node ID and an action. */
|
|
|
|
struct STransition {
|
|
|
|
enum ENode fNext;
|
|
|
|
enum EAction fAction;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This table describes an ATM (state machine) which parses resource
|
|
|
|
bundle text files rather strictly. Each row represents a node. The
|
|
|
|
columns of that row represent transitions into other nodes. Most
|
|
|
|
transitions are "eError" because most transitions are
|
|
|
|
disallowed. For example, if the parser has just seen a tag name, it
|
|
|
|
enters node 4 ("eGotTag"). The state table then marks only one
|
|
|
|
valid transition, which is into node 5, upon seeing an eOpenBrace
|
|
|
|
token. We allow an extra comma after the last element in a
|
|
|
|
comma-delimited list (transition from eList to eIdle on
|
|
|
|
kCloseBrace). */
|
|
|
|
static struct STransition gTransitionTable [] = {
|
2000-05-18 21:25:51 +00:00
|
|
|
/* kString kOpenBrace kCloseBrace kComma
|
|
|
|
/*eError*/ {eError,eNOP}, {eError,eNOP}, {eError,eNOP}, {eError,eNOP},
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
/*eInitial*/ {eGotLoc,eOpen}, {eError,eNOP}, {eError,eNOP}, {eError,eNOP},
|
|
|
|
/*eGotLoc*/ {eError,eNOP}, {eIdle,eNOP}, {eError,eNOP}, {eError,eNOP},
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
/*eIdle*/ {eGotTag,eSetTag}, {eError,eNOP}, {eInitial,eClose}, {eError,eNOP},
|
|
|
|
/*eGotTag*/ {eError,eNOP}, {eNode5,eNOP}, {eError,eNOP}, {eError,eNOP},
|
|
|
|
/*eNode5*/ {eNode6,eNOP}, {e2dArray,eBeg2dList},{eError,eNOP}, {eError,eNOP},
|
2000-05-15 18:39:17 +00:00
|
|
|
/*eNode6*/ {eError,eNOP}, {eTagList,eBegTagged},{eIdle,eStr}, {eList,eBegList},
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
/*eList*/ {eNode8,eListStr}, {eError,eNOP}, {eIdle,eEndList}, {eError,eNOP},
|
|
|
|
/*eNode8*/ {eError,eNOP}, {eError,eNOP}, {eIdle,eEndList}, {eList,eNOP},
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2000-05-18 21:25:51 +00:00
|
|
|
/*eTagList*/ {eNode10,eTaggedStr},{eError,eNOP}, {eError,eNOP}, {eError,eNOP},
|
|
|
|
/*eNode10*/ {eError,eNOP}, {eError,eNOP}, {eNode11,eNOP}, {eError,eNOP},
|
|
|
|
/*eNode11*/ {eNode12,eNOP}, {eError,eNOP}, {eIdle,eEndTagged},{eError,eNOP},
|
|
|
|
/*eNode12*/ {eError,eNOP}, {eTagList,eSubtag}, {eError,eNOP}, {eError,eNOP},
|
|
|
|
|
|
|
|
/*e2dArray*/ {eNode14,e2dStr}, {eError,eNOP}, {eNode15,eNOP}, {eError,eNOP},
|
|
|
|
/*eNode14*/ {eError,eNOP}, {eError,eNOP}, {eNode15,eNOP}, {e2dArray,eNOP},
|
|
|
|
/*eNode15*/ {eError,eNOP}, {e2dArray,eNewRow}, {eIdle,eEnd2dList},{eNode16,eNOP},
|
|
|
|
/*eNode16*/ {eError,eNOP}, {e2dArray,eNewRow}, {eIdle,eEnd2dList},{eError,eNOP},
|
|
|
|
/*eTypeStart*/{eGotType,eSetType}, {eError,eNOP}, {eError,eNOP}, {eError,eNOP},
|
|
|
|
/*eGotType*/ {eError,eNOP}, {eError,eNOP}, {eError,eNOP}, {eError,eNOP}
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Row length is 4 */
|
|
|
|
#define GETTRANSITION(row,col) (gTransitionTable[col + (row<<2)])
|
2000-05-18 21:25:51 +00:00
|
|
|
/* Not anymore, it is 5 now */
|
|
|
|
/*#define GETTRANSITION(row,col) (gTransitionTable[col + (row*5)])*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-03-28 22:08:58 +00:00
|
|
|
/*********************************************************************
|
|
|
|
* Hashtable glue
|
|
|
|
********************************************************************/
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool get(UHashtable *hash, const struct UString* tag) {
|
2000-03-28 22:08:58 +00:00
|
|
|
return uhash_get(hash, tag) != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void put(UHashtable *hash, const struct UString *tag,
|
|
|
|
UErrorCode* status) {
|
|
|
|
struct UString* key = uprv_malloc(sizeof(struct UString));
|
|
|
|
ustr_init(key);
|
|
|
|
ustr_cpy(key, tag, status);
|
|
|
|
uhash_put(hash, key, (void*)1, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void freeUString(void* ustr) {
|
|
|
|
ustr_deinit(ustr);
|
|
|
|
uprv_free(ustr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t hashUString(const void* ustr) {
|
|
|
|
return uhash_hashUChars(((struct UString*)ustr)->fChars);
|
|
|
|
}
|
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool compareUString(const void* ustr1, const void* ustr2) {
|
2000-03-28 22:08:58 +00:00
|
|
|
return uhash_compareUChars(((struct UString*)ustr1)->fChars,
|
|
|
|
((struct UString*)ustr2)->fChars);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* parse
|
|
|
|
********************************************************************/
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
struct SRBRoot*
|
1999-12-01 21:36:40 +00:00
|
|
|
parse(FileStream *f, const char *cp,
|
1999-08-16 21:50:52 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
struct UFILE *file;
|
|
|
|
enum ETokenType type;
|
|
|
|
enum ENode node;
|
|
|
|
struct STransition t;
|
|
|
|
|
|
|
|
struct UString token;
|
|
|
|
struct UString tag;
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
char cTag[1024];
|
|
|
|
char cSubTag[1024];
|
|
|
|
struct SRBRoot *bundle = NULL;
|
|
|
|
struct SResource *rootTable = NULL;
|
|
|
|
struct SResource *temp = NULL;
|
|
|
|
struct SResource *temp1 = NULL;
|
|
|
|
struct SResource *temp2 = NULL;
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool colEl = FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/* Hashtable for keeping track of seen tag names */
|
|
|
|
struct UHashtable *data;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*status)) return NULL;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
/* setup */
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
ustr_init(&token);
|
|
|
|
ustr_init(&tag);
|
2000-05-15 18:39:17 +00:00
|
|
|
/*
|
|
|
|
cTag = uprv_malloc(1024);
|
|
|
|
if(cTag == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
cSubTag = uprv_malloc(1024);
|
|
|
|
if(cSubTag == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
node = eInitial;
|
|
|
|
data = 0;
|
|
|
|
|
2000-01-28 22:40:27 +00:00
|
|
|
file = u_finit((FILE *)f, 0, cp);
|
|
|
|
/* file = u_finit(f, cp, status); */
|
2000-06-01 17:05:12 +00:00
|
|
|
if(file == NULL) {
|
|
|
|
setErrorText("Could not initialize input file - most probably because of wrong converter\n");
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
bundle = bundle_open(status);
|
|
|
|
rootTable = bundle -> fRoot;
|
|
|
|
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status) || file == NULL) {
|
|
|
|
goto finish;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* iterate through the stream */
|
|
|
|
for(;;) {
|
|
|
|
|
|
|
|
/* get next token from stream */
|
|
|
|
type = getNextToken(file, &token, status);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case tok_EOF:
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = (node == eInitial) ? U_ZERO_ERROR : U_INVALID_FORMAT_ERROR;
|
2000-05-15 18:39:17 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
setErrorText("Unexpected EOF encountered");
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
goto finish;
|
|
|
|
/*break;*/
|
|
|
|
|
|
|
|
case tok_error:
|
1999-10-07 00:07:53 +00:00
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
goto finish;
|
|
|
|
/*break;*/
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = GETTRANSITION(node, type);
|
|
|
|
node = t.fNext;
|
|
|
|
|
|
|
|
if(node == eError) {
|
2000-05-15 18:39:17 +00:00
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
goto finish;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(t.fAction) {
|
|
|
|
case eNOP:
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Record the last string as the tag name */
|
|
|
|
case eSetTag:
|
2000-05-15 18:39:17 +00:00
|
|
|
ustr_cpy(&tag, &token, status);
|
|
|
|
u_UCharsToChars(tag.fChars, cTag, u_strlen(tag.fChars)+1);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
if(uprv_strchr(cTag, ':')) {
|
|
|
|
/* type modificator - do the type modification*/
|
|
|
|
} else if(uprv_strcmp(cTag, "CollationElements") == 0) {
|
|
|
|
colEl = TRUE;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
/*if(uhash_get(data, uhash_hashUString(tag.fChars)) != 0) {*/
|
|
|
|
if(get(data, &tag)) {
|
|
|
|
char *s;
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
s = uprv_malloc(1024);
|
|
|
|
strcpy(s, "Duplicate tag name detected: ");
|
|
|
|
u_austrcpy(s+strlen(s), tag.fChars);
|
|
|
|
setErrorText(s);
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Record a singleton string */
|
|
|
|
case eStr:
|
2000-05-15 18:39:17 +00:00
|
|
|
if(temp != NULL) {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-20 02:56:59 +00:00
|
|
|
temp = string_open(bundle, cTag, token.fChars, token.fLength, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
table_add(rootTable, temp, status);
|
2000-05-18 21:25:51 +00:00
|
|
|
if(colEl == TRUE) {
|
|
|
|
const UChar * defaultRulesArray;
|
2000-06-01 17:05:12 +00:00
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
2000-05-18 21:25:51 +00:00
|
|
|
uint32_t defaultRulesArrayLength = 0;
|
|
|
|
/* do the collation elements */
|
|
|
|
int32_t len = 0;
|
2000-06-01 17:05:12 +00:00
|
|
|
uint8_t *binColData = NULL;
|
2000-05-18 21:25:51 +00:00
|
|
|
UCollator *coll = NULL;
|
|
|
|
UChar *rules = NULL;
|
|
|
|
defaultRulesArray = ucol_getDefaultRulesArray(&defaultRulesArrayLength);
|
|
|
|
rules = uprv_malloc(sizeof(defaultRulesArray[0])*(defaultRulesArrayLength + token.fLength));
|
|
|
|
uprv_memcpy(rules, defaultRulesArray, defaultRulesArrayLength*sizeof(defaultRulesArray[0]));
|
|
|
|
uprv_memcpy(rules + defaultRulesArrayLength, token.fChars, token.fLength*sizeof(token.fChars[0]));
|
|
|
|
|
2000-06-01 17:05:12 +00:00
|
|
|
coll = ucol_openRules(rules, defaultRulesArrayLength + token.fLength, UCOL_DECOMP_CAN, 0, &intStatus);
|
2000-05-24 19:58:40 +00:00
|
|
|
ucol_setNormalization(coll, UCOL_NO_NORMALIZATION);
|
2000-05-22 19:51:21 +00:00
|
|
|
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_SUCCESS(intStatus) && coll !=NULL) {
|
|
|
|
binColData = ucol_cloneRuleData(coll, &len, &intStatus);
|
2000-05-18 21:25:51 +00:00
|
|
|
if(U_SUCCESS(*status) && data != NULL) {
|
2000-06-01 17:05:12 +00:00
|
|
|
temp1 = bin_open(bundle, "%%Collation", len, binColData, status);
|
2000-05-18 21:25:51 +00:00
|
|
|
table_add(rootTable, temp1, status);
|
2000-06-01 17:05:12 +00:00
|
|
|
uprv_free(binColData);
|
2000-05-18 21:25:51 +00:00
|
|
|
}
|
|
|
|
ucol_close(coll);
|
2000-06-01 17:05:12 +00:00
|
|
|
} else {
|
|
|
|
setErrorText("Warning: %%Collation could not be constructed from CollationElements - check context!");
|
|
|
|
}
|
2000-05-18 21:25:51 +00:00
|
|
|
uprv_free(rules);
|
|
|
|
colEl = FALSE;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
/*uhash_put(data, tag.fChars, status);*/
|
|
|
|
put(data, &tag, status);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
temp = NULL;
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Begin a string list */
|
|
|
|
case eBegList:
|
2000-05-15 18:39:17 +00:00
|
|
|
if(temp != NULL) {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
temp = array_open(bundle, cTag, status);
|
2000-05-20 02:56:59 +00:00
|
|
|
temp1 = string_open(bundle, NULL, token.fChars, token.fLength, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
array_add(temp, temp1, status);
|
|
|
|
temp1 = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Record a comma-delimited list string */
|
|
|
|
case eListStr:
|
2000-05-20 02:56:59 +00:00
|
|
|
temp1 = string_open(bundle, NULL, token.fChars, token.fLength, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
array_add(temp, temp1, status);
|
|
|
|
temp1 = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* End a string list */
|
|
|
|
case eEndList:
|
2000-05-15 18:39:17 +00:00
|
|
|
/*uhash_put(data, tag.fChars, status);*/
|
|
|
|
put(data, &tag, status);
|
|
|
|
table_add(rootTable, temp, status);
|
|
|
|
temp = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eBeg2dList:
|
2000-05-15 18:39:17 +00:00
|
|
|
if(temp != NULL) {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
temp = array_open(bundle, cTag, status);
|
|
|
|
temp1 = array_open(bundle, NULL, status);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eEnd2dList:
|
2000-05-15 18:39:17 +00:00
|
|
|
/*uhash_put(data, tag.fChars, status);*/
|
|
|
|
put(data, &tag, status);
|
|
|
|
array_add(temp, temp1, status);
|
|
|
|
table_add(rootTable, temp, status);
|
|
|
|
temp1 = NULL;
|
|
|
|
temp = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case e2dStr:
|
2000-05-20 02:56:59 +00:00
|
|
|
temp2 = string_open(bundle, NULL, token.fChars, token.fLength, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
array_add(temp1, temp2, status);
|
|
|
|
temp2 = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eNewRow:
|
2000-05-15 18:39:17 +00:00
|
|
|
array_add(temp, temp1, status);
|
|
|
|
temp1 = array_open(bundle, NULL, status);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eBegTagged:
|
2000-05-15 18:39:17 +00:00
|
|
|
if(temp != NULL) {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
temp = table_open(bundle, cTag, status);
|
|
|
|
u_UCharsToChars(token.fChars, cSubTag, u_strlen(token.fChars)+1);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eEndTagged:
|
2000-05-15 18:39:17 +00:00
|
|
|
/*uhash_put(data, tag.fChars, status);*/
|
|
|
|
put(data, &tag, status);
|
|
|
|
table_add(rootTable, temp, status);
|
|
|
|
temp = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eTaggedStr:
|
2000-05-20 02:56:59 +00:00
|
|
|
temp1 = string_open(bundle, cSubTag, token.fChars, token.fLength, status);
|
2000-05-15 18:39:17 +00:00
|
|
|
table_add(temp, temp1, status);
|
|
|
|
temp1 = NULL;
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Record the last string as the subtag */
|
|
|
|
case eSubtag:
|
2000-05-15 18:39:17 +00:00
|
|
|
u_UCharsToChars(token.fChars, cSubTag, u_strlen(token.fChars)+1);
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
if(table_get(temp, cSubTag, status) != 0) {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
setErrorText("Duplicate subtag found in tagged list");
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eOpen:
|
|
|
|
if(data != 0) {
|
2000-05-15 18:39:17 +00:00
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
bundle_setlocale(bundle, token.fChars, status);
|
2000-05-22 19:51:21 +00:00
|
|
|
if(didInitRoot == FALSE) {
|
|
|
|
U_STRING_INIT(rootName, "root", 4);
|
|
|
|
didInitRoot = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(u_strcmp(token.fChars, rootName) == 0) {
|
|
|
|
const UChar * defaultRulesArray;
|
|
|
|
uint32_t defaultRulesArrayLength = 0;
|
|
|
|
/* do the collation elements */
|
|
|
|
int32_t len = 0;
|
|
|
|
uint8_t *data = NULL;
|
|
|
|
uint8_t *data2 = NULL;
|
|
|
|
UCollator *coll = NULL;
|
|
|
|
|
|
|
|
UChar *rules = NULL;
|
|
|
|
defaultRulesArray = ucol_getDefaultRulesArray(&defaultRulesArrayLength);
|
|
|
|
rules = uprv_malloc(sizeof(defaultRulesArray[0])*(defaultRulesArrayLength));
|
|
|
|
uprv_memcpy(rules, defaultRulesArray, defaultRulesArrayLength*sizeof(defaultRulesArray[0]));
|
|
|
|
|
2000-05-24 19:58:40 +00:00
|
|
|
coll = ucol_openRules(rules, defaultRulesArrayLength, UCOL_DECOMP_CAN, 0, status);
|
|
|
|
ucol_setNormalization(coll, UCOL_DEFAULT_NORMALIZATION);
|
2000-05-22 19:51:21 +00:00
|
|
|
|
|
|
|
if(U_SUCCESS(*status) && coll !=NULL) {
|
|
|
|
data = ucol_cloneRuleData(coll, &len, status);
|
|
|
|
if(U_SUCCESS(*status) && data != NULL) {
|
|
|
|
temp1 = bin_open(bundle, "%%Collation", len, data, status);
|
|
|
|
table_add(rootTable, temp1, status);
|
|
|
|
uprv_free(data);
|
|
|
|
}
|
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
uprv_free(rules);
|
|
|
|
}
|
2000-06-01 17:05:12 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
goto finish;
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
data = uhash_open(hashUString, compareUString, status);
|
|
|
|
uhash_setKeyDeleter(data, freeUString);
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
case eClose:
|
2000-05-15 18:39:17 +00:00
|
|
|
if(data == 0) {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
break;
|
2000-05-18 21:25:51 +00:00
|
|
|
case eSetType:
|
|
|
|
/* type recognition */
|
|
|
|
if(!didInit) {
|
|
|
|
U_STRING_INIT(k_start_string, "string", 6);
|
|
|
|
U_STRING_INIT(k_start_binary, "binary", 6);
|
|
|
|
U_STRING_INIT(k_start_table, "table", 5);
|
|
|
|
U_STRING_INIT(k_start_int, "int", 3);
|
|
|
|
U_STRING_INIT(k_start_array, "array", 5);
|
|
|
|
U_STRING_INIT(k_start_intvector, "intvector", 9);
|
|
|
|
U_STRING_INIT(k_start_reserved, "reserved", 8);
|
|
|
|
didInit=TRUE;
|
|
|
|
}
|
|
|
|
if(u_strcmp(token.fChars, k_start_string) == 0) {
|
|
|
|
node = eGotTag;
|
|
|
|
} else if(u_strcmp(token.fChars, k_start_array) == 0) {
|
|
|
|
node = eGotTag;
|
|
|
|
} else if(u_strcmp(token.fChars, k_start_table) == 0) {
|
|
|
|
node = eGotTag;
|
|
|
|
} else if(u_strcmp(token.fChars, k_start_binary) == 0) {
|
|
|
|
/* start of binary */
|
|
|
|
} else if(u_strcmp(token.fChars, k_start_int) == 0) {
|
|
|
|
/* start of integer */
|
|
|
|
} else if(u_strcmp(token.fChars, k_start_intvector) == 0) {
|
|
|
|
/* start of intvector */
|
|
|
|
} else if(u_strcmp(token.fChars, k_start_reserved) == 0) {
|
|
|
|
/* start of reserved */
|
|
|
|
} else {
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
|
|
|
/* clean up */
|
|
|
|
|
|
|
|
if(data != 0)
|
|
|
|
uhash_close(data);
|
|
|
|
|
|
|
|
ustr_deinit(&token);
|
|
|
|
ustr_deinit(&tag);
|
2000-05-15 18:39:17 +00:00
|
|
|
|
|
|
|
/*uprv_free(cTag);*/
|
|
|
|
/*uprv_free(cSubTag);*/
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
if(file != 0)
|
|
|
|
u_fclose(file);
|
|
|
|
|
2000-05-15 18:39:17 +00:00
|
|
|
return bundle;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|