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