[sword-cvs] icu-sword/source/tools/gennorm gennorm.c,1.4,1.5 gennorm.vcproj,1.1,1.2 store.c,1.3,1.4
sword@www.crosswire.org
sword@www.crosswire.org
Tue, 6 Apr 2004 03:10:48 -0700
Update of /cvs/core/icu-sword/source/tools/gennorm
In directory www:/tmp/cvs-serv8911/source/tools/gennorm
Modified Files:
gennorm.c gennorm.vcproj store.c
Log Message:
ICU 2.8 sync
Index: gennorm.c
===================================================================
RCS file: /cvs/core/icu-sword/source/tools/gennorm/gennorm.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- gennorm.c 10 Sep 2003 02:42:56 -0000 1.4
+++ gennorm.c 6 Apr 2004 10:10:06 -0000 1.5
@@ -26,6 +26,7 @@
#include "unicode/putil.h"
#include "cmemory.h"
#include "cstring.h"
+#include "unicode/uclean.h"
#include "unicode/udata.h"
#include "unewdata.h"
#include "uoptions.h"
Index: gennorm.vcproj
===================================================================
RCS file: /cvs/core/icu-sword/source/tools/gennorm/gennorm.vcproj,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gennorm.vcproj 10 Sep 2003 02:42:56 -0000 1.1
+++ gennorm.vcproj 6 Apr 2004 10:10:06 -0000 1.2
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding = "Windows-1252"?>
+<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
- Version="7.00"
+ Version="7.10"
Name="gennorm"
SccProjectName=""
SccLocalPath="">
@@ -37,9 +37,9 @@
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"
- CommandLine="copy $(TargetPath) ..\..\..\bin
+ CommandLine="copy "$(TargetPath)" ..\..\..\bin
"
- Outputs="..\..\..\bin\$(InputName).exe"/>
+ Outputs="..\..\..\bin\$(TargetFileName)"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
@@ -66,7 +66,13 @@
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Debug|Win32"
@@ -97,9 +103,9 @@
CompileAs="0"/>
<Tool
Name="VCCustomBuildTool"
- CommandLine="copy $(TargetPath) ..\..\..\bin
+ CommandLine="copy "$(TargetPath)" ..\..\..\bin
"
- Outputs="..\..\..\bin\$(InputName).exe"/>
+ Outputs="..\..\..\bin\$(TargetFileName)"/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386"
@@ -127,9 +133,17 @@
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
+ <References>
+ </References>
<Files>
<Filter
Name="Source Files"
Index: store.c
===================================================================
RCS file: /cvs/core/icu-sword/source/tools/gennorm/store.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- store.c 10 Sep 2003 02:42:56 -0000 1.3
+++ store.c 6 Apr 2004 10:10:06 -0000 1.4
@@ -26,6 +26,7 @@
#include "unicode/udata.h"
#include "utrie.h"
#include "unicode/uset.h"
+#include "toolutil.h"
#include "unewdata.h"
#include "unormimp.h"
#include "gennorm.h"
@@ -86,96 +87,15 @@
static int32_t indexes[_NORM_INDEX_TOP]={ 0 };
-/* tool memory helper ------------------------------------------------------- */
-
-/*
- * UToolMemory is used for generic, custom memory management.
- * It is allocated with enough space for count*size bytes starting
- * at array.
- * The array is declared with a union of large data types so
- * that its base address is aligned for any types.
- * If size is a multiple of a data type size, then such items
- * can be safely allocated inside the array, at offsets that
- * are themselves multiples of size.
- */
-typedef struct UToolMemory {
- char name[64];
- uint32_t count, size, index;
- union {
- uint32_t u;
- double d;
- void *p;
- } array[1];
-} UToolMemory;
-
-static UToolMemory *
-utm_open(const char *name, uint32_t count, uint32_t size) {
- UToolMemory *mem=(UToolMemory *)uprv_malloc(sizeof(UToolMemory)+count*size);
- if(mem==NULL) {
- fprintf(stderr, "error: %s - out of memory\n", name);
- exit(U_MEMORY_ALLOCATION_ERROR);
- }
- uprv_strcpy(mem->name, name);
- mem->count=count;
- mem->size=size;
- mem->index=0;
- return mem;
-}
-
-static void
-utm_close(UToolMemory *mem) {
- if(mem!=NULL) {
- uprv_free(mem);
- }
-}
-
-
-
-static void *
-utm_getStart(UToolMemory *mem) {
- return (char *)mem->array;
-}
-
-static int32_t
-utm_countItems(UToolMemory *mem) {
- return mem->index;
-}
-
-static void *
-utm_alloc(UToolMemory *mem) {
- char *p=(char *)mem->array+mem->index*mem->size;
- if(++mem->index<=mem->count) {
- uprv_memset(p, 0, mem->size);
- return p;
- } else {
- fprintf(stderr, "error: %s - trying to use more than %ld preallocated units\n",
- mem->name, (long)mem->count);
- exit(U_MEMORY_ALLOCATION_ERROR);
- }
-}
-
-static void *
-utm_allocN(UToolMemory *mem, int32_t n) {
- char *p=(char *)mem->array+mem->index*mem->size;
- if((mem->index+=(uint32_t)n)<=mem->count) {
- uprv_memset(p, 0, n*mem->size);
- return p;
- } else {
- fprintf(stderr, "error: %s - trying to use more than %ld preallocated units\n",
- mem->name, (long)mem->count);
- exit(U_MEMORY_ALLOCATION_ERROR);
- }
-}
-
/* builder data ------------------------------------------------------------- */
typedef void EnumTrieFn(void *context, uint32_t code, Norm *norm);
static UNewTrie
- normTrie={ {0},0,0,0,0,0,0,0,0,{0} },
- norm32Trie={ {0},0,0,0,0,0,0,0,0,{0} },
- fcdTrie={ {0},0,0,0,0,0,0,0,0,{0} },
- auxTrie={ {0},0,0,0,0,0,0,0,0,{0} };
+ *normTrie,
+ *norm32Trie,
+ *fcdTrie,
+ *auxTrie;
static UToolMemory *normMem, *utf32Mem, *extraMem, *combiningTriplesMem;
@@ -228,30 +148,39 @@
init() {
uint16_t *p16;
+ normTrie = (UNewTrie *)uprv_malloc(sizeof(UNewTrie));
+ uprv_memset(normTrie, 0, sizeof(UNewTrie));
+ norm32Trie = (UNewTrie *)uprv_malloc(sizeof(UNewTrie));
+ uprv_memset(norm32Trie, 0, sizeof(UNewTrie));
+ fcdTrie = (UNewTrie *)uprv_malloc(sizeof(UNewTrie));
+ uprv_memset(fcdTrie, 0, sizeof(UNewTrie));
+ auxTrie = (UNewTrie *)uprv_malloc(sizeof(UNewTrie));
+ uprv_memset(auxTrie, 0, sizeof(UNewTrie));
+
/* initialize the two tries */
- if(NULL==utrie_open(&normTrie, NULL, 30000, 0, FALSE)) {
+ if(NULL==utrie_open(normTrie, NULL, 30000, 0, 0, FALSE)) {
fprintf(stderr, "error: failed to initialize tries\n");
exit(U_MEMORY_ALLOCATION_ERROR);
}
/* allocate Norm structures and reset the first one */
- normMem=utm_open("gennorm normalization structs", 20000, sizeof(Norm));
+ normMem=utm_open("gennorm normalization structs", 20000, 20000, sizeof(Norm));
norms=utm_alloc(normMem);
/* allocate UTF-32 string memory */
- utf32Mem=utm_open("gennorm UTF-32 strings", 30000, 4);
+ utf32Mem=utm_open("gennorm UTF-32 strings", 30000, 30000, 4);
/* reset all "have seen" flags */
uprv_memset(haveSeenFlags, 0, sizeof(haveSeenFlags));
/* allocate extra data memory for UTF-16 decomposition strings and other values */
- extraMem=utm_open("gennorm extra 16-bit memory", _NORM_EXTRA_INDEX_TOP, 2);
+ extraMem=utm_open("gennorm extra 16-bit memory", _NORM_EXTRA_INDEX_TOP, _NORM_EXTRA_INDEX_TOP, 2);
/* initialize the extraMem counter for the top of FNC strings */
p16=(uint16_t *)utm_alloc(extraMem);
*p16=1;
/* allocate temporary memory for combining triples */
- combiningTriplesMem=utm_open("gennorm combining triples", 0x4000, sizeof(CombiningTriple));
+ combiningTriplesMem=utm_open("gennorm combining triples", 0x4000, 0x4000, sizeof(CombiningTriple));
/* set the minimum code points for no/maybe quick check values to the end of the BMP */
indexes[_NORM_INDEX_MIN_NFC_NO_MAYBE]=0xffff;
@@ -272,13 +201,13 @@
Norm *p;
uint32_t i;
- i=utrie_get32(&normTrie, (UChar32)code, NULL);
+ i=utrie_get32(normTrie, (UChar32)code, NULL);
if(i!=0) {
p=norms+i;
} else {
/* allocate Norm */
p=(Norm *)utm_alloc(normMem);
- if(!utrie_set32(&normTrie, (UChar32)code, (uint32_t)(p-norms))) {
+ if(!utrie_set32(normTrie, (UChar32)code, (uint32_t)(p-norms))) {
fprintf(stderr, "error: too many normalization entries\n");
exit(U_BUFFER_OVERFLOW_ERROR);
}
@@ -291,7 +220,7 @@
getNorm(uint32_t code) {
uint32_t i;
- i=utrie_get32(&normTrie, (UChar32)code, NULL);
+ i=utrie_get32(normTrie, (UChar32)code, NULL);
if(i==0) {
return NULL;
}
@@ -321,7 +250,7 @@
count=0;
for(code=0; code<=0x10ffff;) {
- i=utrie_get32(&normTrie, code, &isInBlockZero);
+ i=utrie_get32(normTrie, code, &isInBlockZero);
if(isInBlockZero) {
code+=UTRIE_DATA_BLOCK_LENGTH;
} else {
@@ -499,7 +428,7 @@
triples=utm_getStart(combiningTriplesMem);
/* add lead and trail indexes to the triples for sorting */
- count=(uint16_t)combiningTriplesMem->index;
+ count=(uint16_t)utm_countItems(combiningTriplesMem);
for(i=0; i<count; ++i) {
/* findCombiningCP() must always find the code point */
triples[i].leadIndex=findCombiningCP(triples[i].lead, TRUE);
@@ -931,7 +860,7 @@
norm->specialTag=_NORM_EXTRA_INDEX_TOP+_NORM_EXTRA_HANGUL;
norm->qcFlags=_NORM_QC_NFD|_NORM_QC_NFKD;
- if(!utrie_setRange32(&normTrie, 0xac00, 0xd7a4, (uint32_t)(norm-norms), TRUE)) {
+ if(!utrie_setRange32(normTrie, 0xac00, 0xd7a4, (uint32_t)(norm-norms), TRUE)) {
fprintf(stderr, "error: too many normalization entries (setting Hangul)\n");
exit(U_BUFFER_OVERFLOW_ERROR);
}
@@ -1256,12 +1185,12 @@
uint32_t n;
int32_t i, normLength, count;
- count=(int32_t)normMem->index;
+ count=(int32_t)utm_countItems(normMem);
for(i=0; i<count; ++i) {
norms[i].value32=make32BitNorm(norms+i);
}
- pNormData=utrie_getData(&norm32Trie, &normLength);
+ pNormData=utrie_getData(norm32Trie, &normLength);
count=0;
for(i=0; i<normLength; ++i) {
@@ -1283,7 +1212,7 @@
int32_t i, count, fcdLength;
uint16_t bothCCs;
- count=(int32_t)normMem->index;
+ count=utm_countItems(normMem);
for(i=0; i<count; ++i) {
bothCCs=norms[i].canonBothCCs;
if(bothCCs==0) {
@@ -1294,7 +1223,7 @@
norms[i].value32=bothCCs;
}
- pFCDData=utrie_getData(&fcdTrie, &fcdLength);
+ pFCDData=utrie_getData(fcdTrie, &fcdLength);
for(i=0; i<fcdLength; ++i) {
n=pFCDData[i];
@@ -1391,7 +1320,7 @@
/* search for all triples with c as lead code point */
triples=utm_getStart(combiningTriplesMem);
- count=combiningTriplesMem->index;
+ count=utm_countItems(combiningTriplesMem);
/* triples are not sorted by code point but for each lead CP there is one contiguous block */
for(i=0; i<count && lead!=triples[i].lead; ++i) {}
@@ -1503,7 +1432,7 @@
/* search for all triples with c as lead code point */
triples=utm_getStart(combiningTriplesMem);
- count=combiningTriplesMem->index;
+ count=utm_countItems(combiningTriplesMem);
c=s[0];
/* triples are not sorted by code point but for each lead CP there is one contiguous block */
@@ -1600,7 +1529,7 @@
uint32_t *pData;
int32_t i, length;
- pData=utrie_getData(&auxTrie, &length);
+ pData=utrie_getData(auxTrie, &length);
for(i=0; i<length; ++i) {
norm=norms+pData[i];
@@ -1746,9 +1675,9 @@
enumTrie(makeCanonSetFn, NULL);
/* clone the normalization builder trie to make the final data tries */
- if( NULL==utrie_clone(&norm32Trie, &normTrie, NULL, 0) ||
- NULL==utrie_clone(&fcdTrie, &normTrie, NULL, 0) ||
- NULL==utrie_clone(&auxTrie, &normTrie, NULL, 0)
+ if( NULL==utrie_clone(norm32Trie, normTrie, NULL, 0) ||
+ NULL==utrie_clone(fcdTrie, normTrie, NULL, 0) ||
+ NULL==utrie_clone(auxTrie, normTrie, NULL, 0)
) {
fprintf(stderr, "error: unable to clone the normalization trie\n");
exit(U_MEMORY_ALLOCATION_ERROR);
@@ -1795,19 +1724,19 @@
int32_t normTrieSize, fcdTrieSize, auxTrieSize;
- normTrieSize=utrie_serialize(&norm32Trie, normTrieBlock, sizeof(normTrieBlock), getFoldedNormValue, FALSE, &errorCode);
+ normTrieSize=utrie_serialize(norm32Trie, normTrieBlock, sizeof(normTrieBlock), getFoldedNormValue, FALSE, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "error: utrie_serialize(normalization properties) failed, %s\n", u_errorName(errorCode));
exit(errorCode);
}
- fcdTrieSize=utrie_serialize(&fcdTrie, fcdTrieBlock, sizeof(fcdTrieBlock), getFoldedFCDValue, TRUE, &errorCode);
+ fcdTrieSize=utrie_serialize(fcdTrie, fcdTrieBlock, sizeof(fcdTrieBlock), getFoldedFCDValue, TRUE, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "error: utrie_serialize(FCD data) failed, %s\n", u_errorName(errorCode));
exit(errorCode);
}
- auxTrieSize=utrie_serialize(&auxTrie, auxTrieBlock, sizeof(auxTrieBlock), getFoldedAuxValue, TRUE, &errorCode);
+ auxTrieSize=utrie_serialize(auxTrie, auxTrieBlock, sizeof(auxTrieBlock), getFoldedAuxValue, TRUE, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "error: utrie_serialize(auxiliary data) failed, %s\n", u_errorName(errorCode));
exit(errorCode);
@@ -1829,7 +1758,7 @@
canonStartSetsTop+=canonStartSets[_NORM_SET_INDEX_CANON_SUPP_TABLE_LENGTH];
/* make sure that the FCD trie is 4-aligned */
- if((extraMem->index+combiningTableTop)&1) {
+ if((utm_countItems(extraMem)+combiningTableTop)&1) {
combiningTable[combiningTableTop++]=0x1234; /* add one 16-bit word for an even number */
}
@@ -1841,7 +1770,7 @@
size=
_NORM_INDEX_TOP*4+
normTrieSize+
- extraMem->index*2+
+ utm_countItems(extraMem)*2+
combiningTableTop*2+
fcdTrieSize+
auxTrieSize+
@@ -1849,7 +1778,7 @@
if(beVerbose) {
printf("size of normalization trie %5u bytes\n", normTrieSize);
- printf("size of 16-bit extra memory %5u UChars/uint16_t\n", extraMem->index);
+ printf("size of 16-bit extra memory %5u UChars/uint16_t\n", utm_countItems(extraMem));
printf(" of that: FC_NFKC_Closure size %5u UChars/uint16_t\n", ((uint16_t *)utm_getStart(extraMem))[0]);
printf("size of combining table %5u uint16_t\n", combiningTableTop);
printf("size of FCD trie %5u bytes\n", fcdTrieSize);
@@ -1864,7 +1793,7 @@
}
indexes[_NORM_INDEX_TRIE_SIZE]=normTrieSize;
- indexes[_NORM_INDEX_UCHAR_COUNT]=(uint16_t)extraMem->index;
+ indexes[_NORM_INDEX_UCHAR_COUNT]=(uint16_t)utm_countItems(extraMem);
indexes[_NORM_INDEX_COMBINE_DATA_COUNT]=combiningTableTop;
indexes[_NORM_INDEX_COMBINE_FWD_COUNT]=combineFwdTop;
@@ -1891,7 +1820,7 @@
udata_writeBlock(pData, indexes, sizeof(indexes));
udata_writeBlock(pData, normTrieBlock, normTrieSize);
- udata_writeBlock(pData, utm_getStart(extraMem), extraMem->index*2);
+ udata_writeBlock(pData, utm_getStart(extraMem), utm_countItems(extraMem)*2);
udata_writeBlock(pData, combiningTable, combiningTableTop*2);
udata_writeBlock(pData, fcdTrieBlock, fcdTrieSize);
udata_writeBlock(pData, auxTrieBlock, auxTrieSize);
@@ -1919,7 +1848,7 @@
cleanUpData(void) {
int32_t i, count;
- count=(int32_t)normMem->index;
+ count=utm_countItems(normMem);
for(i=0; i<count; ++i) {
uset_close(norms[i].canonStart);
}
@@ -1928,10 +1857,15 @@
utm_close(utf32Mem);
utm_close(extraMem);
utm_close(combiningTriplesMem);
- utrie_close(&normTrie);
- utrie_close(&norm32Trie);
- utrie_close(&fcdTrie);
- utrie_close(&auxTrie);
+ utrie_close(normTrie);
+ utrie_close(norm32Trie);
+ utrie_close(fcdTrie);
+ utrie_close(auxTrie);
+
+ uprv_free(normTrie);
+ uprv_free(norm32Trie);
+ uprv_free(fcdTrie);
+ uprv_free(auxTrie);
}
#endif /* #if !UCONFIG_NO_NORMALIZATION */