extern int main(int argc, char* argv[]) { const char *encoding = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = "."; int tostdout = 0; int prbom = 0; const char *pname; UResourceBundle *bundle = NULL; UErrorCode status = U_ZERO_ERROR; int32_t i = 0; UConverter *converter; const char* arg; /* Get the name of tool. */ pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (!pname) { pname = uprv_strrchr(*argv, U_FILE_ALT_SEP_CHAR); } #endif if (!pname) { pname = *argv; } else { ++pname; } /* error handling, printing usage message */ argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", pname, argv[-argc]); } if(argc<0 || options[0].doesOccur || options[1].doesOccur) { fprintf(argc < 0 ? stderr : stdout, "%csage: %s [ -h, -?, --help ] [ -V, --version ]\n" " [ -v, --verbose ] [ -e, --encoding encoding ] [ --bom ]\n" " [ -t, --truncate [ size ] ]\n" " [ -s, --sourcedir source ] [ -d, --destdir destination ]\n" " [ -i, --icudatadir directory ] [ -c, --to-stdout ]\n" " [ -A, --suppressAliases]\n" " bundle ...\n", argc < 0 ? 'u' : 'U', pname); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[10].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", pname, DERB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); return U_ZERO_ERROR; } if(options[2].doesOccur) { encoding = options[2].value; } if (options[3].doesOccur) { tostdout = 1; } if(options[4].doesOccur) { trunc = TRUE; if(options[4].value != NULL) { truncsize = atoi(options[4].value); /* user defined printable size */ } else { truncsize = DERB_DEFAULT_TRUNC; /* we'll use default omitting size */ } } else { trunc = FALSE; } if(options[5].doesOccur) { verbose = TRUE; } if (options[6].doesOccur) { outputDir = options[6].value; } if(options[7].doesOccur) { inputDir = options[7].value; /* we'll use users resources */ } if (options[8].doesOccur) { prbom = 1; } if (options[9].doesOccur) { u_setDataDirectory(options[9].value); } if (options[11].doesOccur) { suppressAliases = TRUE; } converter = ucnv_open(encoding, &status); if (U_FAILURE(status)) { fprintf(stderr, "%s: couldn't create %s converter for encoding\n", pname, encoding ? encoding : ucnv_getDefaultName()); return 2; } ucnv_setFromUCallBack(converter, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); if (U_FAILURE(status)) { fprintf(stderr, "%s: couldn't configure converter for encoding\n", pname); return 3; } defaultConverter = ucnv_open(0, &status); if (U_FAILURE(status)) { fprintf(stderr, "%s: couldn't create %s converter for encoding\n", ucnv_getDefaultName(), pname); return 2; } for (i = 1; i < argc; ++i) { static const UChar sp[] = { 0x0020 }; /* " " */ char infile[4096]; /* XXX Sloppy. */ char locale[64]; const char *thename = 0, *p, *q; UBool fromICUData = FALSE; arg = getLongPathname(argv[i]); if (verbose) { printf("processing bundle \"%s\"\n", argv[i]); } p = uprv_strrchr(arg, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (p == NULL) { p = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); } #endif if (!p) { p = arg; } else { p++; } q = uprv_strrchr(p, '.'); if (!q) { for (q = p; *q; ++q) ; } uprv_strncpy(locale, p, q - p); locale[q - p] = 0; if (!(fromICUData = !uprv_strcmp(inputDir, "-"))) { UBool absfilename = *arg == U_FILE_SEP_CHAR; #ifdef U_WINDOWS if (!absfilename) { absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); } #endif if (absfilename) { thename = arg; } else { q = uprv_strrchr(arg, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (q == NULL) { q = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); } #endif uprv_strcpy(infile, inputDir); if(q != NULL) { uprv_strcat(infile, U_FILE_SEP_STRING); strncat(infile, arg, q-arg); } thename = infile; } } status = U_ZERO_ERROR; if (thename) { bundle = ures_openDirect(thename, locale, &status); } else { bundle = ures_open(fromICUData ? 0 : inputDir, locale, &status); } if (status == U_ZERO_ERROR) { FILE *out; const char *filename = 0; const char *ext = 0; if (!locale || !tostdout) { filename = uprv_strrchr(arg, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (!filename) { filename = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); } #endif if (!filename) { filename = arg; } else { ++filename; } ext = uprv_strrchr(arg, '.'); if (!ext) { ext = filename + uprv_strlen(filename); } } if (tostdout) { out = stdout; #if defined(U_WINDOWS) || defined(U_CYGWIN) if (setmode(fileno(out), O_BINARY) == -1) { fprintf(stderr, "%s: couldn't set standard output to binary mode\n", pname); return 4; } #endif } else { char thefile[4096], *tp; int32_t len; if (outputDir) { uprv_strcpy(thefile, outputDir); uprv_strcat(thefile, U_FILE_SEP_STRING); } else { *thefile = 0; } uprv_strcat(thefile, filename); tp = thefile + uprv_strlen(thefile); len = (int32_t)uprv_strlen(ext); if (len) { tp -= len - 1; } else { *tp++ = '.'; } uprv_strcpy(tp, "txt"); out = fopen(thefile, "w"); if (!out) { fprintf(stderr, "%s: couldn't create %s\n", pname, thefile); return 4; } } if (prbom) { /* XXX: Should be done only for UTFs */ static const UChar bom[] = { 0xFEFF }; printString(out, converter, bom, (int32_t)(sizeof(bom)/sizeof(*bom))); } printCString(out, converter, "// -*- Coding: ", -1); printCString(out, converter, encoding ? encoding : getEncodingName(ucnv_getDefaultName()), -1); printCString(out, converter, "; -*-\n//\n", -1); printCString(out, converter, "// This file was dumped by derb(8) from ", -1); if (thename) { printCString(out, converter, thename, -1); } else if (fromICUData) { printCString(out, converter, "the ICU internal ", -1); printCString(out, converter, locale, -1); printCString(out, converter, " locale", -1); } printCString(out, converter, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n", -1); if (locale) { printCString(out, converter, locale, -1); } else { printCString(out, converter, filename, (int32_t)(ext - filename)); printString(out, converter, sp, (int32_t)(sizeof(sp)/sizeof(*sp))); } printOutBundle(out, converter, bundle, 0, pname, &status); if (out != stdout) { fclose(out); } } else { reportError(pname, &status, "opening resource file"); } ures_close(bundle); } ucnv_close(defaultConverter); ucnv_close(converter); return 0; }
static void printOutBundle(FILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) { static const UChar cr[] = { '\n' }; /* int32_t noOfElements = ures_getSize(resource);*/ int32_t i = 0; const char *key = ures_getKey(resource); switch(ures_getType(resource)) { case RES_STRING : { int32_t len=0; const UChar* thestr = ures_getString(resource, &len, status); UChar *string = quotedString(thestr); /* TODO: String truncation */ if(trunc && len > truncsize) { char msg[128]; printIndent(out, converter, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, converter, msg, -1); len = truncsize/2; } printIndent(out, converter, indent); if(key != NULL) { static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */ static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */ printCString(out, converter, key, (int32_t)uprv_strlen(key)); printString(out, converter, openStr, (int32_t)(sizeof(openStr)/sizeof(*openStr))); printString(out, converter, string, len); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); } else { static const UChar openStr[] = { 0x0022 }; /* "\"" */ static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */ printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); printString(out, converter, string, (int32_t)(u_strlen(string))); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); } if(verbose) { printCString(out, converter, "// STRING", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); uprv_free(string); } break; case RES_INT : { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */ static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */ UChar num[20]; printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); uprv_itou(num, 20, ures_getInt(resource, status), 10, 0); printString(out, converter, num, u_strlen(num)); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, "// INT", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); break; } case RES_BINARY : { int32_t len = 0; const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); if(trunc && len > truncsize) { char msg[128]; printIndent(out, converter, indent); sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", (long)len, (long)(truncsize/2)); printCString(out, converter, msg, -1); len = truncsize; } if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); for(i = 0; i<len; i++) { printHex(out, converter, *data++); } printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, " // BINARY", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); } else { reportError(pname, status, "getting binary value"); } } break; case RES_INT_VECTOR : { int32_t len = 0; const int32_t *data = ures_getIntVector(resource, &len, status); if(U_SUCCESS(*status)) { static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0076, 0x0065, 0x0063, 0x0074, 0x006F, 0x0072, 0x0020, 0x007B, 0x0020 }; /* ":intvector { " */ static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ UChar num[20]; printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); for(i = 0; i < len - 1; i++) { int32_t numLen = uprv_itou(num, 20, data[i], 10, 0); num[numLen++] = 0x002C; /* ',' */ num[numLen++] = 0x0020; /* ' ' */ num[numLen] = 0; printString(out, converter, num, u_strlen(num)); } if(len > 0) { uprv_itou(num, 20, data[len - 1], 10, 0); printString(out, converter, num, u_strlen(num)); } printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); if(verbose) { printCString(out, converter, "// INTVECTOR", -1); } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); } else { reportError(pname, status, "getting int vector"); } } break; case RES_TABLE : case RES_ARRAY : { static const UChar openStr[] = { 0x007B }; /* "{" */ static const UChar closeStr[] = { 0x007D, '\n' }; /* "}\n" */ UResourceBundle *t = NULL; ures_resetIterator(resource); printIndent(out, converter, indent); if(key != NULL) { printCString(out, converter, key, -1); } printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); if(verbose) { if(ures_getType(resource) == RES_TABLE) { printCString(out, converter, "// TABLE", -1); } else { printCString(out, converter, "// ARRAY", -1); } } printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); if(suppressAliases == FALSE) { while(U_SUCCESS(*status) && ures_hasNext(resource)) { t = ures_getNextResource(resource, t, status); if(U_SUCCESS(*status)) { printOutBundle(out, converter, t, indent+indentsize, pname, status); } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } else { /* we have to use low level access to do this */ Resource r = RES_BOGUS; for(i = 0; i < ures_getSize(resource); i++) { /* need to know if it's an alias */ if(ures_getType(resource) == RES_TABLE) { r = derb_getTableItem(resource->fResData.pRoot, resource->fRes, (int16_t)i); key = derb_getTableKey(resource->fResData.pRoot, resource->fRes, (int16_t)i); } else { r = derb_getArrayItem(resource->fResData.pRoot, resource->fRes, i); } if(U_SUCCESS(*status)) { if(RES_GET_TYPE(r) == RES_ALIAS) { printOutAlias(out, converter, resource, r, key, indent+indentsize, pname, status); } else { t = ures_getByIndex(resource, i, t, status); printOutBundle(out, converter, t, indent+indentsize, pname, status); } } else { reportError(pname, status, "While processing table"); *status = U_ZERO_ERROR; } } } printIndent(out, converter, indent); printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); ures_close(t); } break; default: break; } }
void printOutBundle(UFILE *out, UResourceBundle *resource, int32_t indent, UErrorCode *status) { int32_t i = 0; const char *key = ures_getKey(resource); switch(ures_getType(resource)) { case URES_STRING : { int32_t len=0; const UChar*thestr = ures_getString(resource, &len, status); UChar *string = quotedString(thestr); /* TODO: String truncation */ /* if(trunc && len > truncsize) { printIndent(out, indent); u_fprintf(out, "// WARNING: this string, size %d is truncated to %d\n", len, truncsize/2); len = truncsize/2; } */ printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s { \"%S\" } ", key, string); } else { u_fprintf(out, "\"%S\",", string); } if(VERBOSE) { u_fprintf(out, " // STRING"); } u_fprintf(out, "\n"); free(string); } break; case URES_INT : printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s", key); } u_fprintf(out, ":int { %li } ", ures_getInt(resource, status)); if(VERBOSE) { u_fprintf(out, " // INT"); } u_fprintf(out, "\n"); break; case URES_BINARY : { int32_t len = 0; const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); if(trunc && len > truncsize) { printIndent(out, indent); u_fprintf(out, "// WARNING: this resource, size %li is truncated to %li\n", len, truncsize/2); len = truncsize/2; } if(U_SUCCESS(*status)) { printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s", key); } u_fprintf(out, ":binary { "); for(i = 0; i<len; i++) { printHex(out, data++); } u_fprintf(out, " }"); if(VERBOSE) { u_fprintf(out, " // BINARY"); } u_fprintf(out, "\n"); } else { reportError(status); } } break; case URES_INT_VECTOR : { int32_t len = 0; const int32_t *data = ures_getIntVector(resource, &len, status); if(U_SUCCESS(*status)) { printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s", key); } u_fprintf(out, ":intvector { "); for(i = 0; i<len-1; i++) { u_fprintf(out, "%d, ", data[i]); } if(len > 0) { u_fprintf(out, "%d ", data[len-1]); } u_fprintf(out, "}"); if(VERBOSE) { u_fprintf(out, " // INTVECTOR"); } u_fprintf(out, "\n"); } else { reportError(status); } } break; case URES_TABLE : case URES_ARRAY : { UResourceBundle *t = NULL; ures_resetIterator(resource); printIndent(out, indent); if(key != NULL) { u_fprintf(out, "%s ", key); } u_fprintf(out, "{"); if(VERBOSE) { if(ures_getType(resource) == URES_TABLE) { u_fprintf(out, " // TABLE"); } else { u_fprintf(out, " // ARRAY"); } } u_fprintf(out, "\n"); while(ures_hasNext(resource)) { t = ures_getNextResource(resource, t, status); printOutBundle(out, t, indent+indentsize, status); } printIndent(out, indent); u_fprintf(out, "}\n"); ures_close(t); } break; default: break; } }
extern int main(int argc, char* argv[]) { UResourceBundle *bundle = NULL; UErrorCode status = U_ZERO_ERROR; UFILE *out = NULL; int32_t i = 0; const char* arg; char resPathBuffer[1024]; #ifdef WIN32 currdir = _getcwd(NULL, 0); #else currdir = getcwd(NULL, 0); #endif argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "error in command line argument \"%s\"\n", argv[-argc]); } if(argc<2 || options[0].doesOccur || options[1].doesOccur) { fprintf(stderr, "usage: %s [-options] locale(s)\n", argv[0]); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[2].doesOccur) { locale = options[2].value; } else { locale = 0; } if(options[3].doesOccur) { encoding = options[3].value; } else { encoding = NULL; } if(options[4].doesOccur) { if(options[4].value != NULL) { resPath = options[4].value; /* we'll use users resources */ } else { resPath = NULL; /* we'll use ICU system resources for dumping */ } } else { strcpy(resPathBuffer, currdir); /*strcat(resPathBuffer, U_FILE_SEP_STRING); strcat(resPathBuffer, "uresb");*/ resPath = resPathBuffer; /* we'll just dump uresb samples resources */ } if(options[5].doesOccur) { trunc = TRUE; if(options[5].value != NULL) { truncsize = atoi(options[5].value); /* user defined printable size */ } else { truncsize = URESB_DEFAULTTRUNC; /* we'll use default omitting size */ } } else { trunc = FALSE; } if(options[6].doesOccur) { VERBOSE = TRUE; } outerr = u_finit(stderr, locale, encoding); out = u_finit(stdout, locale, encoding); for(i = 1; i < argc; ++i) { status = U_ZERO_ERROR; arg = getLongPathname(argv[i]); u_fprintf(out, "uresb: processing file \"%s\" in path \"%s\"\n", arg, resPath); bundle = ures_open(resPath, arg, &status); if(U_SUCCESS(status)) { u_fprintf(out, "%s\n", arg); printOutBundle(out, bundle, 0, &status); } else { reportError(&status); } ures_close(bundle); } u_fclose(out); u_fclose(outerr); return 0; }
extern int main(int argc, char* argv[]) { const char *encoding = NULL; const char *outputDir = NULL; /* NULL = no output directory, use current */ const char *inputDir = "."; int tostdout = 0; int prbom = 0; const char *pname; UResourceBundle *bundle = NULL; int32_t i = 0; const char* arg; /* Get the name of tool. */ pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (!pname) { pname = uprv_strrchr(*argv, U_FILE_ALT_SEP_CHAR); } #endif if (!pname) { pname = *argv; } else { ++pname; } /* error handling, printing usage message */ argc=u_parseArgs(argc, argv, UPRV_LENGTHOF(options), options); /* error handling, printing usage message */ if(argc<0) { fprintf(stderr, "%s: error in command line argument \"%s\"\n", pname, argv[-argc]); } if(argc<0 || options[0].doesOccur || options[1].doesOccur) { fprintf(argc < 0 ? stderr : stdout, "%csage: %s [ -h, -?, --help ] [ -V, --version ]\n" " [ -v, --verbose ] [ -e, --encoding encoding ] [ --bom ]\n" " [ -t, --truncate [ size ] ]\n" " [ -s, --sourcedir source ] [ -d, --destdir destination ]\n" " [ -i, --icudatadir directory ] [ -c, --to-stdout ]\n" " [ -A, --suppressAliases]\n" " bundle ...\n", argc < 0 ? 'u' : 'U', pname); return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; } if(options[10].doesOccur) { fprintf(stderr, "%s version %s (ICU version %s).\n" "%s\n", pname, DERB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); return U_ZERO_ERROR; } if(options[2].doesOccur) { encoding = options[2].value; } if (options[3].doesOccur) { if(options[2].doesOccur) { fprintf(stderr, "%s: Error: don't specify an encoding (-e) when writing to stdout (-c).\n", pname); return 3; } tostdout = 1; } if(options[4].doesOccur) { opt_truncate = TRUE; if(options[4].value != NULL) { truncsize = atoi(options[4].value); /* user defined printable size */ } else { truncsize = DERB_DEFAULT_TRUNC; /* we'll use default omitting size */ } } else { opt_truncate = FALSE; } if(options[5].doesOccur) { verbose = TRUE; } if (options[6].doesOccur) { outputDir = options[6].value; } if(options[7].doesOccur) { inputDir = options[7].value; /* we'll use users resources */ } if (options[8].doesOccur) { prbom = 1; } if (options[9].doesOccur) { u_setDataDirectory(options[9].value); } if (options[11].doesOccur) { suppressAliases = TRUE; } fflush(stderr); // use ustderr now. ustderr = u_finit(stderr, NULL, NULL); for (i = 1; i < argc; ++i) { static const UChar sp[] = { 0x0020 }; /* " " */ arg = getLongPathname(argv[i]); if (verbose) { u_fprintf(ustderr, "processing bundle \"%s\"\n", argv[i]); } icu::CharString locale; UErrorCode status = U_ZERO_ERROR; { const char *p = findBasename(arg); const char *q = uprv_strrchr(p, '.'); if (q == NULL) { locale.append(p, status); } else { locale.append(p, (int32_t)(q - p), status); } } if (U_FAILURE(status)) { return status; } icu::CharString infile; const char *thename = NULL; UBool fromICUData = !uprv_strcmp(inputDir, "-"); if (!fromICUData) { UBool absfilename = *arg == U_FILE_SEP_CHAR; #if U_PLATFORM_HAS_WIN32_API if (!absfilename) { absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); } #endif if (absfilename) { thename = arg; } else { const char *q = uprv_strrchr(arg, U_FILE_SEP_CHAR); #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR if (q == NULL) { q = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); } #endif infile.append(inputDir, status); if(q != NULL) { infile.appendPathPart(icu::StringPiece(arg, (int32_t)(q - arg)), status); } if (U_FAILURE(status)) { return status; } thename = infile.data(); } } if (thename) { bundle = ures_openDirect(thename, locale.data(), &status); } else { bundle = ures_open(fromICUData ? 0 : inputDir, locale.data(), &status); } if (U_SUCCESS(status)) { UFILE *out = NULL; const char *filename = 0; const char *ext = 0; if (locale.isEmpty() || !tostdout) { filename = findBasename(arg); ext = uprv_strrchr(filename, '.'); if (!ext) { ext = uprv_strchr(filename, 0); } } if (tostdout) { out = u_get_stdout(); } else { icu::CharString thefile; if (outputDir) { thefile.append(outputDir, status); } thefile.appendPathPart(filename, status); if (*ext) { thefile.truncate(thefile.length() - (int32_t)uprv_strlen(ext)); } thefile.append(".txt", status); if (U_FAILURE(status)) { return status; } out = u_fopen(thefile.data(), "w", NULL, encoding); if (!out) { u_fprintf(ustderr, "%s: couldn't create %s\n", pname, thefile.data()); u_fclose(ustderr); return 4; } } // now, set the callback. ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); if (U_FAILURE(status)) { u_fprintf(ustderr, "%s: couldn't configure converter for encoding\n", pname); u_fclose(ustderr); if(!tostdout) { u_fclose(out); } return 3; } if (prbom) { /* XXX: Should be done only for UTFs */ u_fputc(0xFEFF, out); } u_fprintf(out, "// -*- Coding: %s; -*-\n//\n", encoding ? encoding : getEncodingName(ucnv_getDefaultName())); u_fprintf(out, "// This file was dumped by derb(8) from "); if (thename) { u_fprintf(out, "%s", thename); } else if (fromICUData) { u_fprintf(out, "the ICU internal %s locale", locale.data()); } u_fprintf(out, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n"); if (!locale.isEmpty()) { u_fprintf(out, "%s", locale.data()); } else { u_fprintf(out, "%.*s%.*S", (int32_t)(ext - filename), filename, UPRV_LENGTHOF(sp), sp); } printOutBundle(out, bundle, 0, pname, &status); if (!tostdout) { u_fclose(out); } } else { reportError(pname, &status, "opening resource file"); } ures_close(bundle); } return 0; }