2001-06-20 22:24:42 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
2005-01-04 00:46:14 +00:00
|
|
|
* Copyright (C) 2001-2005, International Business Machines
|
2001-06-20 22:24:42 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: gennorm.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2001may25
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* This program reads the Unicode character database text file,
|
|
|
|
* parses it, and extracts the data for normalization.
|
|
|
|
* It then preprocesses it and writes a binary file for efficient use
|
|
|
|
* in various Unicode text normalization processes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uchar.h"
|
2004-09-13 23:40:06 +00:00
|
|
|
#include "unicode/ustring.h"
|
2001-06-20 22:24:42 +00:00
|
|
|
#include "unicode/putil.h"
|
2003-08-14 21:34:54 +00:00
|
|
|
#include "unicode/uclean.h"
|
2001-06-20 22:24:42 +00:00
|
|
|
#include "unicode/udata.h"
|
2004-09-13 23:40:06 +00:00
|
|
|
#include "unicode/uset.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2001-06-20 22:24:42 +00:00
|
|
|
#include "unewdata.h"
|
|
|
|
#include "uoptions.h"
|
|
|
|
#include "uparse.h"
|
|
|
|
#include "unormimp.h"
|
|
|
|
|
|
|
|
U_CDECL_BEGIN
|
|
|
|
#include "gennorm.h"
|
|
|
|
U_CDECL_END
|
|
|
|
|
|
|
|
UBool beVerbose=FALSE, haveCopyright=TRUE;
|
|
|
|
|
|
|
|
/* prototypes --------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
2002-05-31 01:16:58 +00:00
|
|
|
parseDerivedNormalizationProperties(const char *filename, UErrorCode *pErrorCode, UBool reportError);
|
2001-06-20 22:24:42 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
parseDB(const char *filename, UErrorCode *pErrorCode);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------------- */
|
|
|
|
|
2004-09-13 23:40:06 +00:00
|
|
|
enum {
|
|
|
|
HELP_H,
|
|
|
|
HELP_QUESTION_MARK,
|
|
|
|
VERBOSE,
|
|
|
|
COPYRIGHT,
|
|
|
|
DESTDIR,
|
|
|
|
SOURCEDIR,
|
|
|
|
UNICODE_VERSION,
|
2005-01-04 00:46:14 +00:00
|
|
|
ICUDATADIR,
|
2005-05-03 23:14:17 +00:00
|
|
|
CSOURCE,
|
2005-01-04 00:46:14 +00:00
|
|
|
STORE_FLAGS
|
2004-09-13 23:40:06 +00:00
|
|
|
};
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
static UOption options[]={
|
|
|
|
UOPTION_HELP_H,
|
|
|
|
UOPTION_HELP_QUESTION_MARK,
|
|
|
|
UOPTION_VERBOSE,
|
|
|
|
UOPTION_COPYRIGHT,
|
|
|
|
UOPTION_DESTDIR,
|
|
|
|
UOPTION_SOURCEDIR,
|
2005-05-03 23:14:17 +00:00
|
|
|
UOPTION_DEF("unicode", 'u', UOPT_REQUIRES_ARG),
|
2005-01-04 00:46:14 +00:00
|
|
|
UOPTION_ICUDATADIR,
|
2005-05-03 23:14:17 +00:00
|
|
|
UOPTION_DEF("csource", 'C', UOPT_NO_ARG),
|
|
|
|
UOPTION_DEF("prune", 'p', UOPT_REQUIRES_ARG)
|
2001-06-20 22:24:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int
|
|
|
|
main(int argc, char* argv[]) {
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
2001-06-20 22:24:42 +00:00
|
|
|
char filename[300];
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
2001-06-20 22:24:42 +00:00
|
|
|
const char *srcDir=NULL, *destDir=NULL, *suffix=NULL;
|
|
|
|
char *basename=NULL;
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
/* preset then read command line options */
|
|
|
|
options[4].value=u_getDataDirectory();
|
|
|
|
options[5].value="";
|
|
|
|
options[6].value="3.0.0";
|
2004-09-13 23:40:06 +00:00
|
|
|
options[ICUDATADIR].value=u_getDataDirectory();
|
2001-06-20 22:24:42 +00:00
|
|
|
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
|
|
|
|
|
|
|
|
/* error handling, printing usage message */
|
|
|
|
if(argc<0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"error in command line argument \"%s\"\n",
|
|
|
|
argv[-argc]);
|
|
|
|
}
|
|
|
|
if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
|
2001-11-20 02:46:46 +00:00
|
|
|
/*
|
|
|
|
* Broken into chucks because the C89 standard says the minimum
|
|
|
|
* required supported string length is 509 bytes.
|
|
|
|
*/
|
2001-06-20 22:24:42 +00:00
|
|
|
fprintf(stderr,
|
2001-11-20 02:46:46 +00:00
|
|
|
"Usage: %s [-options] [suffix]\n"
|
|
|
|
"\n"
|
|
|
|
"Read the UnicodeData.txt file and other Unicode properties files and\n"
|
2002-07-17 03:56:50 +00:00
|
|
|
"create a binary file " U_ICUDATA_NAME "_" DATA_NAME "." DATA_TYPE " with the normalization data\n"
|
2001-11-20 02:46:46 +00:00
|
|
|
"\n",
|
2001-06-20 22:24:42 +00:00
|
|
|
argv[0]);
|
2001-11-20 02:46:46 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Options:\n"
|
|
|
|
"\t-h or -? or --help this usage text\n"
|
|
|
|
"\t-v or --verbose verbose output\n"
|
|
|
|
"\t-c or --copyright include a copyright notice\n"
|
2005-05-05 17:41:51 +00:00
|
|
|
"\t-u or --unicode Unicode version, followed by the version like 3.0.0\n"
|
|
|
|
"\t-C or --csource generate a .c source file rather than the .icu binary\n");
|
2005-01-04 00:46:14 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"\t-p or --prune flags Prune for data modularization:\n"
|
|
|
|
"\t Determine what data is to be stored.\n"
|
|
|
|
"\t 0 (zero) stores minimal data (only for NFD)\n"
|
|
|
|
"\t lowercase letters turn off data, uppercase turn on (use with 0)\n");
|
|
|
|
fprintf(stderr,
|
|
|
|
"\t k: compatibility decompositions (NFKC, NFKD)\n"
|
|
|
|
"\t c: composition data (NFC, NFKC)\n"
|
|
|
|
"\t f: FCD data (will be generated at load time)\n"
|
|
|
|
"\t a: auxiliary data (canonical closure etc.)\n"
|
|
|
|
"\t x: exclusion sets (Unicode 3.2-level normalization)\n");
|
2001-11-20 02:46:46 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"\t-d or --destdir destination directory, followed by the path\n"
|
|
|
|
"\t-s or --sourcedir source directory, followed by the path\n"
|
2004-09-14 13:47:24 +00:00
|
|
|
"\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
|
|
|
|
"\t followed by path, defaults to <%s>\n"
|
2001-11-20 02:46:46 +00:00
|
|
|
"\tsuffix suffix that is to be appended with a '-'\n"
|
|
|
|
"\t to the source file basenames before opening;\n"
|
2004-09-14 13:47:24 +00:00
|
|
|
"\t 'gennorm new' will read UnicodeData-new.txt etc.\n",
|
|
|
|
u_getDataDirectory());
|
2001-06-20 22:24:42 +00:00
|
|
|
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the options values */
|
|
|
|
beVerbose=options[2].doesOccur;
|
|
|
|
haveCopyright=options[3].doesOccur;
|
|
|
|
srcDir=options[5].value;
|
|
|
|
destDir=options[4].value;
|
|
|
|
|
|
|
|
if(argc>=2) {
|
|
|
|
suffix=argv[1];
|
|
|
|
} else {
|
|
|
|
suffix=NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#if UCONFIG_NO_NORMALIZATION
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
"gennorm writes a dummy " U_ICUDATA_NAME "_" DATA_NAME "." DATA_TYPE
|
|
|
|
" because UCONFIG_NO_NORMALIZATION is set, \n"
|
|
|
|
"see icu/source/common/unicode/uconfig.h\n");
|
|
|
|
generateData(destDir);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
setUnicodeVersion(options[6].value);
|
|
|
|
|
2004-09-13 23:40:06 +00:00
|
|
|
if (options[ICUDATADIR].doesOccur) {
|
|
|
|
u_setDataDirectory(options[ICUDATADIR].value);
|
|
|
|
}
|
|
|
|
|
2005-01-04 00:46:14 +00:00
|
|
|
if(options[STORE_FLAGS].doesOccur) {
|
|
|
|
const char *s=options[STORE_FLAGS].value;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
while((c=*s++)!=0) {
|
|
|
|
switch(c) {
|
|
|
|
case '0':
|
|
|
|
gStoreFlags=0; /* store minimal data (only for NFD) */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* lowercase letters: omit data */
|
|
|
|
case 'k':
|
|
|
|
gStoreFlags&=~U_MASK(UGENNORM_STORE_COMPAT);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
gStoreFlags&=~U_MASK(UGENNORM_STORE_COMPOSITION);
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
gStoreFlags&=~U_MASK(UGENNORM_STORE_FCD);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
gStoreFlags&=~U_MASK(UGENNORM_STORE_AUX);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
gStoreFlags&=~U_MASK(UGENNORM_STORE_EXCLUSIONS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* uppercase letters: include data (use with 0) */
|
|
|
|
case 'K':
|
|
|
|
gStoreFlags|=U_MASK(UGENNORM_STORE_COMPAT);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
gStoreFlags|=U_MASK(UGENNORM_STORE_COMPOSITION);
|
|
|
|
break;
|
|
|
|
case 'F':
|
|
|
|
gStoreFlags|=U_MASK(UGENNORM_STORE_FCD);
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
gStoreFlags|=U_MASK(UGENNORM_STORE_AUX);
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
gStoreFlags|=U_MASK(UGENNORM_STORE_EXCLUSIONS);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "ignoring undefined prune flag '%c'\n", c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-13 23:40:06 +00:00
|
|
|
/*
|
|
|
|
* Verify that we can work with properties
|
|
|
|
* but don't call u_init() because that needs unorm.icu which we are just
|
|
|
|
* going to build here.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
U_STRING_DECL(ideo, "[:Ideographic:]", 15);
|
|
|
|
USet *set;
|
|
|
|
|
|
|
|
U_STRING_INIT(ideo, "[:Ideographic:]", 15);
|
|
|
|
set=uset_openPattern(ideo, -1, &errorCode);
|
|
|
|
if(U_FAILURE(errorCode) || !uset_contains(set, 0xf900)) {
|
|
|
|
fprintf(stderr, "gennorm is unable to work with properties (uprops.icu): %s\n", u_errorName(errorCode));
|
|
|
|
exit(errorCode);
|
|
|
|
}
|
|
|
|
uset_close(set);
|
|
|
|
}
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
/* prepare the filename beginning with the source dir */
|
|
|
|
uprv_strcpy(filename, srcDir);
|
|
|
|
basename=filename+uprv_strlen(filename);
|
|
|
|
if(basename>filename && *(basename-1)!=U_FILE_SEP_CHAR) {
|
|
|
|
*basename++=U_FILE_SEP_CHAR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize */
|
|
|
|
init();
|
|
|
|
|
2002-05-31 01:16:58 +00:00
|
|
|
/* process DerivedNormalizationProps.txt (name changed for Unicode 3.2, to <=31 characters) */
|
2001-06-20 22:24:42 +00:00
|
|
|
if(suffix==NULL) {
|
2002-05-31 01:16:58 +00:00
|
|
|
uprv_strcpy(basename, "DerivedNormalizationProps.txt");
|
2001-06-20 22:24:42 +00:00
|
|
|
} else {
|
2002-05-31 01:16:58 +00:00
|
|
|
uprv_strcpy(basename, "DerivedNormalizationProps");
|
2001-06-20 22:24:42 +00:00
|
|
|
basename[30]='-';
|
|
|
|
uprv_strcpy(basename+31, suffix);
|
|
|
|
uprv_strcat(basename+31, ".txt");
|
|
|
|
}
|
2002-05-31 01:16:58 +00:00
|
|
|
parseDerivedNormalizationProperties(filename, &errorCode, FALSE);
|
|
|
|
if(U_FAILURE(errorCode)) {
|
|
|
|
/* can be only U_FILE_ACCESS_ERROR - try filename from before Unicode 3.2 */
|
|
|
|
if(suffix==NULL) {
|
|
|
|
uprv_strcpy(basename, "DerivedNormalizationProperties.txt");
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(basename, "DerivedNormalizationProperties");
|
|
|
|
basename[30]='-';
|
|
|
|
uprv_strcpy(basename+31, suffix);
|
|
|
|
uprv_strcat(basename+31, ".txt");
|
|
|
|
}
|
|
|
|
parseDerivedNormalizationProperties(filename, &errorCode, TRUE);
|
|
|
|
}
|
2001-06-20 22:24:42 +00:00
|
|
|
|
|
|
|
/* process UnicodeData.txt */
|
|
|
|
if(suffix==NULL) {
|
|
|
|
uprv_strcpy(basename, "UnicodeData.txt");
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(basename, "UnicodeData");
|
|
|
|
basename[11]='-';
|
|
|
|
uprv_strcpy(basename+12, suffix);
|
|
|
|
uprv_strcat(basename+12, ".txt");
|
|
|
|
}
|
|
|
|
parseDB(filename, &errorCode);
|
|
|
|
|
|
|
|
/* process parsed data */
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
processData();
|
|
|
|
|
|
|
|
/* write the properties data file */
|
2005-05-03 23:14:17 +00:00
|
|
|
generateData(destDir, options[CSOURCE].doesOccur);
|
2001-07-03 16:45:54 +00:00
|
|
|
|
|
|
|
cleanUpData();
|
2001-06-20 22:24:42 +00:00
|
|
|
}
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
return errorCode;
|
|
|
|
}
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#if !UCONFIG_NO_NORMALIZATION
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
/* parser for DerivedNormalizationProperties.txt ---------------------------- */
|
|
|
|
|
2002-07-23 23:01:08 +00:00
|
|
|
static void U_CALLCONV
|
2001-06-20 22:24:42 +00:00
|
|
|
derivedNormalizationPropertiesLineFn(void *context,
|
|
|
|
char *fields[][2], int32_t fieldCount,
|
|
|
|
UErrorCode *pErrorCode) {
|
2002-03-07 19:49:37 +00:00
|
|
|
UChar string[32];
|
2001-06-20 22:24:42 +00:00
|
|
|
char *s;
|
|
|
|
uint32_t start, end;
|
|
|
|
int32_t count;
|
|
|
|
uint8_t qcFlags;
|
|
|
|
|
|
|
|
/* get code point range */
|
2002-02-25 18:45:32 +00:00
|
|
|
count=u_parseCodePointRange(fields[0][0], &start, &end, pErrorCode);
|
2001-06-20 22:24:42 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
fprintf(stderr, "gennorm: error parsing DerivedNormalizationProperties.txt mapping at %s\n", fields[0][0]);
|
|
|
|
exit(*pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ignore hangul - handle explicitly */
|
|
|
|
if(start==0xac00) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get property - ignore unrecognized ones */
|
2002-02-25 18:45:32 +00:00
|
|
|
s=(char *)u_skipWhitespace(fields[1][0]);
|
2001-06-20 22:24:42 +00:00
|
|
|
if(*s=='N' && s[1]=='F') {
|
2002-03-07 19:49:37 +00:00
|
|
|
/* quick check flag */
|
2001-06-20 22:24:42 +00:00
|
|
|
qcFlags=0x11;
|
|
|
|
s+=2;
|
|
|
|
if(*s=='K') {
|
|
|
|
qcFlags<<=1;
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*s=='C' && s[1]=='_') {
|
|
|
|
s+=2;
|
|
|
|
} else if(*s=='D' && s[1]=='_') {
|
|
|
|
qcFlags<<=2;
|
|
|
|
s+=2;
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-11-12 00:38:34 +00:00
|
|
|
if(0==uprv_strncmp(s, "NO", 2)) {
|
2001-06-20 22:24:42 +00:00
|
|
|
qcFlags&=0xf;
|
2004-11-12 00:38:34 +00:00
|
|
|
} else if(0==uprv_strncmp(s, "MAYBE", 5)) {
|
2001-06-20 22:24:42 +00:00
|
|
|
qcFlags&=0x30;
|
2004-11-12 00:38:34 +00:00
|
|
|
} else if(0==uprv_strncmp(s, "QC", 2) && *(s=(char *)u_skipWhitespace(s+2))==';') {
|
2004-04-02 17:41:06 +00:00
|
|
|
/*
|
|
|
|
* Unicode 4.0.1:
|
|
|
|
* changes single field "NFD_NO" -> two fields "NFD_QC; N" etc.
|
|
|
|
*/
|
|
|
|
/* start of the field */
|
|
|
|
s=(char *)u_skipWhitespace(s+1);
|
|
|
|
if(*s=='N') {
|
|
|
|
qcFlags&=0xf;
|
|
|
|
} else if(*s=='M') {
|
|
|
|
qcFlags&=0x30;
|
|
|
|
} else {
|
|
|
|
return; /* do nothing for "Yes" because it's the default value */
|
|
|
|
}
|
2001-06-20 22:24:42 +00:00
|
|
|
} else {
|
2004-04-02 17:41:06 +00:00
|
|
|
return; /* do nothing for "Yes" because it's the default value */
|
2001-06-20 22:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set this flag for all code points in this range */
|
|
|
|
while(start<=end) {
|
|
|
|
setQCFlags(start++, qcFlags);
|
|
|
|
}
|
2002-05-31 01:16:58 +00:00
|
|
|
} else if(0==uprv_memcmp(s, "Comp_Ex", 7) || 0==uprv_memcmp(s, "Full_Composition_Exclusion", 26)) {
|
2002-03-07 19:49:37 +00:00
|
|
|
/* full composition exclusion */
|
2001-06-20 22:24:42 +00:00
|
|
|
while(start<=end) {
|
|
|
|
setCompositionExclusion(start++);
|
|
|
|
}
|
2004-04-02 17:41:06 +00:00
|
|
|
} else if(
|
2004-04-03 07:16:55 +00:00
|
|
|
((0==uprv_memcmp(s, "FNC", 3) && *(s=(char *)u_skipWhitespace(s+3))==';') ||
|
|
|
|
(0==uprv_memcmp(s, "FC_NFKC", 7) && *(s=(char *)u_skipWhitespace(s+7))==';'))
|
|
|
|
|
2004-04-02 17:41:06 +00:00
|
|
|
) {
|
2002-03-07 19:49:37 +00:00
|
|
|
/* FC_NFKC_Closure, parse field 2 to get the string */
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
/* start of the field */
|
|
|
|
s=(char *)u_skipWhitespace(s+1);
|
|
|
|
|
|
|
|
/* find the end of the field */
|
|
|
|
for(t=s; *t!=';' && *t!='#' && *t!=0 && *t!='\n' && *t!='\r'; ++t) {}
|
|
|
|
*t=0;
|
|
|
|
|
|
|
|
string[0]=(UChar)u_parseString(s, string+1, 31, NULL, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
fprintf(stderr, "gennorm error: illegal FNC string at %s\n", fields[0][0]);
|
|
|
|
exit(*pErrorCode);
|
|
|
|
}
|
|
|
|
while(start<=end) {
|
|
|
|
setFNC(start++, string);
|
|
|
|
}
|
2001-06-20 22:24:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-05-31 01:16:58 +00:00
|
|
|
parseDerivedNormalizationProperties(const char *filename, UErrorCode *pErrorCode, UBool reportError) {
|
2001-06-20 22:24:42 +00:00
|
|
|
char *fields[2][2];
|
|
|
|
|
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_parseDelimitedFile(filename, ';', fields, 2, derivedNormalizationPropertiesLineFn, NULL, pErrorCode);
|
2002-05-31 01:16:58 +00:00
|
|
|
if(U_FAILURE(*pErrorCode) && (reportError || *pErrorCode!=U_FILE_ACCESS_ERROR)) {
|
2002-03-15 19:22:46 +00:00
|
|
|
fprintf(stderr, "gennorm error: u_parseDelimitedFile(\"%s\") failed - %s\n", filename, u_errorName(*pErrorCode));
|
|
|
|
exit(*pErrorCode);
|
|
|
|
}
|
2001-06-20 22:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* parser for UnicodeData.txt ----------------------------------------------- */
|
|
|
|
|
2002-07-23 23:01:08 +00:00
|
|
|
static void U_CALLCONV
|
2001-06-20 22:24:42 +00:00
|
|
|
unicodeDataLineFn(void *context,
|
|
|
|
char *fields[][2], int32_t fieldCount,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
uint32_t decomp[40];
|
|
|
|
Norm norm;
|
|
|
|
const char *s;
|
|
|
|
char *end;
|
|
|
|
uint32_t code, value;
|
|
|
|
int32_t length;
|
|
|
|
UBool isCompat, something=FALSE;
|
|
|
|
|
|
|
|
/* ignore First and Last entries for ranges */
|
|
|
|
if( *fields[1][0]=='<' &&
|
2002-05-23 22:10:23 +00:00
|
|
|
(length=(int32_t)(fields[1][1]-fields[1][0]))>=9 &&
|
2001-06-20 22:24:42 +00:00
|
|
|
(0==uprv_memcmp(", First>", fields[1][1]-8, 8) || 0==uprv_memcmp(", Last>", fields[1][1]-7, 7))
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reset the properties */
|
|
|
|
uprv_memset(&norm, 0, sizeof(Norm));
|
|
|
|
|
2005-05-17 18:19:02 +00:00
|
|
|
/*
|
|
|
|
* The combiningIndex must not be initialized to 0 because 0 is the
|
|
|
|
* combiningIndex of the first forward-combining character.
|
|
|
|
*/
|
|
|
|
norm.combiningIndex=0xffff;
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
/* get the character code, field 0 */
|
|
|
|
code=(uint32_t)uprv_strtoul(fields[0][0], &end, 16);
|
|
|
|
if(end<=fields[0][0] || end!=fields[0][1]) {
|
|
|
|
fprintf(stderr, "gennorm: syntax error in field 0 at %s\n", fields[0][0]);
|
|
|
|
*pErrorCode=U_PARSE_ERROR;
|
|
|
|
exit(U_PARSE_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get canonical combining class, field 3 */
|
|
|
|
value=(uint32_t)uprv_strtoul(fields[3][0], &end, 10);
|
|
|
|
if(end<=fields[3][0] || end!=fields[3][1] || value>0xff) {
|
|
|
|
fprintf(stderr, "gennorm: syntax error in field 3 at %s\n", fields[0][0]);
|
|
|
|
*pErrorCode=U_PARSE_ERROR;
|
|
|
|
exit(U_PARSE_ERROR);
|
|
|
|
}
|
|
|
|
if(value>0) {
|
|
|
|
norm.udataCC=(uint8_t)value;
|
|
|
|
something=TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the decomposition, field 5 */
|
|
|
|
if(fields[5][0]<fields[5][1]) {
|
|
|
|
if(*(s=fields[5][0])=='<') {
|
|
|
|
++s;
|
|
|
|
isCompat=TRUE;
|
|
|
|
|
|
|
|
/* skip and ignore the compatibility type name */
|
|
|
|
do {
|
|
|
|
if(s==fields[5][1]) {
|
|
|
|
/* missing '>' */
|
|
|
|
fprintf(stderr, "gennorm: syntax error in field 5 at %s\n", fields[0][0]);
|
|
|
|
*pErrorCode=U_PARSE_ERROR;
|
|
|
|
exit(U_PARSE_ERROR);
|
|
|
|
}
|
|
|
|
} while(*s++!='>');
|
|
|
|
} else {
|
|
|
|
isCompat=FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse the decomposition string */
|
2002-02-25 18:45:32 +00:00
|
|
|
length=u_parseCodePoints(s, decomp, sizeof(decomp)/4, pErrorCode);
|
2001-06-20 22:24:42 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
2002-03-15 19:22:46 +00:00
|
|
|
fprintf(stderr, "gennorm error parsing UnicodeData.txt decomposition of U+%04lx - %s\n",
|
|
|
|
(long)code, u_errorName(*pErrorCode));
|
2001-06-20 22:24:42 +00:00
|
|
|
exit(*pErrorCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* store the string */
|
|
|
|
if(length>0) {
|
|
|
|
something=TRUE;
|
|
|
|
if(isCompat) {
|
|
|
|
norm.lenNFKD=(uint8_t)length;
|
|
|
|
norm.nfkd=decomp;
|
|
|
|
} else {
|
|
|
|
if(length>2) {
|
|
|
|
fprintf(stderr, "gennorm: error - length of NFD(U+%04lx) = %ld >2 in UnicodeData - illegal\n",
|
2001-07-03 16:45:54 +00:00
|
|
|
(long)code, (long)length);
|
2001-06-20 22:24:42 +00:00
|
|
|
*pErrorCode=U_PARSE_ERROR;
|
|
|
|
exit(U_PARSE_ERROR);
|
|
|
|
}
|
|
|
|
norm.lenNFD=(uint8_t)length;
|
|
|
|
norm.nfd=decomp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for non-character code points */
|
|
|
|
if((code&0xfffe)==0xfffe || (uint32_t)(code-0xfdd0)<0x20 || code>0x10ffff) {
|
|
|
|
fprintf(stderr, "gennorm: error - properties for non-character code point U+%04lx\n",
|
2001-07-03 16:45:54 +00:00
|
|
|
(long)code);
|
2001-06-20 22:24:42 +00:00
|
|
|
*pErrorCode=U_PARSE_ERROR;
|
|
|
|
exit(U_PARSE_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(something) {
|
|
|
|
/* there are normalization values, so store them */
|
2002-03-07 19:49:37 +00:00
|
|
|
#if 0
|
2001-06-20 22:24:42 +00:00
|
|
|
if(beVerbose) {
|
|
|
|
printf("store values for U+%04lx: cc=%d, lenNFD=%ld, lenNFKD=%ld\n",
|
2001-07-03 16:45:54 +00:00
|
|
|
(long)code, norm.udataCC, (long)norm.lenNFD, (long)norm.lenNFKD);
|
2001-06-20 22:24:42 +00:00
|
|
|
}
|
2002-03-07 19:49:37 +00:00
|
|
|
#endif
|
2001-06-20 22:24:42 +00:00
|
|
|
storeNorm(code, &norm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parseDB(const char *filename, UErrorCode *pErrorCode) {
|
|
|
|
char *fields[15][2];
|
|
|
|
|
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_parseDelimitedFile(filename, ';', fields, 15, unicodeDataLineFn, NULL, pErrorCode);
|
2002-03-15 19:22:46 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
fprintf(stderr, "gennorm error: u_parseDelimitedFile(\"%s\") failed - %s\n", filename, u_errorName(*pErrorCode));
|
|
|
|
exit(*pErrorCode);
|
|
|
|
}
|
2001-06-20 22:24:42 +00:00
|
|
|
}
|
|
|
|
|
2003-05-06 01:37:52 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_NORMALIZATION */
|
|
|
|
|
2001-06-20 22:24:42 +00:00
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|