1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
*******************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2008-03-13 22:43:56 +00:00
|
|
|
* Copyright (C) 1998-2008, 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"
|
2003-08-14 21:34:54 +00:00
|
|
|
#include "unicode/uclean.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);
|
2003-12-07 21:41:09 +00:00
|
|
|
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"
|
|
|
|
|
2003-06-18 22:32:27 +00:00
|
|
|
static char theCurrentFileName[2048];
|
2002-03-19 22:05:09 +00:00
|
|
|
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,
|
2008-03-14 18:51:29 +00:00
|
|
|
/* PACKAGE_NAME, This option is deprecated and should not be used ever. */
|
2002-07-10 20:30:56 +00:00
|
|
|
BUNDLE_NAME,
|
2003-10-24 23:07:00 +00:00
|
|
|
WRITE_XLIFF,
|
2003-04-30 00:49:01 +00:00
|
|
|
STRICT,
|
2003-05-20 00:50:45 +00:00
|
|
|
NO_BINARY_COLLATION,
|
|
|
|
/*added by Jing*/
|
2007-09-28 19:59:53 +00:00
|
|
|
LANGUAGE,
|
|
|
|
NO_COLLATION_RULES
|
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,
|
2008-03-14 18:51:29 +00:00
|
|
|
/* UOPTION_PACKAGE_NAME, This option is deprecated and should not be used ever. */
|
2002-07-10 20:30:56 +00:00
|
|
|
UOPTION_BUNDLE_NAME,
|
2003-10-24 23:07:00 +00:00
|
|
|
UOPTION_DEF( "write-xliff", 'x', UOPT_OPTIONAL_ARG),
|
2003-04-30 00:49:01 +00:00
|
|
|
UOPTION_DEF( "strict", 'k', UOPT_NO_ARG), /* 14 */
|
2003-05-20 00:50:45 +00:00
|
|
|
UOPTION_DEF( "noBinaryCollation", 'C', UOPT_NO_ARG),/* 15 */
|
2007-09-28 19:59:53 +00:00
|
|
|
UOPTION_DEF( "language", 'l', UOPT_REQUIRES_ARG), /* 16 */
|
|
|
|
UOPTION_DEF( "omitCollationRules", 'R', UOPT_NO_ARG),/* 17 */
|
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;
|
2003-10-24 23:07:00 +00:00
|
|
|
static UBool write_xliff = 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;
|
2003-05-20 00:50:45 +00:00
|
|
|
/*added by Jing*/
|
|
|
|
static const char* language = NULL;
|
2003-10-24 23:07:00 +00:00
|
|
|
static const char* xliffOutputFileName = 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;
|
2003-12-07 21:41:09 +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"
|
2008-03-13 22:43:56 +00:00
|
|
|
"\t defaults to ASCII and \\uXXXX format.\n");
|
2008-03-14 18:51:29 +00:00
|
|
|
/* This option is deprecated and should not be used ever.
|
|
|
|
"\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"); */
|
2002-07-24 21:21:05 +00:00
|
|
|
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"
|
2007-09-28 19:59:53 +00:00
|
|
|
"\t-x or --write-xliff write an XLIFF file for the resource bundle. Followed by\n"
|
|
|
|
"\t an optional output file name.\n"
|
2003-05-20 00:50:45 +00:00
|
|
|
"\t-k or --strict use pedantic parsing of syntax\n"
|
|
|
|
/*added by Jing*/
|
2007-09-28 19:59:53 +00:00
|
|
|
"\t-l or --language for XLIFF: language code compliant with BCP 47.\n");
|
|
|
|
fprintf(stderr,
|
|
|
|
"\t-C or --noBinaryCollation do not generate binary collation image;\n"
|
|
|
|
"\t makes .res file smaller but collator instantiation much slower;\n"
|
|
|
|
"\t maintains ability to get tailoring rules\n"
|
|
|
|
"\t-R or --omitCollationRules do not include collation (tailoring) rules;\n"
|
|
|
|
"\t makes .res file smaller and maintains collator instantiation speed\n"
|
|
|
|
"\t but tailoring rules will not be available (they are rarely used)\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;
|
|
|
|
}
|
2008-03-14 18:51:29 +00:00
|
|
|
/* This option is deprecated and should never be used.
|
|
|
|
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
|
|
|
}
|
2008-03-13 22:43:56 +00:00
|
|
|
}*/
|
2002-07-17 03:56:50 +00:00
|
|
|
|
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);
|
|
|
|
}
|
2003-08-15 01:26:22 +00:00
|
|
|
/* Initialize ICU */
|
|
|
|
u_init(&status);
|
|
|
|
if (U_FAILURE(status) && status != U_FILE_ACCESS_ERROR) {
|
|
|
|
/* Note: u_init() will try to open ICU property data.
|
|
|
|
* failures here are expected when building ICU from scratch.
|
|
|
|
* ignore them.
|
|
|
|
*/
|
|
|
|
fprintf(stderr, "%s: can not initialize ICU. status = %s\n",
|
|
|
|
argv[0], u_errorName(status));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
status = U_ZERO_ERROR;
|
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;
|
|
|
|
}
|
|
|
|
|
2003-10-24 23:07:00 +00:00
|
|
|
if(options[WRITE_XLIFF].doesOccur) {
|
|
|
|
write_xliff = TRUE;
|
|
|
|
if(options[WRITE_XLIFF].value != NULL){
|
|
|
|
xliffOutputFileName = options[WRITE_XLIFF].value;
|
|
|
|
}
|
2002-10-10 01:05:51 +00:00
|
|
|
}
|
2003-04-30 00:49:01 +00:00
|
|
|
|
2007-09-28 19:59:53 +00:00
|
|
|
initParser(options[NO_BINARY_COLLATION].doesOccur, options[NO_COLLATION_RULES].doesOccur);
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2003-05-20 00:50:45 +00:00
|
|
|
/*added by Jing*/
|
|
|
|
if(options[LANGUAGE].doesOccur) {
|
|
|
|
language = options[LANGUAGE].value;
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
/* generate the binary files */
|
|
|
|
for(i = 1; i < argc; ++i) {
|
|
|
|
status = U_ZERO_ERROR;
|
|
|
|
arg = getLongPathname(argv[i]);
|
2003-12-07 21:41:09 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-02-23 23:38:13 +00:00
|
|
|
/* Dont return warnings as a failure */
|
|
|
|
if (! U_FAILURE(status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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];
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2002-10-10 01:05:51 +00:00
|
|
|
int32_t dirlen = 0;
|
|
|
|
int32_t filelen = 0;
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2002-10-10 01:05:51 +00:00
|
|
|
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) {
|
|
|
|
/*
|
2003-12-07 21:41:09 +00:00
|
|
|
* When a filename ../../../data/root.txt is specified,
|
2001-11-16 23:47:05 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2003-12-07 21:41:09 +00:00
|
|
|
int32_t filenameSize = (int32_t)(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
|
|
|
/*
|
2003-12-07 21:41:09 +00:00
|
|
|
* append the input dir to openFileName if the first char in
|
2001-11-05 23:16:09 +00:00
|
|
|
* 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);
|
2003-12-07 21:41:09 +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);
|
2003-12-07 21:41:09 +00:00
|
|
|
|
2002-10-10 01:05:51 +00:00
|
|
|
if(*status == U_FILE_ACCESS_ERROR) {
|
2003-12-07 21:41:09 +00:00
|
|
|
|
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? */
|
2004-08-13 20:35:04 +00:00
|
|
|
if (cp!=NULL && isVerbose()) {
|
2002-10-10 01:05:51 +00:00
|
|
|
printf("autodetected encoding %s\n", cp);
|
|
|
|
}
|
2001-07-11 20:31:32 +00:00
|
|
|
/* Parse the data into an SRBRoot */
|
2006-04-21 01:15:46 +00:00
|
|
|
data = parse(ucbuf, inputDir, outputDir, status);
|
2001-07-11 20:31:32 +00:00
|
|
|
|
|
|
|
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);
|
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);
|
2003-10-24 23:07:00 +00:00
|
|
|
}else if(write_xliff ==TRUE){
|
|
|
|
bundle_write_xml(data,outputDir,outputEnc, filename, outputFileName, sizeof(outputFileName),language, xliffOutputFileName,status);
|
2002-10-10 01:05:51 +00:00
|
|
|
}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)
|
|
|
|
{
|
2003-12-07 21:41:09 +00:00
|
|
|
pkgLen = (int32_t)(1 + uprv_strlen(packageName));
|
2002-07-17 03:56:50 +00:00
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
*/
|