From db5f63663f0b966bdf5c083093babc05dd37cc71 Mon Sep 17 00:00:00 2001 From: Syn Wee Quek Date: Fri, 29 Aug 2003 22:39:27 +0000 Subject: [PATCH] ICU-2338 genbrk now using the toolutil/unewdata.h functions and write copyright text if requested X-SVN-Rev: 12991 --- icu4c/source/tools/genbrk/genbrk.cpp | 56 +++++++++++++++------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/icu4c/source/tools/genbrk/genbrk.cpp b/icu4c/source/tools/genbrk/genbrk.cpp index 6a78ff240c4..e9b683da785 100644 --- a/icu4c/source/tools/genbrk/genbrk.cpp +++ b/icu4c/source/tools/genbrk/genbrk.cpp @@ -52,11 +52,22 @@ static UOption options[]={ { "rules", NULL, NULL, NULL, 'r', UOPT_REQUIRES_ARG, 0 }, /* 3 */ { "out", NULL, NULL, NULL, 'o', UOPT_REQUIRES_ARG, 0 }, /* 4 */ UOPTION_ICUDATADIR, /* 5 */ - UOPTION_DESTDIR /* 6 */ + UOPTION_DESTDIR, /* 6 */ + UOPTION_COPYRIGHT, /* 7 */ }; void usageAndDie(int retCode) { - printf("Usage: %s [-v] -r rule-file -o output-file\n", progName); + printf("Usage: genbrk [-v] [-options] -r rule-file -o output-file\n", progName); + printf("\tRead in break iteration rules text and write out the binary data\n" + "options:\n" + "\t-h or -? or --help this usage text\n" + "\t-V or --version show a version message\n" + "\t-c or --copyright include a copyright notice\n" + "\t-v or --verbose turn on verbose output\n" + "\t-i or --icudatadir directory for locating any needed intermediate data files,\n" + "\t followed by path, defaults to %s\n", + "\t-d or --destdir destination directory, followed by the path\n", + u_getDataDirectory()); exit (retCode); } @@ -113,8 +124,7 @@ int main(int argc, char **argv) { const char *ruleFileName; const char *outFileName; const char *outDir = NULL; - char *outFullFileName; - int32_t outFullFileNameLen; + const char *copyright = NULL; // // Pick up and check the command line arguments, @@ -140,7 +150,6 @@ int main(int argc, char **argv) { } ruleFileName = options[3].value; outFileName = options[4].value; - outFullFileNameLen = strlen(outFileName); if (options[5].doesOccur) { u_setDataDirectory(options[5].value); @@ -158,15 +167,10 @@ int main(int argc, char **argv) { /* Combine the directory with the file name */ if(options[6].doesOccur) { outDir = options[6].value; - outFullFileNameLen += strlen(outDir); } - outFullFileName = (char*)malloc(outFullFileNameLen + 2); - outFullFileName[0] = 0; - if (outDir) { - strcpy(outFullFileName, outDir); - strcat(outFullFileName, U_FILE_SEP_STRING); + if (options[7].doesOccur) { + copyright = U_COPYRIGHT_STRING; } - strcat(outFullFileName, outFileName); #if UCONFIG_NO_BREAK_ITERATION @@ -319,28 +323,30 @@ int main(int argc, char **argv) { // Create the output file // size_t bytesWritten; - file = fopen(outFullFileName, "wb"); - if (file == 0) { - fprintf(stderr, "Could not open output file \"%s\"\n", outFullFileName); - exit(-1); + UNewDataMemory *pData; + pData = udata_create(outDir, NULL, outFileName, &(dh.info), copyright, &status); + if(U_FAILURE(status)) { + fprintf(stderr, "genbrk: Could not open output file \"%s\", \"%s\"\n", + outFileName, u_errorName(status)); + exit(status); } - - bytesWritten = fwrite(&dh, 1, sizeof(DataHeader), file); - - // // Write the data itself. - // - bytesWritten = fwrite(outData, 1, outDataSize, file); + udata_writeBlock(pData, outData, outDataSize); + // finish up + bytesWritten = udata_finish(pData, &status); + if(U_FAILURE(status)) { + fprintf(stderr, "genbrk: error %d writing the output file\n", status); + exit(status); + } + if (bytesWritten != outDataSize) { - fprintf(stderr, "Error writing to output file \"%s\"\n", outFullFileName); + fprintf(stderr, "Error writing to output file \"%s\"\n", outFileName); exit(-1); } - fclose(file); delete bi; delete[] ruleSourceU; delete[] ruleBufferC; - free(outFullFileName); u_cleanup();