ICU-4497 write a .c file with hardcoded Unicode character data

X-SVN-Rev: 17532
This commit is contained in:
Markus Scherer 2005-04-30 03:16:28 +00:00
parent cad9e84aba
commit b83dda29e5
4 changed files with 117 additions and 39 deletions

View file

@ -58,7 +58,8 @@ enum
DESTDIR,
SOURCEDIR,
UNICODE_VERSION,
ICUDATADIR
ICUDATADIR,
CSOURCE
};
/* Keep these values in sync with the above enums */
@ -69,8 +70,9 @@ static UOption options[]={
UOPTION_COPYRIGHT,
UOPTION_DESTDIR,
UOPTION_SOURCEDIR,
{ "unicode", NULL, NULL, NULL, 'u', UOPT_REQUIRES_ARG, 0 },
UOPTION_ICUDATADIR
UOPTION_DEF("unicode", 'u', UOPT_REQUIRES_ARG),
UOPTION_ICUDATADIR,
UOPTION_DEF("csource", 'C', UOPT_NO_ARG)
};
extern int
@ -112,7 +114,8 @@ main(int argc, char* argv[]) {
"\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"
"\t-u or --unicode Unicode version, followed by the version like 3.0.0\n");
"\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");
fprintf(stderr,
"\t-d or --destdir destination directory, followed by the path\n"
"\t-s or --sourcedir source directory, followed by the path\n"
@ -167,7 +170,7 @@ main(int argc, char* argv[]) {
/* process parsed data */
if(U_SUCCESS(errorCode)) {
/* write the properties data file */
generateData(destDir);
generateData(destDir, options[CSOURCE].doesOccur);
}
exitStore();

View file

@ -73,7 +73,7 @@ extern void
repeatProps(uint32_t first, uint32_t last, uint32_t props);
extern void
generateData(const char *dataDir);
generateData(const char *dataDir, UBool csource);
/* props2.c */
U_CFUNC void
@ -86,6 +86,6 @@ U_CFUNC void
generateAdditionalProperties(char *filename, const char *suffix, UErrorCode *pErrorCode);
U_CFUNC int32_t
writeAdditionalData(uint8_t *p, int32_t capacity, int32_t indexes[16]);
writeAdditionalData(FILE *f, uint8_t *p, int32_t capacity, int32_t indexes[16]);
#endif

View file

@ -27,6 +27,7 @@
#include "uprops.h"
#include "propsvec.h"
#include "uparse.h"
#include "writesrc.h"
#include "genprops.h"
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
@ -662,7 +663,7 @@ numericLineFn(void *context,
/* data serialization ------------------------------------------------------- */
U_CFUNC int32_t
writeAdditionalData(uint8_t *p, int32_t capacity, int32_t indexes[UPROPS_INDEX_COUNT]) {
writeAdditionalData(FILE *f, uint8_t *p, int32_t capacity, int32_t indexes[UPROPS_INDEX_COUNT]) {
int32_t length;
UErrorCode errorCode;
@ -673,11 +674,31 @@ writeAdditionalData(uint8_t *p, int32_t capacity, int32_t indexes[UPROPS_INDEX_C
exit(errorCode);
}
if(p!=NULL) {
p+=length;
capacity-=length;
if(beVerbose) {
printf("size in bytes of additional props trie:%5u\n", (int)length);
}
if(f!=NULL) {
UTrie trie2={ NULL };
utrie_unserialize(&trie2, p, length, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(
stderr,
"genprops error: failed to utrie_unserialize(trie for additional properties) - %s\n",
u_errorName(errorCode));
exit(errorCode);
}
usrc_writeUTrieArrays(f,
"static const uint16_t propsVectorsTrie_index[%ld]={\n", NULL,
&trie2,
"\n};\n\n");
usrc_writeUTrieStruct(f,
"static const UTrie propsVectorsTrie={\n",
&trie2, "propsVectorsTrie_index", NULL, NULL,
"};\n\n");
}
p+=length;
capacity-=length;
/* set indexes */
indexes[UPROPS_ADDITIONAL_VECTORS_INDEX]=
@ -699,7 +720,16 @@ writeAdditionalData(uint8_t *p, int32_t capacity, int32_t indexes[UPROPS_INDEX_C
}
if(p!=NULL && (pvCount*4)<=capacity) {
uprv_memcpy(p, pv, pvCount*4);
if(f!=NULL) {
usrc_writeArray(f,
"static const uint32_t propsVectors[%ld]={\n",
pv, 32, pvCount,
"};\n\n");
fprintf(f, "static const int32_t countPropsVectors=%ld;\n", (long)pvCount);
fprintf(f, "static const int32_t propsVectorsColumns=%ld;\n", (long)indexes[UPROPS_ADDITIONAL_VECTORS_COLUMNS_INDEX]);
} else {
uprv_memcpy(p, pv, pvCount*4);
}
if(beVerbose) {
printf("number of additional props vectors: %5u\n", (int)pvCount/UPROPS_VECTOR_WORDS);
printf("number of 32-bit words per vector: %5u\n", UPROPS_VECTOR_WORDS);

View file

@ -25,6 +25,7 @@
#include "utrie.h"
#include "unicode/udata.h"
#include "unewdata.h"
#include "writesrc.h"
#include "uprops.h"
#include "genprops.h"
@ -379,7 +380,7 @@ repeatProps(uint32_t first, uint32_t last, uint32_t x) {
/* generate output data ----------------------------------------------------- */
extern void
generateData(const char *dataDir) {
generateData(const char *dataDir, UBool csource) {
static int32_t indexes[UPROPS_INDEX_COUNT]={
0, 0, 0, 0,
0, 0, 0, 0,
@ -415,37 +416,81 @@ generateData(const char *dataDir) {
printf("trie size in bytes: %5u\n", (int)trieSize);
}
additionalPropsSize=writeAdditionalData(additionalProps, sizeof(additionalProps), indexes);
if(csource) {
/* write .c file for hardcoded data */
UTrie trie={ NULL };
FILE *f;
utrie_unserialize(&trie, trieBlock, trieSize, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(
stderr,
"genprops error: failed to utrie_unserialize(ucase.icu trie) - %s\n",
u_errorName(errorCode));
return;
}
f=usrc_create(dataDir, "uchar_props_data.c");
if(f!=NULL) {
usrc_writeArray(f,
"static const UVersionInfo formatVersion={",
dataInfo.formatVersion, 8, 4,
"};\n\n");
usrc_writeArray(f,
"static const UVersionInfo dataVersion={",
dataInfo.dataVersion, 8, 4,
"};\n\n");
usrc_writeUTrieArrays(f,
"static const uint16_t propsTrie_index[%ld]={\n", NULL,
&trie,
"\n};\n\n");
usrc_writeUTrieStruct(f,
"static const UTrie propsTrie={\n",
&trie, "propsTrie_index", NULL, NULL,
"};\n\n");
additionalPropsSize=writeAdditionalData(f, additionalProps, sizeof(additionalProps), indexes);
size=4*offset+additionalPropsSize; /* total size of data */
usrc_writeArray(f,
"static const int32_t indexes[UPROPS_INDEX_COUNT]={",
indexes, 32, UPROPS_INDEX_COUNT,
"};\n\n");
fclose(f);
}
} else {
/* write the data */
pData=udata_create(dataDir, DATA_TYPE, DATA_NAME, &dataInfo,
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops: unable to create data memory, %s\n", u_errorName(errorCode));
exit(errorCode);
}
additionalPropsSize=writeAdditionalData(NULL, additionalProps, sizeof(additionalProps), indexes);
size=4*offset+additionalPropsSize; /* total size of data */
udata_writeBlock(pData, indexes, sizeof(indexes));
udata_writeBlock(pData, trieBlock, trieSize);
udata_writeBlock(pData, additionalProps, additionalPropsSize);
/* finish up */
dataLength=udata_finish(pData, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops: error %d writing the output file\n", errorCode);
exit(errorCode);
}
if(dataLength!=(long)size) {
fprintf(stderr, "genprops: data length %ld != calculated size %lu\n",
dataLength, (unsigned long)size);
exit(U_INTERNAL_PROGRAM_ERROR);
}
}
size=4*offset+additionalPropsSize; /* total size of data */
if(beVerbose) {
printf("data size: %6lu\n", (unsigned long)size);
}
/* write the data */
pData=udata_create(dataDir, DATA_TYPE, DATA_NAME, &dataInfo,
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops: unable to create data memory, %s\n", u_errorName(errorCode));
exit(errorCode);
}
udata_writeBlock(pData, indexes, sizeof(indexes));
udata_writeBlock(pData, trieBlock, trieSize);
udata_writeBlock(pData, additionalProps, additionalPropsSize);
/* finish up */
dataLength=udata_finish(pData, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops: error %d writing the output file\n", errorCode);
exit(errorCode);
}
if(dataLength!=(long)size) {
fprintf(stderr, "genprops: data length %ld != calculated size %lu\n",
dataLength, (unsigned long)size);
exit(U_INTERNAL_PROGRAM_ERROR);
}
}
/*