ICU-4497 write a .c file with hardcoded Unicode character data
X-SVN-Rev: 17510
This commit is contained in:
parent
9e9e7cffbe
commit
42dd6c4e8d
@ -187,7 +187,8 @@ enum
|
||||
DESTDIR,
|
||||
SOURCEDIR,
|
||||
UNICODE_VERSION,
|
||||
ICUDATADIR
|
||||
ICUDATADIR,
|
||||
CSOURCE
|
||||
};
|
||||
|
||||
/* Keep these values in sync with the above enums */
|
||||
@ -198,8 +199,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
|
||||
@ -241,7 +243,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"
|
||||
@ -316,7 +319,7 @@ main(int argc, char* argv[]) {
|
||||
|
||||
if(U_SUCCESS(errorCode)) {
|
||||
/* write the properties data file */
|
||||
generateData(destDir);
|
||||
generateData(destDir, options[CSOURCE].doesOccur);
|
||||
}
|
||||
|
||||
u_cleanup();
|
||||
|
@ -120,7 +120,7 @@ extern void
|
||||
makeExceptions(void);
|
||||
|
||||
extern void
|
||||
generateData(const char *dataDir);
|
||||
generateData(const char *dataDir, UBool csource);
|
||||
|
||||
U_CDECL_END
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "unicode/udata.h"
|
||||
#include "unewdata.h"
|
||||
#include "propsvec.h"
|
||||
#include "writesrc.h"
|
||||
#include "gencase.h"
|
||||
|
||||
#define LENGTHOF(array) (sizeof(array)/sizeof((array)[0]))
|
||||
@ -1026,7 +1027,7 @@ makeExceptions() {
|
||||
/* generate output data ----------------------------------------------------- */
|
||||
|
||||
extern void
|
||||
generateData(const char *dataDir) {
|
||||
generateData(const char *dataDir, UBool csource) {
|
||||
static int32_t indexes[UCASE_IX_TOP]={
|
||||
UCASE_IX_TOP
|
||||
};
|
||||
@ -1076,30 +1077,58 @@ generateData(const char *dataDir) {
|
||||
printf("data size: %5d\n", (int)indexes[UCASE_IX_LENGTH]);
|
||||
}
|
||||
|
||||
/* write the data */
|
||||
pData=udata_create(dataDir, UCASE_DATA_TYPE, UCASE_DATA_NAME, &dataInfo,
|
||||
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
fprintf(stderr, "gencase: unable to create data memory, %s\n", u_errorName(errorCode));
|
||||
exit(errorCode);
|
||||
}
|
||||
if(csource) {
|
||||
/* write .c file for hardcoded data */
|
||||
FILE *f=usrc_create(dataDir, "ucase_props_data.c");
|
||||
if(f!=NULL) {
|
||||
fputs("static const uint8_t ucase_props_formatVersion[4]=", f);
|
||||
usrc_writeArray(f, dataInfo.formatVersion, 8, 4);
|
||||
|
||||
udata_writeBlock(pData, indexes, sizeof(indexes));
|
||||
udata_writeBlock(pData, trieBlock, trieSize);
|
||||
udata_writeBlock(pData, exceptions, 2*exceptionsTop);
|
||||
udata_writeBlock(pData, unfold, 2*unfoldTop);
|
||||
fputs("static const uint8_t ucase_props_dataVersion[4]=", f);
|
||||
usrc_writeArray(f, dataInfo.dataVersion, 8, 4);
|
||||
|
||||
/* finish up */
|
||||
dataLength=udata_finish(pData, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
fprintf(stderr, "gencase: error %d writing the output file\n", errorCode);
|
||||
exit(errorCode);
|
||||
}
|
||||
fputs("static const int32_t ucase_props_indexes[UCASE_IX_TOP]=", f);
|
||||
usrc_writeArray(f, indexes, 32, UCASE_IX_TOP);
|
||||
|
||||
if(dataLength!=indexes[UCASE_IX_LENGTH]) {
|
||||
fprintf(stderr, "gencase: data length %ld != calculated size %d\n",
|
||||
dataLength, (int)indexes[UCASE_IX_LENGTH]);
|
||||
exit(U_INTERNAL_PROGRAM_ERROR);
|
||||
usrc_writeUTrie(f, trieBlock, trieSize,
|
||||
"static const UTrie ucase_props_trie",
|
||||
"static const", "ucase_props",
|
||||
NULL);
|
||||
|
||||
fprintf(f, "static const uint16_t ucase_props_exceptions[%ld]=", (long)exceptionsTop);
|
||||
usrc_writeArray(f, exceptions, 16, exceptionsTop);
|
||||
|
||||
fprintf(f, "static const uint16_t ucase_props_unfold[%ld]=", (long)unfoldTop);
|
||||
usrc_writeArray(f, unfold, 16, unfoldTop);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
} else {
|
||||
/* write the data */
|
||||
pData=udata_create(dataDir, UCASE_DATA_TYPE, UCASE_DATA_NAME, &dataInfo,
|
||||
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
fprintf(stderr, "gencase: 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, exceptions, 2*exceptionsTop);
|
||||
udata_writeBlock(pData, unfold, 2*unfoldTop);
|
||||
|
||||
/* finish up */
|
||||
dataLength=udata_finish(pData, &errorCode);
|
||||
if(U_FAILURE(errorCode)) {
|
||||
fprintf(stderr, "gencase: error %d writing the output file\n", errorCode);
|
||||
exit(errorCode);
|
||||
}
|
||||
|
||||
if(dataLength!=indexes[UCASE_IX_LENGTH]) {
|
||||
fprintf(stderr, "gencase: data length %ld != calculated size %d\n",
|
||||
dataLength, (int)indexes[UCASE_IX_LENGTH]);
|
||||
exit(U_INTERNAL_PROGRAM_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
utrie_close(pTrie);
|
||||
|
Loading…
Reference in New Issue
Block a user