ICU-1220 added a --list-converters option.
X-SVN-Rev: 6743
This commit is contained in:
parent
0ad967b412
commit
78f86d2bfd
@ -1,6 +1,6 @@
|
||||
// -*- Coding: utf-8; -*- [all uconv resource files]
|
||||
// Copyright (c) 2000 IBM, Inc. and Others.
|
||||
// $Revision: 1.5 $
|
||||
// $Revision: 1.6 $
|
||||
//
|
||||
// Root translation file for uconv messages.
|
||||
// So you want to translate this file??? Great!
|
||||
@ -41,7 +41,8 @@ root
|
||||
}
|
||||
|
||||
|
||||
cantGetNames { "Couldn''t get available converter names. {0}\n" } // 0: err
|
||||
cantGetNames { "Couldn''t get available converter names.\n" } // 0: err
|
||||
cantGetAliases { "Couldn''t get aliasesnames for {0}. {1}\n" } // 0: name 1: err
|
||||
|
||||
noFromCodeset { "No conversion from encoding given (use -f)\n" }
|
||||
noToCodeset { "No conversion to encoding given (use -t)\n" }
|
||||
|
@ -19,7 +19,10 @@
|
||||
.BI "\-l\fP, \fB\-\-list"
|
||||
]
|
||||
[
|
||||
.BI "\-L\fP, \fB\-\-list-transliterators"
|
||||
.BI "\-\-list\-converters\"
|
||||
]
|
||||
[
|
||||
.BI "\-L\fP, \fB\-\-list\-transliterators"
|
||||
]
|
||||
[
|
||||
.BI "\-x" " trasnsliterator
|
||||
@ -42,23 +45,31 @@ Print help about usage and exit.
|
||||
.TP
|
||||
.BI "\-l\fP, \fB\-\-list"
|
||||
List all the available encodings and exit.
|
||||
.BI "\-\-list\-converters"
|
||||
List all the available encodings and their aliases in a format compatible
|
||||
with
|
||||
.BR convrtrs.txt (5).
|
||||
.TP
|
||||
.BI "\-L\fP, \fB\-\-list-transliterators"
|
||||
.BI "\-L\fP, \fB\-\-list\-transliterators"
|
||||
List all the available transliterators and exit.
|
||||
.TP
|
||||
.BI "\-x" " transliterator"
|
||||
Run the transcoding through the given
|
||||
.IR transliterator .
|
||||
.TP
|
||||
.BI "\-f\fP, \fB\-\-from-code" " encoding"
|
||||
.BI "\-f\fP, \fB\-\-from\-code" " encoding"
|
||||
Set the original encoding of the data to
|
||||
.IR encoding .
|
||||
.TP
|
||||
.BI "\-t\fP, \fB\-\-to-code" " encoding"
|
||||
.BI "\-t\fP, \fB\-\-to\-code" " encoding"
|
||||
Transcode the data to
|
||||
.IR encoding .
|
||||
.SH CAVEATS AND BUGS
|
||||
The
|
||||
.BI "\-\-list-converters"
|
||||
option does not yet list tags after the converter names.
|
||||
.PP
|
||||
The
|
||||
.BI "\-L\fP, \fB\-\-list-transliterators"
|
||||
option is not implemented at this point and
|
||||
.B uconv
|
||||
@ -68,4 +79,5 @@ of 1 if it is used.
|
||||
@VERSION@
|
||||
.SH COPYRIGHT
|
||||
Copyright (C) 2001 IBM, Inc. and others.
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR convrtrs.txt (5)
|
||||
|
@ -7,7 +7,6 @@
|
||||
//
|
||||
// uconv demonstration example of ICU and codepage conversion
|
||||
// Purpose is to be a similar tool as the UNIX iconv program.
|
||||
// Shows the usage of the ICU classes: UnicodeConverter, UnicodeString
|
||||
//
|
||||
// Usage: uconv [flag] [file]
|
||||
// -f [codeset] Convert file from this codeset
|
||||
@ -55,62 +54,97 @@ static void initMsg(const char *pname) {
|
||||
static int ps = 0;
|
||||
|
||||
if (!ps) {
|
||||
char dataPath[500];
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
char dataPath[500];
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
|
||||
ps = 1;
|
||||
ps = 1;
|
||||
|
||||
/* Get messages. */
|
||||
|
||||
strcpy(dataPath, u_getDataDirectory());
|
||||
strcat(dataPath, "uconvmsg");
|
||||
|
||||
gBundle = u_wmsg_setPath(dataPath, &err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
fprintf(stderr, "%s: warning: couldn't open resource bundle %s: %s\n",
|
||||
pname,
|
||||
dataPath,
|
||||
u_errorName(err));
|
||||
}
|
||||
/* Get messages. */
|
||||
|
||||
strcpy(dataPath, u_getDataDirectory());
|
||||
strcat(dataPath, "uconvmsg");
|
||||
|
||||
gBundle = u_wmsg_setPath(dataPath, &err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
fprintf(stderr, "%s: warning: couldn't open resource bundle %s: %s\n",
|
||||
pname,
|
||||
dataPath,
|
||||
u_errorName(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Print all available codepage converters
|
||||
static void printAllConverters(const char *pname)
|
||||
static void printAllConverters(const char *pname, int allinfo)
|
||||
{
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
int32_t num;
|
||||
int32_t num = ucnv_countAvailable();
|
||||
uint16_t num_stds = ucnv_countStandards();
|
||||
|
||||
#if 0
|
||||
size_t numprint = 0;
|
||||
#endif
|
||||
static const size_t maxline = 70;
|
||||
#endif
|
||||
|
||||
// getAvailable returns a string-table with all available codepages
|
||||
const char* const* convtable = UnicodeConverter::getAvailableNames(num, err);
|
||||
if (U_FAILURE(err))
|
||||
if (num <= 0)
|
||||
{
|
||||
initMsg(pname);
|
||||
u_wmsg("cantGetNames", u_wmsg_errorName(err));
|
||||
initMsg(pname);
|
||||
u_wmsg("cantGetNames");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i<num-1; i++)
|
||||
for (int32_t i = 0; i<num; i++)
|
||||
{
|
||||
// ucnv_getAvailableName gets the codepage name at a specific
|
||||
// index
|
||||
|
||||
const char *name = ucnv_getAvailableName(i);
|
||||
#if 0
|
||||
numprint += printf("%-20s", convtable[i]);
|
||||
numprint += printf("%-20s", name);
|
||||
if (numprint>maxline)
|
||||
{
|
||||
putchar('\n');
|
||||
numprint = 0;
|
||||
}
|
||||
#else
|
||||
printf("%s ", convtable[i]);
|
||||
printf("%s ", name);
|
||||
if (allinfo) {
|
||||
uint16_t num_aliases;
|
||||
|
||||
err = U_ZERO_ERROR;
|
||||
num_aliases = ucnv_countAliases(name, &err);
|
||||
if (U_FAILURE(err)) {
|
||||
UnicodeString str(name);
|
||||
putchar('\t');
|
||||
u_wmsg("cantGetAliases", str.getBuffer(), u_wmsg_errorName(err));
|
||||
} else if (num_aliases > 1) {
|
||||
uint16_t a;
|
||||
|
||||
putchar('\t');
|
||||
|
||||
for (a = 1; a < num_aliases; ++a) {
|
||||
const char *alias = ucnv_getAlias(name, a, &err);
|
||||
|
||||
if (U_FAILURE(err)) {
|
||||
UnicodeString str(name);
|
||||
putchar('\t');
|
||||
u_wmsg("cantGetAliases", str.getBuffer(), u_wmsg_errorName(err));
|
||||
break;
|
||||
}
|
||||
|
||||
printf("%s", alias);
|
||||
|
||||
|
||||
if (a < num_aliases) {
|
||||
putchar(' ');
|
||||
}
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
puts(convtable[num-1]);
|
||||
}
|
||||
|
||||
// Convert a file from one encoding to another
|
||||
@ -334,7 +368,11 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else if (strcmp("-l", *iter) == 0 || !strcmp("--list", *iter))
|
||||
{
|
||||
printAllConverters(pname);
|
||||
printAllConverters(pname, 0);
|
||||
goto normal_exit;
|
||||
}
|
||||
else if (strcmp("--list-converters", *iter) == 0) {
|
||||
printAllConverters(pname, 1);
|
||||
goto normal_exit;
|
||||
}
|
||||
else if (strcmp("-h", *iter) == 0 || !strcmp("-?", *iter) == 0 || !strcmp("--help", *iter))
|
||||
@ -342,12 +380,12 @@ int main(int argc, char** argv)
|
||||
usage(pname, 0);
|
||||
}
|
||||
else if (**iter == '-' && (*iter)[1]) {
|
||||
usage(pname, 1);
|
||||
} else if (!infilestr) {
|
||||
usage(pname, 1);
|
||||
} else if (!infilestr) {
|
||||
infilestr = *iter;
|
||||
} else {
|
||||
usage(pname, 1);
|
||||
}
|
||||
usage(pname, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (fromcpage==0 && tocpage==0)
|
||||
@ -413,3 +451,13 @@ int main(int argc, char** argv)
|
||||
fclose(file);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Hey, Emacs, please set the following:
|
||||
*
|
||||
* Local Variables:
|
||||
* indent-tabs-mode: nil
|
||||
* End:
|
||||
*
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user