ICU-2248 modularize ICU - make data generator tools write dummy data files, satisfying makefile dependencies

X-SVN-Rev: 9936
This commit is contained in:
Markus Scherer 2002-10-01 17:44:04 +00:00
parent 864d2ef0ba
commit 5e90151e49
6 changed files with 200 additions and 69 deletions

View File

@ -15,8 +15,6 @@
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
/* This file defines the format of the memory-mapped data file
* containing system time zone data for icu. See also gentz
* and tz.pl.
@ -67,6 +65,8 @@
#define TZ_DATA_NAME "tz"
#define TZ_DATA_TYPE "icu"
#if !UCONFIG_NO_FORMATTING
// Fields in UDataInfo:
// TZ_SIG[] is encoded as numeric literals for compatibility with the HP compiler

View File

@ -28,6 +28,11 @@
#include "unicode/utypes.h"
#define UCA_DATA_TYPE "icu"
#define UCA_DATA_NAME "ucadata"
#define INVC_DATA_TYPE "icu"
#define INVC_DATA_NAME "invuca"
#if !UCONFIG_NO_COLLATION
#include "unicode/ucol.h"
@ -408,11 +413,6 @@ ucol_cloneRuleData(const UCollator *coll, int32_t *length, UErrorCode *status);
#define getExpansionSuffix(coleiter) ((coleiter)->iteratordata_.CEpos - (coleiter)->iteratordata_.toReturn)
#define setExpansionSuffix(coleiter, offset) ((coleiter)->iteratordata_.toReturn = (coleiter)->iteratordata_.CEpos - leftoverces)
#define UCA_DATA_TYPE "icu"
#define UCA_DATA_NAME "ucadata"
#define INVC_DATA_TYPE "icu"
#define INVC_DATA_NAME "invuca"
/* This is an enum that lists magic special byte values from the fractional UCA */
/* TODO: all the #defines that refer to special byte values from the UCA should be changed to point here */

View File

