1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2001-03-21 23:22:16 +00:00
|
|
|
* Copyright (C) 1998-2001, International Business Machines
|
1999-12-13 22:28:37 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* File genrb.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
2000-11-28 19:53:40 +00:00
|
|
|
* 05/25/99 stephen Creation.
|
2001-05-10 21:43:01 +00:00
|
|
|
* 5/10/01 Ram removed ustdio dependency
|
1999-08-16 21:50:52 +00:00
|
|
|
*******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
#include "genrb.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* Protos */
|
2002-07-17 03:56:50 +00:00
|
|
|
static void processFile(const char *filename, const char* cp, const char *inputDir, const char *outputDir, const char *packageName, UErrorCode *status);
|
|
|
|
static char *make_res_filename(const char *filename, const char *outputDir,
|
2002-07-24 21:21:05 +00:00
|
|
|
const char *packageName, UErrorCode *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
/* File suffixes */
|
|
|
|
#define RES_SUFFIX ".res"
|
|
|
|
#define COL_SUFFIX ".col"
|
|
|
|
|
2002-03-19 22:05:09 +00:00
|
|
|
static char theCurrentFileName[4096];
|
|
|
|
const char *gCurrentFileName = theCurrentFileName;
|
2002-03-16 03:40:05 +00:00
|
|
|
#ifdef XP_MAC_CONSOLE
|
|
|
|
#include <console.h>
|
|
|
|
#endif
|
2000-05-15 18:39:17 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
enum
|
|
|
|
{
|
2000-05-15 18:39:17 +00:00
|
|
|
HELP1,
|
|
|
|
HELP2,
|
2002-01-04 23:48:46 +00:00
|
|
|
VERBOSE,
|
2001-10-10 18:32:06 +00:00
|
|
|
QUIET,
|
2000-05-15 18:39:17 +00:00
|
|
|
VERSION,
|
|
|
|
SOURCEDIR,
|
|
|
|
DESTDIR,
|
2001-05-16 19:13:53 +00:00
|
|
|
ENCODING,
|
2001-11-03 02:54:08 +00:00
|
|
|
ICUDATADIR,
|
2002-03-16 03:40:05 +00:00
|
|
|
WRITE_JAVA,
|
2002-07-17 03:56:50 +00:00
|
|
|
COPYRIGHT,
|
2002-07-10 20:30:56 +00:00
|
|
|
PACKAGE_NAME,
|
|
|
|
BUNDLE_NAME,
|
2002-10-10 01:05:51 +00:00
|
|
|
WRITE_XML,
|
2002-11-08 23:16:10 +00:00
|
|
|
TOUCHFILE,
|
|
|
|
STRICT
|
2000-05-15 18:39:17 +00:00
|
|
|
};
|
|
|
|
|
2000-05-24 21:54:28 +00:00
|
|
|
UOption options[]={
|
2002-03-16 03:40:05 +00:00
|
|
|
UOPTION_HELP_H,
|
|
|
|
UOPTION_HELP_QUESTION_MARK,
|
|
|
|
UOPTION_VERBOSE,
|
|
|
|
UOPTION_QUIET,
|
|
|
|
UOPTION_VERSION,
|
|
|
|
UOPTION_SOURCEDIR,
|
|
|
|
UOPTION_DESTDIR,
|
|
|
|
UOPTION_ENCODING,
|
|
|
|
UOPTION_ICUDATADIR,
|
|
|
|
UOPTION_WRITE_JAVA,
|
2002-07-17 03:56:50 +00:00
|
|
|
UOPTION_COPYRIGHT,
|
2002-07-10 20:30:56 +00:00
|
|
|
UOPTION_PACKAGE_NAME,
|
|
|
|
UOPTION_BUNDLE_NAME,
|
2002-10-10 01:05:51 +00:00
|
|
|
UOPTION_DEF( "write-xml", 'x', UOPT_NO_ARG),
|
2002-11-08 23:16:10 +00:00
|
|
|
UOPTION_DEF( "touchfile", 't', UOPT_NO_ARG),
|
|
|
|
UOPTION_DEF( "strict", 'k', UOPT_NO_ARG) /* 14 */
|
2002-10-10 01:05:51 +00:00
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-03-16 03:40:05 +00:00
|
|
|
static UBool write_java = FALSE;
|
2002-10-10 01:05:51 +00:00
|
|
|
static UBool write_xml = FALSE;
|
2002-07-24 21:21:05 +00:00
|
|
|
static UBool touchfile = FALSE;
|
2002-03-16 03:40:05 +00:00
|
|
|
static const char* outputEnc ="";
|
2002-07-24 21:21:05 +00:00
|
|
|
static const char* gPackageName=NULL;
|
2002-07-10 20:30:56 +00:00
|
|
|
static const char* bundleName=NULL;
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
int
|
|
|
|
main(int argc,
|
2002-03-15 23:41:40 +00:00
|
|
|
char* argv[])
|
|
|
|
{
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
const char *arg = NULL;
|
|
|
|
const char *outputDir = NULL; /* NULL = no output directory, use current */
|
|
|
|
const char *inputDir = NULL;
|
|
|
|
const char *encoding = "";
|
|
|
|
int i;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
2000-08-28 21:36:13 +00:00
|
|
|
|
2001-09-25 19:28:25 +00:00
|
|
|
argc = u_parseArgs(argc, argv, (int32_t)(sizeof(options)/sizeof(options[0])), options);
|
2001-05-16 19:13:53 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* error handling, printing usage message */
|
|
|
|
if(argc<0) {
|
2002-01-04 23:48:46 +00:00
|
|
|
fprintf(stderr, "%s: error in command line argument \"%s\"\n", argv[0], argv[-argc]);
|
2001-07-11 20:31:32 +00:00
|
|
|
} else if(argc<2) {
|
|
|
|
argc = -1;
|
2000-05-15 18:39:17 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if(options[VERSION].doesOccur) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s version %s (ICU version %s).\n"
|
|
|
|
"%s\n",
|
|
|
|
argv[0], GENRB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING);
|
|
|
|
return U_ZERO_ERROR;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if(argc<0 || options[HELP1].doesOccur || options[HELP2].doesOccur) {
|
2001-11-20 02:46:46 +00:00
|
|
|
/*
|
|
|
|
* Broken into chucks because the C89 standard says the minimum
|
|
|
|
* required supported string length is 509 bytes.
|
|
|
|
*/
|
2001-07-11 20:31:32 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Usage: %s [OPTIONS] [FILES]\n"
|
2001-11-20 02:46:46 +00:00
|
|
|
"\tReads the list of resource bundle source files and creates\n"
|
|
|
|
"\tbinary version of reosurce bundles (.res files)\n",
|
|
|
|
argv[0]);
|
|
|
|
fprintf(stderr,
|
2001-10-10 18:32:06 +00:00
|
|
|
"Options:\n"
|
2002-07-24 21:21:05 +00:00
|
|
|
"\t-h or -? or --help this usage text\n"
|
|
|
|
"\t-q or --quiet do not display warnings\n"
|
|
|
|
"\t-v or --verbose print extra information when processing files\n"
|
|
|
|
"\t-V or --version prints out version number and exits\n"
|
|
|
|
"\t-c or --copyright include copyright notice\n");
|
2001-11-20 02:46:46 +00:00
|
|
|
fprintf(stderr,
|
2002-07-24 21:21:05 +00:00
|
|
|
"\t-e or --encoding encoding of source files\n"
|
|
|
|
"\t-d of --destdir destination directory, followed by the path, defaults to %s\n"
|
|
|
|
"\t-s or --sourcedir source directory for files followed by path, defaults to %s\n"
|
|
|
|
"\t-i or --icudatadir directory for locating any needed intermediate data files,\n"
|
|
|
|
"\t followed by path, defaults to %s\n",
|
2001-11-20 02:46:46 +00:00
|
|
|
u_getDataDirectory(), u_getDataDirectory(), u_getDataDirectory());
|
2002-04-04 02:45:18 +00:00
|
|
|
fprintf(stderr,
|
2002-07-24 21:21:05 +00:00
|
|
|
"\t-j or --write-java write a Java ListResourceBundle for ICU4J, followed by optional encoding\n"
|
|
|
|
"\t defaults to ASCII and \\uXXXX format.\n"
|
|
|
|
"\t-p or --package-name For ICU4J: package name for writing the ListResourceBundle for ICU4J,\n"
|
|
|
|
"\t defaults to com.ibm.icu.impl.data\n"
|
|
|
|
"\t For ICU4C: Package name on output. Specfiying\n"
|
|
|
|
"\t 'ICUDATA' defaults to the current ICU4C data name.\n");
|
|
|
|
fprintf(stderr,
|
|
|
|
"\t-b or --bundle-name bundle name for writing the ListResourceBundle for ICU4J,\n"
|
2002-10-10 01:05:51 +00:00
|
|
|
"\t defaults to LocaleElements\n"
|
2002-11-08 23:16:10 +00:00
|
|
|
"\t-x or --write-xml write a XML file for the resource bundle.\n"
|
|
|
|
"\t-k or --strict use pedantic parsing of syntax\n");
|
2002-07-10 20:30:56 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
return argc < 0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
|
|
|
|
}
|
|
|
|
|
2002-01-04 23:48:46 +00:00
|
|
|
if(options[VERBOSE].doesOccur) {
|
2002-11-08 23:16:10 +00:00
|
|
|
setVerbose(TRUE);
|
2002-01-04 23:48:46 +00:00
|
|
|
}
|
2001-10-10 18:32:06 +00:00
|
|
|
|
|
|
|
if(options[QUIET].doesOccur) {
|
|
|
|
setShowWarning(FALSE);
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
2002-11-08 23:16:10 +00:00
|
|
|
if(options[STRICT].doesOccur) {
|
|
|
|
setStrict(TRUE);
|
|
|
|
}
|
2001-11-03 02:54:08 +00:00
|
|
|
if(options[COPYRIGHT].doesOccur){
|
|
|
|
setIncludeCopyright(TRUE);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if(options[SOURCEDIR].doesOccur) {
|
|
|
|
inputDir = options[SOURCEDIR].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(options[DESTDIR].doesOccur) {
|
|
|
|
outputDir = options[DESTDIR].value;
|
|
|
|
}
|
2002-07-17 03:56:50 +00:00
|
|
|
if(options[PACKAGE_NAME].doesOccur) {
|
2002-07-24 21:21:05 +00:00
|
|
|
gPackageName = options[PACKAGE_NAME].value;
|
|
|
|
if(!strcmp(gPackageName, "ICUDATA"))
|
2002-07-17 03:56:50 +00:00
|
|
|
{
|
2002-07-24 21:21:05 +00:00
|
|
|
gPackageName = U_ICUDATA_NAME;
|
2002-07-17 03:56:50 +00:00
|
|
|
}
|
2002-07-24 21:21:05 +00:00
|
|
|
if(gPackageName[0] == 0)
|
2002-07-17 03:56:50 +00:00
|
|
|
{
|
2002-07-24 21:21:05 +00:00
|
|
|
gPackageName = NULL;
|
2002-07-17 03:56:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:21:05 +00:00
|
|
|
if(options[TOUCHFILE].doesOccur) {
|
|
|
|
if(gPackageName == NULL) {
|
|
|
|
fprintf(stderr, "%s: Don't use touchfile (-t) option with no package.\n",
|
|
|
|
argv[0]);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
touchfile = TRUE;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if(options[ENCODING].doesOccur) {
|
|
|
|
encoding = options[ENCODING].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(options[ICUDATADIR].doesOccur) {
|
|
|
|
u_setDataDirectory(options[ICUDATADIR].value);
|
|
|
|
}
|
2002-03-16 03:40:05 +00:00
|
|
|
if(options[WRITE_JAVA].doesOccur) {
|
|
|
|
write_java = TRUE;
|
|
|
|
outputEnc = options[WRITE_JAVA].value;
|
|
|
|
}
|
2002-07-17 03:56:50 +00:00
|
|
|
|
2002-07-10 20:30:56 +00:00
|
|
|
if(options[BUNDLE_NAME].doesOccur) {
|
|
|
|
bundleName = options[BUNDLE_NAME].value;
|
|
|
|
}
|
|
|
|
|
2002-10-10 01:05:51 +00:00
|
|
|
if(options[WRITE_XML].doesOccur) {
|
|
|
|
write_xml = TRUE;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
initParser();
|
|
|
|
|
|
|
|
/* generate the binary files */
|
|
|
|
for(i = 1; i < argc; ++i) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
arg = getLongPathname(argv[i]);
|
|
|
|
|
2002-03-21 18:30:19 +00:00
|
|
|
if (inputDir) {
|
|
|
|
uprv_strcpy(theCurrentFileName, inputDir);
|
|
|
|
uprv_strcat(theCurrentFileName, U_FILE_SEP_STRING);
|
|
|
|
} else {
|
|
|
|
*theCurrentFileName = 0;
|
|
|
|
}
|
|
|
|
uprv_strcat(theCurrentFileName, arg);
|
|
|
|
|
2002-11-08 23:16:10 +00:00
|
|
|
if (isVerbose()) {
|
|
|
|
printf("Processing file \"%s\"\n", theCurrentFileName);
|
2002-03-21 18:30:19 +00:00
|
|
|
}
|
2002-07-24 21:21:05 +00:00
|
|
|
processFile(arg, encoding, inputDir, outputDir, gPackageName, &status);
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Process a file */
|
|
|
|
static void
|
2002-07-17 03:56:50 +00:00
|
|
|
processFile(const char *filename, const char *cp, const char *inputDir, const char *outputDir, const char *packageName, UErrorCode *status) {
|
2002-10-10 01:05:51 +00:00
|
|
|
/*FileStream *in = NULL;*/
|
2001-07-11 20:31:32 +00:00
|
|
|
struct SRBRoot *data = NULL;
|
|
|
|
UCHARBUF *ucbuf = NULL;
|
|
|
|
char *rbname = NULL;
|
|
|
|
char *openFileName = NULL;
|
2001-11-16 23:47:05 +00:00
|
|
|
char *inputDirBuf = NULL;
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-03-19 17:49:17 +00:00
|
|
|
char outputFileName[256];
|
2002-10-10 01:05:51 +00:00
|
|
|
|
|
|
|
int32_t dirlen = 0;
|
|
|
|
int32_t filelen = 0;
|
|
|
|
|
|
|
|
if (status==NULL || U_FAILURE(*status)) {
|
2001-07-11 20:31:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-10-10 01:05:51 +00:00
|
|
|
if(filename==NULL){
|
|
|
|
*status=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}else{
|
|
|
|
filelen = (int32_t)uprv_strlen(filename);
|
|
|
|
}
|
|
|
|
if(inputDir == NULL) {
|
2001-11-16 23:47:05 +00:00
|
|
|
const char *filenameBegin = uprv_strrchr(filename, U_FILE_SEP_CHAR);
|
2002-10-10 01:05:51 +00:00
|
|
|
openFileName = (char *) uprv_malloc(dirlen + filelen + 2);
|
|
|
|
openFileName[0] = '\0';
|
2001-11-16 23:47:05 +00:00
|
|
|
if (filenameBegin != NULL) {
|
|
|
|
/*
|
|
|
|
* When a filename ../../../data/root.txt is specified,
|
|
|
|
* we presume that the input directory is ../../../data
|
|
|
|
* This is very important when the resource file includes
|
|
|
|
* another file, like UCARules.txt or thaidict.brk.
|
|
|
|
*/
|
|
|
|
int32_t filenameSize = filenameBegin - filename + 1;
|
2001-11-19 17:35:27 +00:00
|
|
|
inputDirBuf = uprv_strncpy((char *)uprv_malloc(filenameSize), filename, filenameSize);
|
2002-07-01 18:04:55 +00:00
|
|
|
|
|
|
|
/* test for NULL */
|
|
|
|
if(inputDirBuf == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:21:05 +00:00
|
|
|
inputDirBuf[filenameSize - 1] = 0;
|
2001-11-16 23:47:05 +00:00
|
|
|
inputDir = inputDirBuf;
|
2002-10-10 01:05:51 +00:00
|
|
|
dirlen = (int32_t)uprv_strlen(inputDir);
|
|
|
|
|
2001-11-16 23:47:05 +00:00
|
|
|
}
|
2002-10-10 01:05:51 +00:00
|
|
|
}else{
|
|
|
|
dirlen = (int32_t)uprv_strlen(inputDir);
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if(inputDir[dirlen-1] != U_FILE_SEP_CHAR) {
|
|
|
|
openFileName = (char *) uprv_malloc(dirlen + filelen + 2);
|
2002-07-01 18:04:55 +00:00
|
|
|
|
2002-07-24 21:21:05 +00:00
|
|
|
/* test for NULL */
|
|
|
|
if(openFileName == NULL) {
|
2002-07-01 18:04:55 +00:00
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finish;
|
2002-07-24 21:21:05 +00:00
|
|
|
}
|
2002-07-01 18:04:55 +00:00
|
|
|
|
2001-11-16 23:47:05 +00:00
|
|
|
openFileName[0] = '\0';
|
2001-11-05 23:16:09 +00:00
|
|
|
/*
|
|
|
|
* append the input dir to openFileName if the first char in
|
|
|
|
* filename is not file seperation char and the last char input directory is not '.'.
|
|
|
|
* This is to support :
|
|
|
|
* genrb -s. /home/icu/data
|
|
|
|
* genrb -s. icu/data
|
|
|
|
* The user cannot mix notations like
|
|
|
|
* genrb -s. /icu/data --- the absolute path specified. -s redundant
|
|
|
|
* user should use
|
|
|
|
* genrb -s. icu/data --- start from CWD and look in icu/data dir
|
|
|
|
*/
|
|
|
|
if( (filename[0] != U_FILE_SEP_CHAR) && (inputDir[dirlen-1] !='.')){
|
|
|
|
uprv_strcpy(openFileName, inputDir);
|
|
|
|
openFileName[dirlen] = U_FILE_SEP_CHAR;
|
|
|
|
}
|
2001-11-16 23:47:05 +00:00
|
|
|
openFileName[dirlen + 1] = '\0';
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
|
|
|
openFileName = (char *) uprv_malloc(dirlen + filelen + 1);
|
2002-07-01 18:04:55 +00:00
|
|
|
|
|
|
|
/* test for NULL */
|
|
|
|
if(openFileName == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
uprv_strcpy(openFileName, inputDir);
|
2002-10-10 01:05:51 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 01:05:51 +00:00
|
|
|
uprv_strcat(openFileName, filename);
|
|
|
|
|
|
|
|
ucbuf = ucbuf_open(openFileName, &cp,getShowWarning(),TRUE, status);
|
|
|
|
|
|
|
|
if(*status == U_FILE_ACCESS_ERROR) {
|
|
|
|
|
2002-01-04 23:48:46 +00:00
|
|
|
fprintf(stderr, "couldn't open file %s\n", openFileName == NULL ? filename : openFileName);
|
2001-07-11 20:31:32 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
2001-09-28 23:25:24 +00:00
|
|
|
if (ucbuf == NULL || U_FAILURE(*status)) {
|
2002-10-10 01:05:51 +00:00
|
|
|
fprintf(stderr, "An error occured processing file %s. Error: %s\n", openFileName == NULL ? filename : openFileName,u_errorName(*status));
|
2001-09-28 23:25:24 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
2002-10-10 01:05:51 +00:00
|
|
|
/* auto detected popular encodings? */
|
|
|
|
if (cp!=NULL) {
|
|
|
|
printf("autodetected encoding %s\n", cp);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
/* Parse the data into an SRBRoot */
|
|
|
|
data = parse(ucbuf, inputDir, status);
|
|
|
|
|
|
|
|
if (data == NULL || U_FAILURE(*status)) {
|
2002-12-04 23:31:10 +00:00
|
|
|
fprintf(stderr, "couldn't parse the file %s. Error:%s\n", filename,u_errorName(*status));
|
2001-07-11 20:31:32 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine the target rb filename */
|
2002-07-17 03:56:50 +00:00
|
|
|
rbname = make_res_filename(filename, outputDir, packageName, status);
|
2002-07-24 21:21:05 +00:00
|
|
|
if(touchfile == TRUE) {
|
|
|
|
FileStream *q;
|
|
|
|
char msg[1024];
|
|
|
|
char *tfname = NULL;
|
|
|
|
|
|
|
|
tfname = make_res_filename(filename, outputDir, NULL, status);
|
|
|
|
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error writing touchfile for \"%s\"\n", filename);
|
|
|
|
*status = U_FILE_ACCESS_ERROR;
|
|
|
|
} else {
|
|
|
|
uprv_strcat(tfname, ".res");
|
|
|
|
sprintf(msg, "This empty file tells nmake that %s in package %s has been updated.\n",
|
|
|
|
filename, packageName);
|
|
|
|
|
|
|
|
q = T_FileStream_open(tfname, "w");
|
|
|
|
if(q == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error writing touchfile \"%s\"\n", tfname);
|
|
|
|
*status = U_FILE_ACCESS_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
T_FileStream_write(q, msg, uprv_strlen(msg));
|
|
|
|
T_FileStream_close(q);
|
|
|
|
}
|
|
|
|
uprv_free(tfname);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
if(U_FAILURE(*status)) {
|
2002-12-04 23:31:10 +00:00
|
|
|
fprintf(stderr, "couldn't make the res fileName for bundle %s. Error:%s\n", filename,u_errorName(*status));
|
2001-07-11 20:31:32 +00:00
|
|
|
goto finish;
|
|
|
|
}
|
2002-10-10 01:05:51 +00:00
|
|
|
if(write_java== TRUE){
|
|
|
|
bundle_write_java(data,outputDir,outputEnc, outputFileName, sizeof(outputFileName),packageName,bundleName,status);
|
|
|
|
}else if(write_xml ==TRUE){
|
|
|
|
bundle_write_xml(data,outputDir,outputEnc, outputFileName, sizeof(outputFileName),status);
|
|
|
|
}else{
|
2002-03-16 03:40:05 +00:00
|
|
|
/* Write the data to the file */
|
2002-07-17 03:56:50 +00:00
|
|
|
bundle_write(data, outputDir, packageName, outputFileName, sizeof(outputFileName), status);
|
2002-03-19 17:49:17 +00:00
|
|
|
}
|
2002-03-19 20:09:29 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
2002-03-22 18:57:09 +00:00
|
|
|
fprintf(stderr, "couldn't write bundle %s. Error:%s\n", outputFileName,u_errorName(*status));
|
2002-03-16 03:40:05 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
bundle_close(data, status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-08-21 22:17:55 +00:00
|
|
|
finish:
|
2001-11-01 19:43:21 +00:00
|
|
|
|
2001-11-16 23:47:05 +00:00
|
|
|
if (inputDirBuf != NULL) {
|
|
|
|
uprv_free(inputDirBuf);
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (openFileName != NULL) {
|
|
|
|
uprv_free(openFileName);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if(ucbuf) {
|
|
|
|
ucbuf_close(ucbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rbname) {
|
|
|
|
uprv_free(rbname);
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
1999-12-13 03:41:08 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* Generate the target .res file name from the input file name */
|
|
|
|
static char*
|
|
|
|
make_res_filename(const char *filename,
|
|
|
|
const char *outputDir,
|
2002-07-17 03:56:50 +00:00
|
|
|
const char *packageName,
|
2001-07-11 20:31:32 +00:00
|
|
|
UErrorCode *status) {
|
1999-12-13 03:41:08 +00:00
|
|
|
char *basename;
|
2001-07-11 20:31:32 +00:00
|
|
|
char *dirname;
|
|
|
|
char *resName;
|
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
int32_t pkgLen = 0; /* length of package prefix */
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
if (U_FAILURE(*status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
1999-12-13 03:41:08 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
if(packageName != NULL)
|
|
|
|
{
|
|
|
|
pkgLen = 1 + uprv_strlen(packageName);
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
/* setup */
|
|
|
|
basename = dirname = resName = 0;
|
|
|
|
|
|
|
|
/* determine basename, and compiled file names */
|
1999-12-28 23:57:50 +00:00
|
|
|
basename = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1));
|
1999-12-13 03:41:08 +00:00
|
|
|
if(basename == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
2001-07-11 20:31:32 +00:00
|
|
|
goto finish;
|
1999-12-13 03:41:08 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
1999-12-13 03:41:08 +00:00
|
|
|
get_basename(basename, filename);
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
dirname = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(filename) + 1));
|
|
|
|
if(dirname == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finish;
|
1999-12-13 03:41:08 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
get_dirname(dirname, filename);
|
|
|
|
|
|
|
|
if (outputDir == NULL) {
|
|
|
|
/* output in same dir as .txt */
|
|
|
|
resName = (char*) uprv_malloc(sizeof(char) * (uprv_strlen(dirname)
|
2002-07-17 03:56:50 +00:00
|
|
|
+ pkgLen
|
2001-07-11 20:31:32 +00:00
|
|
|
+ uprv_strlen(basename)
|
2002-07-17 03:56:50 +00:00
|
|
|
+ uprv_strlen(RES_SUFFIX) + 8));
|
2001-07-11 20:31:32 +00:00
|
|
|
if(resName == 0) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_strcpy(resName, dirname);
|
2002-07-17 03:56:50 +00:00
|
|
|
|
|
|
|
if(packageName != NULL)
|
|
|
|
{
|
|
|
|
uprv_strcat(resName, packageName);
|
|
|
|
uprv_strcat(resName, "_");
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
uprv_strcat(resName, basename);
|
2002-07-17 03:56:50 +00:00
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
} else {
|
2001-09-25 19:28:25 +00:00
|
|
|
int32_t dirlen = (int32_t)uprv_strlen(outputDir);
|
|
|
|
int32_t basenamelen = (int32_t)uprv_strlen(basename);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
resName = (char*) uprv_malloc(sizeof(char) * (dirlen + pkgLen + basenamelen + 8));
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
if (resName == NULL) {
|
|
|
|
*status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
uprv_strcpy(resName, outputDir);
|
|
|
|
|
|
|
|
if(outputDir[dirlen] != U_FILE_SEP_CHAR) {
|
|
|
|
resName[dirlen] = U_FILE_SEP_CHAR;
|
|
|
|
resName[dirlen + 1] = '\0';
|
|
|
|
}
|
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
if(packageName != NULL)
|
|
|
|
{
|
|
|
|
uprv_strcat(resName, packageName);
|
|
|
|
uprv_strcat(resName, "_");
|
|
|
|
}
|
|
|
|
|
2001-07-11 20:31:32 +00:00
|
|
|
uprv_strcat(resName, basename);
|
1999-12-13 03:41:08 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
finish:
|
|
|
|
uprv_free(basename);
|
|
|
|
uprv_free(dirname);
|
|
|
|
|
|
|
|
return resName;
|
1999-12-15 21:42:15 +00:00
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
2000-03-04 01:19:19 +00:00
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*/
|