1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2011-04-21 21:10:13 +00:00
|
|
|
* Copyright (C) 1998-2011, 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
|
|
|
********************************************************************************
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* makeconv.c:
|
|
|
|
* tool creating a binary (compressed) representation of the conversion mapping
|
|
|
|
* table (IBM NLTC ucmap format).
|
2000-05-12 19:59:03 +00:00
|
|
|
*
|
|
|
|
* 05/04/2000 helena Added fallback mapping into the picture...
|
2000-06-27 20:47:56 +00:00
|
|
|
* 06/29/2000 helena Major rewrite of the callback APIs.
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
2001-03-21 23:22:16 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
#include <stdio.h>
|
2001-01-03 00:18:57 +00:00
|
|
|
#include "unicode/putil.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/ucnv_err.h"
|
2000-06-27 20:47:56 +00:00
|
|
|
#include "ucnv_bld.h"
|
1999-10-18 22:48:32 +00:00
|
|
|
#include "ucnv_imp.h"
|
2000-04-19 23:05:27 +00:00
|
|
|
#include "ucnv_cnv.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "cstring.h"
|
|
|
|
#include "cmemory.h"
|
2004-09-14 16:58:51 +00:00
|
|
|
#include "uinvchar.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
#include "filestrm.h"
|
1999-12-14 01:30:27 +00:00
|
|
|
#include "toolutil.h"
|
2000-04-18 23:51:15 +00:00
|
|
|
#include "uoptions.h"
|
1999-12-28 23:57:50 +00:00
|
|
|
#include "unicode/udata.h"
|
1999-12-04 02:31:40 +00:00
|
|
|
#include "unewdata.h"
|
2003-11-07 23:57:24 +00:00
|
|
|
#include "uparse.h"
|
2003-10-25 00:29:13 +00:00
|
|
|
#include "ucm.h"
|
2000-11-15 00:56:35 +00:00
|
|
|
#include "makeconv.h"
|
|
|
|
#include "genmbcs.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2007-10-25 17:05:36 +00:00
|
|
|
#define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0]))
|
|
|
|
|
2000-07-13 00:26:14 +00:00
|
|
|
#define DEBUG 0
|
2000-04-19 23:05:27 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
typedef struct ConvData {
|
|
|
|
UCMFile *ucm;
|
|
|
|
NewConverter *cnvData, *extData;
|
|
|
|
UConverterSharedData sharedData;
|
|
|
|
UConverterStaticData staticData;
|
|
|
|
} ConvData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
initConvData(ConvData *data) {
|
|
|
|
uprv_memset(data, 0, sizeof(ConvData));
|
|
|
|
data->sharedData.structSize=sizeof(UConverterSharedData);
|
|
|
|
data->staticData.structSize=sizeof(UConverterStaticData);
|
|
|
|
data->sharedData.staticData=&data->staticData;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cleanupConvData(ConvData *data) {
|
|
|
|
if(data!=NULL) {
|
|
|
|
if(data->cnvData!=NULL) {
|
|
|
|
data->cnvData->close(data->cnvData);
|
|
|
|
data->cnvData=NULL;
|
|
|
|
}
|
|
|
|
if(data->extData!=NULL) {
|
|
|
|
data->extData->close(data->extData);
|
|
|
|
data->extData=NULL;
|
|
|
|
}
|
|
|
|
ucm_close(data->ucm);
|
|
|
|
data->ucm=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-20 19:43:32 +00:00
|
|
|
/*
|
|
|
|
* from ucnvstat.c - static prototypes of data-based converters
|
|
|
|
*/
|
|
|
|
extern const UConverterStaticData * ucnv_converterStaticData[UCNV_NUMBER_OF_SUPPORTED_CONVERTER_TYPES];
|
|
|
|
|
2000-04-19 23:05:27 +00:00
|
|
|
/*
|
|
|
|
* Global - verbosity
|
2000-02-05 00:19:15 +00:00
|
|
|
*/
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool VERBOSE = FALSE;
|
2007-10-25 17:05:36 +00:00
|
|
|
UBool SMALL = FALSE;
|
2010-02-27 03:39:15 +00:00
|
|
|
UBool IGNORE_SISO_CHECK = FALSE;
|
2000-02-05 00:19:15 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
static void
|
|
|
|
createConverter(ConvData *data, const char* converterName, UErrorCode *pErrorCode);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-04-19 23:05:27 +00:00
|
|
|
/*
|
|
|
|
* Set up the UNewData and write the converter..
|
|
|
|
*/
|
2003-10-25 00:29:13 +00:00
|
|
|
static void
|
|
|
|
writeConverterData(ConvData *data, const char *cnvName, const char *cnvDir, UErrorCode *status);
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool haveCopyright=TRUE;
|
2000-04-18 23:51:15 +00:00
|
|
|
|
2000-07-13 00:26:14 +00:00
|
|
|
static UDataInfo dataInfo={
|
1999-12-04 02:31:40 +00:00
|
|
|
sizeof(UDataInfo),
|
|
|
|
0,
|
|
|
|
|
|
|
|
U_IS_BIG_ENDIAN,
|
|
|
|
U_CHARSET_FAMILY,
|
|
|
|
sizeof(UChar),
|
|
|
|
0,
|
|
|
|
|
2001-02-06 22:11:41 +00:00
|
|
|
{0x63, 0x6e, 0x76, 0x74}, /* dataFormat="cnvt" */
|
2001-02-26 19:44:41 +00:00
|
|
|
{6, 2, 0, 0}, /* formatVersion */
|
2001-02-06 22:11:41 +00:00
|
|
|
{0, 0, 0, 0} /* dataVersion (calculated at runtime) */
|
1999-12-04 02:31:40 +00:00
|
|
|
};
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
static void
|
|
|
|
writeConverterData(ConvData *data, const char *cnvName, const char *cnvDir, UErrorCode *status)
|
1999-12-04 02:31:40 +00:00
|
|
|
{
|
2000-11-15 00:56:35 +00:00
|
|
|
UNewDataMemory *mem = NULL;
|
|
|
|
uint32_t sz2;
|
|
|
|
uint32_t size = 0;
|
2003-10-25 00:29:13 +00:00
|
|
|
int32_t tableType;
|
2000-11-15 00:56:35 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
tableType=TABLE_NONE;
|
|
|
|
if(data->cnvData!=NULL) {
|
|
|
|
tableType|=TABLE_BASE;
|
|
|
|
}
|
|
|
|
if(data->extData!=NULL) {
|
|
|
|
tableType|=TABLE_EXT;
|
|
|
|
}
|
|
|
|
|
2000-11-15 00:56:35 +00:00
|
|
|
mem = udata_create(cnvDir, "cnv", cnvName, &dataInfo, haveCopyright ? U_COPYRIGHT_STRING : NULL, status);
|
1999-12-04 02:31:40 +00:00
|
|
|
|
2000-11-15 00:56:35 +00:00
|
|
|
if(U_FAILURE(*status))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Couldn't create the udata %s.%s: %s\n",
|
|
|
|
cnvName,
|
|
|
|
"cnv",
|
|
|
|
u_errorName(*status));
|
|
|
|
return;
|
|
|
|
}
|
2000-04-19 23:05:27 +00:00
|
|
|
|
2000-11-15 00:56:35 +00:00
|
|
|
if(VERBOSE)
|
|
|
|
{
|
2007-02-06 05:24:14 +00:00
|
|
|
printf("- Opened udata %s.%s\n", cnvName, "cnv");
|
2000-11-15 00:56:35 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2000-11-15 00:56:35 +00:00
|
|
|
/* all read only, clean, platform independent data. Mmmm. :) */
|
2003-10-25 00:29:13 +00:00
|
|
|
udata_writeBlock(mem, &data->staticData, sizeof(UConverterStaticData));
|
2000-11-15 00:56:35 +00:00
|
|
|
size += sizeof(UConverterStaticData); /* Is 4-aligned - by size */
|
|
|
|
/* Now, write the table */
|
2003-10-25 00:29:13 +00:00
|
|
|
if(tableType&TABLE_BASE) {
|
|
|
|
size += data->cnvData->write(data->cnvData, &data->staticData, mem, tableType);
|
|
|
|
}
|
|
|
|
if(tableType&TABLE_EXT) {
|
|
|
|
size += data->extData->write(data->extData, &data->staticData, mem, tableType);
|
|
|
|
}
|
2000-11-15 00:56:35 +00:00
|
|
|
|
|
|
|
sz2 = udata_finish(mem, status);
|
|
|
|
if(size != sz2)
|
2000-04-19 23:05:27 +00:00
|
|
|
{
|
2004-05-17 06:33:22 +00:00
|
|
|
fprintf(stderr, "error: wrote %u bytes to the .cnv file but counted %u bytes\n", (int)sz2, (int)size);
|
2000-11-15 00:56:35 +00:00
|
|
|
*status=U_INTERNAL_PROGRAM_ERROR;
|
2000-04-19 23:05:27 +00:00
|
|
|
}
|
2000-11-15 00:56:35 +00:00
|
|
|
if(VERBOSE)
|
2000-04-19 23:05:27 +00:00
|
|
|
{
|
2007-02-06 05:24:14 +00:00
|
|
|
printf("- Wrote %u bytes to the udata.\n", (int)sz2);
|
2000-04-19 23:05:27 +00:00
|
|
|
}
|
1999-12-04 02:31:40 +00:00
|
|
|
}
|
|
|
|
|
2007-10-25 17:05:36 +00:00
|
|
|
enum {
|
|
|
|
OPT_HELP_H,
|
|
|
|
OPT_HELP_QUESTION_MARK,
|
|
|
|
OPT_COPYRIGHT,
|
|
|
|
OPT_VERSION,
|
|
|
|
OPT_DESTDIR,
|
|
|
|
OPT_VERBOSE,
|
|
|
|
OPT_SMALL,
|
2010-02-27 03:39:15 +00:00
|
|
|
OPT_IGNORE_SISO_CHECK,
|
2007-10-25 17:05:36 +00:00
|
|
|
OPT_COUNT
|
|
|
|
};
|
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
static UOption options[]={
|
2007-10-25 17:05:36 +00:00
|
|
|
UOPTION_HELP_H,
|
|
|
|
UOPTION_HELP_QUESTION_MARK,
|
|
|
|
UOPTION_COPYRIGHT,
|
|
|
|
UOPTION_VERSION,
|
|
|
|
UOPTION_DESTDIR,
|
|
|
|
UOPTION_VERBOSE,
|
2010-02-27 03:39:15 +00:00
|
|
|
{ "small", NULL, NULL, NULL, '\1', UOPT_NO_ARG, 0 },
|
|
|
|
{ "ignore-siso-check", NULL, NULL, NULL, '\1', UOPT_NO_ARG, 0 }
|
2000-04-18 23:51:15 +00:00
|
|
|
};
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-09-21 21:49:32 +00:00
|
|
|
int main(int argc, char* argv[])
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-10-25 00:29:13 +00:00
|
|
|
ConvData data;
|
2003-07-03 18:02:55 +00:00
|
|
|
UErrorCode err = U_ZERO_ERROR, localError;
|
2000-08-28 23:15:05 +00:00
|
|
|
char outFileName[UCNV_MAX_FULL_FILE_NAME_LENGTH];
|
|
|
|
const char* destdir, *arg;
|
|
|
|
size_t destdirlen;
|
|
|
|
char* dot = NULL, *outBasename;
|
|
|
|
char cnvName[UCNV_MAX_FULL_FILE_NAME_LENGTH];
|
2002-07-17 03:56:50 +00:00
|
|
|
char cnvNameWithPkg[UCNV_MAX_FULL_FILE_NAME_LENGTH];
|
2000-10-03 20:18:22 +00:00
|
|
|
UVersionInfo icuVersion;
|
2004-03-30 06:15:34 +00:00
|
|
|
UBool printFilename;
|
2000-08-28 21:36:13 +00:00
|
|
|
|
2003-08-14 21:34:54 +00:00
|
|
|
err = U_ZERO_ERROR;
|
|
|
|
|
2002-03-15 23:41:40 +00:00
|
|
|
U_MAIN_INIT_ARGS(argc, argv);
|
2000-07-13 00:26:14 +00:00
|
|
|
|
2000-10-03 20:18:22 +00:00
|
|
|
/* Set up the ICU version number */
|
|
|
|
u_getVersion(icuVersion);
|
|
|
|
uprv_memcpy(&dataInfo.dataVersion, &icuVersion, sizeof(UVersionInfo));
|
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
/* preset then read command line options */
|
2007-10-25 17:05:36 +00:00
|
|
|
options[OPT_DESTDIR].value=u_getDataDirectory();
|
|
|
|
argc=u_parseArgs(argc, argv, LENGTHOF(options), options);
|
2000-04-18 23:51:15 +00:00
|
|
|
|
|
|
|
/* error handling, printing usage message */
|
|
|
|
if(argc<0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"error in command line argument \"%s\"\n",
|
|
|
|
argv[-argc]);
|
|
|
|
} else if(argc<2) {
|
|
|
|
argc=-1;
|
|
|
|
}
|
2007-10-25 17:05:36 +00:00
|
|
|
if(argc<0 || options[OPT_HELP_H].doesOccur || options[OPT_HELP_QUESTION_MARK].doesOccur) {
|
|
|
|
FILE *stdfile=argc<0 ? stderr : stdout;
|
|
|
|
fprintf(stdfile,
|
2000-04-18 23:51:15 +00:00
|
|
|
"usage: %s [-options] files...\n"
|
|
|
|
"\tread .ucm codepage mapping files and write .cnv files\n"
|
2002-03-15 23:41:40 +00:00
|
|
|
"options:\n"
|
|
|
|
"\t-h or -? or --help this usage text\n"
|
|
|
|
"\t-V or --version show a version message\n"
|
|
|
|
"\t-c or --copyright include a copyright notice\n"
|
|
|
|
"\t-d or --destdir destination directory, followed by the path\n"
|
|
|
|
"\t-v or --verbose Turn on verbose output\n",
|
2000-04-18 23:51:15 +00:00
|
|
|
argv[0]);
|
2007-10-25 17:05:36 +00:00
|
|
|
fprintf(stdfile,
|
|
|
|
"\t --small Generate smaller .cnv files. They will be\n"
|
|
|
|
"\t significantly smaller but may not be compatible with\n"
|
|
|
|
"\t older versions of ICU and will require heap memory\n"
|
2010-02-27 03:39:15 +00:00
|
|
|
"\t allocation when loaded.\n"
|
|
|
|
"\t --ignore-siso-check Use SI/SO other than 0xf/0xe.\n");
|
2000-04-18 23:51:15 +00:00
|
|
|
return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
|
|
|
|
}
|
2000-02-09 01:29:21 +00:00
|
|
|
|
2007-10-25 17:05:36 +00:00
|
|
|
if(options[OPT_VERSION].doesOccur) {
|
|
|
|
printf("makeconv version %hu.%hu, ICU tool to read .ucm codepage mapping files and write .cnv files\n",
|
|
|
|
dataInfo.formatVersion[0], dataInfo.formatVersion[1]);
|
|
|
|
printf("%s\n", U_COPYRIGHT_STRING);
|
2000-04-18 23:51:15 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2000-02-29 18:42:28 +00:00
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
/* get the options values */
|
2007-10-25 17:05:36 +00:00
|
|
|
haveCopyright = options[OPT_COPYRIGHT].doesOccur;
|
|
|
|
destdir = options[OPT_DESTDIR].value;
|
|
|
|
VERBOSE = options[OPT_VERBOSE].doesOccur;
|
|
|
|
SMALL = options[OPT_SMALL].doesOccur;
|
2000-02-29 18:42:28 +00:00
|
|
|
|
2010-02-27 03:39:15 +00:00
|
|
|
if (options[OPT_IGNORE_SISO_CHECK].doesOccur) {
|
|
|
|
IGNORE_SISO_CHECK = TRUE;
|
|
|
|
}
|
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
if (destdir != NULL && *destdir != 0) {
|
2000-02-09 01:29:21 +00:00
|
|
|
uprv_strcpy(outFileName, destdir);
|
|
|
|
destdirlen = uprv_strlen(destdir);
|
|
|
|
outBasename = outFileName + destdirlen;
|
|
|
|
if (*(outBasename - 1) != U_FILE_SEP_CHAR) {
|
|
|
|
*outBasename++ = U_FILE_SEP_CHAR;
|
|
|
|
++destdirlen;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
destdirlen = 0;
|
|
|
|
outBasename = outFileName;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2000-08-09 17:24:54 +00:00
|
|
|
#if DEBUG
|
|
|
|
{
|
|
|
|
int i;
|
2000-07-13 00:26:14 +00:00
|
|
|
printf("makeconv: processing %d files...\n", argc - 1);
|
|
|
|
for(i=1; i<argc; ++i) {
|
|
|
|
printf("%s ", argv[i]);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
2000-08-09 17:24:54 +00:00
|
|
|
#endif
|
2000-02-09 01:29:21 +00:00
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
err = U_ZERO_ERROR;
|
2006-12-13 01:38:41 +00:00
|
|
|
printFilename = (UBool) (argc > 2 || VERBOSE);
|
2003-09-13 08:46:41 +00:00
|
|
|
for (++argv; --argc; ++argv)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2003-09-13 08:46:41 +00:00
|
|
|
arg = getLongPathname(*argv);
|
1999-12-14 01:30:27 +00:00
|
|
|
|
2008-01-09 00:04:19 +00:00
|
|
|
/* Check for potential buffer overflow */
|
|
|
|
if(strlen(arg) > UCNV_MAX_FULL_FILE_NAME_LENGTH)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", u_errorName(U_BUFFER_OVERFLOW_ERROR));
|
|
|
|
return U_BUFFER_OVERFLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
/*produces the right destination path for display*/
|
|
|
|
if (destdirlen != 0)
|
2000-02-09 01:29:21 +00:00
|
|
|
{
|
2003-09-13 08:46:41 +00:00
|
|
|
const char *basename;
|
|
|
|
|
|
|
|
/* find the last file sepator */
|
2003-11-07 23:57:24 +00:00
|
|
|
basename = findBasename(arg);
|
2003-09-13 08:46:41 +00:00
|
|
|
uprv_strcpy(outBasename, basename);
|
2000-02-07 20:54:50 +00:00
|
|
|
}
|
2003-09-13 08:46:41 +00:00
|
|
|
else
|
2000-02-09 01:29:21 +00:00
|
|
|
{
|
2003-09-13 08:46:41 +00:00
|
|
|
uprv_strcpy(outFileName, arg);
|
2000-02-07 20:54:50 +00:00
|
|
|
}
|
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
/*removes the extension if any is found*/
|
|
|
|
dot = uprv_strrchr(outBasename, '.');
|
|
|
|
if (dot)
|
2000-02-09 01:29:21 +00:00
|
|
|
{
|
2003-09-13 08:46:41 +00:00
|
|
|
*dot = '\0';
|
2000-02-09 01:29:21 +00:00
|
|
|
}
|
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
/* the basename without extension is the converter name */
|
|
|
|
uprv_strcpy(cnvName, outBasename);
|
2000-02-09 01:29:21 +00:00
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
/*Adds the target extension*/
|
|
|
|
uprv_strcat(outBasename, CONVERTER_FILE_EXTENSION);
|
2000-02-09 01:29:21 +00:00
|
|
|
|
2000-08-09 17:24:54 +00:00
|
|
|
#if DEBUG
|
2000-07-13 00:26:14 +00:00
|
|
|
printf("makeconv: processing %s ...\n", arg);
|
|
|
|
fflush(stdout);
|
2000-08-09 17:24:54 +00:00
|
|
|
#endif
|
2003-09-13 08:46:41 +00:00
|
|
|
localError = U_ZERO_ERROR;
|
2003-10-25 00:29:13 +00:00
|
|
|
initConvData(&data);
|
|
|
|
createConverter(&data, arg, &localError);
|
1999-12-04 02:31:40 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
if (U_FAILURE(localError))
|
2000-02-09 01:29:21 +00:00
|
|
|
{
|
2003-09-13 08:46:41 +00:00
|
|
|
/* if an error is found, print out an error msg and keep going */
|
|
|
|
fprintf(stderr, "Error creating converter for \"%s\" file for \"%s\" (%s)\n", outFileName, arg,
|
|
|
|
u_errorName(localError));
|
|
|
|
if(U_SUCCESS(err)) {
|
|
|
|
err = localError;
|
|
|
|
}
|
2000-02-09 01:29:21 +00:00
|
|
|
}
|
2003-09-13 08:46:41 +00:00
|
|
|
else
|
2000-02-09 01:29:21 +00:00
|
|
|
{
|
2008-01-09 00:04:19 +00:00
|
|
|
/* Insure the static data name matches the file name */
|
|
|
|
/* Changed to ignore directory and only compare base name
|
|
|
|
LDH 1/2/08*/
|
|
|
|
char *p;
|
|
|
|
p = strrchr(cnvName, U_FILE_SEP_CHAR); /* Find last file separator */
|
|
|
|
|
|
|
|
if(p == NULL) /* OK, try alternate */
|
|
|
|
{
|
|
|
|
p = strrchr(cnvName, U_FILE_ALT_SEP_CHAR);
|
|
|
|
if(p == NULL)
|
|
|
|
{
|
|
|
|
p=cnvName; /* If no separators, no problem */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p++; /* If found separtor, don't include it in compare */
|
|
|
|
}
|
|
|
|
if(uprv_stricmp(p,data.staticData.name))
|
2003-09-13 08:46:41 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Warning: %s%s claims to be '%s'\n",
|
2008-01-09 00:04:19 +00:00
|
|
|
cnvName, CONVERTER_FILE_EXTENSION,
|
2003-10-25 00:29:13 +00:00
|
|
|
data.staticData.name);
|
2003-09-13 08:46:41 +00:00
|
|
|
}
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
uprv_strcpy((char*)data.staticData.name, cnvName);
|
2003-09-13 08:46:41 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
if(!uprv_isInvariantString((char*)data.staticData.name, -1)) {
|
2003-09-13 08:46:41 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Error: A converter name must contain only invariant characters.\n"
|
|
|
|
"%s is not a valid converter name.\n",
|
2003-10-25 00:29:13 +00:00
|
|
|
data.staticData.name);
|
2003-09-13 08:46:41 +00:00
|
|
|
if(U_SUCCESS(err)) {
|
|
|
|
err = U_INVALID_TABLE_FORMAT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 19:47:47 +00:00
|
|
|
uprv_strcpy(cnvNameWithPkg, cnvName);
|
2003-09-13 08:46:41 +00:00
|
|
|
|
|
|
|
localError = U_ZERO_ERROR;
|
2003-10-25 00:29:13 +00:00
|
|
|
writeConverterData(&data, cnvNameWithPkg, destdir, &localError);
|
2003-09-13 08:46:41 +00:00
|
|
|
|
|
|
|
if(U_FAILURE(localError))
|
|
|
|
{
|
|
|
|
/* if an error is found, print out an error msg and keep going*/
|
|
|
|
fprintf(stderr, "Error writing \"%s\" file for \"%s\" (%s)\n", outFileName, arg,
|
2003-07-03 18:02:55 +00:00
|
|
|
u_errorName(localError));
|
2003-09-13 08:46:41 +00:00
|
|
|
if(U_SUCCESS(err)) {
|
|
|
|
err = localError;
|
|
|
|
}
|
|
|
|
}
|
2004-03-30 06:15:34 +00:00
|
|
|
else if (printFilename)
|
2003-09-13 08:46:41 +00:00
|
|
|
{
|
2006-12-13 01:38:41 +00:00
|
|
|
puts(outBasename);
|
2003-09-13 08:46:41 +00:00
|
|
|
}
|
2000-02-09 01:29:21 +00:00
|
|
|
}
|
2003-09-13 08:46:41 +00:00
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
2003-10-25 00:29:13 +00:00
|
|
|
|
|
|
|
cleanupConvData(&data);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
return err;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-17 00:34:04 +00:00
|
|
|
static void
|
|
|
|
getPlatformAndCCSIDFromName(const char *name, int8_t *pPlatform, int32_t *pCCSID) {
|
|
|
|
if( (name[0]=='i' || name[0]=='I') &&
|
|
|
|
(name[1]=='b' || name[1]=='B') &&
|
|
|
|
(name[2]=='m' || name[2]=='M')
|
|
|
|
) {
|
|
|
|
name+=3;
|
|
|
|
if(*name=='-') {
|
|
|
|
++name;
|
|
|
|
}
|
|
|
|
*pPlatform=UCNV_IBM;
|
|
|
|
*pCCSID=(int32_t)uprv_strtoul(name, NULL, 10);
|
|
|
|
} else {
|
|
|
|
*pPlatform=UCNV_UNKNOWN;
|
|
|
|
*pCCSID=0;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
static void
|
|
|
|
readHeader(ConvData *data,
|
|
|
|
FileStream* convFile,
|
|
|
|
const char* converterName,
|
|
|
|
UErrorCode *pErrorCode) {
|
2011-04-21 21:10:13 +00:00
|
|
|
char line[1024];
|
2003-10-25 00:29:13 +00:00
|
|
|
char *s, *key, *value;
|
|
|
|
const UConverterStaticData *prototype;
|
2001-02-26 19:44:41 +00:00
|
|
|
UConverterStaticData *staticData;
|
2000-07-13 00:26:14 +00:00
|
|
|
|
2001-02-26 19:44:41 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
2000-12-20 18:41:36 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
staticData=&data->staticData;
|
2001-02-26 19:44:41 +00:00
|
|
|
staticData->platform=UCNV_IBM;
|
|
|
|
staticData->subCharLen=0;
|
|
|
|
|
|
|
|
while(T_FileStream_readLine(convFile, line, sizeof(line))) {
|
2003-10-25 00:29:13 +00:00
|
|
|
/* basic parsing and handling of state-related items */
|
|
|
|
if(ucm_parseHeaderLine(data->ucm, line, &key, &value)) {
|
2001-02-26 19:44:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* stop at the beginning of the mapping section */
|
2003-10-25 00:29:13 +00:00
|
|
|
if(uprv_strcmp(line, "CHARMAP")==0) {
|
2001-02-26 19:44:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-08-28 23:15:05 +00:00
|
|
|
|
2001-02-26 19:44:41 +00:00
|
|
|
/* collect the information from the header field, ignore unknown keys */
|
|
|
|
if(uprv_strcmp(key, "code_set_name")==0) {
|
|
|
|
if(*value!=0) {
|
2003-10-25 00:29:13 +00:00
|
|
|
uprv_strcpy((char *)staticData->name, value);
|
2001-03-17 00:34:04 +00:00
|
|
|
getPlatformAndCCSIDFromName(value, &staticData->platform, &staticData->codepage);
|
2001-02-26 19:44:41 +00:00
|
|
|
}
|
|
|
|
} else if(uprv_strcmp(key, "subchar")==0) {
|
2003-10-25 00:29:13 +00:00
|
|
|
uint8_t bytes[UCNV_EXT_MAX_BYTES];
|
|
|
|
int8_t length;
|
|
|
|
|
|
|
|
s=value;
|
2003-10-29 21:31:51 +00:00
|
|
|
length=ucm_parseBytes(bytes, line, (const char **)&s);
|
2003-10-25 00:29:13 +00:00
|
|
|
if(1<=length && length<=4 && *s==0) {
|
|
|
|
staticData->subCharLen=length;
|
|
|
|
uprv_memcpy(staticData->subChar, bytes, length);
|
2001-02-26 19:44:41 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "error: illegal <subchar> %s\n", value);
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if(uprv_strcmp(key, "subchar1")==0) {
|
2003-10-25 00:29:13 +00:00
|
|
|
uint8_t bytes[UCNV_EXT_MAX_BYTES];
|
2001-02-26 19:44:41 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
s=value;
|
2003-12-04 00:48:12 +00:00
|
|
|
if(1==ucm_parseBytes(bytes, line, (const char **)&s) && *s==0) {
|
2003-10-25 00:29:13 +00:00
|
|
|
staticData->subChar1=bytes[0];
|
2001-02-26 19:44:41 +00:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "error: illegal <subchar1> %s\n", value);
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-09 01:29:21 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
/* copy values from the UCMFile to the static data */
|
|
|
|
staticData->maxBytesPerChar=(int8_t)data->ucm->states.maxCharLength;
|
|
|
|
staticData->minBytesPerChar=(int8_t)data->ucm->states.minCharLength;
|
|
|
|
staticData->conversionType=data->ucm->states.conversionType;
|
|
|
|
|
2001-02-26 19:44:41 +00:00
|
|
|
if(staticData->conversionType==UCNV_UNSUPPORTED_CONVERTER) {
|
2003-10-25 00:29:13 +00:00
|
|
|
fprintf(stderr, "ucm error: missing conversion type (<uconv_class>)\n");
|
2001-02-26 19:44:41 +00:00
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
2003-10-25 00:29:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now that we know the type, copy any 'default' values from the table.
|
|
|
|
* We need not check the type any further because the parser only
|
|
|
|
* recognizes what we have prototypes for.
|
2003-11-12 23:42:44 +00:00
|
|
|
*
|
|
|
|
* For delta (extension-only) tables, copy values from the base file
|
|
|
|
* instead, see createConverter().
|
2003-10-25 00:29:13 +00:00
|
|
|
*/
|
2003-11-12 23:42:44 +00:00
|
|
|
if(data->ucm->baseName[0]==0) {
|
|
|
|
prototype=ucnv_converterStaticData[staticData->conversionType];
|
|
|
|
if(prototype!=NULL) {
|
|
|
|
if(staticData->name[0]==0) {
|
|
|
|
uprv_strcpy((char *)staticData->name, prototype->name);
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
if(staticData->codepage==0) {
|
|
|
|
staticData->codepage=prototype->codepage;
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
if(staticData->platform==0) {
|
|
|
|
staticData->platform=prototype->platform;
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
if(staticData->minBytesPerChar==0) {
|
|
|
|
staticData->minBytesPerChar=prototype->minBytesPerChar;
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
if(staticData->maxBytesPerChar==0) {
|
|
|
|
staticData->maxBytesPerChar=prototype->maxBytesPerChar;
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
if(staticData->subCharLen==0) {
|
|
|
|
staticData->subCharLen=prototype->subCharLen;
|
|
|
|
if(prototype->subCharLen>0) {
|
|
|
|
uprv_memcpy(staticData->subChar, prototype->subChar, prototype->subCharLen);
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->ucm->states.outputType<0) {
|
2003-11-12 23:42:44 +00:00
|
|
|
data->ucm->states.outputType=(int8_t)data->ucm->states.maxCharLength-1;
|
2003-10-25 00:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( staticData->subChar1!=0 &&
|
|
|
|
(staticData->minBytesPerChar>1 ||
|
|
|
|
(staticData->conversionType!=UCNV_MBCS &&
|
|
|
|
staticData->conversionType!=UCNV_EBCDIC_STATEFUL))
|
2003-04-11 21:05:50 +00:00
|
|
|
) {
|
|
|
|
fprintf(stderr, "error: <subchar1> defined for a type other than MBCS or EBCDIC_STATEFUL\n");
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
2000-07-13 00:26:14 +00:00
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
/* return TRUE if a base table was read, FALSE for an extension table */
|
|
|
|
static UBool
|
|
|
|
readFile(ConvData *data, const char* converterName,
|
|
|
|
UErrorCode *pErrorCode) {
|
2011-04-21 21:10:13 +00:00
|
|
|
char line[1024];
|
2003-10-25 00:29:13 +00:00
|
|
|
char *end;
|
|
|
|
FileStream *convFile;
|
2003-11-07 23:57:24 +00:00
|
|
|
|
|
|
|
UCMStates *baseStates;
|
2003-10-25 00:29:13 +00:00
|
|
|
UBool dataIsBase;
|
|
|
|
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2000-04-19 23:05:27 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
data->ucm=ucm_open();
|
|
|
|
|
|
|
|
convFile=T_FileStream_open(converterName, "r");
|
|
|
|
if(convFile==NULL) {
|
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
|
|
|
readHeader(data, convFile, converterName, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return FALSE;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
if(data->ucm->baseName[0]==0) {
|
|
|
|
dataIsBase=TRUE;
|
2003-11-07 23:57:24 +00:00
|
|
|
baseStates=&data->ucm->states;
|
2010-02-27 03:39:15 +00:00
|
|
|
ucm_processStates(baseStates, IGNORE_SISO_CHECK);
|
2003-11-07 23:57:24 +00:00
|
|
|
} else {
|
|
|
|
dataIsBase=FALSE;
|
|
|
|
baseStates=NULL;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
/* read the base table */
|
|
|
|
ucm_readTable(data->ucm, convFile, dataIsBase, baseStates, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
/* read an extension table if there is one */
|
|
|
|
while(T_FileStream_readLine(convFile, line, sizeof(line))) {
|
|
|
|
end=uprv_strchr(line, 0);
|
|
|
|
while(line<end &&
|
|
|
|
(*(end-1)=='\n' || *(end-1)=='\r' || *(end-1)==' ' || *(end-1)=='\t')) {
|
|
|
|
--end;
|
|
|
|
}
|
|
|
|
*end=0;
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
if(line[0]=='#' || u_skipWhitespace(line)==end) {
|
|
|
|
continue; /* ignore empty and comment lines */
|
2003-10-25 00:29:13 +00:00
|
|
|
}
|
2003-10-30 03:23:11 +00:00
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
if(0==uprv_strcmp(line, "CHARMAP")) {
|
|
|
|
/* read the extension table */
|
|
|
|
ucm_readTable(data->ucm, convFile, FALSE, baseStates, pErrorCode);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "unexpected text after the base mapping table\n");
|
|
|
|
}
|
|
|
|
break;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
T_FileStream_close(convFile);
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
if(data->ucm->base->flagsType==UCM_FLAGS_MIXED || data->ucm->ext->flagsType==UCM_FLAGS_MIXED) {
|
|
|
|
fprintf(stderr, "error: some entries have the mapping precision (with '|'), some do not\n");
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
return dataIsBase;
|
|
|
|
}
|
2001-03-21 23:22:16 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
static void
|
2003-11-07 23:57:24 +00:00
|
|
|
createConverter(ConvData *data, const char *converterName, UErrorCode *pErrorCode) {
|
2003-10-25 00:29:13 +00:00
|
|
|
ConvData baseData;
|
|
|
|
UBool dataIsBase;
|
2000-04-19 23:05:27 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
UConverterStaticData *staticData;
|
|
|
|
UCMStates *states, *baseStates;
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
2001-03-21 23:22:16 +00:00
|
|
|
}
|
2000-04-19 23:05:27 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
initConvData(data);
|
1999-12-04 02:31:40 +00:00
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
dataIsBase=readFile(data, converterName, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
staticData=&data->staticData;
|
|
|
|
states=&data->ucm->states;
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
if(dataIsBase) {
|
2007-02-06 05:24:14 +00:00
|
|
|
/*
|
|
|
|
* Build a normal .cnv file with a base table
|
|
|
|
* and an optional extension table.
|
|
|
|
*/
|
2003-10-25 00:29:13 +00:00
|
|
|
data->cnvData=MBCSOpen(data->ucm);
|
|
|
|
if(data->cnvData==NULL) {
|
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
|
|
|
|
} else if(!data->cnvData->isValid(data->cnvData,
|
2003-11-12 23:42:44 +00:00
|
|
|
staticData->subChar, staticData->subCharLen)
|
2003-10-25 00:29:13 +00:00
|
|
|
) {
|
|
|
|
fprintf(stderr, " the substitution character byte sequence is illegal in this codepage structure!\n");
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
|
2003-11-12 23:42:44 +00:00
|
|
|
} else if(staticData->subChar1!=0 &&
|
|
|
|
!data->cnvData->isValid(data->cnvData, &staticData->subChar1, 1)
|
|
|
|
) {
|
|
|
|
fprintf(stderr, " the subchar1 byte is illegal in this codepage structure!\n");
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
|
2007-02-06 05:24:14 +00:00
|
|
|
} else if(
|
|
|
|
data->ucm->ext->mappingsLength>0 &&
|
|
|
|
!ucm_checkBaseExt(states, data->ucm->base, data->ucm->ext, data->ucm->ext, FALSE)
|
|
|
|
) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
} else if(data->ucm->base->flagsType&UCM_FLAGS_EXPLICIT) {
|
|
|
|
/* sort the table so that it can be turned into UTF-8-friendly data */
|
|
|
|
ucm_sortTable(data->ucm->base);
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
|
2007-02-06 05:24:14 +00:00
|
|
|
if(U_SUCCESS(*pErrorCode)) {
|
|
|
|
if(
|
|
|
|
/* add the base table after ucm_checkBaseExt()! */
|
|
|
|
!data->cnvData->addTable(data->cnvData, data->ucm->base, &data->staticData)
|
2003-10-25 00:29:13 +00:00
|
|
|
) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
2007-02-06 05:24:14 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* addTable() may have requested moving more mappings to the extension table
|
|
|
|
* if they fit into the base toUnicode table but not into the
|
|
|
|
* base fromUnicode table.
|
|
|
|
* (Especially for UTF-8-friendly fromUnicode tables.)
|
|
|
|
* Such mappings will have the MBCS_FROM_U_EXT_FLAG set, which causes them
|
|
|
|
* to be excluded from the extension toUnicode data.
|
|
|
|
* See MBCSOkForBaseFromUnicode() for which mappings do not fit into
|
|
|
|
* the base fromUnicode table.
|
|
|
|
*/
|
|
|
|
ucm_moveMappings(data->ucm->base, data->ucm->ext);
|
|
|
|
ucm_sortTable(data->ucm->ext);
|
|
|
|
if(data->ucm->ext->mappingsLength>0) {
|
|
|
|
/* prepare the extension table, if there is one */
|
|
|
|
data->extData=CnvExtOpen(data->ucm);
|
|
|
|
if(data->extData==NULL) {
|
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
} else if(
|
|
|
|
!data->extData->addTable(data->extData, data->ucm->ext, &data->staticData)
|
|
|
|
) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
}
|
|
|
|
}
|
2001-01-02 22:55:14 +00:00
|
|
|
}
|
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
} else {
|
2007-02-06 05:24:14 +00:00
|
|
|
/* Build an extension-only .cnv file. */
|
2003-11-07 23:57:24 +00:00
|
|
|
char baseFilename[500];
|
|
|
|
char *basename;
|
|
|
|
|
|
|
|
initConvData(&baseData);
|
|
|
|
|
|
|
|
/* assemble a path/filename for data->ucm->baseName */
|
|
|
|
uprv_strcpy(baseFilename, converterName);
|
|
|
|
basename=(char *)findBasename(baseFilename);
|
|
|
|
uprv_strcpy(basename, data->ucm->baseName);
|
|
|
|
uprv_strcat(basename, ".ucm");
|
|
|
|
|
|
|
|
/* read the base table */
|
|
|
|
dataIsBase=readFile(&baseData, baseFilename, pErrorCode);
|
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
} else if(!dataIsBase) {
|
|
|
|
fprintf(stderr, "error: the <icu:base> file \"%s\" is not a base table file\n", baseFilename);
|
2003-10-25 00:29:13 +00:00
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
2003-11-07 23:57:24 +00:00
|
|
|
} else {
|
|
|
|
/* prepare the extension table */
|
|
|
|
data->extData=CnvExtOpen(data->ucm);
|
|
|
|
if(data->extData==NULL) {
|
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
2003-11-12 23:42:44 +00:00
|
|
|
} else {
|
|
|
|
/* fill in gaps in extension file header fields */
|
|
|
|
UCMapping *m, *mLimit;
|
|
|
|
uint8_t fallbackFlags;
|
|
|
|
|
|
|
|
baseStates=&baseData.ucm->states;
|
|
|
|
if(states->conversionType==UCNV_DBCS) {
|
|
|
|
staticData->minBytesPerChar=(int8_t)(states->minCharLength=2);
|
|
|
|
} else if(states->minCharLength==0) {
|
|
|
|
staticData->minBytesPerChar=(int8_t)(states->minCharLength=baseStates->minCharLength);
|
|
|
|
}
|
|
|
|
if(states->maxCharLength<states->minCharLength) {
|
|
|
|
staticData->maxBytesPerChar=(int8_t)(states->maxCharLength=baseStates->maxCharLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(staticData->subCharLen==0) {
|
|
|
|
uprv_memcpy(staticData->subChar, baseData.staticData.subChar, 4);
|
|
|
|
staticData->subCharLen=baseData.staticData.subCharLen;
|
|
|
|
}
|
2003-11-13 05:15:40 +00:00
|
|
|
/*
|
|
|
|
* do not copy subChar1 -
|
|
|
|
* only use what is explicitly specified
|
|
|
|
* because it cannot be unset in the extension file header
|
|
|
|
*/
|
2003-11-12 23:42:44 +00:00
|
|
|
|
|
|
|
/* get the fallback flags */
|
|
|
|
fallbackFlags=0;
|
|
|
|
for(m=baseData.ucm->base->mappings, mLimit=m+baseData.ucm->base->mappingsLength;
|
|
|
|
m<mLimit && fallbackFlags!=3;
|
|
|
|
++m
|
|
|
|
) {
|
|
|
|
if(m->f==1) {
|
|
|
|
fallbackFlags|=1;
|
|
|
|
} else if(m->f==3) {
|
|
|
|
fallbackFlags|=2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fallbackFlags&1) {
|
|
|
|
staticData->hasFromUnicodeFallback=TRUE;
|
|
|
|
}
|
|
|
|
if(fallbackFlags&2) {
|
|
|
|
staticData->hasToUnicodeFallback=TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(1!=ucm_countChars(baseStates, staticData->subChar, staticData->subCharLen)) {
|
|
|
|
fprintf(stderr, " the substitution character byte sequence is illegal in this codepage structure!\n");
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
|
2010-03-03 18:08:17 +00:00
|
|
|
} else if(staticData->subChar1!=0 && 1!=ucm_countChars(baseStates, &staticData->subChar1, 1)) {
|
2003-11-12 23:42:44 +00:00
|
|
|
fprintf(stderr, " the subchar1 byte is illegal in this codepage structure!\n");
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
|
|
|
|
} else if(
|
|
|
|
!ucm_checkValidity(data->ucm->ext, baseStates) ||
|
2007-02-06 05:24:14 +00:00
|
|
|
!ucm_checkBaseExt(baseStates, baseData.ucm->base, data->ucm->ext, data->ucm->ext, FALSE)
|
2003-11-12 23:42:44 +00:00
|
|
|
) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
2007-02-06 05:24:14 +00:00
|
|
|
} else {
|
|
|
|
if(states->maxCharLength>1) {
|
|
|
|
/*
|
|
|
|
* When building a normal .cnv file with a base table
|
|
|
|
* for an MBCS (not SBCS) table with explicit precision flags,
|
|
|
|
* the MBCSAddTable() function marks some mappings for moving
|
|
|
|
* to the extension table.
|
|
|
|
* They fit into the base toUnicode table but not into the
|
|
|
|
* base fromUnicode table.
|
|
|
|
* (Note: We do have explicit precision flags because they are
|
|
|
|
* required for extension table generation, and
|
|
|
|
* ucm_checkBaseExt() verified it.)
|
|
|
|
*
|
|
|
|
* We do not call MBCSAddTable() here (we probably could)
|
|
|
|
* so we need to do the analysis before building the extension table.
|
2007-02-06 15:56:38 +00:00
|
|
|
* We assume that MBCSAddTable() will build a UTF-8-friendly table.
|
2007-02-06 05:24:14 +00:00
|
|
|
* Redundant mappings in the extension table are ok except they cost some size.
|
|
|
|
*
|
|
|
|
* Do this after ucm_checkBaseExt().
|
|
|
|
*/
|
2007-10-25 17:05:36 +00:00
|
|
|
const MBCSData *mbcsData=MBCSGetDummy();
|
2007-02-06 05:24:14 +00:00
|
|
|
int32_t needsMove=0;
|
|
|
|
for(m=baseData.ucm->base->mappings, mLimit=m+baseData.ucm->base->mappingsLength;
|
|
|
|
m<mLimit;
|
|
|
|
++m
|
|
|
|
) {
|
2007-10-25 17:05:36 +00:00
|
|
|
if(!MBCSOkForBaseFromUnicode(mbcsData, m->b.bytes, m->bLen, m->u, m->f)) {
|
2007-02-06 05:24:14 +00:00
|
|
|
m->f|=MBCS_FROM_U_EXT_FLAG;
|
|
|
|
m->moveFlag=UCM_MOVE_TO_EXT;
|
|
|
|
++needsMove;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(needsMove!=0) {
|
|
|
|
ucm_moveMappings(baseData.ucm->base, data->ucm->ext);
|
|
|
|
ucm_sortTable(data->ucm->ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!data->extData->addTable(data->extData, data->ucm->ext, &data->staticData)) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
}
|
2003-11-12 23:42:44 +00:00
|
|
|
}
|
2003-11-07 23:57:24 +00:00
|
|
|
}
|
2001-01-02 22:55:14 +00:00
|
|
|
}
|
2000-11-15 00:56:35 +00:00
|
|
|
|
2003-11-07 23:57:24 +00:00
|
|
|
cleanupConvData(&baseData);
|
|
|
|
}
|
1999-12-04 02:31:40 +00:00
|
|
|
}
|
|
|
|
|
2000-02-29 18:42:28 +00:00
|
|
|
/*
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
*/
|