ICU-282 pass a directory argument to udata_create().

X-SVN-Rev: 866
This commit is contained in:
Yves Arrouye 2000-02-29 18:42:28 +00:00
parent f909d9d085
commit 57eacb7563
8 changed files with 154 additions and 31 deletions

View File

@ -94,6 +94,7 @@ extern int
main(int argc, char *argv[]) {
char line[512];
const char *path, *arg, *convfile = 0;
const char *destdir = 0;
FileStream *in;
UNewDataMemory *out;
char *s;
@ -126,6 +127,10 @@ main(int argc, char *argv[]) {
}
}
if (!destdir) {
destdir = u_getDataDirectory();
}
if (convfile) {
path = convfile;
} else {
@ -165,7 +170,7 @@ main(int argc, char *argv[]) {
qsort(aliases, aliasCount, sizeof(Alias), compareAliases);
/* create the output file */
out=udata_create(DATA_TYPE, DATA_NAME, &dataInfo,
out=udata_create(DATA_TYPE, DATA_NAME, destdir, &dataInfo,
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "gencnval: unable to open output file - error %s\n", u_errorName(errorCode));
@ -327,3 +332,12 @@ static int
compareAliases(const void *alias1, const void *alias2) {
return uprv_stricmp(((Alias *)alias1)->alias, ((Alias *)alias2)->alias);
}
/*
* Hey, Emacs, please set the following:
*
* Local Variables:
* indent-tabs-mode: nil
* End:
*
*/

View File

@ -128,7 +128,7 @@ static int
compareWords(const void *word1, const void *word2);
static void
generateData();
generateData(const char *dataDir);
static uint32_t
generateAlgorithmicData(UNewDataMemory *pData);
@ -172,6 +172,7 @@ extern int
main(int argc, char *argv[]) {
FileStream *in;
char *arg, *filename=NULL;
const char *destdir = 0;
int i;
bool_t store10Names=FALSE;
@ -221,10 +222,14 @@ main(int argc, char *argv[]) {
}
}
if (!destdir) {
destdir = u_getDataDirectory();
}
init();
parseDB(in, store10Names);
compress();
generateData();
generateData(destdir);
if(in!=T_FileStream_stdin()) {
T_FileStream_close(in);
@ -620,7 +625,7 @@ compareWords(const void *word1, const void *word2) {
/* generate output data ----------------------------------------------------- */
static void
generateData() {
generateData(const char *dataDir) {
UNewDataMemory *pData;
UErrorCode errorCode=U_ZERO_ERROR;
uint16_t groupWords[3];
@ -629,7 +634,7 @@ generateData() {
long dataLength;
int16_t token;
pData=udata_create(DATA_TYPE, DATA_NAME, &dataInfo,
pData=udata_create(DATA_TYPE, DATA_NAME, dataDir, &dataInfo,
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "gennames: unable to create data memory, error %d\n", errorCode);
@ -1021,3 +1026,12 @@ allocWord(uint32_t length) {
wordBottom=bottom;
return stringStore+bottom;
}
/*
* Hey, Emacs, please set the following:
*
* Local Variables:
* indent-tabs-mode: nil
* End:
*
*/

View File

@ -37,7 +37,7 @@ extern bool_t beVerbose=FALSE, haveCopyright=TRUE;
extern const char *const
genCategoryNames[U_CHAR_CATEGORY_COUNT]={
NULL,
NULL,
"Lu", "Ll", "Lt", "Lm", "Lo", "Mn", "Me",
"Mc", "Nd", "Nl", "No",
"Zs", "Zl", "Zp",
@ -50,7 +50,7 @@ genCategoryNames[U_CHAR_CATEGORY_COUNT]={
extern const char *const
bidiNames[U_CHAR_DIRECTION_COUNT]={
"L", "R", "EN", "ES", "ET", "AN", "CS", "B", "S",
"L", "R", "EN", "ES", "ET", "AN", "CS", "B", "S",
"WS", "ON", "LRE", "LRO", "AL", "RLE", "RLO", "PDF", "NSM", "BN"
};
@ -73,6 +73,7 @@ checkLineIndex(uint32_t code, int16_t limit, int16_t length);
extern int
main(int argc, char *argv[]) {
FileStream *in;
const char *destdir = 0;
char *arg, *filename=NULL;
int i;
@ -117,6 +118,10 @@ main(int argc, char *argv[]) {
}
}
if (!destdir) {
destdir = u_getDataDir();
}
init();
initStore();
parseDB(in);
@ -124,7 +129,7 @@ main(int argc, char *argv[]) {
compactProps();
compactStage3();
compactStage2();
generateData();
generateData(destdir);
if(in!=T_FileStream_stdin()) {
T_FileStream_close(in);
@ -369,3 +374,12 @@ checkLineIndex(uint32_t code, int16_t index, int16_t length) {
exit(U_PARSE_ERROR);
}
}
/*
* Hey, Emacs, please set the following:
*
* Local Variables:
* indent-tabs-mode: nil
* End:
*
*/

View File

@ -61,6 +61,7 @@ extern void
compactProps(void);
extern void
generateData(void);
generateData(const char *dataDir);
#endif

View File

@ -881,7 +881,7 @@ compareProps(const void *l, const void *r) {
/* generate output data ----------------------------------------------------- */
extern void
generateData(void) {
generateData(const char *dataDir) {
static uint16_t indexes[8]={
STAGE_2_BITS, STAGE_3_BITS,
0, 0,
@ -926,7 +926,7 @@ generateData(void) {
}
/* write the data */
pData=udata_create(DATA_TYPE, DATA_NAME, &dataInfo,
pData=udata_create(DATA_TYPE, DATA_NAME, dataDir, &dataInfo,
haveCopyright ? U_COPYRIGHT_STRING : NULL, &errorCode);
if(U_FAILURE(errorCode)) {
fprintf(stderr, "genprops: unable to create data memory, error %d\n", errorCode);
@ -1040,3 +1040,12 @@ addUChars(const UChar *s, uint16_t length) {
ucharsTop=top;
return (uint16_t)(p-uchars);
}
/*
* Hey, Emacs, please set the following:
*
* Local Variables:
* indent-tabs-mode: nil
* End:
*
*/

View File

@ -103,7 +103,7 @@ class gentz {
public:
int main(int argc, char *argv[]);
private:
int32_t writeTzDatFile();
int32_t writeTzDatFile(const char *destdir);
void parseTzTextFile(FileStream* in);
// High level parsing
@ -165,6 +165,7 @@ int gentz::main(int argc, char *argv[]) {
////////////////////////////////////////////////////////////
useCopyright = TRUE;
const char* infile = 0;
const char* destdir = 0;
for (int i=1; i<argc; ++i) {
const char* arg = argv[i];
if (arg[0] == '-') {
@ -190,7 +191,9 @@ int gentz::main(int argc, char *argv[]) {
if (infile == 0) {
usage(argv[0]);
}
if (destdir == 0) {
destdir = u_getDataDirectory();
}
////////////////////////////////////////////////////////////
// Read the input file
////////////////////////////////////////////////////////////
@ -208,14 +211,14 @@ int gentz::main(int argc, char *argv[]) {
////////////////////////////////////////////////////////////
// Write the output file
////////////////////////////////////////////////////////////
int32_t wlen = writeTzDatFile();
int32_t wlen = writeTzDatFile(destdir);
fprintf(stdout, "Output file: %s.%s, %ld bytes\n",
TZ_DATA_NAME, TZ_DATA_TYPE, wlen);
return 0; // success
}
int32_t gentz::writeTzDatFile() {
int32_t gentz::writeTzDatFile(const char *destdir) {
UNewDataMemory *pdata;
UErrorCode status = U_ZERO_ERROR;
@ -223,7 +226,7 @@ int32_t gentz::writeTzDatFile() {
*(uint16_t*)&(dataInfo.dataVersion[0]) = header.versionYear;
*(uint16_t*)&(dataInfo.dataVersion[2]) = header.versionSuffix;
pdata = udata_create(TZ_DATA_TYPE, TZ_DATA_NAME, &dataInfo,
pdata = udata_create(TZ_DATA_TYPE, TZ_DATA_NAME, destdir, &dataInfo,
useCopyright ? U_COPYRIGHT_STRING : 0, &status);
if (U_FAILURE(status)) {
die("Unable to create data memory");

View File

@ -122,7 +122,7 @@ $(TARGET) : $(OBJECTS)
# Rule to build a compiled cnv file
@DATABUILDDIR@/%.cnv : $(top_srcdir)/../data/%.ucm
@echo -n "$< -> "
@ICU_DATA=@DATABUILDDIR@/ ./makeconv $<
@./makeconv -d @DATABUILDDIR@ $<
ifneq ($(MAKECMDGOALS),distclean)
-include $(DEPS)

View File

@ -247,12 +247,12 @@ static const UDataInfo dataInfo={
};
void writeConverterData(UConverterSharedData_1_4 *mySharedData, const char *cnvName, UErrorCode *status)
void writeConverterData(UConverterSharedData_1_4 *mySharedData, const char *cnvName, const char *cnvDir, UErrorCode *status)
{
UNewDataMemory *mem;
uint32_t sz2;
mem = udata_create("cnv", cnvName, &dataInfo, U_COPYRIGHT_STRING, status);
mem = udata_create("cnv", cnvName, cnvDir, &dataInfo, U_COPYRIGHT_STRING, status);
WriteConverterSharedData(mem, mySharedData);
@ -261,24 +261,85 @@ void writeConverterData(UConverterSharedData_1_4 *mySharedData, const char *cnvN
/* printf("Done. Wrote %d bytes.\n", sz2); */
}
static void copyright() {
printf("Copyright (C) 1998-1999, International Business Machines\n");
printf("Corporation and others. All Rights Reserved.\n");
}
static void usage(const char *pname, int exitcode) {
FILE *where = exitcode ? stderr : stdout;
fprintf(where, "%csage: %s [ -h, --help ] [ --version ] [ --copyright ] [ -d destdir ] file ...\n", exitcode ? 'u' : 'U', pname);
if (!exitcode) {
fputc('\n', where);
fprintf(where, "Options: -h, --help\tdisplay this help and exit\n");
fprintf(where, " --version\tdisplay the tool's version and exit\n");
fprintf(where, " --copyright\tdisplay a copyright statement and exit\n");
fprintf(where, " -d destdir\tsets the output directory (defaults to ICU data dir)\n");
}
exit(exitcode);
}
int main(int argc, char** argv)
{
UConverterSharedData_1_4* mySharedData = NULL;
UErrorCode err = U_ZERO_ERROR;
char outFileName[UCNV_MAX_FULL_FILE_NAME_LENGTH];
const char* destdir = u_getDataDirectory();
char *pname = *argv;
const char* destdir = 0;
size_t destdirlen;
char* dot = NULL, *arg, *outBasename;
char cnvName[UCNV_MAX_FULL_FILE_NAME_LENGTH];
if (argc == 1)
{
/*prints out a usage message*/
printf("usage: %s file1 file2 file3 ...\n", argv[0]);
}
/* Lame getopt() thingy. */
if (destdir != NULL && *destdir != 0) {
for (++argv; *argv && **argv == '-' && (*argv)[1]; ++argv) {
switch ((*argv)[1]) {
case 'd':
if ((*argv)[2]) {
destdir = *argv + 2;
} else if (*++argv) {
destdir = *argv;
} else {
usage(pname, 1);
}
break;
case 'h':
if (!(*argv)[2]) {
usage(pname, 0);
} else {
usage(pname, 1);
}
break;
case '-':
if (!strcmp(*argv, "--help")) {
usage(pname, 0);
} else if (!strcmp(*argv, "--copyright")) {
copyright();
exit(0);
} else if (!strcmp(*argv, "--version")) {
printf("makeconv version 1.0, by IBM and others\n");
exit(0);
} else {
usage(pname, 1);
}
break;
default:
usage(pname, 1);
}
}
if (!*argv) {
usage(pname, 1);
}
if (!destdir) {
destdir = u_getDataDirectory();
}
if (destdir != NULL && *destdir != 0) {
uprv_strcpy(outFileName, destdir);
destdirlen = uprv_strlen(destdir);
outBasename = outFileName + destdirlen;
@ -291,10 +352,10 @@ int main(int argc, char** argv)
outBasename = outFileName;
}
while (--argc)
for (; *argv; ++argv)
{
err = U_ZERO_ERROR;
arg = getLongPathname(argv[argc]);
arg = getLongPathname(*argv);
/*produces the right destination path for display*/
if (destdirlen != 0)
@ -339,7 +400,7 @@ int main(int argc, char** argv)
}
else
{
writeConverterData(mySharedData, cnvName, &err);
writeConverterData(mySharedData, cnvName, destdir, &err);
makeconv_deleteSharedConverterData(mySharedData);
if(U_FAILURE(err))
@ -946,4 +1007,11 @@ static void WriteConverterSharedData(UNewDataMemory *pData, const UConverterShar
}
/*
* Hey, Emacs, please set the following:
*
* Local Variables:
* indent-tabs-mode: nil
* End:
*
*/