mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-07 14:31:31 +00:00
ICU-2338 genbrk now using the toolutil/unewdata.h functions and write copyright text if requested
X-SVN-Rev: 12991
This commit is contained in:
parent
5fe7930239
commit
db5f63663f
1 changed files with 31 additions and 25 deletions
|
@ -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();
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue