[ICU-157] genrb fixed so it works without DLL by using invariant converter

X-Commit-URL: https://ssl.icu-project.org/trac/changeset/273
This commit is contained in:
Vladimir Weinstein 1999-12-01 21:36:40 +00:00
parent db66db0029
commit ba20090f93
5 changed files with 60 additions and 24 deletions

View file

@ -33,7 +33,7 @@
/* Protos */
static void usage();
static void version();
static void processFile(const char *filename, UErrorCode *status);
static void processFile(const char *filename, const char* cp, UErrorCode *status);
static char* make_res_filename(const char *filename, UErrorCode *status);
static char* make_col_filename(const char *filename, UErrorCode *status);
int main(int argc, char **argv);
@ -45,6 +45,7 @@ int main(int argc, char **argv);
/* The version of genrb */
#define GENRB_VERSION "1.0"
char *encoding = "";
int
main(int argc,
@ -52,11 +53,13 @@ main(int argc,
{
int printUsage = 0;
int printVersion = 0;
int useConversionLibrary = 0;
int optind = 1;
int i;
char *arg;
UErrorCode status;
if(argc == 1)
printUsage = 1;
@ -73,6 +76,17 @@ main(int argc,
else if(icu_strcmp(arg, "-h") == 0 || icu_strcmp(arg, "--help") == 0) {
printUsage = 1;
}
else if(icu_strncmp(arg, "-e", 2) == 0) {
useConversionLibrary = 1;
if(icu_strlen(arg) > icu_strlen("-e")) {
encoding = arg+2;
} else {
encoding = 0;
}
}
/* POSIX.1 says all arguments after -- are not options */
else if(icu_strcmp(arg, "--") == 0) {
/* skip the -- */
@ -105,7 +119,7 @@ main(int argc,
/* generate the binary files */
for(i = optind; i < argc; ++i) {
status = U_ZERO_ERROR;
processFile(argv[i], &status);
processFile(argv[i], encoding, &status);
if(U_FAILURE(status)) {
printf("genrb: %s processing file \"%s\"\n", errorName(status), argv[i]);
if(getErrorText() != 0)
@ -122,8 +136,11 @@ usage()
{
puts("Usage: genrb [OPTIONS] [FILES]");
puts("Options:");
puts(" -e Resource bundle is encoded with system default encoding");
puts(" -eEncoding Resource bundle uses specified Encoding");
puts(" -h, --help Print this message and exit.");
puts(" -v, --version Print the version number of genrb and exit.");
encoding!=NULL?puts(encoding):puts("encoding is NULL");
}
/* Version information */
@ -140,7 +157,7 @@ version()
/* Process a file */
static void
processFile(const char *filename,
processFile(const char *filename, const char *cp,
UErrorCode *status)
{
FileStream *in;
@ -162,7 +179,7 @@ processFile(const char *filename,
}
/* Parse the data into an SRBItemList */
data = parse(in, status);
data = parse(in, cp, status);
/* Determine the target rb filename */
rbname = make_res_filename(filename, status);

View file

@ -128,7 +128,7 @@ static struct STransition gTransitionTable [] = {
#define GETTRANSITION(row,col) (gTransitionTable[col + (row<<2)])
struct SRBItemList*
parse(FileStream *f,
parse(FileStream *f, const char *cp,
UErrorCode *status)
{
struct UFILE *file;
@ -165,7 +165,7 @@ parse(FileStream *f,
current = 0;
item = 0;
file = u_finit(f, status);
file = u_finit(f, cp, status);
list = rblist_open(status);
if(U_FAILURE(*status)) goto finish;

View file

@ -26,6 +26,6 @@
#include "rblist.h"
/* Parse a ResourceBundle text file */
struct SRBItemList* parse(FileStream *f, UErrorCode *status);
struct SRBItemList* parse(FileStream *f, const char *cp, UErrorCode *status);
#endif

View file

@ -16,6 +16,7 @@
* Date Name Description
* 11/19/98 stephen Creation.
* 03/12/99 stephen Modified for new C API.
* 12/01/99 weiv ufille_fill_uchar_buffer modified to be able to use invariant conversion
*******************************************************************************
*/
@ -23,12 +24,13 @@
#include "ustdio.h"
#include "ufile.h"
#include "cmemory.h"
#include "cstring.h"
#define MIN(a,b) (a < b ? a : b)
#define MAX(a,b) (a > b ? a : b)
UFILE*
u_finit(FileStream *f,
u_finit(FileStream *f, const char *cp,
UErrorCode *status)
{
UFILE *result = (UFILE*) icu_malloc(sizeof(UFILE));
@ -42,13 +44,25 @@ u_finit(FileStream *f,
result->fUCPos = result->fUCBuffer;
result->fUCLimit = result->fUCBuffer;
result->fConverter = ucnv_open(0, status);
if(U_FAILURE(*status) || result->fConverter == 0) {
T_FileStream_close(result->fFile);
icu_free(result);
return 0;
if(cp == 0) { //weiv: we're using the default converter
result->fConverter = ucnv_open(0, status);
if(U_FAILURE(*status) || result->fConverter == 0) {
T_FileStream_close(result->fFile);
icu_free(result);
return 0;
}
} else if (icu_strlen(cp)>icu_strlen("")) { //weiv: we're specifying the converter
result->fConverter = ucnv_open(cp, status);
if(U_FAILURE(*status) || result->fConverter == 0) {
T_FileStream_close(result->fFile);
icu_free(result);
return 0;
}
} else { //weiv: we'll go for invariant converter
result->fConverter = NULL;
}
return result;
}
@ -90,7 +104,7 @@ ufile_fill_uchar_buffer(UFILE *f,
availLength = UFILE_UCHARBUFFER_SIZE - dataSize;
/* Determine the # of codepage bytes needed to fill our UChar buffer */
maxCPBytes = availLength * ucnv_getMaxCharSize(f->fConverter);
maxCPBytes = availLength * (f->fConverter!=NULL?ucnv_getMaxCharSize(f->fConverter):1); //weiv: Probably shoud #define it somewhere
/* Read in the data to convert */
bytesRead = T_FileStream_read(f->fFile,f->fCharBuffer,
@ -103,15 +117,20 @@ ufile_fill_uchar_buffer(UFILE *f,
myTarget = f->fUCBuffer + dataSize;
bufferSize = UFILE_UCHARBUFFER_SIZE;
/* Perform the conversion */
ucnv_toUnicode(f->fConverter,
&myTarget,
f->fUCBuffer + bufferSize,
&mySource,
mySourceEnd,
NULL,
TRUE,
status);
if(f->fConverter != NULL) { //weiv: we have a good converter, so we'll just use it
/* Perform the conversion */
ucnv_toUnicode(f->fConverter,
&myTarget,
f->fUCBuffer + bufferSize,
&mySource,
mySourceEnd,
NULL,
TRUE,
status);
} else { //weiv: we couldn't obtain a converter, so we'll go with invariant conversion
u_charsToUChars(mySource, myTarget, bytesRead);
myTarget += bytesRead;
}
/* update the pointers into our array */
f->fUCPos = f->fUCBuffer;

View file

@ -29,7 +29,7 @@
#define U_EOF 0xFFFF
UFILE*
u_finit(FileStream *f,
u_finit(FileStream *f, const char *cp,
UErrorCode *status);
void