mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 22:44:49 +00:00
ICU-1220 Better help format. Removed releaseBuffer() calls.
X-SVN-Rev: 5860
This commit is contained in:
parent
84fc77e777
commit
b5aae87f9e
4 changed files with 57 additions and 41 deletions
|
@ -1,6 +1,6 @@
|
|||
// -*- Coding: utf-8; -*- [all uconv resource files]
|
||||
// Copyright (c) 2000 IBM, Inc. and Others.
|
||||
// $Revision: 1.1 $
|
||||
// $Revision: 1.2 $
|
||||
//
|
||||
// Root translation file for uconv messages.
|
||||
// So you want to translate this file??? Great!
|
||||
|
@ -28,22 +28,28 @@ root
|
|||
{
|
||||
// uconv errors
|
||||
|
||||
usage { "Usage: uconv [flag] [file]\n"
|
||||
"-f [codeset] Convert file from this codeset\n"
|
||||
"-t [codeset] Convert file to this code set\n"
|
||||
"-h Show this help text\n"
|
||||
"-l List all available codepages\n" }
|
||||
lcUsageWord { "usage" }
|
||||
ucUsageWord { "Usage" }
|
||||
usage { "{0}: {1} [ -h, --help ] [ -l, --list ] [ -L, --list-transliterators ] [ -x transliterator ] -f, --from-code code -t, --to-code code [ file ]\n" }
|
||||
|
||||
help { "Options: -h, --help\t\tprint this message\n"
|
||||
" -l, --list\t\tlist all available encodings\n"
|
||||
" -L, --list-transliterators\tlist all available transliterators\n"
|
||||
" -f, --from-code code\tset the original encoding\n"
|
||||
" -t, --to-code code\tset the destination encoding\n"
|
||||
" -x transliterator\trun everything through transliterator\n"
|
||||
}
|
||||
|
||||
|
||||
cantGetNames { "Can''t get available converter names. {0}\n" } // 0: err
|
||||
cantGetNames { "Couldn''t get available converter names. {0}\n" } // 0: err
|
||||
|
||||
noFromCodeset { "No conversion from codeset given (use -f)\n" }
|
||||
noToCodeset { "No conversion to codeset given (use -t)\n" }
|
||||
noFromCodeset { "No conversion from encoding given (use -f)\n" }
|
||||
noToCodeset { "No conversion to encoding given (use -t)\n" }
|
||||
|
||||
cantOpenFromCodeset { "Couldn''t open the from codeset {0}: {1}\n" } // 0:set, 1: err
|
||||
cantOpenToCodeset { "Couldn''t open the to codeset {0}: {1}\n" } // 0: set, 1: err
|
||||
cantOpenFromCodeset { "Couldn''t open the from encoding {0}: {1}\n" } // 0:set, 1: err
|
||||
cantOpenToCodeset { "Couldn''t open the to encoding {0}: {1}\n" } // 0: set, 1: err
|
||||
|
||||
cantOpenInputF { "Couldn''t open the input file \"{0}\", {1}.\n" } // 0: file, 1: strerror [OS error string]
|
||||
cantOpenInputF { "Couldn''t open the input file {0}, {1}.\n" } // 0: file, 1: strerror [OS error string]
|
||||
|
||||
cantWrite { "The converted text couldn't be written: {0} \n" } // 0: OS error string
|
||||
cantRead { "Error reading from input file {0} \n" } // 0: OS error string
|
||||
|
@ -78,4 +84,4 @@ root
|
|||
U_RESOURCE_TYPE_MISMATCH { "Resource type mismatch" }
|
||||
U_ILLEGAL_ESCAPE_SEQUENCE { "Illegal escape sequence found" }
|
||||
U_UNSUPPORTED_ESCAPE_SEQUENCE {"Unsupported escape sequence found" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -122,7 +122,6 @@ static UBool convertFile(const char* fromcpage,
|
|||
UnicodeString str(fromcpage,"");
|
||||
u_wmsg("cantOpenFromCodeset",str.getBuffer(),
|
||||
u_wmsg_errorName(err));
|
||||
str.releaseBuffer();
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
|
@ -133,7 +132,6 @@ static UBool convertFile(const char* fromcpage,
|
|||
UnicodeString str(tocpage,"");
|
||||
u_wmsg("cantOpenToCodeset",str.getBuffer(),
|
||||
u_wmsg_errorName(err));
|
||||
str.releaseBuffer();
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
|
@ -151,7 +149,6 @@ static UBool convertFile(const char* fromcpage,
|
|||
{
|
||||
UnicodeString str(strerror(errno), "");
|
||||
u_wmsg("cantRead",str.getBuffer());
|
||||
str.releaseBuffer();
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
|
@ -228,7 +225,6 @@ static UBool convertFile(const char* fromcpage,
|
|||
{
|
||||
UnicodeString str(strerror(errno),"");
|
||||
u_wmsg("cantWrite", str.getBuffer());
|
||||
str.releaseBuffer();
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
|
@ -251,6 +247,8 @@ static UBool convertFile(const char* fromcpage,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static UResourceBundle *gBundle = 0;
|
||||
|
||||
static void initMsg(const char *pname) {
|
||||
static int ps = 0;
|
||||
|
||||
|
@ -265,7 +263,7 @@ static void initMsg(const char *pname) {
|
|||
strcpy(dataPath, u_getDataDirectory());
|
||||
strcat(dataPath, "uconvmsg");
|
||||
|
||||
u_wmsg_setPath(dataPath, &err);
|
||||
gBundle = u_wmsg_setPath(dataPath, &err);
|
||||
if(U_FAILURE(err))
|
||||
{
|
||||
fprintf(stderr, "%s: warning: couldn't open resource bundle %s: %s\n",
|
||||
|
@ -276,10 +274,24 @@ static void initMsg(const char *pname) {
|
|||
}
|
||||
}
|
||||
|
||||
static void printUsage(const char *pname)
|
||||
static void usage(const char *pname, int ecode)
|
||||
{
|
||||
const UChar *msg;
|
||||
int32_t msgLen;
|
||||
UErrorCode err = U_ZERO_ERROR;
|
||||
|
||||
initMsg(pname);
|
||||
u_wmsg("usage");
|
||||
msg = ures_getStringByKey(gBundle, ecode ? "lcUsageWord" : "ucUsageWord", &msgLen, &err);
|
||||
UnicodeString upname(pname);
|
||||
UnicodeString mname(msg, msgLen);
|
||||
|
||||
u_wmsg("usage", mname.getBuffer(), upname.getBuffer());
|
||||
if (!ecode) {
|
||||
putchar('\n');
|
||||
u_wmsg("help");
|
||||
}
|
||||
|
||||
exit(ecode);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
@ -301,39 +313,39 @@ int main(int argc, char** argv)
|
|||
for (; iter!=end; iter++)
|
||||
{
|
||||
// Check for from charset
|
||||
if (strcmp("-f", *iter) == 0)
|
||||
if (strcmp("-f", *iter) == 0 || !strcmp("--from-code", *iter))
|
||||
{
|
||||
iter++;
|
||||
if (iter!=end)
|
||||
fromcpage = *iter;
|
||||
}
|
||||
else if (strcmp("-t", *iter) == 0)
|
||||
else if (strcmp("-t", *iter) == 0 || !strcmp("--to-code", *iter))
|
||||
{
|
||||
iter++;
|
||||
if (iter!=end)
|
||||
tocpage = *iter;
|
||||
}
|
||||
else if (strcmp("-l", *iter) == 0)
|
||||
else if (strcmp("-l", *iter) == 0 || !strcmp("--list", *iter))
|
||||
{
|
||||
printAllConverters();
|
||||
goto normal_exit;
|
||||
}
|
||||
else if (strcmp("-h", *iter) == 0)
|
||||
else if (strcmp("-h", *iter) == 0 || !strcmp("--help", *iter))
|
||||
{
|
||||
printUsage(pname);
|
||||
goto normal_exit;
|
||||
usage(pname, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
else if (**iter == '-' && (*iter)[1]) {
|
||||
usage(pname, 1);
|
||||
} else if (!infilestr) {
|
||||
infilestr = *iter;
|
||||
}
|
||||
|
||||
} else {
|
||||
usage(pname, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (fromcpage==0 && tocpage==0)
|
||||
{
|
||||
printUsage(pname);
|
||||
goto normal_exit;
|
||||
usage(pname, 1);
|
||||
}
|
||||
|
||||
if (fromcpage==0)
|
||||
|
@ -352,7 +364,7 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
// Open the correct input file or connect to stdin for reading input
|
||||
if (infilestr!=0)
|
||||
if (infilestr!=0 && strcmp(infilestr, "-"))
|
||||
{
|
||||
file = fopen(infilestr, "rb");
|
||||
if (file==0)
|
||||
|
@ -363,8 +375,6 @@ int main(int argc, char** argv)
|
|||
u_wmsg("cantOpenInputF",
|
||||
str1.getBuffer(),
|
||||
str2.getBuffer());
|
||||
str1.releaseBuffer();
|
||||
str2.releaseBuffer();
|
||||
return 1;
|
||||
}
|
||||
infile = file;
|
||||
|
|
|
@ -10,12 +10,12 @@ and print it to stderr
|
|||
|
||||
#ifndef _UWMSG
|
||||
#define _UWMSG
|
||||
#include "unicode/utypes.h"
|
||||
#include "unicode/ures.h"
|
||||
|
||||
/* Set the path to wmsg's bundle.
|
||||
Caller owns storage.
|
||||
*/
|
||||
U_CAPI void u_wmsg_setPath(const char *path, UErrorCode *err);
|
||||
U_CAPI UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err);
|
||||
|
||||
/* Format a message and print it's output to stderr */
|
||||
U_CAPI void u_wmsg(const char *tag, ... );
|
||||
|
|
|
@ -81,17 +81,17 @@ uprint(const UChar *s,
|
|||
|
||||
static UResourceBundle *gBundle = NULL;
|
||||
|
||||
U_CAPI void u_wmsg_setPath(const char *path, UErrorCode *err)
|
||||
U_CAPI UResourceBundle *u_wmsg_setPath(const char *path, UErrorCode *err)
|
||||
{
|
||||
if(U_FAILURE(*err))
|
||||
{
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(gBundle != NULL)
|
||||
{
|
||||
*err = U_ILLEGAL_ARGUMENT_ERROR;
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -101,7 +101,7 @@ U_CAPI void u_wmsg_setPath(const char *path, UErrorCode *err)
|
|||
gBundle = b;
|
||||
}
|
||||
|
||||
return;
|
||||
return gBundle;
|
||||
}
|
||||
|
||||
/* Format a message and print it's output to stderr */
|
||||
|
|
Loading…
Add table
Reference in a new issue