1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2002-01-22 17:20:23 +00:00
|
|
|
* Copyright (C) 1998-2002, 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:
|
|
|
|
*
|
2001-09-26 03:45:06 +00:00
|
|
|
* Date Name Description
|
2002-01-22 17:20:23 +00:00
|
|
|
* 05/26/99 stephen Creation.
|
2001-09-26 03:45:06 +00:00
|
|
|
* 02/25/00 weiv Overhaul to write udata
|
|
|
|
* 5/10/01 Ram removed ustdio dependency
|
2001-08-24 01:47:58 +00:00
|
|
|
* 06/10/2001 Dominic Ludlam <dom@recoil.org> Rewritten
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2001-03-08 17:40:42 +00:00
|
|
|
#include "ucol_imp.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "parse.h"
|
2002-04-23 22:25:44 +00:00
|
|
|
#include "errmsg.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "uhash.h"
|
|
|
|
#include "cmemory.h"
|
2002-03-20 23:56:22 +00:00
|
|
|
#include "cstring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "read.h"
|
|
|
|
#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"
|
2001-01-03 00:18:57 +00:00
|
|
|
#include "unicode/putil.h"
|
2000-05-18 21:25:51 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* Number of tokens to read ahead of the current stream position */
|
|
|
|
#define MAX_LOOKAHEAD 2
|
|
|
|
|
|
|
|
#define U_ICU_UNIDATA "unidata"
|
2002-01-22 17:20:23 +00:00
|
|
|
#define CR 0x000D
|
|
|
|
#define LF 0x000A
|
|
|
|
#define SPACE 0x0020
|
|
|
|
#define ESCAPE 0x005C
|
|
|
|
|
|
|
|
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_int, "int", 3);
|
2001-07-11 20:31:32 +00:00
|
|
|
U_STRING_DECL(k_type_integer, "integer", 7);
|
2002-01-22 17:20:23 +00:00
|
|
|
U_STRING_DECL(k_type_array, "array", 5);
|
2002-06-14 06:00:15 +00:00
|
|
|
U_STRING_DECL(k_type_alias, "alias", 5);
|
2001-07-11 20:31:32 +00:00
|
|
|
U_STRING_DECL(k_type_intvector, "intvector", 9);
|
2002-01-22 17:20:23 +00:00
|
|
|
U_STRING_DECL(k_type_import, "import", 6);
|
2001-07-11 20:31:32 +00:00
|
|
|
U_STRING_DECL(k_type_reserved, "reserved", 8);
|
|
|
|
|
|
|
|
enum EResourceType
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
RT_UNKNOWN,
|
|
|
|
RT_STRING,
|
|
|
|
RT_BINARY,
|
|
|
|
RT_TABLE,
|
|
|
|
RT_INTEGER,
|
|
|
|
RT_ARRAY,
|
2002-06-14 06:00:15 +00:00
|
|
|
RT_ALIAS,
|
2001-09-26 03:45:06 +00:00
|
|
|
RT_INTVECTOR,
|
|
|
|
RT_IMPORT,
|
|
|
|
RT_RESERVED
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* only used for debugging */
|
|
|
|
const char *resourceNames[] =
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
"Unknown",
|
|
|
|
"String",
|
|
|
|
"Binary",
|
|
|
|
"Table",
|
|
|
|
"Integer",
|
|
|
|
"Array",
|
2002-06-14 06:00:15 +00:00
|
|
|
"Alias",
|
2001-09-26 03:45:06 +00:00
|
|
|
"Int vector",
|
|
|
|
"Import",
|
|
|
|
"Reserved",
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
struct Lookahead
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
enum ETokenType type;
|
|
|
|
struct UString value;
|
|
|
|
uint32_t line;
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* keep in sync with token defines in read.h */
|
|
|
|
const char *tokenNames[] =
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
"string", /* A string token, such as "MonthNames" */
|
|
|
|
"'{'", /* An opening brace character */
|
|
|
|
"'}'", /* A closing brace character */
|
|
|
|
"','", /* A comma */
|
|
|
|
"':'", /* A colon */
|
|
|
|
|
|
|
|
"<end of file>", /* End of the file has been reached successfully */
|
|
|
|
"<error>", /* An error, such an unterminated quoted string */
|
1999-08-16 21:50:52 +00:00
|
|
|
};
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* Just to store "TRUE" */
|
|
|
|
static const UChar trueValue[] = {0x0054, 0x0052, 0x0055, 0x0045, 0x0000};
|
|
|
|
|
|
|
|
static struct Lookahead lookahead[MAX_LOOKAHEAD + 1];
|
2002-01-22 17:20:23 +00:00
|
|
|
static uint32_t lookaheadPosition;
|
|
|
|
static UCHARBUF *buffer;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
static struct SRBRoot *bundle;
|
2002-01-22 17:20:23 +00:00
|
|
|
static const char *inputdir;
|
|
|
|
static uint32_t inputdirLength;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static struct SResource *parseResource(char *tag, UErrorCode *status);
|
2000-03-28 22:08:58 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
void initParser(void)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
U_STRING_INIT(k_type_string, "string", 6);
|
|
|
|
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_int, "int", 3);
|
|
|
|
U_STRING_INIT(k_type_integer, "integer", 7);
|
|
|
|
U_STRING_INIT(k_type_array, "array", 5);
|
2002-06-14 06:00:15 +00:00
|
|
|
U_STRING_INIT(k_type_alias, "alias", 5);
|
2002-01-22 17:20:23 +00:00
|
|
|
U_STRING_INIT(k_type_intvector, "intvector", 9);
|
|
|
|
U_STRING_INIT(k_type_import, "import", 6);
|
|
|
|
U_STRING_INIT(k_type_reserved, "reserved", 8);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_LOOKAHEAD + 1; i++)
|
|
|
|
{
|
|
|
|
ustr_init(&lookahead[i].value);
|
|
|
|
}
|
2000-03-28 22:08:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* The nature of the lookahead buffer:
|
|
|
|
There are MAX_LOOKAHEAD + 1 slots, used as a circular buffer. This provides
|
|
|
|
MAX_LOOKAHEAD lookahead tokens and a slot for the current token and value.
|
|
|
|
When getToken is called, the current pointer is moved to the next slot and the
|
|
|
|
old slot is filled with the next token from the reader by calling getNextToken.
|
|
|
|
The token values are stored in the slot, which means that token values don't
|
|
|
|
survive a call to getToken, ie.
|
|
|
|
|
|
|
|
UString *value;
|
|
|
|
|
|
|
|
getToken(&value, NULL, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
getToken(NULL, NULL, status); bad - value is now a different string
|
2001-07-11 20:31:32 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
initLookahead(UCHARBUF *buf, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
static uint32_t initTypeStrings = 0;
|
|
|
|
uint32_t i;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (!initTypeStrings)
|
|
|
|
{
|
|
|
|
initTypeStrings = 1;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
lookaheadPosition = 0;
|
|
|
|
buffer = buf;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
resetLineNumber();
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
for (i = 0; i < MAX_LOOKAHEAD; i++)
|
|
|
|
{
|
|
|
|
lookahead[i].type = getNextToken(buffer, &lookahead[i].value, &lookahead[i].line, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
*status = U_ZERO_ERROR;
|
2000-03-28 22:08:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static enum ETokenType
|
|
|
|
getToken(struct UString **tokenValue, uint32_t *linenumber, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
enum ETokenType result;
|
|
|
|
uint32_t i;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
result = lookahead[lookaheadPosition].type;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (tokenValue != NULL)
|
|
|
|
{
|
|
|
|
*tokenValue = &lookahead[lookaheadPosition].value;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (linenumber != NULL)
|
|
|
|
{
|
|
|
|
*linenumber = lookahead[lookaheadPosition].line;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
i = (lookaheadPosition + MAX_LOOKAHEAD) % (MAX_LOOKAHEAD + 1);
|
|
|
|
lookaheadPosition = (lookaheadPosition + 1) % (MAX_LOOKAHEAD + 1);
|
|
|
|
lookahead[i].type = getNextToken(buffer, &lookahead[i].value, &lookahead[i].line, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
/* printf("getToken, returning %s\n", tokenNames[result]); */
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
return result;
|
2000-03-28 22:08:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static enum ETokenType
|
|
|
|
peekToken(uint32_t lookaheadCount, struct UString **tokenValue, uint32_t *linenumber, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
uint32_t i = (lookaheadPosition + lookaheadCount) % (MAX_LOOKAHEAD + 1);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lookaheadCount >= MAX_LOOKAHEAD)
|
|
|
|
{
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
return TOK_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tokenValue != NULL)
|
|
|
|
{
|
|
|
|
*tokenValue = &lookahead[i].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linenumber != NULL)
|
|
|
|
{
|
|
|
|
*linenumber = lookahead[i].line;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lookahead[i].type;
|
2000-03-28 22:08:58 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static void
|
|
|
|
expect(enum ETokenType expectedToken, struct UString **tokenValue, uint32_t *linenumber, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
uint32_t line;
|
|
|
|
enum ETokenType token = getToken(tokenValue, &line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linenumber != NULL)
|
|
|
|
{
|
|
|
|
*linenumber = line;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token != expectedToken)
|
|
|
|
{
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(line, "expecting %s, got %s", tokenNames[expectedToken], tokenNames[token]);
|
|
|
|
}
|
|
|
|
else /* "else" is added by Jing/GCL */
|
|
|
|
{
|
|
|
|
*status = U_ZERO_ERROR;
|
|
|
|
}
|
2000-07-10 20:20:05 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static char *getInvariantString(uint32_t *line, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct UString *tokenValue;
|
|
|
|
char *result;
|
|
|
|
uint32_t count;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
expect(TOK_STRING, &tokenValue, line, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
count = u_strlen(tokenValue->fChars) + 1;
|
|
|
|
result = uprv_malloc(count);
|
2000-03-28 22:08:58 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (result == NULL)
|
|
|
|
{
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
u_UCharsToChars(tokenValue->fChars, result, count);
|
|
|
|
return result;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static enum EResourceType
|
|
|
|
parseResourceType(UErrorCode *status)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct UString *tokenValue;
|
|
|
|
enum EResourceType result = RT_UNKNOWN;
|
|
|
|
uint32_t line=0;
|
|
|
|
|
|
|
|
expect(TOK_STRING, &tokenValue, &line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return RT_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
*status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
if (u_strcmp(tokenValue->fChars, k_type_string) == 0) {
|
|
|
|
result = RT_STRING;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_array) == 0) {
|
|
|
|
result = RT_ARRAY;
|
2002-06-14 06:00:15 +00:00
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_alias) == 0) {
|
|
|
|
result = RT_ALIAS;
|
2002-01-22 17:20:23 +00:00
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_table) == 0) {
|
|
|
|
result = RT_TABLE;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_binary) == 0) {
|
|
|
|
result = RT_BINARY;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_bin) == 0) {
|
|
|
|
result = RT_BINARY;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_int) == 0) {
|
|
|
|
result = RT_INTEGER;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_integer) == 0) {
|
|
|
|
result = RT_INTEGER;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_intvector) == 0) {
|
|
|
|
result = RT_INTVECTOR;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_import) == 0) {
|
|
|
|
result = RT_IMPORT;
|
|
|
|
} else if (u_strcmp(tokenValue->fChars, k_type_reserved) == 0) {
|
|
|
|
result = RT_RESERVED;
|
|
|
|
} else {
|
|
|
|
char tokenBuffer[1024];
|
|
|
|
u_austrncpy(tokenBuffer, tokenValue->fChars, sizeof(tokenBuffer));
|
|
|
|
tokenBuffer[sizeof(tokenBuffer) - 1] = 0;
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(line, "unknown resource type '%s'", tokenBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseUCARules(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result = NULL;
|
|
|
|
struct UString *tokenValue;
|
|
|
|
FileStream *file = NULL;
|
|
|
|
char filename[256] = { '\0' };
|
|
|
|
char cs[128] = { '\0' };
|
|
|
|
uint32_t line;
|
|
|
|
int len=0;
|
|
|
|
expect(TOK_STRING, &tokenValue, &line, status);
|
|
|
|
|
|
|
|
/* make the filename including the directory */
|
|
|
|
if (inputdir != NULL)
|
|
|
|
{
|
|
|
|
uprv_strcat(filename, inputdir);
|
|
|
|
|
|
|
|
if (inputdir[inputdirLength - 1] != U_FILE_SEP_CHAR)
|
|
|
|
{
|
|
|
|
uprv_strcat(filename, U_FILE_SEP_STRING);
|
|
|
|
}
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
u_UCharsToChars(tokenValue->fChars, cs, tokenValue->fLength);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-01-24 18:02:14 +00:00
|
|
|
uprv_strcat(filename,"..");
|
|
|
|
uprv_strcat(filename,U_FILE_SEP_STRING);
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_strcat(filename, U_ICU_UNIDATA);
|
|
|
|
uprv_strcat(filename, U_FILE_SEP_STRING);
|
|
|
|
uprv_strcat(filename, cs);
|
|
|
|
|
|
|
|
/* open the file */
|
|
|
|
file = T_FileStream_open(filename, "rb");
|
|
|
|
|
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
UCHARBUF *ucbuf;
|
|
|
|
UChar32 c = 0;
|
|
|
|
uint32_t size = T_FileStream_size(file);
|
|
|
|
|
|
|
|
/* We allocate more space than actually required
|
|
|
|
* since the actual size needed for storing UChars
|
|
|
|
* is not known in UTF-8 byte stream
|
|
|
|
*/
|
|
|
|
UChar *pTarget = (UChar *) uprv_malloc(sizeof(UChar) * size);
|
|
|
|
UChar *target = pTarget;
|
|
|
|
UChar *targetLimit = pTarget + size;
|
|
|
|
|
|
|
|
ucbuf = ucbuf_open(file, NULL,getShowWarning(), status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
error(line, "couldn't open input file %s\n", filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the rules into the buffer */
|
|
|
|
while (target < targetLimit)
|
|
|
|
{
|
|
|
|
c = ucbuf_getc(ucbuf, status);
|
|
|
|
|
|
|
|
if (c == ESCAPE)
|
|
|
|
{
|
|
|
|
c = unescape(ucbuf, status);
|
|
|
|
|
|
|
|
if (c == U_ERR)
|
|
|
|
{
|
|
|
|
uprv_free(pTarget);
|
|
|
|
T_FileStream_close(file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == SPACE || c == CR || c == LF)
|
|
|
|
{
|
|
|
|
/* ignore spaces carriage returns
|
|
|
|
* and line feed unless in the form \uXXXX
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Append UChar * after dissembling if c > 0xffff*/
|
|
|
|
if (c != U_EOF)
|
|
|
|
{
|
|
|
|
U_APPEND_CHAR32(c, target,len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = string_open(bundle, tag, pTarget, target - pTarget, status);
|
|
|
|
|
|
|
|
uprv_free(pTarget);
|
|
|
|
T_FileStream_close(file);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error(line, "couldn't open input file %s\n", filename);
|
|
|
|
*status = U_FILE_ACCESS_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseString(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct UString *tokenValue;
|
|
|
|
struct SResource *result = NULL;
|
2001-05-18 20:52:25 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (tag != NULL && uprv_strcmp(tag, "%%UCARULES") == 0)
|
|
|
|
{
|
|
|
|
return parseUCARules(tag, startline, status);
|
|
|
|
}
|
2001-05-10 16:54:09 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
expect(TOK_STRING, &tokenValue, NULL, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (U_SUCCESS(*status))
|
|
|
|
{
|
|
|
|
/* create the string now - tokenValue doesn't survive a call to getToken (and therefore
|
2001-09-26 03:45:06 +00:00
|
|
|
doesn't survive expect either) */
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
result = string_open(bundle, tag, tokenValue->fChars, tokenValue->fLength, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
string_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
return result;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2002-06-14 06:00:15 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseAlias(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
|
|
|
struct UString *tokenValue;
|
|
|
|
struct SResource *result = NULL;
|
|
|
|
|
|
|
|
expect(TOK_STRING, &tokenValue, NULL, status);
|
|
|
|
|
|
|
|
if (U_SUCCESS(*status))
|
|
|
|
{
|
|
|
|
/* create the string now - tokenValue doesn't survive a call to getToken (and therefore
|
|
|
|
doesn't survive expect either) */
|
|
|
|
|
|
|
|
result = alias_open(bundle, tag, tokenValue->fChars, tokenValue->fLength, status);
|
|
|
|
|
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
alias_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseCollationElements(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result = NULL;
|
|
|
|
struct SResource *member = NULL;
|
|
|
|
struct UString *tokenValue;
|
|
|
|
enum ETokenType token;
|
|
|
|
char subtag[1024];
|
|
|
|
UVersionInfo version;
|
|
|
|
UBool override = FALSE;
|
|
|
|
uint32_t line;
|
|
|
|
|
|
|
|
result = table_open(bundle, tag, status);
|
|
|
|
|
|
|
|
if (result == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '{' . (name resource)* '}' */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
token = getToken(&tokenValue, &line, status);
|
|
|
|
|
|
|
|
if (token == TOK_CLOSE_BRACE)
|
|
|
|
{
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token != TOK_STRING)
|
|
|
|
{
|
|
|
|
table_close(result, status);
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (token == TOK_EOF)
|
|
|
|
{
|
|
|
|
error(startline, "unterminated table");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error(line, "enexpected token %s", tokenNames[token]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_UCharsToChars(tokenValue->fChars, subtag, u_strlen(tokenValue->fChars) + 1);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
table_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(TOK_OPEN_BRACE, NULL, NULL, status);
|
|
|
|
expect(TOK_STRING, &tokenValue, &line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
table_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uprv_strcmp(subtag, "Version") == 0)
|
|
|
|
{
|
|
|
|
char ver[40];
|
|
|
|
int32_t length = u_strlen(tokenValue->fChars);
|
|
|
|
|
|
|
|
if (length >= (int32_t) sizeof(ver))
|
|
|
|
{
|
|
|
|
length = (int32_t) sizeof(ver) - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_UCharsToChars(tokenValue->fChars, ver, length);
|
|
|
|
u_versionFromString(version, ver);
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(subtag, "Override") == 0)
|
|
|
|
{
|
|
|
|
override = FALSE;
|
|
|
|
|
|
|
|
if (u_strncmp(tokenValue->fChars, trueValue, u_strlen(trueValue)) == 0)
|
|
|
|
{
|
|
|
|
override = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (uprv_strcmp(subtag, "Sequence") == 0)
|
|
|
|
{
|
|
|
|
UErrorCode intStatus = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
/* do the collation elements */
|
|
|
|
int32_t len = 0;
|
|
|
|
uint8_t *data = NULL;
|
|
|
|
UCollator *coll = NULL;
|
|
|
|
UChar *rules = NULL;
|
|
|
|
UParseError parseError;
|
|
|
|
coll = ucol_openRules(tokenValue->fChars, tokenValue->fLength,
|
|
|
|
UCOL_OFF, UCOL_DEFAULT_STRENGTH,&parseError, &intStatus);
|
|
|
|
|
|
|
|
if (U_SUCCESS(intStatus) && coll != NULL)
|
|
|
|
{
|
|
|
|
data = ucol_cloneRuleData(coll, &len, &intStatus);
|
|
|
|
|
|
|
|
/* tailoring rules version */
|
|
|
|
coll->dataInfo.dataVersion[1] = version[0];
|
|
|
|
|
|
|
|
if (U_SUCCESS(intStatus) && data != NULL)
|
|
|
|
{
|
2002-02-14 02:27:03 +00:00
|
|
|
member = bin_open(bundle, "%%CollationBin", len, data, status);
|
2002-06-14 06:00:15 +00:00
|
|
|
/*table_add(bundle->fRoot, member, line, status);*/
|
|
|
|
table_add(result, member, line, status);
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_free(data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
warning(line, "could not obtain rules from collator");
|
|
|
|
}
|
|
|
|
|
|
|
|
ucol_close(coll);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
warning(line, "%%Collation could not be constructed from CollationElements - check context!");
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_free(rules);
|
|
|
|
}
|
|
|
|
|
|
|
|
member = string_open(bundle, subtag, tokenValue->fChars, tokenValue->fLength, status);
|
|
|
|
table_add(result, member, line, status);
|
|
|
|
|
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
table_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
return NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
2000-08-23 20:06:20 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* Necessary, because CollationElements requires the bundle->fRoot member to be present which,
|
|
|
|
if this weren't special-cased, wouldn't be set until the entire file had been processed. */
|
|
|
|
static struct SResource *
|
|
|
|
realParseTable(struct SResource *table, char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *member = NULL;
|
|
|
|
struct UString *tokenValue;
|
|
|
|
enum ETokenType token;
|
|
|
|
char subtag[1024];
|
|
|
|
uint32_t line;
|
|
|
|
UBool readToken = FALSE;
|
|
|
|
|
|
|
|
/* '{' . (name resource)* '}' */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
token = getToken(&tokenValue, &line, status);
|
|
|
|
|
|
|
|
if (token == TOK_CLOSE_BRACE)
|
|
|
|
{
|
|
|
|
if (!readToken) {
|
|
|
|
warning(startline, "Encountered empty table");
|
|
|
|
}
|
|
|
|
return table;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (token != TOK_STRING)
|
|
|
|
{
|
|
|
|
table_close(table, status);
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
|
|
|
|
if (token == TOK_EOF)
|
|
|
|
{
|
|
|
|
error(startline, "unterminated table");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error(line, "enexpected token %s", tokenNames[token]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_UCharsToChars(tokenValue->fChars, subtag, u_strlen(tokenValue->fChars) + 1);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
error(line, "parse error. Stopped parsing with %s", u_errorName(*status));
|
|
|
|
table_close(table, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
member = parseResource(subtag, status);
|
|
|
|
|
|
|
|
if (member == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
error(line, "parse error. Stopped parsing with %s", u_errorName(*status));
|
|
|
|
table_close(table, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
table_add(table, member, line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
error(line, "parse error. Stopped parsing with %s", u_errorName(*status));
|
|
|
|
table_close(table, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
readToken = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
return NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseTable(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (tag != NULL && uprv_strcmp(tag, "CollationElements") == 0)
|
|
|
|
{
|
|
|
|
return parseCollationElements(tag, startline, status);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
result = table_open(bundle, tag, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (result == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
return realParseTable(result, tag, startline, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct SResource *
|
|
|
|
parseArray(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result = NULL;
|
|
|
|
struct SResource *member = NULL;
|
|
|
|
struct UString *tokenValue;
|
|
|
|
enum ETokenType token;
|
|
|
|
UBool readToken = FALSE;
|
|
|
|
|
|
|
|
result = array_open(bundle, tag, status);
|
|
|
|
|
|
|
|
if (result == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '{' . resource [','] '}' */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* check for end of array, but don't consume next token unless it really is the end */
|
|
|
|
token = peekToken(0, &tokenValue, NULL, status);
|
|
|
|
|
|
|
|
if (token == TOK_CLOSE_BRACE)
|
|
|
|
{
|
|
|
|
getToken(NULL, NULL, status);
|
|
|
|
if (!readToken) {
|
|
|
|
warning(startline, "Encountered empty array");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (token == TOK_EOF)
|
|
|
|
{
|
|
|
|
array_close(result, status);
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(startline, "unterminated array");
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
/* string arrays are a special case */
|
|
|
|
if (token == TOK_STRING)
|
|
|
|
{
|
|
|
|
getToken(&tokenValue, NULL, status);
|
|
|
|
member = string_open(bundle, NULL, tokenValue->fChars, tokenValue->fLength, status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
member = parseResource(NULL, status);
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (member == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
array_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_add(result, member, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
array_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* eat optional comma if present */
|
|
|
|
token = peekToken(0, NULL, NULL, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (token == TOK_COMMA)
|
|
|
|
{
|
|
|
|
getToken(NULL, NULL, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
array_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
readToken = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct SResource *
|
|
|
|
parseIntVector(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result = NULL;
|
|
|
|
enum ETokenType token;
|
|
|
|
char *string;
|
|
|
|
int32_t value;
|
|
|
|
UBool readToken = FALSE;
|
|
|
|
/* added by Jing/GCL */
|
|
|
|
char *stopstring;
|
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
result = intvector_open(bundle, tag, status);
|
|
|
|
|
|
|
|
if (result == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* '{' . string [','] '}' */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/* check for end of array, but don't consume next token unless it really is the end */
|
|
|
|
token = peekToken(0, NULL, NULL, status);
|
|
|
|
|
|
|
|
if (token == TOK_CLOSE_BRACE)
|
|
|
|
{
|
|
|
|
/* it's the end, consume the close brace */
|
|
|
|
getToken(NULL, NULL, status);
|
|
|
|
if (!readToken) {
|
|
|
|
warning(startline, "Encountered empty int vector");
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
string = getInvariantString(NULL, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
intvector_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* Commented by Jing/GCL */
|
|
|
|
/*value = uprv_strtol(string, NULL, 10);
|
|
|
|
intvector_add(result, value, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
|
|
|
uprv_free(string);
|
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
token = peekToken(0, NULL, NULL, status);*/
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
/* The following is added by Jing/GCL to handle illegal char in the Intvector */
|
|
|
|
value = uprv_strtoul(string, &stopstring, 0);/* make intvector support decimal,hexdigit,octal digit ranging from -2^31-2^32-1*/
|
|
|
|
len=stopstring-string;
|
|
|
|
|
2002-03-20 23:56:22 +00:00
|
|
|
if(len==uprv_strlen(string))
|
2002-01-22 17:20:23 +00:00
|
|
|
{
|
|
|
|
intvector_add(result, value, status);
|
|
|
|
uprv_free(string);
|
|
|
|
token = peekToken(0, NULL, NULL, status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uprv_free(string);
|
|
|
|
*status=U_INVALID_CHAR_FOUND;
|
|
|
|
}
|
|
|
|
/* The above is added by Jing/GCL */
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
intvector_close(result, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the comma is optional (even though it is required to prevent the reader from concatenating
|
|
|
|
consecutive entries) so that a missing comma on the last entry isn't an error */
|
|
|
|
if (token == TOK_COMMA)
|
|
|
|
{
|
|
|
|
getToken(NULL, NULL, status);
|
|
|
|
}
|
|
|
|
readToken = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not reached */
|
|
|
|
intvector_close(result, status);
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
return NULL;
|
2001-09-26 03:45:06 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2001-09-26 03:45:06 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseBinary(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result = NULL;
|
|
|
|
uint8_t *value;
|
|
|
|
char *string;
|
|
|
|
char toConv[3] = {'\0', '\0', '\0'};
|
|
|
|
uint32_t count;
|
|
|
|
uint32_t i;
|
|
|
|
uint32_t line;
|
|
|
|
/* added by Jing/GCL */
|
|
|
|
char *stopstring;
|
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
string = getInvariantString(&line, status);
|
|
|
|
|
|
|
|
if (string == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
uprv_free(string);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
count = uprv_strlen(string);
|
|
|
|
if (count > 0){
|
2001-09-26 03:45:06 +00:00
|
|
|
if((count % 2)==0){
|
|
|
|
value = uprv_malloc(sizeof(uint8_t) * count);
|
|
|
|
|
|
|
|
if (value == NULL)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_free(string);
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
2001-09-26 03:45:06 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2001-09-26 03:45:06 +00:00
|
|
|
for (i = 0; i < count; i += 2)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
toConv[0] = string[i];
|
|
|
|
toConv[1] = string[i + 1];
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
value[i >> 1] = (uint8_t) uprv_strtoul(toConv, &stopstring, 16);
|
|
|
|
len=stopstring-toConv;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-03-20 23:56:22 +00:00
|
|
|
if(len!=uprv_strlen(toConv))
|
2002-01-22 17:20:23 +00:00
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
uprv_free(string);
|
|
|
|
*status=U_INVALID_CHAR_FOUND;
|
|
|
|
return NULL;
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2001-09-26 03:45:06 +00:00
|
|
|
result = bin_open(bundle, tag, (i >> 1), value, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_free(value);
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
else
|
2001-08-27 18:51:43 +00:00
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
*status = U_INVALID_CHAR_FOUND;
|
2001-08-27 18:51:43 +00:00
|
|
|
uprv_free(string);
|
2001-09-26 03:45:06 +00:00
|
|
|
error(line, "Encountered invalid binary string");
|
2001-08-27 18:51:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = bin_open(bundle, tag, 0, NULL, status);
|
|
|
|
warning(startline, "Encountered empty binary tag");
|
|
|
|
}
|
|
|
|
uprv_free(string);
|
|
|
|
|
|
|
|
return result;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct SResource *
|
|
|
|
parseInteger(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result = NULL;
|
|
|
|
int32_t value;
|
|
|
|
char *string;
|
|
|
|
/* added by Jing/GCL */
|
|
|
|
char *stopstring;
|
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
string = getInvariantString(NULL, status);
|
|
|
|
|
|
|
|
if (string == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
uprv_free(string);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uprv_strlen(string) <= 0)
|
|
|
|
{
|
|
|
|
warning(startline, "Encountered empty integer. Default value is 0.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* commented by Jing/GCL */
|
|
|
|
/* value = uprv_strtol(string, NULL, 10);*/
|
|
|
|
/* result = int_open(bundle, tag, value, status);*/
|
|
|
|
/* The following is added by Jing/GCL*/
|
|
|
|
/* to make integer support hexdecimal, octal digit and decimal*/
|
|
|
|
/* to handle illegal char in the integer*/
|
|
|
|
value = uprv_strtoul(string, &stopstring, 0);
|
|
|
|
len=stopstring-string;
|
2002-03-20 23:56:22 +00:00
|
|
|
if(len==uprv_strlen(string))
|
2002-01-22 17:20:23 +00:00
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
result = int_open(bundle, tag, value, status);
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
*status=U_INVALID_CHAR_FOUND;
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
uprv_free(string);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
return result;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct SResource *
|
|
|
|
parseImport(char *tag, uint32_t startline, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct SResource *result;
|
|
|
|
FileStream *file;
|
|
|
|
int32_t len;
|
|
|
|
uint8_t *data;
|
|
|
|
char *filename;
|
|
|
|
uint32_t line;
|
|
|
|
|
|
|
|
filename = getInvariantString(&line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(TOK_CLOSE_BRACE, NULL, NULL, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
uprv_free(filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the input file for reading */
|
|
|
|
if (inputdir == NULL)
|
|
|
|
{
|
|
|
|
file = T_FileStream_open(filename, "rb");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *fullname = NULL;
|
|
|
|
int32_t count = uprv_strlen(filename);
|
|
|
|
|
|
|
|
if (inputdir[inputdirLength - 1] != U_FILE_SEP_CHAR)
|
|
|
|
{
|
|
|
|
fullname = (char *) uprv_malloc(inputdirLength + count + 2);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_strcpy(fullname, inputdir);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
fullname[inputdirLength] = U_FILE_SEP_CHAR;
|
|
|
|
fullname[inputdirLength + 1] = '\0';
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_strcat(fullname, filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fullname = (char *) uprv_malloc(inputdirLength + count + 1);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_strcpy(fullname, inputdir);
|
|
|
|
uprv_strcat(fullname, filename);
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
file = T_FileStream_open(fullname, "rb");
|
|
|
|
uprv_free(fullname);
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
error(line, "couldn't open input file %s", filename);
|
|
|
|
*status = U_FILE_ACCESS_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
len = T_FileStream_size(file);
|
|
|
|
data = uprv_malloc(len);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
T_FileStream_read (file, data, len);
|
|
|
|
T_FileStream_close (file);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
result = bin_open(bundle, tag, len, data, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
uprv_free(data);
|
|
|
|
uprv_free(filename);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
return result;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
static struct SResource *
|
|
|
|
parseResource(char *tag, UErrorCode *status)
|
|
|
|
{
|
|
|
|
enum ETokenType token;
|
|
|
|
enum EResourceType resType = RT_UNKNOWN;
|
|
|
|
struct UString *tokenValue;
|
|
|
|
uint32_t startline;
|
|
|
|
uint32_t line;
|
|
|
|
|
|
|
|
token = getToken(&tokenValue, &startline, status);
|
|
|
|
|
|
|
|
/* name . [ ':' type ] '{' resource '}' */
|
|
|
|
/* This function parses from the colon onwards. If the colon is present, parse the
|
|
|
|
type then try to parse a resource of that type. If there is no explicit type,
|
|
|
|
work it out using the lookahead tokens. */
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case TOK_EOF:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(startline, "Unexpected EOF encountered");
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case TOK_ERROR:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
case TOK_COLON:
|
|
|
|
resType = parseResourceType(status);
|
|
|
|
expect(TOK_OPEN_BRACE, &tokenValue, &startline, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
break;
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
case TOK_OPEN_BRACE:
|
|
|
|
break;
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
default:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(startline, "syntax error while reading a resource, expected '{' or ':'");
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (resType == RT_UNKNOWN)
|
|
|
|
{
|
|
|
|
/* No explicit type, so try to work it out. At this point, we've read the first '{'.
|
|
|
|
We could have any of the following:
|
|
|
|
{ { => array (nested)
|
|
|
|
{ :/} => array
|
|
|
|
{ string , => string array
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
commented by Jing/GCL
|
|
|
|
{ string { => table
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
added by Jing/GCL
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
{ string :/{ => table
|
|
|
|
{ string } => string
|
|
|
|
*/
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
token = peekToken(0, NULL, &line, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Commented by Jing/GCL */
|
|
|
|
/* if (token == TOK_OPEN_BRACE || token == TOK_COLON )*/
|
|
|
|
if (token == TOK_OPEN_BRACE || token == TOK_COLON ||token ==TOK_CLOSE_BRACE )
|
|
|
|
{
|
|
|
|
resType = RT_ARRAY;
|
|
|
|
}
|
|
|
|
else if (token == TOK_STRING)
|
|
|
|
{
|
|
|
|
token = peekToken(1, NULL, &line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case TOK_COMMA: resType = RT_ARRAY; break;
|
|
|
|
case TOK_OPEN_BRACE: resType = RT_TABLE; break;
|
|
|
|
case TOK_CLOSE_BRACE: resType = RT_STRING; break;
|
|
|
|
/* added by Jing/GCL to make table work when :table is omitted */
|
|
|
|
case TOK_COLON: resType = RT_TABLE; break;
|
|
|
|
default:
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(line, "Unexpected token after string, expected ',', '{' or '}'");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
error(line, "Unexpected token after '{'");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* printf("Type guessed as %s\n", resourceNames[resType]); */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We should now know what we need to parse next, so call the appropriate parser
|
|
|
|
function and return. */
|
|
|
|
switch (resType)
|
|
|
|
{
|
|
|
|
case RT_STRING: return parseString (tag, startline, status);
|
|
|
|
case RT_TABLE: return parseTable (tag, startline, status);
|
|
|
|
case RT_ARRAY: return parseArray (tag, startline, status);
|
2002-06-14 06:00:15 +00:00
|
|
|
case RT_ALIAS: return parseAlias (tag, startline, status);
|
2002-01-22 17:20:23 +00:00
|
|
|
case RT_BINARY: return parseBinary (tag, startline, status);
|
|
|
|
case RT_INTEGER: return parseInteger (tag, startline, status);
|
|
|
|
case RT_IMPORT: return parseImport (tag, startline, status);
|
|
|
|
case RT_INTVECTOR: return parseIntVector (tag, startline, status);
|
|
|
|
|
|
|
|
default:
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
error(startline, "internal error: unknown resource type found and not handled");
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct SRBRoot *
|
|
|
|
parse(UCHARBUF *buf, const char *currentInputDir, UErrorCode *status)
|
|
|
|
{
|
2002-01-22 17:20:23 +00:00
|
|
|
struct UString *tokenValue;
|
|
|
|
uint32_t line;
|
|
|
|
/* added by Jing/GCL */
|
|
|
|
enum EResourceType bundleType;
|
|
|
|
enum ETokenType token;
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
initLookahead(buf, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
inputdir = currentInputDir;
|
|
|
|
inputdirLength = (inputdir != NULL) ? uprv_strlen(inputdir) : 0;
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
bundle = bundle_open(status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if (bundle == NULL || U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
expect(TOK_STRING, &tokenValue, NULL, status);
|
|
|
|
bundle_setlocale(bundle, tokenValue->fChars, status);
|
|
|
|
/* Commented by Jing/GCL */
|
|
|
|
/* 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, &line, status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
2002-01-22 17:20:23 +00:00
|
|
|
if(token==TOK_COLON)
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
*status=U_ZERO_ERROR;
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
*status=U_PARSE_ERROR;
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(U_SUCCESS(*status)){
|
|
|
|
|
|
|
|
bundleType=parseResourceType(status);
|
2001-09-26 03:45:06 +00:00
|
|
|
|
|
|
|
if(bundleType==RT_TABLE)
|
2002-01-22 17:20:23 +00:00
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
expect(TOK_OPEN_BRACE, NULL, &line, status);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*status=U_PARSE_ERROR;
|
|
|
|
error(line, "parse error. Stopped parsing with %s", u_errorName(*status));
|
|
|
|
}
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(token==TOK_OPEN_BRACE)
|
|
|
|
{
|
2001-09-26 03:45:06 +00:00
|
|
|
*status=U_ZERO_ERROR;
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
2002-03-29 23:20:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error(line, "parse error, did not find open-brace '{' or colon ':', stopped with %s", u_errorName(*status));
|
|
|
|
}
|
2002-01-22 17:20:23 +00:00
|
|
|
}
|
|
|
|
/* The above is added by Jing/GCL */
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
bundle_close(bundle, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
realParseTable(bundle->fRoot, NULL, line, status);
|
|
|
|
|
|
|
|
if (U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
/* realParseTable has already closed the table */
|
|
|
|
bundle->fRoot = NULL;
|
|
|
|
bundle_close(bundle, status);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getToken(NULL, &line, status) != TOK_EOF)
|
|
|
|
{
|
|
|
|
warning(line, "extraneous text after resource bundle (perhaps unmatched braces)");
|
|
|
|
}
|
|
|
|
|
|
|
|
return bundle;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|