@ -28,17 +28,6 @@
#include <stdio.h>
#include "unicode/utypes.h"
#if UCONFIG_NO_BREAK_ITERATION
extern int
main(int argc, const char *argv[]) {
fprintf(stderr, "genbrk performs no-op because of UCONFIG_NO_BREAK_ITERATION, see uconfig.h\n");
return 0;
}
#else
#include "unicode/ucnv.h"
#include "unicode/unistr.h"
#include "unicode/rbbi.h"
@ -46,10 +35,14 @@ main(int argc, const char *argv[]) {
#include "unicode/udata.h"
#include "uoptions.h"
#include "unewdata.h"
#include "ucmndata.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DATA_TYPE "brk"
static char *progName;
static UOption options[]={
@ -66,6 +59,49 @@ void usageAndDie(int retCode) {
exit (retCode);
}
#if UCONFIG_NO_BREAK_ITERATION
/* dummy UDataInfo cf. udata.h */
static UDataInfo dummyDataInfo = {
sizeof(UDataInfo),
0,
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
U_SIZEOF_UCHAR,
0,
{ 0, 0, 0, 0 }, /* dummy dataFormat */
{ 0, 0, 0, 0 }, /* dummy formatVersion */
{ 0, 0, 0, 0 } /* dummy dataVersion */
};
#else
//
// Set up the ICU data header, defined in ucmndata.h
//
DataHeader dh ={
{sizeof(DataHeader), // Struct MappedData
0xda,
0x27},
{ // struct UDataInfo
sizeof(UDataInfo), // size
0, // reserved
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
U_SIZEOF_UCHAR,
0, // reserved
{ 0x42, 0x72, 0x6b, 0x20 }, // dataFormat="Brk "
{ 2, 1, 0, 0 }, // formatVersion
{ 3, 1, 0, 0 } // dataVersion (Unicode version)
}};
#endif
//----------------------------------------------------------------------------
//
// main for genbrk
@ -105,6 +141,44 @@ int main(int argc, char **argv) {
u_setDataDirectory(options[5].value);
}
#if UCONFIG_NO_BREAK_ITERATION
UNewDataMemory *pData;
char msg[2048], folder[2048], name[32];
char *basename;
int length;
/* split the outFileName into folder + name + type */
strcpy(folder, outFileName);
basename = strrchr(folder, U_FILE_SEP_CHAR);
if(basename == NULL) {
basename = folder;
} else {
++basename;
}
/* copy the data name and remove it from the folder */
strcpy(name, basename);
*basename = 0;
/* write message with just the name */
sprintf(msg, "genbrk writes dummy %s because of UCONFIG_NO_BREAK_ITERATION, see uconfig.h", name);
fprintf(stderr, "%s\n", msg);
/* remove the type suffix (hardcode to DATA_TYPE) */
length = strlen(name);
if(length > 4 && name[length - 4] == '.') {
name[length - 4] = 0;
}
/* write the dummy data file */
pData = udata_create(folder, DATA_TYPE, name, &dummyDataInfo, NULL, &status);
udata_writeBlock(pData, msg, strlen(msg));
udata_finish(pData, &status);
return (int)status;
#else
//
// Read in the rule source file
//
@ -224,27 +298,6 @@ int main(int argc, char **argv) {
exit(-1);
}
//
// Set up the ICU data header, defined in ucmndata.h
//
DataHeader dh ={
{sizeof(DataHeader), // Struct MappedData
0xda,
0x27},
{ // struct UDataInfo
sizeof(UDataInfo), // size
0, // reserved
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
U_SIZEOF_UCHAR,
0, // reserved
{ 0x42, 0x72, 0x6b, 0x20 }, // dataFormat="Brk "
{ 2, 1, 0, 0 }, // formatVersion
{ 3, 1, 0, 0 } // dataVersion (Unicode version)
}};
bytesWritten = fwrite(&dh, 1, sizeof(DataHeader), file);
//
@ -265,6 +318,6 @@ int main(int argc, char **argv) {
printf("genbrk: tool completed successfully.\n");
return 0;
}
#endif /* #if !UCONFIG_NO_BREAK_ITERATION */
}

View File

@ -28,17 +28,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "unicode/utypes.h"
#if UCONFIG_NO_FORMATTING
extern int
main(int argc, const char *argv[]) {
fprintf(stderr, "gentz performs no-op because of UCONFIG_NO_FORMATTING, see uconfig.h\n");
return 0;
}
#else
#include "unicode/putil.h"
#include "cmemory.h"
#include "cstring.h"
@ -50,6 +39,25 @@ main(int argc, const char *argv[]) {
#define INPUT_FILE "tz.txt"
#define OUTPUT_FILE "tz.icu"
#if UCONFIG_NO_FORMATTING
/* dummy UDataInfo cf. udata.h */
static UDataInfo dummyDataInfo = {
sizeof(UDataInfo),
0,
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
U_SIZEOF_UCHAR,
0,
{ 0, 0, 0, 0 }, /* dummy dataFormat */
{ 0, 0, 0, 0 }, /* dummy formatVersion */
{ 0, 0, 0, 0 } /* dummy dataVersion */
};
#else
/* UDataInfo cf. udata.h */
static UDataInfo dataInfo = {
sizeof(UDataInfo),
@ -65,6 +73,7 @@ static UDataInfo dataInfo = {
{0, 0, 0, 0} /* dataVersion - will be filled in with year.suffix */
};
#endif
class gentz {
// These must match SimpleTimeZone!!!
@ -94,6 +103,7 @@ class gentz {
static const char* END_KEYWORD;
#if! UCONFIG_NO_FORMATTING
enum { BUFLEN = 1024 };
char buffer[BUFLEN];
int32_t lineNumber;
@ -115,6 +125,7 @@ class gentz {
uint32_t maxPerOffset; // Maximum number of zones per offset
uint32_t maxPerEquiv; // Maximum number of zones per equivalency group
uint32_t equivCount; // Number of equivalency groups
#endif
UBool useCopyright;
UBool verbose;
@ -122,6 +133,8 @@ class gentz {
public:
int MMain(int argc, char *argv[]);
#if! UCONFIG_NO_FORMATTING
private:
int32_t writeTzDatFile(const char *destdir);
void parseTzTextFile(FileStream* in);
@ -150,6 +163,7 @@ private:
// Error handling
void die(const char* msg);
#endif
};
int main(int argc, char *argv[]) {
@ -212,6 +226,20 @@ int gentz::MMain(int argc, char* argv[]) {
useCopyright=options[2].doesOccur;
verbose = options[4].doesOccur;
#if UCONFIG_NO_FORMATTING
UNewDataMemory *pData;
const char *msg = "gentz writes dummy " U_ICUDATA_NAME "_" TZ_DATA_NAME "." TZ_DATA_TYPE " because of UCONFIG_NO_FORMATTING, see uconfig.h";
UErrorCode status = U_ZERO_ERROR;
fprintf(stderr, "%s\n", msg);
pData = udata_create(options[3].value, TZ_DATA_TYPE, U_ICUDATA_NAME "_" TZ_DATA_NAME, &dummyDataInfo,
NULL, &status);
udata_writeBlock(pData, msg, strlen(msg));
udata_finish(pData, &status);
return (int)status;
#else
////////////////////////////////////////////////////////////
// Read the input file
@ -239,8 +267,12 @@ int gentz::MMain(int argc, char* argv[]) {
}
return 0; // success
#endif
}
#if !UCONFIG_NO_FORMATTING
int32_t gentz::writeTzDatFile(const char *destdir) {
UNewDataMemory *pdata;
UErrorCode status = U_ZERO_ERROR;

View File

@ -25,31 +25,41 @@
#include <stdio.h>
#include "unicode/utypes.h"
#if UCONFIG_NO_COLLATION
extern int
main(int argc, const char *argv[]) {
fprintf(stderr, "genuca performs no-op because of UCONFIG_NO_COLLATION, see uconfig.h\n");
return 0;
}
#else
#include "unicode/udata.h"
#include "ucol_imp.h"
#include "genuca.h"
#include "uoptions.h"
#include "toolutil.h"
#include "unewdata.h"
#include "cstring.h"
#include "cmemory.h"
UCAElements le;
/*
* Global - verbosity
*/
UBool VERBOSE = FALSE;
#if UCONFIG_NO_COLLATION
/* dummy UDataInfo cf. udata.h */
static UDataInfo dummyDataInfo = {
sizeof(UDataInfo),
0,
U_IS_BIG_ENDIAN,
U_CHARSET_FAMILY,
U_SIZEOF_UCHAR,
0,
{ 0, 0, 0, 0 }, /* dummy dataFormat */
{ 0, 0, 0, 0 }, /* dummy formatVersion */
{ 0, 0, 0, 0 } /* dummy dataVersion */
};
#else
UCAElements le;
int32_t readElement(char **from, char *to, char separator, UErrorCode *status) {
if(U_FAILURE(*status)) {
return 0;
@ -906,6 +916,8 @@ struct {
return 0;
}
#endif /* #if !UCONFIG_NO_COLLATION */
static UOption options[]={
UOPTION_HELP_H, /* 0 Numbers for those who*/
UOPTION_HELP_QUESTION_MARK, /* 1 can't count. */
@ -960,7 +972,12 @@ int main(int argc, char* argv[]) {
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",
ucaDataInfo.formatVersion[0], ucaDataInfo.formatVersion[1]);
#if UCONFIG_NO_COLLATION
0, 0
#else
ucaDataInfo.formatVersion[0], ucaDataInfo.formatVersion[1]
#endif
);
fprintf(stdout, "Copyright (C) 2000-2001, International Business Machines\n");
fprintf(stdout, "Corporation and others. All Rights Reserved.\n");
exit(0);
@ -1001,10 +1018,34 @@ int main(int argc, char* argv[]) {
exit(1);
}
#endif
return write_uca_table(filename, destdir, copyright, &status);
}
#endif /* #if !UCONFIG_NO_COLLATION */
#if UCONFIG_NO_COLLATION
UNewDataMemory *pData;
const char *msg;
msg = "genuca writes dummy " U_ICUDATA_NAME "_" UCA_DATA_NAME "." UCA_DATA_TYPE " because of UCONFIG_NO_COLLATION, see uconfig.h";
fprintf(stderr, "%s\n", msg);
pData = udata_create(destdir, UCA_DATA_TYPE, U_ICUDATA_NAME "_" UCA_DATA_NAME, &dummyDataInfo,
NULL, &status);
udata_writeBlock(pData, msg, strlen(msg));
udata_finish(pData, &status);
msg = "genuca writes dummy " U_ICUDATA_NAME "_" INVC_DATA_NAME "." INVC_DATA_TYPE " because of UCONFIG_NO_COLLATION, see uconfig.h";
fprintf(stderr, "%s\n", msg);
pData = udata_create(destdir, INVC_DATA_TYPE, U_ICUDATA_NAME "_" INVC_DATA_NAME, &dummyDataInfo,
NULL, &status);
udata_writeBlock(pData, msg, strlen(msg));
udata_finish(pData, &status);
return (int)status;
#else
return write_uca_table(filename, destdir, copyright, &status);
#endif
}
/*
* Hey, Emacs, please set the following:

View File

@ -22,6 +22,10 @@
#ifndef UCADATA_H
#define UCADATA_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_COLLATION
#include "ucol_elm.h"
#include <stdio.h>
#include <string.h>
@ -39,5 +43,6 @@ uint32_t getSingleCEValue(char *primary, char *secondary, char *tertiary, UBool
void printOutTable(UCATableHeader *myData, UErrorCode *status);
UCAElements *readAnElement(FILE *data, tempUCATable *t, UCAConstants *consts, UErrorCode *status);
#endif /* #if !UCONFIG_NO_COLLATION */
#endif