2002-01-28 18:47:35 +00:00
|
|
|
|
/*****************************************************************************
|
2001-09-19 23:43:16 +00:00
|
|
|
|
*
|
2003-06-03 20:58:22 +00:00
|
|
|
|
* Copyright (C) 1999-2003, International Business Machines
|
2001-09-19 23:43:16 +00:00
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
|
*
|
2002-01-28 18:47:35 +00:00
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* uconv(1): an iconv(1)-like converter using ICU.
|
|
|
|
|
*
|
|
|
|
|
* Original code by Jonas Utterstr<EFBFBD>m <jonas.utterstrom@vittran.norrnod.se>
|
|
|
|
|
* contributed in 1999.
|
|
|
|
|
*
|
|
|
|
|
* Conversion to the C conversion API and many improvements by
|
2002-02-20 00:22:12 +00:00
|
|
|
|
* Yves Arrouye <yves@realnames.com>, current maintainer.
|
2002-01-28 18:47:35 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-03-01 22:44:21 +00:00
|
|
|
|
#include <unicode/utypes.h>
|
2002-01-28 18:47:35 +00:00
|
|
|
|
#include <unicode/ucnv.h>
|
|
|
|
|
#include <unicode/unistr.h>
|
|
|
|
|
#include <unicode/translit.h>
|
2003-08-14 21:34:54 +00:00
|
|
|
|
#include <unicode/uclean.h>
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-07-12 21:42:24 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
#include "cmemory.h"
|
2002-02-16 07:43:26 +00:00
|
|
|
|
#include "cstring.h"
|
2002-02-16 08:47:31 +00:00
|
|
|
|
#include "ustrfmt.h"
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
|
|
|
|
#include "unicode/uwmsg.h"
|
|
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <io.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-06-07 17:08:34 +00:00
|
|
|
|
#ifdef UCONVMSG_LINK
|
2002-03-15 02:02:57 +00:00
|
|
|
|
/* below from the README */
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
|
#include "unicode/udata.h"
|
|
|
|
|
U_CFUNC char uconvmsg_dat[];
|
2002-03-01 22:44:21 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
#define DEFAULT_BUFSZ 4096
|
2002-03-15 02:02:57 +00:00
|
|
|
|
#define UCONVMSG "uconvmsg"
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
static UResourceBundle *gBundle = 0; /* Bundle containing messages. */
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/*
|
|
|
|
|
* Initialize the message bundle so that message strings can be fetched
|
|
|
|
|
* by u_wmsg().
|
|
|
|
|
*
|
|
|
|
|
*/
|
2001-11-10 01:53:45 +00:00
|
|
|
|
|
|
|
|
|
static void initMsg(const char *pname) {
|
|
|
|
|
static int ps = 0;
|
|
|
|
|
|
|
|
|
|
if (!ps) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
char dataPath[2048]; /* XXX Sloppy: should be PATH_MAX. */
|
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
ps = 1;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-03-01 22:44:21 +00:00
|
|
|
|
/* Set up our static data - if any */
|
2002-06-07 17:08:34 +00:00
|
|
|
|
#ifdef UCONVMSG_LINK
|
2002-03-19 17:14:10 +00:00
|
|
|
|
udata_setAppData(UCONVMSG, (const void*) uconvmsg_dat, &err);
|
2002-03-01 22:44:21 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
|
fprintf(stderr, "%s: warning, problem installing our static resource bundle data uconvmsg: %s - trying anyways.\n",
|
|
|
|
|
pname, u_errorName(err));
|
|
|
|
|
err = U_ZERO_ERROR; /* It may still fail */
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
/* Get messages. */
|
2002-03-15 02:02:57 +00:00
|
|
|
|
gBundle = u_wmsg_setPath(UCONVMSG, &err);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-03-19 17:14:10 +00:00
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"%s: warning: couldn't open bundle %s: %s\n",
|
|
|
|
|
pname, UCONVMSG, u_errorName(err));
|
2002-07-31 00:51:06 +00:00
|
|
|
|
#ifdef UCONVMSG_LINK
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"%s: setAppData was called, internal data %s failed to load\n",
|
2002-07-31 21:06:04 +00:00
|
|
|
|
pname, UCONVMSG);
|
2002-07-31 00:51:06 +00:00
|
|
|
|
#endif
|
2002-03-19 17:14:10 +00:00
|
|
|
|
|
2002-03-15 02:02:57 +00:00
|
|
|
|
err = U_ZERO_ERROR;
|
|
|
|
|
/* that was try #1, try again with a path */
|
2002-03-22 09:51:02 +00:00
|
|
|
|
uprv_strcpy(dataPath, u_getDataDirectory());
|
2002-07-31 00:51:06 +00:00
|
|
|
|
uprv_strcat(dataPath, U_FILE_SEP_STRING);
|
2002-03-22 09:51:02 +00:00
|
|
|
|
uprv_strcat(dataPath, UCONVMSG);
|
2002-03-15 02:02:57 +00:00
|
|
|
|
|
|
|
|
|
gBundle = u_wmsg_setPath(dataPath, &err);
|
|
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
|
fprintf(stderr,
|
2002-07-31 00:51:06 +00:00
|
|
|
|
"%s: warning: still couldn't open bundle %s: %s\n",
|
2002-03-15 02:02:57 +00:00
|
|
|
|
pname, dataPath, u_errorName(err));
|
2002-04-02 01:17:28 +00:00
|
|
|
|
fprintf(stderr, "%s: warning: messages will not be displayed\n", pname);
|
2002-03-15 02:02:57 +00:00
|
|
|
|
}
|
2002-02-20 00:22:12 +00:00
|
|
|
|
}
|
2001-11-10 01:53:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Mapping of callback names to the callbacks passed to the converter
|
|
|
|
|
API. */
|
|
|
|
|
|
2002-01-08 02:34:33 +00:00
|
|
|
|
static struct callback_ent {
|
|
|
|
|
const char *name;
|
|
|
|
|
UConverterFromUCallback fromu;
|
|
|
|
|
const void *fromuctxt;
|
|
|
|
|
UConverterToUCallback tou;
|
|
|
|
|
const void *touctxt;
|
|
|
|
|
} transcode_callbacks[] = {
|
2002-01-28 18:47:35 +00:00
|
|
|
|
{ "substitute",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_SUBSTITUTE, 0,
|
|
|
|
|
UCNV_TO_U_CALLBACK_SUBSTITUTE, 0 },
|
|
|
|
|
{ "skip",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_SKIP, 0,
|
|
|
|
|
UCNV_TO_U_CALLBACK_SKIP, 0 },
|
|
|
|
|
{ "stop",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_STOP, 0,
|
|
|
|
|
UCNV_TO_U_CALLBACK_STOP, 0 },
|
|
|
|
|
{ "escape",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, 0,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, 0},
|
|
|
|
|
{ "escape-icu",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_ICU,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_ICU },
|
|
|
|
|
{ "escape-java",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_JAVA,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_JAVA },
|
|
|
|
|
{ "escape-c",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C },
|
|
|
|
|
{ "escape-xml",
|
2002-02-01 07:39:57 +00:00
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_HEX,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_HEX },
|
2002-01-28 18:47:35 +00:00
|
|
|
|
{ "escape-xml-hex",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_HEX,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_HEX },
|
2002-02-01 07:39:57 +00:00
|
|
|
|
{ "escape-xml-dec",
|
|
|
|
|
UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_XML_DEC },
|
2002-01-28 18:47:35 +00:00
|
|
|
|
{ "escape-unicode", UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_UNICODE,
|
|
|
|
|
UCNV_TO_U_CALLBACK_ESCAPE, UCNV_ESCAPE_UNICODE }
|
2002-01-08 02:34:33 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Return a pointer to a callback record given its name. */
|
|
|
|
|
|
2002-01-08 02:34:33 +00:00
|
|
|
|
static const struct callback_ent *findCallback(const char *name) {
|
2002-01-28 18:47:35 +00:00
|
|
|
|
int i, count =
|
2002-02-20 00:22:12 +00:00
|
|
|
|
sizeof(transcode_callbacks) / sizeof(*transcode_callbacks);
|
2002-01-08 02:34:33 +00:00
|
|
|
|
|
|
|
|
|
/* We'll do a linear search, there aren't many of them and bsearch()
|
|
|
|
|
may not be that portable. */
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
2002-03-18 17:12:52 +00:00
|
|
|
|
if (!uprv_stricmp(name, transcode_callbacks[i].name)) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return &transcode_callbacks[i];
|
|
|
|
|
}
|
2002-01-08 02:34:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Print converter information. If lookfor is set, only that converter will
|
|
|
|
|
be printed, otherwise all converters will be printed. If canon is non
|
|
|
|
|
zero, tags and aliases for each converter are printed too, in the format
|
|
|
|
|
expected for convrters.txt(5). */
|
|
|
|
|
|
|
|
|
|
static int printConverters(const char *pname, const char *lookfor,
|
2002-02-20 00:22:12 +00:00
|
|
|
|
int canon)
|
|
|
|
|
{
|
2001-09-19 23:43:16 +00:00
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
2002-01-05 00:28:34 +00:00
|
|
|
|
int32_t num;
|
|
|
|
|
uint16_t num_stds;
|
|
|
|
|
const char **stds;
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* If there is a specified name, just handle that now. */
|
|
|
|
|
|
2002-01-05 01:08:01 +00:00
|
|
|
|
if (lookfor) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (!canon) {
|
|
|
|
|
printf("%s\n", lookfor);
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
/* Because we are printing a canonical name, we need the
|
|
|
|
|
true converter name. We've done that already except for
|
|
|
|
|
the default name (because we want to print the exact
|
|
|
|
|
name one would get when calling ucnv_getDefaultName()
|
|
|
|
|
in non-canon mode). But since we do not know at this
|
|
|
|
|
point if we have the default name or something else, we
|
|
|
|
|
need to normalize again to the canonical converter
|
|
|
|
|
name. */
|
|
|
|
|
|
|
|
|
|
const char *truename = ucnv_getAlias(lookfor, 0, &err);
|
|
|
|
|
if (U_SUCCESS(err)) {
|
|
|
|
|
lookfor = truename;
|
|
|
|
|
} else {
|
|
|
|
|
err = U_ZERO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-05 00:28:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Print converter names. We come here for one of two reasons: we
|
|
|
|
|
are printing all the names (lookfor was null), or we have a
|
|
|
|
|
single converter to print but in canon mode, hence we need to
|
|
|
|
|
get to it in order to print everything. */
|
|
|
|
|
|
2002-01-05 00:28:34 +00:00
|
|
|
|
num = ucnv_countAvailable();
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (num <= 0) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantGetNames");
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return -1;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
if (lookfor) {
|
|
|
|
|
num = 1; /* We know where we want to be. */
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 00:28:34 +00:00
|
|
|
|
num_stds = ucnv_countStandards();
|
|
|
|
|
stds = (const char **) uprv_malloc(num_stds * sizeof(*stds));
|
2001-11-13 07:22:18 +00:00
|
|
|
|
if (!stds) {
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantGetTag", u_wmsg_errorName(U_MEMORY_ALLOCATION_ERROR));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return -1;
|
2001-11-13 07:22:18 +00:00
|
|
|
|
} else {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
uint16_t s;
|
|
|
|
|
|
|
|
|
|
for (s = 0; s < num_stds; ++s) {
|
|
|
|
|
stds[s] = ucnv_getStandard(s, &err);
|
|
|
|
|
if (U_FAILURE(err)) {
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantGetTag", u_wmsg_errorName(err));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < num; i++) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
const char *name;
|
|
|
|
|
uint16_t num_aliases;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
|
|
|
|
/* Set the name either to what we are looking for, or
|
2002-02-20 00:22:12 +00:00
|
|
|
|
to the current converter name. */
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (lookfor) {
|
2002-01-28 18:47:35 +00:00
|
|
|
|
name = lookfor;
|
|
|
|
|
} else {
|
|
|
|
|
name = ucnv_getAvailableName(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get all the aliases associated to the name. */
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
err = U_ZERO_ERROR;
|
|
|
|
|
num_aliases = ucnv_countAliases(name, &err);
|
|
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
|
printf("%s", name);
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(name, (int32_t)(uprv_strlen(name) + 1));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
putchar('\t');
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantGetAliases", str.getBuffer(),
|
2002-02-20 00:22:12 +00:00
|
|
|
|
u_wmsg_errorName(err));
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
uint16_t a, s, t;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
|
|
|
|
/* Write all the aliases and their tags. */
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
for (a = 0; a < num_aliases; ++a) {
|
|
|
|
|
const char *alias = ucnv_getAlias(name, a, &err);
|
|
|
|
|
|
|
|
|
|
if (U_FAILURE(err)) {
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(name, (int32_t)(uprv_strlen(name) + 1));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
putchar('\t');
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantGetAliases", str.getBuffer(),
|
2002-02-20 00:22:12 +00:00
|
|
|
|
u_wmsg_errorName(err));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%s", alias);
|
|
|
|
|
|
|
|
|
|
/* Look (slowly, linear searching) for a tag. */
|
|
|
|
|
|
|
|
|
|
if (canon) {
|
|
|
|
|
for (s = t = 0; s < num_stds; ++s) {
|
|
|
|
|
const char *standard =
|
|
|
|
|
ucnv_getStandardName(name, stds[s], &err);
|
|
|
|
|
if (U_SUCCESS(err) && standard) {
|
|
|
|
|
if (!strcmp(standard, alias)) {
|
|
|
|
|
if (!t) {
|
|
|
|
|
printf(" {");
|
|
|
|
|
t = 1;
|
|
|
|
|
}
|
|
|
|
|
printf(" %s", stds[s]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (t) {
|
|
|
|
|
printf(" }");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Move on. */
|
|
|
|
|
|
|
|
|
|
if (a < num_aliases - 1) {
|
|
|
|
|
putchar(a || !canon ? ' ' : '\t');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
|
|
|
|
/* Terminate this entry. */
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (canon) {
|
|
|
|
|
putchar('\n');
|
|
|
|
|
} else if (i < num - 1) {
|
|
|
|
|
putchar(' ');
|
|
|
|
|
}
|
2001-11-13 07:22:18 +00:00
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
|
|
|
|
/* Free temporary data. */
|
|
|
|
|
|
|
|
|
|
uprv_free(stds);
|
|
|
|
|
|
|
|
|
|
/* Success. */
|
2001-11-13 07:22:18 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Print all available transliterators. If canon is non zero, print
|
|
|
|
|
one transliterator per line. */
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
static int printTransliterators(int canon)
|
2002-01-28 18:47:35 +00:00
|
|
|
|
{
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#if UCONFIG_NO_TRANSLITERATION
|
|
|
|
|
printf("no transliterators available because of UCONFIG_NO_TRANSLITERATION, see uconfig.h\n");
|
|
|
|
|
return 1;
|
|
|
|
|
#else
|
2002-01-07 20:45:00 +00:00
|
|
|
|
int32_t numtrans = utrans_countAvailableIDs(), i;
|
2002-01-07 21:05:30 +00:00
|
|
|
|
int buflen = 512;
|
|
|
|
|
char *buf = (char *) uprv_malloc(buflen);
|
|
|
|
|
char staticbuf[512];
|
|
|
|
|
|
|
|
|
|
char sepchar = canon ? '\n' : ' ';
|
|
|
|
|
|
|
|
|
|
if (!buf) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
buf = staticbuf;
|
|
|
|
|
buflen = sizeof(staticbuf);
|
2002-01-07 21:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-07 20:45:00 +00:00
|
|
|
|
for (i = 0; i < numtrans; ++i) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
int32_t len = utrans_getAvailableID(i, buf, buflen);
|
|
|
|
|
if (len >= buflen - 1) {
|
|
|
|
|
if (buf != staticbuf) {
|
|
|
|
|
buflen <<= 1;
|
|
|
|
|
if (buflen < len) {
|
|
|
|
|
buflen = len + 64;
|
|
|
|
|
}
|
|
|
|
|
buf = (char *) uprv_realloc(buf, buflen);
|
|
|
|
|
if (!buf) {
|
|
|
|
|
buf = staticbuf;
|
|
|
|
|
buflen = sizeof(staticbuf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
utrans_getAvailableID(i, buf, buflen);
|
|
|
|
|
if (len >= buflen) {
|
2002-03-22 09:51:02 +00:00
|
|
|
|
uprv_strcpy(buf + buflen - 4, "..."); /* Truncate the name. */
|
2002-02-20 00:22:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%s", buf);
|
|
|
|
|
if (i < numtrans - 1) {
|
|
|
|
|
putchar(sepchar);
|
|
|
|
|
}
|
2002-01-07 20:45:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Add a terminating newline if needed. */
|
|
|
|
|
|
2002-01-07 21:05:30 +00:00
|
|
|
|
if (sepchar != '\n') {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
putchar('\n');
|
2002-01-07 21:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Free temporary data. */
|
|
|
|
|
|
2002-01-07 21:05:30 +00:00
|
|
|
|
if (buf != staticbuf) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
uprv_free(buf);
|
2002-01-07 21:05:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Success. */
|
|
|
|
|
|
2002-01-07 20:45:00 +00:00
|
|
|
|
return 0;
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#endif
|
2002-01-07 20:45:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
/* Return the offset of a byte in its source, given the from and to offsets
|
|
|
|
|
vectors and the byte offset itself. */
|
|
|
|
|
|
2002-03-20 02:11:50 +00:00
|
|
|
|
static inline int32_t dataOffset(int32_t whereto,
|
|
|
|
|
const int32_t *fromoffsets, int32_t fromsz,
|
|
|
|
|
const int32_t *tooffsets, int32_t tosz) {
|
|
|
|
|
if (whereto >= 0 && whereto < tosz) {
|
|
|
|
|
whereto = tooffsets[whereto];
|
|
|
|
|
if (whereto >= 0 && whereto < fromsz) {
|
|
|
|
|
return fromoffsets[whereto];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2002-01-09 20:42:19 +00:00
|
|
|
|
}
|
2002-01-07 20:45:00 +00:00
|
|
|
|
|
2001-09-19 23:43:16 +00:00
|
|
|
|
// Convert a file from one encoding to another
|
2002-01-09 01:31:14 +00:00
|
|
|
|
static UBool convertFile(const char *pname,
|
2002-02-20 00:22:12 +00:00
|
|
|
|
const char *fromcpage,
|
|
|
|
|
UConverterToUCallback toucallback,
|
|
|
|
|
const void *touctxt,
|
|
|
|
|
const char *tocpage,
|
|
|
|
|
UConverterFromUCallback fromucallback,
|
|
|
|
|
const void *fromuctxt,
|
|
|
|
|
int fallback,
|
2002-01-31 22:44:42 +00:00
|
|
|
|
size_t bufsz,
|
2002-02-20 00:22:12 +00:00
|
|
|
|
const char *translit,
|
|
|
|
|
const char *infilestr,
|
|
|
|
|
FILE * outfile, int verbose)
|
|
|
|
|
{
|
2002-01-09 01:31:14 +00:00
|
|
|
|
FILE *infile;
|
|
|
|
|
UBool ret = TRUE;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
UConverter *convfrom = 0;
|
|
|
|
|
UConverter *convto = 0;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
UBool flush;
|
2002-01-31 22:44:42 +00:00
|
|
|
|
const char *cbufp;
|
|
|
|
|
char *bufp;
|
|
|
|
|
char *buf = 0;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-02-25 06:24:08 +00:00
|
|
|
|
uint32_t infoffset = 0, outfoffset = 0; /* Where we are in the file, for error reporting. */
|
2002-01-09 01:04:32 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
const UChar *unibufbp;
|
|
|
|
|
UChar *unibufp;
|
|
|
|
|
UChar *unibuf = 0;
|
2002-01-09 20:42:19 +00:00
|
|
|
|
int32_t *fromoffsets = 0, *tooffsets = 0;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-02-25 06:24:08 +00:00
|
|
|
|
size_t rd, wr, tobufsz;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2002-01-31 22:44:42 +00:00
|
|
|
|
Transliterator *t = 0; // Transliterator acting on Unicode data.
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#endif
|
2002-01-31 22:44:42 +00:00
|
|
|
|
UnicodeString u; // String to do the transliteration.
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-09 01:31:14 +00:00
|
|
|
|
// Open the correct input file or connect to stdin for reading input
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (infilestr != 0 && strcmp(infilestr, "-")) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
infile = fopen(infilestr, "rb");
|
|
|
|
|
if (infile == 0) {
|
|
|
|
|
UnicodeString str1(infilestr, "");
|
2002-04-02 01:17:28 +00:00
|
|
|
|
str1.append((UChar32) 0);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
UnicodeString str2(strerror(errno), "");
|
2002-04-02 01:17:28 +00:00
|
|
|
|
str2.append((UChar32) 0);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantOpenInputF", str1.getBuffer(), str2.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
} else {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
infilestr = "-";
|
|
|
|
|
infile = stdin;
|
2002-01-09 01:31:14 +00:00
|
|
|
|
#ifdef WIN32
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (setmode(fileno(stdin), O_BINARY) == -1) {
|
2002-04-02 01:17:28 +00:00
|
|
|
|
initMsg(pname);
|
|
|
|
|
u_wmsg(stderr, "cantSetInBinMode");
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2002-01-09 01:31:14 +00:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (verbose) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
fprintf(stderr, "%s:\n", infilestr);
|
2002-01-09 01:31:14 +00:00
|
|
|
|
}
|
2002-01-31 22:44:42 +00:00
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2002-01-09 01:31:14 +00:00
|
|
|
|
// Create transliterator as needed.
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (translit != NULL && *translit) {
|
2002-02-16 07:43:26 +00:00
|
|
|
|
UParseError parse;
|
2002-02-20 00:22:12 +00:00
|
|
|
|
UnicodeString str(translit), pestr;
|
2002-02-16 07:43:26 +00:00
|
|
|
|
|
|
|
|
|
/* Create from rules or by ID as needed. */
|
|
|
|
|
|
2002-02-16 08:47:31 +00:00
|
|
|
|
parse.line = -1;
|
|
|
|
|
|
2002-02-16 07:43:26 +00:00
|
|
|
|
if (uprv_strchr(translit, ':') || uprv_strchr(translit, '>') || uprv_strchr(translit, '<') || uprv_strchr(translit, '>')) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
t = Transliterator::createFromRules("Uconv", str, UTRANS_FORWARD, parse, err);
|
2002-02-16 07:43:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
t = Transliterator::createInstance(translit, UTRANS_FORWARD, err);
|
|
|
|
|
}
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-04-02 01:17:28 +00:00
|
|
|
|
str.append((UChar32) 0);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
|
2002-02-16 08:47:31 +00:00
|
|
|
|
if (parse.line >= 0) {
|
2002-03-19 17:14:10 +00:00
|
|
|
|
UChar linebuf[20], offsetbuf[20];
|
2003-01-27 17:24:33 +00:00
|
|
|
|
uprv_itou(linebuf, 20, parse.line, 10, 0);
|
|
|
|
|
uprv_itou(offsetbuf, 20, parse.offset, 10, 0);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantCreateTranslitParseErr", str.getBuffer(),
|
|
|
|
|
u_wmsg_errorName(err), linebuf, offsetbuf);
|
|
|
|
|
} else {
|
|
|
|
|
u_wmsg(stderr, "cantCreateTranslit", str.getBuffer(),
|
|
|
|
|
u_wmsg_errorName(err));
|
2002-04-02 01:17:28 +00:00
|
|
|
|
}
|
2002-03-19 17:14:10 +00:00
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (t) {
|
|
|
|
|
delete t;
|
|
|
|
|
t = 0;
|
|
|
|
|
}
|
|
|
|
|
goto error_exit;
|
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
}
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#endif
|
2002-01-31 22:44:42 +00:00
|
|
|
|
|
2001-09-19 23:43:16 +00:00
|
|
|
|
// Create codepage converter. If the codepage or its aliases weren't
|
2002-01-09 01:04:32 +00:00
|
|
|
|
// available, it returns NULL and a failure code. We also set the
|
|
|
|
|
// callbacks, and return errors in the same way.
|
|
|
|
|
|
2001-12-20 00:50:00 +00:00
|
|
|
|
convfrom = ucnv_open(fromcpage, &err);
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(fromcpage, (int32_t)(uprv_strlen(fromcpage) + 1));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantOpenFromCodeset", str.getBuffer(),
|
2002-02-20 00:22:12 +00:00
|
|
|
|
u_wmsg_errorName(err));
|
|
|
|
|
goto error_exit;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
2002-01-31 22:44:42 +00:00
|
|
|
|
ucnv_setToUCallBack(convfrom, toucallback, touctxt, 0, 0, &err);
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantSetCallback", u_wmsg_errorName(err));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
goto error_exit;
|
2002-01-07 21:34:41 +00:00
|
|
|
|
}
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2001-12-20 00:50:00 +00:00
|
|
|
|
convto = ucnv_open(tocpage, &err);
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(tocpage, (int32_t)(uprv_strlen(tocpage) + 1));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantOpenToCodeset", str.getBuffer(),
|
2002-02-20 00:22:12 +00:00
|
|
|
|
u_wmsg_errorName(err));
|
|
|
|
|
goto error_exit;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
2002-01-31 22:44:42 +00:00
|
|
|
|
ucnv_setFromUCallBack(convto, fromucallback, fromuctxt, 0, 0, &err);
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantSetCallback", u_wmsg_errorName(err));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
goto error_exit;
|
2002-01-07 21:34:41 +00:00
|
|
|
|
}
|
2002-01-09 20:42:19 +00:00
|
|
|
|
ucnv_setFallback(convto, fallback);
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
|
|
|
|
// To ensure that the buffer always is of enough size, we
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// must take the worst case scenario, that is the character in
|
|
|
|
|
// the codepage that uses the most bytes and multiply it against
|
|
|
|
|
// the buffer size.
|
2002-01-09 01:04:32 +00:00
|
|
|
|
|
2002-11-07 02:49:10 +00:00
|
|
|
|
// use bufsz+1 to allow for additional BOM/signature character (U+FEFF)
|
|
|
|
|
tobufsz = (bufsz+1) * ucnv_getMaxCharSize(convto);
|
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
buf = new char[tobufsz];
|
|
|
|
|
unibuf = new UChar[bufsz];
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
fromoffsets = new int32_t[bufsz];
|
|
|
|
|
tooffsets = new int32_t[tobufsz];
|
2002-01-09 01:04:32 +00:00
|
|
|
|
|
|
|
|
|
// OK, we can convert now.
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
do {
|
2002-02-25 06:24:08 +00:00
|
|
|
|
char willexit = 0;
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
rd = fread(buf, 1, bufsz, infile);
|
|
|
|
|
if (ferror(infile) != 0) {
|
|
|
|
|
UnicodeString str(strerror(errno));
|
|
|
|
|
str.append((UChar32) 0);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantRead", str.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
goto error_exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert the read buffer into the new coding
|
|
|
|
|
// After the call 'unibufp' will be placed on the last
|
|
|
|
|
// character that was converted in the 'unibuf'.
|
|
|
|
|
// Also the 'cbufp' is positioned on the last converted
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// character.
|
2002-02-20 00:22:12 +00:00
|
|
|
|
// At the last conversion in the file, flush should be set to
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// true so that we get all characters converted
|
2002-02-20 00:22:12 +00:00
|
|
|
|
//
|
|
|
|
|
// The converter must be flushed at the end of conversion so
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// that characters on hold also will be written.
|
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
unibufp = unibuf;
|
|
|
|
|
cbufp = buf;
|
|
|
|
|
flush = rd != bufsz;
|
|
|
|
|
ucnv_toUnicode(convfrom, &unibufp, unibufp + bufsz, &cbufp,
|
|
|
|
|
cbufp + rd, fromoffsets, flush, &err);
|
|
|
|
|
|
2002-05-23 22:10:23 +00:00
|
|
|
|
infoffset += (uint32_t)(cbufp - buf);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
|
|
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
|
char pos[32];
|
2002-02-25 06:24:08 +00:00
|
|
|
|
sprintf(pos, "%u", infoffset - 1);
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "problemCvtToU", str.getBuffer(), u_wmsg_errorName(err));
|
2002-02-25 06:24:08 +00:00
|
|
|
|
willexit = 1;
|
2003-06-07 07:17:17 +00:00
|
|
|
|
err = U_ZERO_ERROR; /* reset the error for the rest of the conversion. */
|
2002-02-20 00:22:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// At the last conversion, the converted characters should be
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// equal to number of chars read.
|
|
|
|
|
|
2002-02-25 06:24:08 +00:00
|
|
|
|
if (flush && !willexit && cbufp != (buf + rd)) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
char pos[32];
|
2002-02-25 06:24:08 +00:00
|
|
|
|
sprintf(pos, "%u", infoffset);
|
2002-05-24 23:30:25 +00:00
|
|
|
|
UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1));
|
2002-02-20 00:22:12 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "premEndInput", str.getBuffer());
|
2002-02-25 06:24:08 +00:00
|
|
|
|
willexit = 1;
|
2002-02-20 00:22:12 +00:00
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
|
// Prepare to transliterate and convert. Transliterate if needed.
|
2002-01-31 22:44:42 +00:00
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if (t) {
|
2002-05-23 22:10:23 +00:00
|
|
|
|
u.setTo(unibuf, (int32_t)(unibufp - unibuf)); // Copy into string.
|
2002-02-20 00:22:12 +00:00
|
|
|
|
t->transliterate(u);
|
2002-10-01 01:26:49 +00:00
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
u.setTo(unibuf, (int32_t)(unibufp - unibuf), (int32_t)(bufsz)); // Share the buffer.
|
2002-02-20 00:22:12 +00:00
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
int32_t ulen = u.length();
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-02-20 00:22:12 +00:00
|
|
|
|
// Convert the Unicode buffer into the destination codepage
|
|
|
|
|
// Again 'bufp' will be placed on the last converted character
|
|
|
|
|
// And 'unibufbp' will be placed on the last converted unicode character
|
|
|
|
|
// At the last conversion flush should be set to true to ensure that
|
|
|
|
|
// all characters left get converted
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2002-02-16 22:07:19 +00:00
|
|
|
|
const UChar *unibufu = unibufbp = u.getBuffer();
|
2002-01-31 22:44:42 +00:00
|
|
|
|
|
|
|
|
|
do {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
int32_t len = ulen > (int32_t)bufsz ? (int32_t)bufsz : ulen;
|
2002-01-31 22:44:42 +00:00
|
|
|
|
|
|
|
|
|
bufp = buf;
|
2002-02-20 00:22:12 +00:00
|
|
|
|
unibufp = (UChar *) (unibufbp + len);
|
2002-01-31 22:44:42 +00:00
|
|
|
|
|
|
|
|
|
ucnv_fromUnicode(convto, &bufp, bufp + tobufsz,
|
|
|
|
|
&unibufbp,
|
|
|
|
|
unibufp,
|
|
|
|
|
tooffsets, flush, &err);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if (U_FAILURE(err)) {
|
2002-02-25 06:24:08 +00:00
|
|
|
|
const char *errtag;
|
2002-01-31 22:44:42 +00:00
|
|
|
|
char pos[32];
|
2002-02-20 00:22:12 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
uint32_t erroffset =
|
2002-05-23 22:10:23 +00:00
|
|
|
|
dataOffset((int32_t)(bufp - buf - 1), fromoffsets, (int32_t)(bufsz), tooffsets, (int32_t)(tobufsz));
|
|
|
|
|
int32_t ferroffset = (int32_t)(infoffset - (unibufp - unibufu) + erroffset);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
|
2002-02-25 06:24:08 +00:00
|
|
|
|
if ((int32_t) ferroffset < 0) {
|
2002-05-23 22:10:23 +00:00
|
|
|
|
ferroffset = (int32_t)(outfoffset + (bufp - buf));
|
2002-02-25 06:24:08 +00:00
|
|
|
|
errtag = "problemCvtFromUOut";
|
|
|
|
|
} else {
|
|
|
|
|
errtag = "problemCvtFromU";
|
|
|
|
|
}
|
|
|
|
|
sprintf(pos, "%u", ferroffset);
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1));
|
2002-01-31 22:44:42 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, errtag, str.getBuffer(),
|
2002-01-31 22:44:42 +00:00
|
|
|
|
u_wmsg_errorName(err));
|
2002-02-25 06:24:08 +00:00
|
|
|
|
willexit = 1;
|
2002-01-31 22:44:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// At the last conversion, the converted characters should be equal to number
|
|
|
|
|
// of consumed characters.
|
2002-02-25 06:24:08 +00:00
|
|
|
|
if (flush && !willexit && unibufbp != (unibufu + (size_t) (unibufp - unibufu))) {
|
2002-01-31 22:44:42 +00:00
|
|
|
|
char pos[32];
|
2002-02-25 06:24:08 +00:00
|
|
|
|
sprintf(pos, "%u", infoffset);
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString str(pos, (int32_t)(uprv_strlen(pos) + 1));
|
2002-01-31 22:44:42 +00:00
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "premEnd", str.getBuffer());
|
2002-02-25 06:24:08 +00:00
|
|
|
|
willexit = 1;
|
2002-01-31 22:44:42 +00:00
|
|
|
|
}
|
2002-02-20 00:22:12 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// Finally, write the converted buffer to the output file
|
2002-02-20 00:22:12 +00:00
|
|
|
|
|
2002-02-25 06:24:08 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
rd = (size_t) (bufp - buf);
|
2002-05-23 22:10:23 +00:00
|
|
|
|
outfoffset += (int32_t)(wr = fwrite(buf, 1, rd, outfile));
|
2002-02-25 06:24:08 +00:00
|
|
|
|
if (wr != rd) {
|
2002-01-31 22:44:42 +00:00
|
|
|
|
UnicodeString str(strerror(errno), "");
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantWrite", str.getBuffer());
|
2002-02-25 06:24:08 +00:00
|
|
|
|
willexit = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (willexit) {
|
2002-01-31 22:44:42 +00:00
|
|
|
|
goto error_exit;
|
|
|
|
|
}
|
2002-05-23 22:10:23 +00:00
|
|
|
|
} while ((ulen -= (int32_t)(bufsz)) > 0);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
} while (!flush); // Stop when we have flushed the
|
2002-01-31 22:44:42 +00:00
|
|
|
|
// converters (this means that it's
|
2002-02-20 00:22:12 +00:00
|
|
|
|
// the end of output)
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
|
|
|
|
goto normal_exit;
|
2002-01-09 20:42:19 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
error_exit:
|
2002-01-09 01:31:14 +00:00
|
|
|
|
ret = FALSE;
|
2002-01-09 20:42:19 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
normal_exit:
|
|
|
|
|
// Cleanup.
|
2002-01-09 20:42:19 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if (convfrom) ucnv_close(convfrom);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (convto) ucnv_close(convto);
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#if !UCONFIG_NO_TRANSLITERATION
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if (t) delete t;
|
2002-10-01 01:26:49 +00:00
|
|
|
|
#endif
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if (buf) delete[] buf;
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (unibuf) delete[] unibuf;
|
2002-01-09 01:31:14 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if (fromoffsets) delete[] fromoffsets;
|
|
|
|
|
if (tooffsets) delete[] tooffsets;
|
2002-01-09 20:42:19 +00:00
|
|
|
|
|
2002-01-09 01:31:14 +00:00
|
|
|
|
if (infile != stdin) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
fclose(infile);
|
2002-01-09 01:31:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-09-19 23:43:16 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
static void usage(const char *pname, int ecode) {
|
2002-01-28 18:47:35 +00:00
|
|
|
|
const UChar *msg;
|
|
|
|
|
int32_t msgLen;
|
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
2002-04-02 01:17:28 +00:00
|
|
|
|
FILE *fp = ecode ? stderr : stdout;
|
2002-03-19 17:14:10 +00:00
|
|
|
|
int res;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
|
|
|
|
initMsg(pname);
|
|
|
|
|
msg =
|
2002-02-20 00:22:12 +00:00
|
|
|
|
ures_getStringByKey(gBundle, ecode ? "lcUsageWord" : "ucUsageWord",
|
|
|
|
|
&msgLen, &err);
|
2002-05-23 22:10:23 +00:00
|
|
|
|
UnicodeString upname(pname, (int32_t)(uprv_strlen(pname) + 1));
|
2002-01-28 18:47:35 +00:00
|
|
|
|
UnicodeString mname(msg, msgLen + 1);
|
|
|
|
|
|
2002-03-19 17:14:10 +00:00
|
|
|
|
res = u_wmsg(fp, "usage", mname.getBuffer(), upname.getBuffer());
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (!ecode) {
|
2002-03-19 17:14:10 +00:00
|
|
|
|
if (!res) {
|
2002-04-02 01:17:28 +00:00
|
|
|
|
fputc('\n', fp);
|
|
|
|
|
}
|
2002-03-19 17:14:10 +00:00
|
|
|
|
if (!u_wmsg(fp, "help")) {
|
|
|
|
|
/* Now dump callbacks and finish. */
|
|
|
|
|
|
|
|
|
|
int i, count =
|
|
|
|
|
sizeof(transcode_callbacks) / sizeof(*transcode_callbacks);
|
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
|
fprintf(fp, " %s", transcode_callbacks[i].name);
|
2002-04-02 01:17:28 +00:00
|
|
|
|
}
|
2002-03-19 17:14:10 +00:00
|
|
|
|
fputc('\n', fp);
|
2002-04-02 01:17:28 +00:00
|
|
|
|
}
|
2002-01-08 02:34:33 +00:00
|
|
|
|
}
|
2001-09-21 00:30:25 +00:00
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
exit(ecode);
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
int main(int argc, char **argv)
|
2001-09-19 23:43:16 +00:00
|
|
|
|
{
|
2002-01-09 01:31:14 +00:00
|
|
|
|
FILE *outfile;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
int ret = 0;
|
2002-01-09 01:31:14 +00:00
|
|
|
|
int seenf = 0;
|
2002-01-07 20:45:00 +00:00
|
|
|
|
|
2002-01-31 22:44:42 +00:00
|
|
|
|
size_t bufsz = DEFAULT_BUFSZ;
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
const char *fromcpage = 0;
|
|
|
|
|
const char *tocpage = 0;
|
2002-01-07 20:45:00 +00:00
|
|
|
|
const char *translit = 0;
|
2002-01-28 18:47:35 +00:00
|
|
|
|
const char *outfilestr = 0;
|
2002-01-09 20:42:19 +00:00
|
|
|
|
int fallback = 0;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-09 01:04:32 +00:00
|
|
|
|
UConverterFromUCallback fromucallback = UCNV_FROM_U_CALLBACK_STOP;
|
2002-01-08 02:34:33 +00:00
|
|
|
|
const void *fromuctxt = 0;
|
2002-01-09 01:04:32 +00:00
|
|
|
|
UConverterToUCallback toucallback = UCNV_TO_U_CALLBACK_STOP;
|
2002-01-08 02:34:33 +00:00
|
|
|
|
const void *touctxt = 0;
|
2002-01-07 21:34:41 +00:00
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
char **iter;
|
|
|
|
|
char **end = argv + argc;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-09 01:04:32 +00:00
|
|
|
|
const char *pname;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-05 01:08:01 +00:00
|
|
|
|
int printConvs = 0, printCanon = 0;
|
|
|
|
|
const char *printName = 0;
|
2002-01-07 20:45:00 +00:00
|
|
|
|
int printTranslits = 0;
|
2001-11-10 07:01:29 +00:00
|
|
|
|
|
2002-01-09 20:42:19 +00:00
|
|
|
|
int verbose = 0;
|
2003-08-14 21:34:54 +00:00
|
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
|
|
|
|
|
|
|
|
|
/* Initialize ICU */
|
|
|
|
|
u_init(&status);
|
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
|
fprintf(stderr, "%s: can not initialize ICU. status = %s\n",
|
|
|
|
|
argv[0], u_errorName(status));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2002-01-09 01:04:32 +00:00
|
|
|
|
|
2002-03-22 09:50:02 +00:00
|
|
|
|
// Get and prettify pname.
|
|
|
|
|
pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR);
|
|
|
|
|
#ifdef WIN32
|
|
|
|
|
if (!pname) {
|
|
|
|
|
pname = uprv_strrchr(*argv, '/');
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
if (!pname) {
|
|
|
|
|
pname = *argv;
|
|
|
|
|
} else {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
++pname;
|
2002-03-22 09:50:02 +00:00
|
|
|
|
}
|
2002-01-28 18:47:35 +00:00
|
|
|
|
|
2001-09-19 23:43:16 +00:00
|
|
|
|
// First, get the arguments from command-line
|
|
|
|
|
// to know the codepages to convert between
|
2002-01-09 01:31:14 +00:00
|
|
|
|
|
|
|
|
|
// XXX When you add to this loop, you need to add to the similar loop
|
|
|
|
|
// below.
|
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
for (iter = argv + 1; iter != end; iter++) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
// Check for from charset
|
|
|
|
|
if (strcmp("-f", *iter) == 0 || !strcmp("--from-code", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end)
|
|
|
|
|
fromcpage = *iter;
|
2002-03-03 07:06:27 +00:00
|
|
|
|
else
|
|
|
|
|
usage(pname, 1);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
} else if (strcmp("-t", *iter) == 0 || !strcmp("--to-code", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end)
|
|
|
|
|
tocpage = *iter;
|
2002-03-03 07:06:27 +00:00
|
|
|
|
else
|
|
|
|
|
usage(pname, 1);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
} else if (strcmp("-x", *iter) == 0) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end)
|
|
|
|
|
translit = *iter;
|
|
|
|
|
else
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
} else if (!strcmp("--fallback", *iter)) {
|
|
|
|
|
fallback = 1;
|
|
|
|
|
} else if (!strcmp("--no-fallback", *iter)) {
|
|
|
|
|
fallback = 0;
|
|
|
|
|
} else if (strcmp("-b", *iter) == 0 || !strcmp("--block-size", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end) {
|
|
|
|
|
bufsz = atoi(*iter);
|
2002-01-31 22:44:42 +00:00
|
|
|
|
if ((int) bufsz <= 0) {
|
|
|
|
|
initMsg(pname);
|
2002-02-20 00:22:12 +00:00
|
|
|
|
UnicodeString str(*iter);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "badBlockSize", str.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return 3;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
} else if (strcmp("-l", *iter) == 0 || !strcmp("--list", *iter)) {
|
|
|
|
|
if (printTranslits) {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
printConvs = 1;
|
|
|
|
|
} else if (strcmp("--default-code", *iter) == 0) {
|
|
|
|
|
if (printTranslits) {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
printName = ucnv_getDefaultName();
|
|
|
|
|
} else if (strcmp("--list-code", *iter) == 0) {
|
|
|
|
|
if (printTranslits) {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end) {
|
|
|
|
|
UErrorCode e = U_ZERO_ERROR;
|
|
|
|
|
printName = ucnv_getAlias(*iter, 0, &e);
|
|
|
|
|
if (U_FAILURE(e) || !printName) {
|
|
|
|
|
UnicodeString str(*iter);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "noSuchCodeset", str.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
} else if (strcmp("--canon", *iter) == 0) {
|
|
|
|
|
printCanon = 1;
|
|
|
|
|
} else if (strcmp("-L", *iter) == 0
|
|
|
|
|
|| !strcmp("--list-transliterators", *iter)) {
|
|
|
|
|
if (printConvs) {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
printTranslits = 1;
|
|
|
|
|
} else if (strcmp("-h", *iter) == 0 || !strcmp("-?", *iter)
|
|
|
|
|
|| !strcmp("--help", *iter)) {
|
|
|
|
|
usage(pname, 0);
|
|
|
|
|
} else if (!strcmp("-c", *iter)) {
|
|
|
|
|
fromucallback = UCNV_FROM_U_CALLBACK_SKIP;
|
|
|
|
|
} else if (!strcmp("--to-callback", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end) {
|
|
|
|
|
const struct callback_ent *cbe = findCallback(*iter);
|
|
|
|
|
if (cbe) {
|
|
|
|
|
fromucallback = cbe->fromu;
|
|
|
|
|
fromuctxt = cbe->fromuctxt;
|
|
|
|
|
} else {
|
|
|
|
|
UnicodeString str(*iter);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "unknownCallback", str.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return 4;
|
2002-01-31 22:44:42 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
usage(pname, 1);
|
2002-01-31 22:44:42 +00:00
|
|
|
|
}
|
2002-02-20 00:22:12 +00:00
|
|
|
|
} else if (!strcmp("--from-callback", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end) {
|
|
|
|
|
const struct callback_ent *cbe = findCallback(*iter);
|
|
|
|
|
if (cbe) {
|
|
|
|
|
toucallback = cbe->tou;
|
|
|
|
|
touctxt = cbe->touctxt;
|
|
|
|
|
} else {
|
|
|
|
|
UnicodeString str(*iter);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "unknownCallback", str.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
} else if (!strcmp("-i", *iter)) {
|
|
|
|
|
toucallback = UCNV_TO_U_CALLBACK_SKIP;
|
|
|
|
|
} else if (!strcmp("--callback", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
if (iter != end) {
|
|
|
|
|
const struct callback_ent *cbe = findCallback(*iter);
|
|
|
|
|
if (cbe) {
|
|
|
|
|
fromucallback = cbe->fromu;
|
|
|
|
|
fromuctxt = cbe->fromuctxt;
|
|
|
|
|
toucallback = cbe->tou;
|
|
|
|
|
touctxt = cbe->touctxt;
|
|
|
|
|
} else {
|
|
|
|
|
UnicodeString str(*iter);
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "unknownCallback", str.getBuffer());
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return 4;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
} else if (!strcmp("-s", *iter) || !strcmp("--silent", *iter)) {
|
|
|
|
|
verbose = 0;
|
|
|
|
|
} else if (!strcmp("-v", *iter) || !strcmp("--verbose", *iter)) {
|
|
|
|
|
verbose = 1;
|
|
|
|
|
} else if (!strcmp("-V", *iter) || !strcmp("--version", *iter)) {
|
|
|
|
|
printf("%s v2.0\n", pname);
|
|
|
|
|
return 0;
|
|
|
|
|
} else if (!strcmp("-o", *iter) || !strcmp("--output", *iter)) {
|
|
|
|
|
++iter;
|
|
|
|
|
if (iter != end && !outfilestr) {
|
|
|
|
|
outfilestr = *iter;
|
|
|
|
|
} else {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
|
|
|
|
} else if (**iter == '-' && (*iter)[1]) {
|
|
|
|
|
usage(pname, 1);
|
|
|
|
|
}
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-01-05 01:08:01 +00:00
|
|
|
|
if (printConvs || printName) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return printConverters(pname, printName, printCanon) ? 2 : 0;
|
2002-01-07 20:45:00 +00:00
|
|
|
|
} else if (printTranslits) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
return printTransliterators(printCanon) ? 3 : 0;
|
2001-11-10 07:01:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-16 18:45:11 +00:00
|
|
|
|
if (!fromcpage || !uprv_strcmp(fromcpage, "-")) {
|
2002-02-16 09:15:06 +00:00
|
|
|
|
fromcpage = ucnv_getDefaultName();
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
2002-02-16 18:45:11 +00:00
|
|
|
|
if (!tocpage || !uprv_strcmp(tocpage, "-")) {
|
2002-02-16 09:15:06 +00:00
|
|
|
|
tocpage = ucnv_getDefaultName();
|
2001-09-19 23:43:16 +00:00
|
|
|
|
}
|
2002-02-16 09:15:06 +00:00
|
|
|
|
|
2002-01-09 01:04:32 +00:00
|
|
|
|
// Open the correct output file or connect to stdout for reading input
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (outfilestr != 0 && strcmp(outfilestr, "-")) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
outfile = fopen(outfilestr, "wb");
|
|
|
|
|
if (outfile == 0) {
|
|
|
|
|
UnicodeString str1(outfilestr, "");
|
|
|
|
|
UnicodeString str2(strerror(errno), "");
|
|
|
|
|
initMsg(pname);
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantCreateOutputF",
|
2002-02-20 00:22:12 +00:00
|
|
|
|
str1.getBuffer(), str2.getBuffer());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2002-01-09 01:04:32 +00:00
|
|
|
|
} else {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
outfilestr = "-";
|
|
|
|
|
outfile = stdout;
|
2001-09-19 23:43:16 +00:00
|
|
|
|
#ifdef WIN32
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (setmode(fileno(outfile), O_BINARY) == -1) {
|
2002-03-19 17:14:10 +00:00
|
|
|
|
u_wmsg(stderr, "cantSetOutBinMode");
|
2002-02-20 00:22:12 +00:00
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
2001-09-19 23:43:16 +00:00
|
|
|
|
#endif
|
2002-01-09 01:04:32 +00:00
|
|
|
|
}
|
2002-01-07 20:45:00 +00:00
|
|
|
|
|
2002-01-09 01:31:14 +00:00
|
|
|
|
/* Loop again on the arguments to find all the input files, and
|
2002-02-20 00:22:12 +00:00
|
|
|
|
convert them. XXX Cheap and sloppy. */
|
2002-01-09 01:31:14 +00:00
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
for (iter = argv + 1; iter != end; iter++) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (strcmp("-f", *iter) == 0 || !strcmp("--from-code", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (strcmp("-t", *iter) == 0 || !strcmp("--to-code", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (strcmp("-x", *iter) == 0) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (!strcmp("--fallback", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("--no-fallback", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (strcmp("-b", *iter) == 0 || !strcmp("--block-size", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (strcmp("-l", *iter) == 0 || !strcmp("--list", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (strcmp("--default-code", *iter) == 0) {
|
|
|
|
|
;
|
|
|
|
|
} else if (strcmp("--list-code", *iter) == 0) {
|
|
|
|
|
;
|
|
|
|
|
} else if (strcmp("--canon", *iter) == 0) {
|
|
|
|
|
;
|
|
|
|
|
} else if (strcmp("-L", *iter) == 0
|
|
|
|
|
|| !strcmp("--list-transliterators", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (strcmp("-h", *iter) == 0 || !strcmp("-?", *iter)
|
|
|
|
|
|| !strcmp("--help", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("-c", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("--to-callback", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (!strcmp("--from-callback", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (!strcmp("-i", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("--callback", *iter)) {
|
|
|
|
|
iter++;
|
|
|
|
|
} else if (!strcmp("-s", *iter) || !strcmp("--silent", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("-v", *iter) || !strcmp("--verbose", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("-V", *iter) || !strcmp("--version", *iter)) {
|
|
|
|
|
;
|
|
|
|
|
} else if (!strcmp("-o", *iter) || !strcmp("--output", *iter)) {
|
|
|
|
|
++iter;
|
|
|
|
|
} else {
|
|
|
|
|
seenf = 1;
|
|
|
|
|
if (!convertFile
|
|
|
|
|
(pname, fromcpage, toucallback, touctxt, tocpage,
|
|
|
|
|
fromucallback, fromuctxt, fallback, bufsz, translit, *iter,
|
|
|
|
|
outfile, verbose)) {
|
|
|
|
|
goto error_exit;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-01-09 01:31:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!seenf) {
|
2002-02-20 00:22:12 +00:00
|
|
|
|
if (!convertFile
|
|
|
|
|
(pname, fromcpage, toucallback, touctxt, tocpage,
|
|
|
|
|
fromucallback, fromuctxt, fallback, bufsz, translit, 0, outfile,
|
|
|
|
|
verbose)) {
|
|
|
|
|
goto error_exit;
|
|
|
|
|
}
|
2002-01-09 01:31:14 +00:00
|
|
|
|
}
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
|
|
|
|
goto normal_exit;
|
2002-02-20 00:22:12 +00:00
|
|
|
|
error_exit:
|
2001-09-19 23:43:16 +00:00
|
|
|
|
ret = 1;
|
2002-02-20 00:22:12 +00:00
|
|
|
|
normal_exit:
|
2001-09-19 23:43:16 +00:00
|
|
|
|
|
2002-01-28 18:47:35 +00:00
|
|
|
|
if (outfile != stdout)
|
2002-02-20 00:22:12 +00:00
|
|
|
|
fclose(outfile);
|
2002-01-09 01:04:32 +00:00
|
|
|
|
|
2001-09-19 23:43:16 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2001-11-10 06:52:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Hey, Emacs, please set the following:
|
|
|
|
|
*
|
|
|
|
|
* Local Variables:
|
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
|
* End:
|
|
|
|
|
*
|
|
|
|
|
*/
|