1999-08-16 21:50:52 +00:00
|
|
|
/*
|
|
|
|
********************************************************************************
|
1999-12-13 22:28:37 +00:00
|
|
|
*
|
2003-06-03 20:58:22 +00:00
|
|
|
* Copyright (C) 1998-2003, 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-08-16 21:50:52 +00:00
|
|
|
#include "ucnv_io.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"
|
|
|
|
#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
|
|
|
|
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;
|
2002-07-17 03:56:50 +00:00
|
|
|
UBool TOUCHFILE = 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)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "- Opened udata %s.%s\n", cnvName, "cnv");
|
|
|
|
}
|
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
|
|
|
{
|
2001-05-21 23:30:57 +00:00
|
|
|
fprintf(stderr, "error: wrote %d bytes to the .cnv file but counted %d bytes\n", sz2, 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
|
|
|
{
|
2001-03-21 23:22:16 +00:00
|
|
|
fprintf(stderr, "- Wrote %d bytes to the udata.\n", sz2);
|
2000-04-19 23:05:27 +00:00
|
|
|
}
|
1999-12-04 02:31:40 +00:00
|
|
|
}
|
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
static UOption options[]={
|
2001-03-21 23:22:16 +00:00
|
|
|
UOPTION_HELP_H, /* 0 Numbers for those who*/
|
2000-04-19 23:05:27 +00:00
|
|
|
UOPTION_HELP_QUESTION_MARK, /* 1 can't count. */
|
|
|
|
UOPTION_COPYRIGHT, /* 2 */
|
|
|
|
UOPTION_VERSION, /* 3 */
|
|
|
|
UOPTION_DESTDIR, /* 4 */
|
2002-07-17 03:56:50 +00:00
|
|
|
UOPTION_VERBOSE, /* 5 */
|
|
|
|
UOPTION_PACKAGE_NAME, /* 6 */
|
|
|
|
UOPTION_DEF( "touchfile", 't', UOPT_NO_ARG) /* 7 */
|
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];
|
2002-07-17 03:56:50 +00:00
|
|
|
char touchFileName[UCNV_MAX_FULL_FILE_NAME_LENGTH];
|
2000-08-28 23:15:05 +00:00
|
|
|
const char* destdir, *arg;
|
2002-07-17 03:56:50 +00:00
|
|
|
const char *pkgName = NULL;
|
2000-08-28 23:15:05 +00:00
|
|
|
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;
|
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 */
|
|
|
|
options[4].value=u_getDataDirectory();
|
|
|
|
argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"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]);
|
2002-07-24 21:21:05 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"\t-p or --pkgname sets the 'package' name for output files.\n"
|
|
|
|
"\t If name is ICUDATA, then the default icu package\n"
|
|
|
|
"\t name will be used.\n"
|
|
|
|
"\t-t or --touchfile Generate additional small file without packagename, for nmake\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
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
if(options[3].doesOccur) {
|
2000-04-19 23:05:27 +00:00
|
|
|
fprintf(stderr,"makeconv version %hu.%hu, ICU tool to read .ucm codepage mapping files and write .cnv files\n",
|
2000-04-18 23:51:15 +00:00
|
|
|
dataInfo.formatVersion[0], dataInfo.formatVersion[1]);
|
2000-04-19 23:05:27 +00:00
|
|
|
fprintf(stderr, "Copyright (C) 1998-2000, International Business Machines\n");
|
|
|
|
fprintf(stderr,"Corporation and others. All Rights Reserved.\n");
|
2000-04-18 23:51:15 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
2000-02-29 18:42:28 +00:00
|
|
|
|
2002-07-17 03:56:50 +00:00
|
|
|
TOUCHFILE = options[7].doesOccur;
|
|
|
|
|
|
|
|
if(!options[6].doesOccur)
|
|
|
|
{
|
2002-07-24 21:21:05 +00:00
|
|
|
fprintf(stderr, "%s : option -p (package name) is required.\n",
|
2002-07-17 03:56:50 +00:00
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pkgName =options[6].value;
|
|
|
|
if(!strcmp(pkgName, "ICUDATA"))
|
|
|
|
{
|
|
|
|
pkgName = U_ICUDATA_NAME;
|
|
|
|
}
|
|
|
|
if(pkgName[0] == 0)
|
|
|
|
{
|
|
|
|
pkgName = NULL;
|
|
|
|
|
2002-07-24 21:21:05 +00:00
|
|
|
if(TOUCHFILE)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s: Don't use touchfile option with an empty packagename.\n",
|
|
|
|
argv[0]);
|
|
|
|
exit(1);
|
|
|
|
}
|
2002-07-17 03:56:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-18 23:51:15 +00:00
|
|
|
/* get the options values */
|
|
|
|
haveCopyright = options[2].doesOccur;
|
|
|
|
destdir = options[4].value;
|
2000-04-19 23:05:27 +00:00
|
|
|
VERBOSE = options[5].doesOccur;
|
2000-02-29 18:42:28 +00:00
|
|
|
|
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;
|
|
|
|
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
|
|
|
|
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
|
|
|
if(TOUCHFILE)
|
|
|
|
{
|
|
|
|
uprv_strcpy(touchFileName, outBasename);
|
|
|
|
uprv_strcat(touchFileName, ".cnv");
|
|
|
|
}
|
2002-07-17 03:56:50 +00:00
|
|
|
|
2003-09-13 08:46:41 +00:00
|
|
|
if(pkgName != NULL)
|
|
|
|
{
|
2003-10-25 00:29:13 +00:00
|
|
|
/* changes both basename and filename */
|
2003-09-13 08:46:41 +00:00
|
|
|
uprv_strcpy(outBasename, pkgName);
|
|
|
|
uprv_strcat(outBasename, "_");
|
|
|
|
uprv_strcat(outBasename, cnvName);
|
|
|
|
}
|
2002-07-24 21:21:05 +00:00
|
|
|
|
2002-07-17 03:56:50 +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
|
|
|
{
|
2003-09-13 08:46:41 +00:00
|
|
|
/* Make the static data name equal to the file name */
|
2003-10-25 00:29:13 +00:00
|
|
|
if( /*VERBOSE && */ uprv_stricmp(cnvName,data.staticData.name))
|
2003-09-13 08:46:41 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Warning: %s%s claims to be '%s'\n",
|
2000-08-14 23:11:00 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pkgName == NULL)
|
|
|
|
{
|
|
|
|
uprv_strcpy(cnvNameWithPkg, cnvName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uprv_strcpy(cnvNameWithPkg, pkgName);
|
|
|
|
uprv_strcat(cnvNameWithPkg, "_");
|
|
|
|
uprv_strcat(cnvNameWithPkg, cnvName);
|
|
|
|
}
|
|
|
|
|
|
|
|
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(TOUCHFILE)
|
|
|
|
{
|
|
|
|
FileStream *q;
|
|
|
|
char msg[1024];
|
|
|
|
|
|
|
|
sprintf(msg, "This empty file tells nmake that %s in package %s has been updated.\n",
|
|
|
|
cnvName, pkgName);
|
|
|
|
|
|
|
|
q = T_FileStream_open(touchFileName, "w");
|
|
|
|
if(q == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Error writing touchfile \"%s\"\n", touchFileName);
|
|
|
|
localError = U_FILE_ACCESS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
T_FileStream_write(q, msg, uprv_strlen(msg));
|
|
|
|
T_FileStream_close(q);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
puts(outFileName);
|
|
|
|
}
|
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) {
|
2001-02-26 19:44:41 +00:00
|
|
|
char line[200];
|
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;
|
|
|
|
if(1==ucm_parseBytes(bytes, line, &s) && *s==0) {
|
|
|
|
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) {
|
|
|
|
char line[200];
|
|
|
|
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;
|
|
|
|
ucm_processStates(baseStates);
|
|
|
|
} 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) {
|
|
|
|
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;
|
|
|
|
|
2003-10-25 00:29:13 +00:00
|
|
|
} else 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(
|
2003-11-12 23:42:44 +00:00
|
|
|
!ucm_checkBaseExt(states, data->ucm->base, data->ucm->ext, data->ucm->ext, FALSE) ||
|
2003-10-25 00:29:13 +00:00
|
|
|
!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
|
|
|
|
|
|
|
/* add the base table after ucm_checkBaseExt()! */
|
|
|
|
if( U_SUCCESS(*pErrorCode) &&
|
|
|
|
!data->cnvData->addTable(data->cnvData, data->ucm->base, &data->staticData)
|
|
|
|
) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
2001-01-02 22:55:14 +00:00
|
|
|
}
|
2003-10-25 00:29:13 +00:00
|
|
|
} else {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(m=data->ucm->base->mappings, mLimit=m+data->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;
|
|
|
|
|
|
|
|
} else if(1!=ucm_countChars(baseStates, &staticData->subChar1, 1)) {
|
|
|
|
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) ||
|
|
|
|
!ucm_checkBaseExt(baseStates, baseData.ucm->base, data->ucm->ext, data->ucm->ext, FALSE) ||
|
|
|
|
!data->extData->addTable(data->extData, data->ucm->ext, &data->staticData)
|
|
|
|
) {
|
|
|
|
*pErrorCode=U_INVALID_TABLE_FORMAT;
|
|
|
|
}
|
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:
|
|
|
|
*
|
|
|
|
*/
|