2001-02-23 04:57:47 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000-2001, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: genuca.cpp
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
2001-02-26 10:28:56 +00:00
|
|
|
* created at the end of XX century
|
|
|
|
* created by: Vladimir Weinstein
|
|
|
|
*
|
2001-02-23 04:57:47 +00:00
|
|
|
* This program reads the Franctional UCA table and generates
|
|
|
|
* internal format for UCA table as well as inverse UCA table.
|
|
|
|
* It then writes binary files containing the data: ucadata.dat
|
|
|
|
* & invuca.dat
|
2001-02-23 19:10:28 +00:00
|
|
|
* Change history:
|
|
|
|
* 02/23/2001 grhoten Made it into a tool
|
2001-02-26 10:28:56 +00:00
|
|
|
* 02/23/2001 weiv Moved element & table handling code to i18n
|
2001-05-10 22:32:08 +00:00
|
|
|
* 05/09/2001 weiv Case bits are now in the CEs, not in front
|
2001-02-23 04:57:47 +00:00
|
|
|
*/
|
|
|
|
|
2001-02-22 23:30:21 +00:00
|
|
|
#include "genuca.h"
|
2001-02-23 01:21:38 +00:00
|
|
|
#include "uoptions.h"
|
|
|
|
#include "toolutil.h"
|
2001-02-23 04:57:47 +00:00
|
|
|
#include "cstring.h"
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2002-02-28 01:42:40 +00:00
|
|
|
#include "cmemory.h"
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
UCAElements le;
|
|
|
|
|
2001-02-23 01:21:38 +00:00
|
|
|
/*
|
|
|
|
* Global - verbosity
|
|
|
|
*/
|
|
|
|
UBool VERBOSE = FALSE;
|
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
int32_t readElement(char **from, char *to, char separator, UErrorCode *status) {
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
char buffer[1024];
|
|
|
|
int32_t i = 0;
|
|
|
|
while(**from != separator) {
|
|
|
|
if(**from != ' ') {
|
|
|
|
*(buffer+i++) = **from;
|
|
|
|
}
|
|
|
|
(*from)++;
|
|
|
|
}
|
|
|
|
(*from)++;
|
|
|
|
*(buffer + i) = 0;
|
|
|
|
//*to = (char *)malloc(strlen(buffer)+1);
|
|
|
|
strcpy(to, buffer);
|
|
|
|
return i/2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-10 22:32:08 +00:00
|
|
|
uint32_t getSingleCEValue(char *primary, char *secondary, char *tertiary, UErrorCode *status) {
|
2001-02-22 21:18:29 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
uint32_t value = 0;
|
|
|
|
char primsave = '\0';
|
|
|
|
char secsave = '\0';
|
|
|
|
char tersave = '\0';
|
|
|
|
char *primend = primary+4;
|
|
|
|
if(strlen(primary) > 4) {
|
|
|
|
primsave = *primend;
|
|
|
|
*primend = '\0';
|
|
|
|
}
|
|
|
|
char *secend = secondary+2;
|
|
|
|
if(strlen(secondary) > 2) {
|
|
|
|
secsave = *secend;
|
|
|
|
*secend = '\0';
|
|
|
|
}
|
|
|
|
char *terend = tertiary+2;
|
|
|
|
if(strlen(tertiary) > 2) {
|
|
|
|
tersave = *terend;
|
|
|
|
*terend = '\0';
|
|
|
|
}
|
2001-05-22 22:25:48 +00:00
|
|
|
uint32_t primvalue = (uint32_t)((*primary!='\0')?strtoul(primary, &primend, 16):0);
|
|
|
|
uint32_t secvalue = (uint32_t)((*secondary!='\0')?strtoul(secondary, &secend, 16):0);
|
|
|
|
uint32_t tervalue = (uint32_t)((*tertiary!='\0')?strtoul(tertiary, &terend, 16):0);
|
2001-02-22 21:18:29 +00:00
|
|
|
if(primvalue <= 0xFF) {
|
|
|
|
primvalue <<= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = ((primvalue<<UCOL_PRIMARYORDERSHIFT)&UCOL_PRIMARYORDERMASK)|
|
|
|
|
((secvalue<<UCOL_SECONDARYORDERSHIFT)&UCOL_SECONDARYORDERMASK)|
|
|
|
|
(tervalue&UCOL_TERTIARYORDERMASK);
|
|
|
|
|
|
|
|
if(primsave!='\0') {
|
|
|
|
*primend = primsave;
|
|
|
|
}
|
|
|
|
if(secsave!='\0') {
|
|
|
|
*secend = secsave;
|
|
|
|
}
|
|
|
|
if(tersave!='\0') {
|
|
|
|
*terend = tersave;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static uint32_t inverseTable[0xFFFF][3];
|
|
|
|
static uint32_t inversePos = 0;
|
|
|
|
static UChar stringContinue[0xFFFF];
|
|
|
|
static uint32_t sContPos = 0;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static void addNewInverse(UCAElements *element, UErrorCode *status) {
|
2001-03-22 21:16:20 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
2001-02-26 10:28:56 +00:00
|
|
|
if(VERBOSE && isContinuation(element->CEs[1])) {
|
2001-11-10 00:13:03 +00:00
|
|
|
//fprintf(stdout, "+");
|
2001-02-26 10:28:56 +00:00
|
|
|
}
|
|
|
|
inversePos++;
|
|
|
|
inverseTable[inversePos][0] = element->CEs[0];
|
|
|
|
if(element->noOfCEs > 1 && isContinuation(element->CEs[1])) {
|
|
|
|
inverseTable[inversePos][1] = element->CEs[1];
|
2001-03-15 21:54:36 +00:00
|
|
|
} else {
|
|
|
|
inverseTable[inversePos][1] = 0;
|
2001-02-26 10:28:56 +00:00
|
|
|
}
|
|
|
|
if(element->cSize < 2) {
|
|
|
|
inverseTable[inversePos][2] = element->cPoints[0];
|
|
|
|
} else { /* add a new store of cruft */
|
|
|
|
inverseTable[inversePos][2] = ((element->cSize+1) << UCOL_INV_SHIFTVALUE) | sContPos;
|
|
|
|
memcpy(stringContinue+sContPos, element->cPoints, element->cSize*sizeof(UChar));
|
|
|
|
sContPos += element->cSize+1;
|
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static void insertInverse(UCAElements *element, uint32_t position, UErrorCode *status) {
|
2001-03-15 21:54:36 +00:00
|
|
|
uint8_t space[4096];
|
2001-03-15 02:36:03 +00:00
|
|
|
|
2001-03-22 21:16:20 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-03-15 02:36:03 +00:00
|
|
|
if(VERBOSE && isContinuation(element->CEs[1])) {
|
2001-11-10 00:13:03 +00:00
|
|
|
//fprintf(stdout, "+");
|
2001-03-15 02:36:03 +00:00
|
|
|
}
|
|
|
|
if(position <= inversePos) {
|
|
|
|
/*move stuff around */
|
2001-03-15 21:54:36 +00:00
|
|
|
uprv_memcpy(space, inverseTable[position], (inversePos - position+1)*sizeof(inverseTable[0]));
|
|
|
|
uprv_memcpy(inverseTable[position+1], space, (inversePos - position+1)*sizeof(inverseTable[0]));
|
2001-03-15 02:36:03 +00:00
|
|
|
}
|
|
|
|
inverseTable[position][0] = element->CEs[0];
|
|
|
|
if(element->noOfCEs > 1 && isContinuation(element->CEs[1])) {
|
|
|
|
inverseTable[position][1] = element->CEs[1];
|
|
|
|
} else {
|
|
|
|
inverseTable[position][1] = 0;
|
|
|
|
}
|
|
|
|
if(element->cSize < 2) {
|
|
|
|
inverseTable[position][2] = element->cPoints[0];
|
|
|
|
} else { /* add a new store of cruft */
|
|
|
|
inverseTable[position][2] = ((element->cSize+1) << UCOL_INV_SHIFTVALUE) | sContPos;
|
|
|
|
memcpy(stringContinue+sContPos, element->cPoints, element->cSize*sizeof(UChar));
|
|
|
|
sContPos += element->cSize+1;
|
|
|
|
}
|
|
|
|
inversePos++;
|
|
|
|
}
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static void addToExistingInverse(UCAElements *element, uint32_t position, UErrorCode *status) {
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-03-22 21:16:20 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
if((inverseTable[position][2] & UCOL_INV_SIZEMASK) == 0) { /* single element, have to make new extension place and put both guys there */
|
2001-02-23 19:10:28 +00:00
|
|
|
stringContinue[sContPos] = (UChar)inverseTable[position][2];
|
2001-02-22 21:18:29 +00:00
|
|
|
inverseTable[position][2] = ((element->cSize+3) << UCOL_INV_SHIFTVALUE) | sContPos;
|
|
|
|
sContPos++;
|
|
|
|
stringContinue[sContPos++] = 0xFFFF;
|
|
|
|
memcpy(stringContinue+sContPos, element->cPoints, element->cSize*sizeof(UChar));
|
|
|
|
sContPos += element->cSize;
|
|
|
|
stringContinue[sContPos++] = 0xFFFE;
|
2001-02-26 10:28:56 +00:00
|
|
|
} else { /* adding to the already existing continuing table */
|
2001-02-22 21:18:29 +00:00
|
|
|
uint32_t contIndex = inverseTable[position][2] & UCOL_INV_OFFSETMASK;
|
|
|
|
uint32_t contSize = (inverseTable[position][2] & UCOL_INV_SIZEMASK) >> UCOL_INV_SHIFTVALUE;
|
|
|
|
|
|
|
|
if(contIndex+contSize < sContPos) {
|
2001-02-26 10:28:56 +00:00
|
|
|
/*fprintf(stderr, ".", sContPos, contIndex+contSize);*/
|
|
|
|
memcpy(stringContinue+contIndex+contSize+element->cSize+1, stringContinue+contIndex+contSize, (element->cSize+1)*sizeof(UChar));
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stringContinue[contIndex+contSize-1] = 0xFFFF;
|
|
|
|
memcpy(stringContinue+contIndex+contSize, element->cPoints, element->cSize*sizeof(UChar));
|
|
|
|
sContPos += element->cSize+1;
|
|
|
|
stringContinue[contIndex+contSize+element->cSize] = 0xFFFE;
|
|
|
|
|
|
|
|
inverseTable[position][2] = ((contSize+element->cSize+1) << UCOL_INV_SHIFTVALUE) | contIndex;
|
2001-02-26 10:28:56 +00:00
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static uint32_t addToInverse(UCAElements *element, UErrorCode *status) {
|
2001-03-15 21:54:36 +00:00
|
|
|
uint32_t comp = 0;
|
|
|
|
uint32_t position = inversePos;
|
2001-05-10 22:32:08 +00:00
|
|
|
uint32_t saveElement = element->CEs[0];
|
|
|
|
element->CEs[0] &= 0xFFFFFF3F;
|
2001-03-15 21:54:36 +00:00
|
|
|
if(element->noOfCEs == 1) {
|
|
|
|
element->CEs[1] = 0;
|
|
|
|
}
|
|
|
|
if(inversePos == 0) {
|
|
|
|
inverseTable[0][0] = inverseTable[0][1] = inverseTable[0][2] = 0;
|
|
|
|
addNewInverse(element, status);
|
|
|
|
} else if(inverseTable[inversePos][0] > element->CEs[0]) {
|
|
|
|
while(inverseTable[--position][0] > element->CEs[0]) {}
|
2001-03-15 02:36:03 +00:00
|
|
|
if(inverseTable[position][0] == element->CEs[0]) {
|
2001-03-15 21:54:36 +00:00
|
|
|
if(isContinuation(element->CEs[1])) {
|
|
|
|
comp = element->CEs[1];
|
|
|
|
} else {
|
|
|
|
comp = 0;
|
|
|
|
}
|
|
|
|
if(inverseTable[position][1] > comp) {
|
|
|
|
while(inverseTable[--position][1] > comp) {}
|
|
|
|
}
|
|
|
|
if(inverseTable[position][1] == comp) {
|
|
|
|
addToExistingInverse(element, position, status);
|
|
|
|
} else {
|
|
|
|
insertInverse(element, position+1, status);
|
|
|
|
}
|
2001-03-15 02:36:03 +00:00
|
|
|
} else {
|
|
|
|
insertInverse(element, position+1, status);
|
|
|
|
}
|
2001-03-15 21:54:36 +00:00
|
|
|
} else if(inverseTable[inversePos][0] == element->CEs[0]) {
|
|
|
|
if(element->noOfCEs > 1 && isContinuation(element->CEs[1])) {
|
|
|
|
comp = element->CEs[1];
|
|
|
|
if(inverseTable[position][1] > comp) {
|
|
|
|
while(inverseTable[--position][1] > comp) {}
|
|
|
|
}
|
|
|
|
if(inverseTable[position][1] == comp) {
|
|
|
|
addToExistingInverse(element, position, status);
|
|
|
|
} else {
|
|
|
|
insertInverse(element, position+1, status);
|
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
} else {
|
2001-02-26 10:28:56 +00:00
|
|
|
addToExistingInverse(element, inversePos, status);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addNewInverse(element, status);
|
|
|
|
}
|
2001-05-10 22:32:08 +00:00
|
|
|
element->CEs[0] = saveElement;
|
2001-02-26 10:28:56 +00:00
|
|
|
return inversePos;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static InverseTableHeader *assembleInverseTable(UErrorCode *status)
|
2001-02-23 01:21:38 +00:00
|
|
|
{
|
2001-02-26 10:28:56 +00:00
|
|
|
InverseTableHeader *result = NULL;
|
|
|
|
uint32_t headerByteSize = paddedsize(sizeof(InverseTableHeader));
|
|
|
|
uint32_t inverseTableByteSize = (inversePos+2)*sizeof(uint32_t)*3;
|
|
|
|
uint32_t contsByteSize = sContPos * sizeof(UChar);
|
2001-03-15 21:54:36 +00:00
|
|
|
uint32_t i = 0;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2002-02-28 01:42:40 +00:00
|
|
|
result = (InverseTableHeader *)uprv_malloc(headerByteSize + inverseTableByteSize + contsByteSize);
|
2001-02-26 10:28:56 +00:00
|
|
|
if(result != NULL) {
|
|
|
|
result->byteSize = headerByteSize + inverseTableByteSize + contsByteSize;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
inversePos++;
|
|
|
|
inverseTable[inversePos][0] = 0xFFFFFFFF;
|
|
|
|
inverseTable[inversePos][1] = 0xFFFFFFFF;
|
|
|
|
inverseTable[inversePos][2] = 0x0000FFFF;
|
|
|
|
inversePos++;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-03-15 21:54:36 +00:00
|
|
|
for(i = 2; i<inversePos; i++) {
|
|
|
|
if(inverseTable[i-1][0] > inverseTable[i][0]) {
|
|
|
|
fprintf(stderr, "Error at %i: %08X & %08X\n", i, inverseTable[i-1][0], inverseTable[i][0]);
|
|
|
|
} else if(inverseTable[i-1][0] == inverseTable[i][0] && !(inverseTable[i-1][1] < inverseTable[i][1])) {
|
|
|
|
fprintf(stderr, "Continuation error at %i: %08X %08X & %08X %08X\n", i, inverseTable[i-1][0], inverseTable[i-1][1], inverseTable[i][0], inverseTable[i][1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
result->tableSize = inversePos;
|
|
|
|
result->contsSize = sContPos;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
result->table = headerByteSize;
|
|
|
|
result->conts = headerByteSize + inverseTableByteSize;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
memcpy((uint8_t *)result + result->table, inverseTable, inverseTableByteSize);
|
|
|
|
memcpy((uint8_t *)result + result->conts, stringContinue, contsByteSize);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
return result;
|
2001-02-23 01:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static void writeOutInverseData(InverseTableHeader *data,
|
2001-02-23 01:21:38 +00:00
|
|
|
const char *outputDir,
|
2001-02-23 19:10:28 +00:00
|
|
|
const char *copyright,
|
2001-02-23 01:21:38 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-02-22 21:18:29 +00:00
|
|
|
UNewDataMemory *pData;
|
|
|
|
|
|
|
|
long dataLength;
|
|
|
|
|
2001-10-23 21:48:14 +00:00
|
|
|
pData=udata_create(outputDir, INVC_DATA_TYPE, INVC_DATA_NAME, &invUcaDataInfo,
|
2001-02-23 19:10:28 +00:00
|
|
|
copyright, status);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
fprintf(stderr, "Error: unable to create data memory, error %d\n", *status);
|
2001-02-23 01:21:38 +00:00
|
|
|
return;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write the data to the file */
|
2002-01-04 23:48:46 +00:00
|
|
|
if (VERBOSE) {
|
|
|
|
fprintf(stdout, "Writing out inverse UCA table: %s%c%s.%s\n", outputDir, U_FILE_SEP_CHAR,
|
2001-02-23 19:10:28 +00:00
|
|
|
INVC_DATA_NAME,
|
|
|
|
INVC_DATA_TYPE);
|
2002-01-04 23:48:46 +00:00
|
|
|
}
|
2001-02-23 01:21:38 +00:00
|
|
|
udata_writeBlock(pData, data, data->byteSize);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
/* finish up */
|
|
|
|
dataLength=udata_finish(pData, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
fprintf(stderr, "Error: error %d writing the output file\n", *status);
|
2001-02-23 01:21:38 +00:00
|
|
|
return;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
static int32_t hex2num(char hex) {
|
2001-02-22 21:18:29 +00:00
|
|
|
if(hex>='0' && hex <='9') {
|
|
|
|
return hex-'0';
|
|
|
|
} else if(hex>='a' && hex<='f') {
|
|
|
|
return hex-'a'+10;
|
|
|
|
} else if(hex>='A' && hex<='F') {
|
|
|
|
return hex-'A'+10;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UCAElements *readAnElement(FILE *data, UErrorCode *status) {
|
|
|
|
char buffer[2048], primary[100], secondary[100], tertiary[100];
|
|
|
|
UBool detectedContraction;
|
|
|
|
int32_t i = 0;
|
2001-02-27 20:09:03 +00:00
|
|
|
unsigned int theValue;
|
2001-02-22 21:18:29 +00:00
|
|
|
char *pointer = NULL;
|
|
|
|
char *commentStart = NULL;
|
|
|
|
char *startCodePoint = NULL;
|
|
|
|
char *endCodePoint = NULL;
|
|
|
|
char *spacePointer = NULL;
|
|
|
|
char *result = fgets(buffer, 2048, data);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*primary = *secondary = *tertiary = '\0';
|
|
|
|
if(result == NULL) {
|
|
|
|
if(feof(data)) {
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "empty line but no EOF!\n");
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(buffer[0] == '#' || buffer[0] == '\n') {
|
|
|
|
return NULL; // just a comment, skip whole line
|
|
|
|
}
|
|
|
|
|
|
|
|
UCAElements *element = ≤ //(UCAElements *)malloc(sizeof(UCAElements));
|
|
|
|
|
|
|
|
if(buffer[0] == '[') {
|
2001-05-03 23:10:45 +00:00
|
|
|
const char *vt = "[variable top = ";
|
2001-04-19 17:08:07 +00:00
|
|
|
uint32_t vtLen = uprv_strlen(vt);
|
|
|
|
if(uprv_strncmp(buffer, vt, vtLen) == 0) {
|
2001-02-22 21:18:29 +00:00
|
|
|
element->variableTop = TRUE;
|
2002-03-08 02:16:37 +00:00
|
|
|
if(sscanf(buffer+vtLen, "%4x", &theValue) != 1) /* read first code point */
|
2001-04-19 17:08:07 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, " scanf(hex) failed!\n ");
|
|
|
|
}
|
2001-05-03 23:10:45 +00:00
|
|
|
element->cPoints[0] = (UChar)theValue;
|
2001-02-22 21:18:29 +00:00
|
|
|
return element; // just a comment, skip whole line
|
2001-04-19 17:08:07 +00:00
|
|
|
} else {
|
|
|
|
*status = U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
element->variableTop = FALSE;
|
|
|
|
|
|
|
|
startCodePoint = buffer;
|
|
|
|
endCodePoint = strchr(startCodePoint, ';');
|
|
|
|
|
|
|
|
if(endCodePoint == 0) {
|
|
|
|
fprintf(stderr, "error - line with no code point!\n");
|
|
|
|
*status = U_INVALID_FORMAT_ERROR; /* No code point - could be an error, but probably only an empty line */
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
*(endCodePoint) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(element != NULL) {
|
|
|
|
memset(element, 0, sizeof(*element));
|
|
|
|
} else {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
element->cPoints = element->uchars;
|
|
|
|
|
|
|
|
spacePointer = strchr(buffer, ' ');
|
2002-03-08 02:16:37 +00:00
|
|
|
if(sscanf(buffer, "%4x", &theValue) != 1) /* read first code point */
|
2001-02-27 20:09:03 +00:00
|
|
|
{
|
2001-03-22 21:16:20 +00:00
|
|
|
fprintf(stderr, " scanf(hex) failed!\n ");
|
2001-02-27 20:09:03 +00:00
|
|
|
}
|
2001-05-03 23:10:45 +00:00
|
|
|
element->cPoints[0] = (UChar)theValue;
|
2001-02-27 20:09:03 +00:00
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
if(spacePointer == 0) {
|
|
|
|
detectedContraction = FALSE;
|
|
|
|
element->cSize = 1;
|
|
|
|
} else {
|
|
|
|
i = 1;
|
|
|
|
detectedContraction = TRUE;
|
|
|
|
while(spacePointer != NULL) {
|
2002-03-08 02:16:37 +00:00
|
|
|
sscanf(spacePointer+1, "%4x", &theValue);
|
2001-02-28 21:17:28 +00:00
|
|
|
element->cPoints[i++] = (UChar)theValue;
|
2001-02-22 21:18:29 +00:00
|
|
|
spacePointer = strchr(spacePointer+1, ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
element->cSize = i;
|
|
|
|
|
|
|
|
//fprintf(stderr, "Number of codepoints in contraction: %i\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
startCodePoint = endCodePoint+1;
|
2001-05-10 22:32:08 +00:00
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
commentStart = strchr(startCodePoint, '#');
|
|
|
|
if(commentStart == NULL) {
|
2001-05-10 22:32:08 +00:00
|
|
|
commentStart = strlen(startCodePoint) + startCodePoint - 1;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
uint32_t CEindex = 0;
|
|
|
|
element->noOfCEs = 0;
|
|
|
|
for(;;) {
|
|
|
|
endCodePoint = strchr(startCodePoint, ']');
|
|
|
|
if(endCodePoint == NULL || endCodePoint >= commentStart) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pointer = strchr(startCodePoint, '[');
|
|
|
|
pointer++;
|
|
|
|
|
|
|
|
element->sizePrim[i]=readElement(&pointer, primary, ',', status);
|
|
|
|
element->sizeSec[i]=readElement(&pointer, secondary, ',', status);
|
|
|
|
element->sizeTer[i]=readElement(&pointer, tertiary, ']', status);
|
|
|
|
|
|
|
|
|
|
|
|
/* I want to get the CEs entered right here, including continuation */
|
2001-05-10 22:32:08 +00:00
|
|
|
element->CEs[CEindex++] = getSingleCEValue(primary, secondary, tertiary, status);
|
|
|
|
|
|
|
|
uint32_t CEi = 1;
|
|
|
|
while(2*CEi<element->sizePrim[i] || CEi<element->sizeSec[i] || CEi<element->sizeTer[i]) {
|
|
|
|
uint32_t value = UCOL_CONTINUATION_MARKER; /* Continuation marker */
|
|
|
|
if(2*CEi<element->sizePrim[i]) {
|
|
|
|
value |= ((hex2num(*(primary+4*CEi))&0xF)<<28);
|
|
|
|
value |= ((hex2num(*(primary+4*CEi+1))&0xF)<<24);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(2*CEi+1<element->sizePrim[i]) {
|
|
|
|
value |= ((hex2num(*(primary+4*CEi+2))&0xF)<<20);
|
|
|
|
value |= ((hex2num(*(primary+4*CEi+3))&0xF)<<16);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CEi<element->sizeSec[i]) {
|
|
|
|
value |= ((hex2num(*(secondary+2*CEi))&0xF)<<12);
|
|
|
|
value |= ((hex2num(*(secondary+2*CEi+1))&0xF)<<8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(CEi<element->sizeTer[i]) {
|
|
|
|
value |= ((hex2num(*(tertiary+2*CEi))&0x3)<<4);
|
|
|
|
value |= (hex2num(*(tertiary+2*CEi+1))&0xF);
|
|
|
|
}
|
|
|
|
|
|
|
|
CEi++;
|
|
|
|
|
|
|
|
element->CEs[CEindex++] = value;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-05-10 22:32:08 +00:00
|
|
|
startCodePoint = endCodePoint+1;
|
|
|
|
i++;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
element->noOfCEs = CEindex;
|
|
|
|
|
2001-03-05 20:08:31 +00:00
|
|
|
element->isThai = UCOL_ISTHAIPREVOWEL(element->cPoints[0]);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
// we don't want any strange stuff after useful data!
|
|
|
|
while(pointer < commentStart) {
|
|
|
|
if(*pointer != ' ') {
|
|
|
|
*status=U_INVALID_FORMAT_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2001-03-22 21:16:20 +00:00
|
|
|
pointer++;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
fprintf(stderr, "problem putting stuff in hash table\n");
|
|
|
|
*status = U_INTERNAL_PROGRAM_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-23 01:21:38 +00:00
|
|
|
void writeOutData(UCATableHeader *data,
|
2001-06-08 05:51:29 +00:00
|
|
|
UChar contractions[][3],
|
2001-06-05 22:52:56 +00:00
|
|
|
uint32_t noOfcontractions,
|
2001-02-23 01:21:38 +00:00
|
|
|
const char *outputDir,
|
2001-02-23 19:10:28 +00:00
|
|
|
const char *copyright,
|
2001-02-23 01:21:38 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
2001-02-22 21:18:29 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-06-05 22:52:56 +00:00
|
|
|
uint32_t size = data->size;
|
|
|
|
|
|
|
|
if(noOfcontractions != 0) {
|
|
|
|
contractions[noOfcontractions][0] = 0;
|
|
|
|
contractions[noOfcontractions][1] = 0;
|
|
|
|
contractions[noOfcontractions][2] = 0;
|
|
|
|
noOfcontractions++;
|
|
|
|
|
|
|
|
|
|
|
|
data->contractionUCACombos = size;
|
2001-06-08 05:51:29 +00:00
|
|
|
data->size += paddedsize((noOfcontractions*3*sizeof(UChar)));
|
2001-06-05 22:52:56 +00:00
|
|
|
}
|
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
UNewDataMemory *pData;
|
2001-02-26 10:28:56 +00:00
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
long dataLength;
|
|
|
|
|
2001-10-23 21:48:14 +00:00
|
|
|
pData=udata_create(outputDir, UCA_DATA_TYPE, UCA_DATA_NAME, &ucaDataInfo,
|
2001-02-23 19:10:28 +00:00
|
|
|
copyright, status);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
fprintf(stderr, "Error: unable to create data memory, error %d\n", *status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the data to the file */
|
2002-01-04 23:48:46 +00:00
|
|
|
if (VERBOSE) {
|
|
|
|
fprintf(stdout, "Writing out UCA table: %s%c%s.%s\n", outputDir,
|
|
|
|
U_FILE_SEP_CHAR,
|
2001-02-23 19:10:28 +00:00
|
|
|
UCA_DATA_NAME,
|
|
|
|
UCA_DATA_TYPE);
|
2002-01-04 23:48:46 +00:00
|
|
|
}
|
2001-06-05 22:52:56 +00:00
|
|
|
udata_writeBlock(pData, data, size);
|
|
|
|
|
|
|
|
if(noOfcontractions != 0) {
|
2001-06-08 05:51:29 +00:00
|
|
|
udata_writeBlock(pData, contractions, noOfcontractions*3*sizeof(UChar));
|
|
|
|
udata_writePadding(pData, paddedsize((noOfcontractions*3*sizeof(UChar))) - noOfcontractions*3*sizeof(uint16_t));
|
2001-06-05 22:52:56 +00:00
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
/* finish up */
|
|
|
|
dataLength=udata_finish(pData, status);
|
|
|
|
if(U_FAILURE(*status)) {
|
|
|
|
fprintf(stderr, "Error: error %d writing the output file\n", *status);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-23 01:21:38 +00:00
|
|
|
static int32_t
|
|
|
|
write_uca_table(const char *filename,
|
|
|
|
const char *outputDir,
|
2001-02-23 19:10:28 +00:00
|
|
|
const char *copyright,
|
2001-02-23 01:21:38 +00:00
|
|
|
UErrorCode *status)
|
|
|
|
{
|
|
|
|
FILE *data = fopen(filename, "r");
|
2001-03-22 21:16:20 +00:00
|
|
|
uint32_t line = 0;
|
2001-02-22 21:18:29 +00:00
|
|
|
UCAElements *element = NULL;
|
|
|
|
UChar variableTopValue = 0;
|
2001-02-26 10:28:56 +00:00
|
|
|
UCATableHeader *myD = (UCATableHeader *)uprv_malloc(sizeof(UCATableHeader));
|
2001-03-30 00:23:46 +00:00
|
|
|
UColOptionSet *opts = (UColOptionSet *)uprv_malloc(sizeof(UColOptionSet));
|
2001-06-08 05:51:29 +00:00
|
|
|
UChar contractionCEs[256][3];
|
2001-06-05 22:52:56 +00:00
|
|
|
uint32_t noOfContractions = 0;
|
2001-02-26 10:28:56 +00:00
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
if(data == NULL) {
|
2001-02-23 01:21:38 +00:00
|
|
|
fprintf(stderr, "Couldn't open file: %s\n", filename);
|
2001-02-22 21:18:29 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2001-03-15 21:54:36 +00:00
|
|
|
memset(inverseTable, 0xDA, sizeof(int32_t)*3*0xFFFF);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-03-30 00:23:46 +00:00
|
|
|
opts->variableTopValue = variableTopValue;
|
|
|
|
opts->strength = UCOL_TERTIARY;
|
|
|
|
opts->frenchCollation = UCOL_OFF;
|
|
|
|
opts->alternateHandling = UCOL_NON_IGNORABLE; /* attribute for handling variable elements*/
|
|
|
|
opts->caseFirst = UCOL_OFF; /* who goes first, lower case or uppercase */
|
|
|
|
opts->caseLevel = UCOL_OFF; /* do we have an extra case level */
|
2001-06-05 22:52:56 +00:00
|
|
|
opts->normalizationMode = UCOL_OFF; /* attribute for normalization */
|
2001-10-10 01:48:36 +00:00
|
|
|
opts->hiraganaQ = UCOL_OFF; /* attribute for JIS X 4061, used only in Japanese */
|
2001-02-26 23:52:44 +00:00
|
|
|
/* populate the version info struct with version info*/
|
2001-02-28 02:50:48 +00:00
|
|
|
myD->version[0] = UCOL_BUILDER_VERSION;
|
2001-02-26 23:52:44 +00:00
|
|
|
/*TODO:The fractional rules version should be taken from FractionalUCA.txt*/
|
2001-06-21 22:51:27 +00:00
|
|
|
myD->version[1] = UCOL_FRACTIONAL_UCA_VERSION;
|
2001-03-08 21:01:34 +00:00
|
|
|
myD->jamoSpecial = FALSE;
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-09-20 20:16:39 +00:00
|
|
|
tempUCATable *t = uprv_uca_initTempTable(myD, opts, NULL, IMPLICIT_TAG, status);
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
IMPLICIT_TAG = 9,
|
|
|
|
/*
|
|
|
|
*****************************************************************************************
|
|
|
|
* NON_CHARACTER FDD0 - FDEF, FFFE, FFFF, 1FFFE, 1FFFF, 2FFFE, 2FFFF,...e.g. **FFFE, **FFFF
|
|
|
|
******************************************************************************************
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// * set to zero
|
2001-11-06 22:55:29 +00:00
|
|
|
struct {
|
|
|
|
UChar32 start;
|
|
|
|
UChar32 end;
|
|
|
|
int32_t value;
|
|
|
|
} ranges[] =
|
|
|
|
{
|
2001-12-19 07:00:45 +00:00
|
|
|
#if 0
|
2001-11-06 22:55:29 +00:00
|
|
|
{0xAC00, 0xD7AF, UCOL_SPECIAL_FLAG | (HANGUL_SYLLABLE_TAG << 24) }, //0 HANGUL_SYLLABLE_TAG,/* AC00-D7AF*/
|
|
|
|
{0xD800, 0xDBFF, UCOL_SPECIAL_FLAG | (LEAD_SURROGATE_TAG << 24) }, //1 LEAD_SURROGATE_TAG, /* D800-DBFF*/
|
|
|
|
{0xDC00, 0xDFFF, UCOL_SPECIAL_FLAG | (TRAIL_SURROGATE_TAG << 24) }, //2 TRAIL_SURROGATE DC00-DFFF
|
|
|
|
{0x3400, 0x4DB5, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //3 CJK_IMPLICIT_TAG, /* 0x3400-0x4DB5*/
|
|
|
|
{0x4E00, 0x9FA5, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //4 CJK_IMPLICIT_TAG, /* 0x4E00-0x9FA5*/
|
|
|
|
{0xF900, 0xFA2D, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //5 CJK_IMPLICIT_TAG, /* 0xF900-0xFA2D*/
|
|
|
|
{0x20000, 0x2A6D6, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //6 CJK_IMPLICIT_TAG, /* 0x20000-0x2A6D6*/
|
|
|
|
{0x2F800, 0x2FA1D, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //7 CJK_IMPLICIT_TAG, /* 0x2F800-0x2FA1D*/
|
2001-12-19 07:00:45 +00:00
|
|
|
#endif
|
|
|
|
{0xAC00, 0xD7B0, UCOL_SPECIAL_FLAG | (HANGUL_SYLLABLE_TAG << 24) }, //0 HANGUL_SYLLABLE_TAG,/* AC00-D7AF*/
|
|
|
|
{0xD800, 0xDC00, UCOL_SPECIAL_FLAG | (LEAD_SURROGATE_TAG << 24) }, //1 LEAD_SURROGATE_TAG, /* D800-DBFF*/
|
|
|
|
{0xDC00, 0xE000, UCOL_SPECIAL_FLAG | (TRAIL_SURROGATE_TAG << 24) }, //2 TRAIL_SURROGATE DC00-DFFF
|
|
|
|
{0x3400, 0x4DB6, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //3 CJK_IMPLICIT_TAG, /* 0x3400-0x4DB5*/
|
|
|
|
{0x4E00, 0x9FA6, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //4 CJK_IMPLICIT_TAG, /* 0x4E00-0x9FA5*/
|
|
|
|
{0xF900, 0xFA2E, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //5 CJK_IMPLICIT_TAG, /* 0xF900-0xFA2D*/
|
2001-12-28 20:55:24 +00:00
|
|
|
//{0x20000, 0x2A6D7, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //6 CJK_IMPLICIT_TAG, /* 0x20000-0x2A6D6*/
|
|
|
|
//{0x2F800, 0x2FA1E, UCOL_SPECIAL_FLAG | (CJK_IMPLICIT_TAG << 24) }, //7 CJK_IMPLICIT_TAG, /* 0x2F800-0x2FA1D*/
|
2001-11-06 22:55:29 +00:00
|
|
|
};
|
|
|
|
uint32_t i = 0;
|
|
|
|
|
|
|
|
for(i = 0; i<sizeof(ranges)/sizeof(ranges[0]); i++) {
|
2001-12-19 07:00:45 +00:00
|
|
|
/*ucmpe32_setRange32(t->mapping, ranges[i].start, ranges[i].end, ranges[i].value); */
|
|
|
|
utrie_setRange32(t->mapping, ranges[i].start, ranges[i].end, ranges[i].value, TRUE);
|
2001-11-06 22:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-02-08 04:53:41 +00:00
|
|
|
int32_t surrogateCount = 0;
|
2001-02-22 21:18:29 +00:00
|
|
|
while(!feof(data)) {
|
2001-02-23 01:21:38 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2002-02-08 04:53:41 +00:00
|
|
|
fprintf(stderr, "Something returned an error %i (%s) while processing line %i of %s. Exiting...\n",
|
2002-01-09 23:05:09 +00:00
|
|
|
*status, u_errorName(*status), line, filename);
|
2001-02-23 01:21:38 +00:00
|
|
|
exit(*status);
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-02-23 01:21:38 +00:00
|
|
|
element = readAnElement(data, status);
|
2001-02-22 21:18:29 +00:00
|
|
|
line++;
|
|
|
|
if(element != NULL) {
|
|
|
|
// we have read the line, now do something sensible with the read data!
|
2001-04-19 17:08:07 +00:00
|
|
|
if(element->variableTop == TRUE && variableTopValue == 0) {
|
2001-03-30 00:23:46 +00:00
|
|
|
t->options->variableTopValue = element->cPoints[0];
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
|
2001-06-05 22:52:56 +00:00
|
|
|
// if element is a contraction, we want to add it to contractions
|
|
|
|
if(element->cSize > 1) { // this is a contraction
|
2001-11-06 22:55:29 +00:00
|
|
|
if(UTF_IS_LEAD(element->cPoints[0]) && UTF_IS_TRAIL(element->cPoints[1]) && element->cSize == 2) {
|
2001-11-10 00:13:03 +00:00
|
|
|
surrogateCount++;
|
2001-06-05 22:52:56 +00:00
|
|
|
} else {
|
2001-11-06 22:55:29 +00:00
|
|
|
contractionCEs[noOfContractions][0] = element->cPoints[0];
|
|
|
|
contractionCEs[noOfContractions][1] = element->cPoints[1];
|
|
|
|
if(element->cSize > 2) { // the third one
|
|
|
|
contractionCEs[noOfContractions][2] = element->cPoints[2];
|
|
|
|
} else {
|
|
|
|
contractionCEs[noOfContractions][2] = 0;
|
|
|
|
}
|
|
|
|
noOfContractions++;
|
2001-06-05 22:52:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-22 21:18:29 +00:00
|
|
|
/* we're first adding to inverse, because addAnElement will reverse the order */
|
|
|
|
/* of code points and stuff... we don't want that to happen */
|
2001-03-22 21:16:20 +00:00
|
|
|
addToInverse(element, status);
|
|
|
|
uprv_uca_addAnElement(t, element, status);
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-02-23 01:21:38 +00:00
|
|
|
if (VERBOSE) {
|
|
|
|
fprintf(stdout, "\nLines read: %i\n", line);
|
2001-11-10 00:13:03 +00:00
|
|
|
fprintf(stdout, "Surrogate count: %i\n", surrogateCount);
|
|
|
|
fprintf(stdout, "Raw data breakdown:\n");
|
2001-12-19 07:00:45 +00:00
|
|
|
/*fprintf(stdout, "Compact array stage1 top: %i, stage2 top: %i\n", t->mapping->stage1Top, t->mapping->stage2Top);*/
|
2001-11-10 00:13:03 +00:00
|
|
|
fprintf(stdout, "Number of contractions: %i\n", noOfContractions);
|
|
|
|
fprintf(stdout, "Contraction image size: %i\n", t->image->contractionSize);
|
|
|
|
fprintf(stdout, "Expansions size: %i\n", t->expansions->position);
|
2001-02-23 01:21:38 +00:00
|
|
|
}
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
/* test */
|
2001-02-26 10:28:56 +00:00
|
|
|
UCATableHeader *myData = uprv_uca_assembleTable(t, status);
|
2001-11-10 00:13:03 +00:00
|
|
|
|
|
|
|
if (VERBOSE) {
|
|
|
|
fprintf(stdout, "Compacted data breakdown:\n");
|
2001-12-19 07:00:45 +00:00
|
|
|
/*fprintf(stdout, "Compact array stage1 top: %i, stage2 top: %i\n", t->mapping->stage1Top, t->mapping->stage2Top);*/
|
2001-11-10 00:13:03 +00:00
|
|
|
fprintf(stdout, "Number of contractions: %i\n", noOfContractions);
|
|
|
|
fprintf(stdout, "Contraction image size: %i\n", t->image->contractionSize);
|
|
|
|
fprintf(stdout, "Expansions size: %i\n", t->expansions->position);
|
|
|
|
}
|
|
|
|
|
2001-06-05 22:52:56 +00:00
|
|
|
writeOutData(myData, contractionCEs, noOfContractions, outputDir, copyright, status);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-23 01:21:38 +00:00
|
|
|
InverseTableHeader *inverse = assembleInverseTable(status);
|
2001-02-23 19:10:28 +00:00
|
|
|
writeOutInverseData(inverse, outputDir, copyright, status);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2001-02-26 10:28:56 +00:00
|
|
|
uprv_uca_closeTempTable(t);
|
|
|
|
uprv_free(myD);
|
2001-03-30 00:23:46 +00:00
|
|
|
uprv_free(opts);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
|
|
|
|
2001-05-03 23:10:45 +00:00
|
|
|
uprv_free(myData);
|
|
|
|
uprv_free(inverse);
|
2001-02-23 01:21:38 +00:00
|
|
|
fclose(data);
|
2001-02-22 21:18:29 +00:00
|
|
|
|
2002-04-02 02:55:31 +00:00
|
|
|
return 0;
|
2001-02-22 21:18:29 +00:00
|
|
|
}
|
2001-02-23 01:21:38 +00:00
|
|
|
|
|
|
|
static UOption options[]={
|
|
|
|
UOPTION_HELP_H, /* 0 Numbers for those who*/
|
|
|
|
UOPTION_HELP_QUESTION_MARK, /* 1 can't count. */
|
|
|
|
UOPTION_COPYRIGHT, /* 2 */
|
|
|
|
UOPTION_VERSION, /* 3 */
|
|
|
|
UOPTION_DESTDIR, /* 4 */
|
2001-02-23 04:57:47 +00:00
|
|
|
UOPTION_SOURCEDIR, /* 5 */
|
2002-03-15 23:41:40 +00:00
|
|
|
UOPTION_VERBOSE, /* 6 */
|
|
|
|
UOPTION_ICUDATADIR /* 7 */
|
2001-02-23 04:57:47 +00:00
|
|
|
/* weiv can't count :))))) */
|
2001-02-23 01:21:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2001-02-23 04:57:47 +00:00
|
|
|
const char* destdir = NULL;
|
|
|
|
const char* srcDir = NULL;
|
|
|
|
char filename[300];
|
|
|
|
char *basename = NULL;
|
2001-02-23 19:10:28 +00:00
|
|
|
const char *copyright = NULL;
|
2001-02-23 01:21:38 +00:00
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
2001-02-23 01:21:38 +00:00
|
|
|
|
|
|
|
/* preset then read command line options */
|
|
|
|
options[4].value=u_getDataDirectory();
|
2001-02-23 04:57:47 +00:00
|
|
|
options[5].value="";
|
2001-02-23 01:21:38 +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]);
|
|
|
|
} else if(argc<2) {
|
|
|
|
argc=-1;
|
|
|
|
}
|
2001-02-23 04:57:47 +00:00
|
|
|
if(options[0].doesOccur || options[1].doesOccur) {
|
2001-02-23 01:21:38 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s [-options] file\n"
|
|
|
|
"\tRead in UCA collation text data and write out the binary collation data\n"
|
2002-03-15 23:41:40 +00:00
|
|
|
"options:\n"
|
|
|
|
"\t-h or -? or --help this usage text\n"
|
|
|
|
"\t-V or --version show a version message\n"
|
|
|
|
"\t-c or --copyright include a copyright notice\n"
|
|
|
|
"\t-d or --destdir destination directory, followed by the path\n"
|
|
|
|
"\t-s or --sourcedir source directory, followed by the path\n"
|
|
|
|
"\t-v or --verbose turn on verbose output\n"
|
|
|
|
"\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
|
|
|
|
"\t followed by path, defaults to %s\n",
|
2002-04-04 18:41:16 +00:00
|
|
|
argv[0], u_getDataDirectory());
|
2001-02-23 01:21:38 +00:00
|
|
|
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(options[3].doesOccur) {
|
|
|
|
fprintf(stdout, "genuca version %hu.%hu, ICU tool to read UCA text data and create UCA data tables for collation.\n",
|
2001-10-23 21:48:14 +00:00
|
|
|
ucaDataInfo.formatVersion[0], ucaDataInfo.formatVersion[1]);
|
2001-02-23 01:21:38 +00:00
|
|
|
fprintf(stdout, "Copyright (C) 2000-2001, International Business Machines\n");
|
|
|
|
fprintf(stdout, "Corporation and others. All Rights Reserved.\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the options values */
|
|
|
|
destdir = options[4].value;
|
2001-02-23 04:57:47 +00:00
|
|
|
srcDir = options[5].value;
|
|
|
|
VERBOSE = options[6].doesOccur;
|
|
|
|
|
2001-02-23 19:10:28 +00:00
|
|
|
if (options[2].doesOccur) {
|
|
|
|
copyright = U_COPYRIGHT_STRING;
|
|
|
|
}
|
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
if (options[7].doesOccur) {
|
|
|
|
u_setDataDirectory(options[7].value);
|
|
|
|
}
|
|
|
|
|
2001-11-10 00:13:03 +00:00
|
|
|
/* prepare the filename beginning with the source dir */
|
|
|
|
uprv_strcpy(filename, srcDir);
|
|
|
|
basename=filename+uprv_strlen(filename);
|
2001-02-23 04:57:47 +00:00
|
|
|
|
2001-11-10 00:13:03 +00:00
|
|
|
if(basename>filename && *(basename-1)!=U_FILE_SEP_CHAR) {
|
2002-03-15 23:41:40 +00:00
|
|
|
*basename++ = U_FILE_SEP_CHAR;
|
2001-11-10 00:13:03 +00:00
|
|
|
}
|
2001-02-23 04:57:47 +00:00
|
|
|
|
2001-11-10 00:13:03 +00:00
|
|
|
if(argc < 0) {
|
2001-02-23 04:57:47 +00:00
|
|
|
uprv_strcpy(basename, "FractionalUCA.txt");
|
|
|
|
} else {
|
|
|
|
argv++;
|
2001-11-10 00:13:03 +00:00
|
|
|
uprv_strcpy(basename, getLongPathname(*argv));
|
2001-02-23 04:57:47 +00:00
|
|
|
}
|
2001-02-23 01:21:38 +00:00
|
|
|
|
2001-02-23 19:10:28 +00:00
|
|
|
return write_uca_table(filename, destdir, copyright, &status);
|
2001-02-23 01:21:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|