michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 1999-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: derb.c michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2000sep6 michael@0: * created by: Vladimir Weinstein as an ICU workshop example michael@0: * maintained by: Yves Arrouye michael@0: */ michael@0: michael@0: #include "unicode/ucnv.h" michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/putil.h" michael@0: #include "unicode/ustdio.h" michael@0: michael@0: #include "uresimp.h" michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: #include "uoptions.h" michael@0: #include "toolutil.h" michael@0: #include "ustrfmt.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #define DERB_VERSION "1.1" michael@0: michael@0: #define DERB_DEFAULT_TRUNC 80 michael@0: michael@0: static const int32_t indentsize = 4; michael@0: static int32_t truncsize = DERB_DEFAULT_TRUNC; michael@0: static UBool opt_truncate = FALSE; michael@0: michael@0: static const char *getEncodingName(const char *encoding); michael@0: static void reportError(const char *pname, UErrorCode *status, const char *when); michael@0: static UChar *quotedString(const UChar *string); michael@0: static void printOutBundle(UFILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status); michael@0: static void printString(UFILE *out, UConverter *converter, const UChar *str, int32_t len); michael@0: static void printCString(UFILE *out, UConverter *converter, const char *str, int32_t len); michael@0: static void printIndent(UFILE *out, UConverter *converter, int32_t indent); michael@0: static void printHex(UFILE *out, UConverter *converter, uint8_t what); michael@0: michael@0: static UOption options[]={ michael@0: UOPTION_HELP_H, michael@0: UOPTION_HELP_QUESTION_MARK, michael@0: /* 2 */ UOPTION_ENCODING, michael@0: /* 3 */ { "to-stdout", NULL, NULL, NULL, 'c', UOPT_NO_ARG, 0 } , michael@0: /* 4 */ { "truncate", NULL, NULL, NULL, 't', UOPT_OPTIONAL_ARG, 0 }, michael@0: /* 5 */ UOPTION_VERBOSE, michael@0: /* 6 */ UOPTION_DESTDIR, michael@0: /* 7 */ UOPTION_SOURCEDIR, michael@0: /* 8 */ { "bom", NULL, NULL, NULL, 0, UOPT_NO_ARG, 0 }, michael@0: /* 9 */ UOPTION_ICUDATADIR, michael@0: /* 10 */ UOPTION_VERSION, michael@0: /* 11 */ { "suppressAliases", NULL, NULL, NULL, 'A', UOPT_NO_ARG, 0 }, michael@0: }; michael@0: michael@0: static UBool verbose = FALSE; michael@0: static UBool suppressAliases = FALSE; michael@0: static UFILE *ustderr = NULL; michael@0: michael@0: extern int michael@0: main(int argc, char* argv[]) { michael@0: const char *encoding = NULL; michael@0: const char *outputDir = NULL; /* NULL = no output directory, use current */ michael@0: const char *inputDir = "."; michael@0: int tostdout = 0; michael@0: int prbom = 0; michael@0: michael@0: const char *pname; michael@0: michael@0: UResourceBundle *bundle = NULL; michael@0: UErrorCode status = U_ZERO_ERROR; michael@0: int32_t i = 0; michael@0: michael@0: UConverter *converter = NULL; // not used michael@0: michael@0: const char* arg; michael@0: michael@0: /* Get the name of tool. */ michael@0: pname = uprv_strrchr(*argv, U_FILE_SEP_CHAR); michael@0: #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR michael@0: if (!pname) { michael@0: pname = uprv_strrchr(*argv, U_FILE_ALT_SEP_CHAR); michael@0: } michael@0: #endif michael@0: if (!pname) { michael@0: pname = *argv; michael@0: } else { michael@0: ++pname; michael@0: } michael@0: michael@0: /* error handling, printing usage message */ michael@0: argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options); michael@0: michael@0: /* error handling, printing usage message */ michael@0: if(argc<0) { michael@0: fprintf(stderr, michael@0: "%s: error in command line argument \"%s\"\n", pname, michael@0: argv[-argc]); michael@0: } michael@0: if(argc<0 || options[0].doesOccur || options[1].doesOccur) { michael@0: fprintf(argc < 0 ? stderr : stdout, michael@0: "%csage: %s [ -h, -?, --help ] [ -V, --version ]\n" michael@0: " [ -v, --verbose ] [ -e, --encoding encoding ] [ --bom ]\n" michael@0: " [ -t, --truncate [ size ] ]\n" michael@0: " [ -s, --sourcedir source ] [ -d, --destdir destination ]\n" michael@0: " [ -i, --icudatadir directory ] [ -c, --to-stdout ]\n" michael@0: " [ -A, --suppressAliases]\n" michael@0: " bundle ...\n", argc < 0 ? 'u' : 'U', michael@0: pname); michael@0: return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR; michael@0: } michael@0: michael@0: if(options[10].doesOccur) { michael@0: fprintf(stderr, michael@0: "%s version %s (ICU version %s).\n" michael@0: "%s\n", michael@0: pname, DERB_VERSION, U_ICU_VERSION, U_COPYRIGHT_STRING); michael@0: return U_ZERO_ERROR; michael@0: } michael@0: if(options[2].doesOccur) { michael@0: encoding = options[2].value; michael@0: } michael@0: michael@0: if (options[3].doesOccur) { michael@0: if(options[2].doesOccur) { michael@0: fprintf(stderr, "%s: Error: don't specify an encoding (-e) when writing to stdout (-c).\n", pname); michael@0: return 3; michael@0: } michael@0: tostdout = 1; michael@0: } michael@0: michael@0: if(options[4].doesOccur) { michael@0: opt_truncate = TRUE; michael@0: if(options[4].value != NULL) { michael@0: truncsize = atoi(options[4].value); /* user defined printable size */ michael@0: } else { michael@0: truncsize = DERB_DEFAULT_TRUNC; /* we'll use default omitting size */ michael@0: } michael@0: } else { michael@0: opt_truncate = FALSE; michael@0: } michael@0: michael@0: if(options[5].doesOccur) { michael@0: verbose = TRUE; michael@0: } michael@0: michael@0: if (options[6].doesOccur) { michael@0: outputDir = options[6].value; michael@0: } michael@0: michael@0: if(options[7].doesOccur) { michael@0: inputDir = options[7].value; /* we'll use users resources */ michael@0: } michael@0: michael@0: if (options[8].doesOccur) { michael@0: prbom = 1; michael@0: } michael@0: michael@0: if (options[9].doesOccur) { michael@0: u_setDataDirectory(options[9].value); michael@0: } michael@0: michael@0: if (options[11].doesOccur) { michael@0: suppressAliases = TRUE; michael@0: } michael@0: michael@0: fflush(stderr); // use ustderr now. michael@0: ustderr = u_finit(stderr, NULL, NULL); michael@0: michael@0: for (i = 1; i < argc; ++i) { michael@0: static const UChar sp[] = { 0x0020 }; /* " " */ michael@0: char infile[4096]; /* XXX Sloppy. */ michael@0: char locale[64]; michael@0: const char *thename = 0, *p, *q; michael@0: UBool fromICUData = FALSE; michael@0: michael@0: arg = getLongPathname(argv[i]); michael@0: michael@0: if (verbose) { michael@0: u_fprintf(ustderr, "processing bundle \"%s\"\n", argv[i]); michael@0: } michael@0: michael@0: p = uprv_strrchr(arg, U_FILE_SEP_CHAR); michael@0: #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR michael@0: if (p == NULL) { michael@0: p = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); michael@0: } michael@0: #endif michael@0: if (!p) { michael@0: p = arg; michael@0: } else { michael@0: p++; michael@0: } michael@0: q = uprv_strrchr(p, '.'); michael@0: if (!q) { michael@0: for (q = p; *q; ++q) michael@0: ; michael@0: } michael@0: uprv_strncpy(locale, p, q - p); michael@0: locale[q - p] = 0; michael@0: michael@0: if (!(fromICUData = !uprv_strcmp(inputDir, "-"))) { michael@0: UBool absfilename = *arg == U_FILE_SEP_CHAR; michael@0: #if U_PLATFORM_HAS_WIN32_API michael@0: if (!absfilename) { michael@0: absfilename = (uprv_strlen(arg) > 2 && isalpha(arg[0]) michael@0: && arg[1] == ':' && arg[2] == U_FILE_SEP_CHAR); michael@0: } michael@0: #endif michael@0: if (absfilename) { michael@0: thename = arg; michael@0: } else { michael@0: q = uprv_strrchr(arg, U_FILE_SEP_CHAR); michael@0: #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR michael@0: if (q == NULL) { michael@0: q = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); michael@0: } michael@0: #endif michael@0: uprv_strcpy(infile, inputDir); michael@0: if(q != NULL) { michael@0: uprv_strcat(infile, U_FILE_SEP_STRING); michael@0: strncat(infile, arg, q-arg); michael@0: } michael@0: thename = infile; michael@0: } michael@0: } michael@0: status = U_ZERO_ERROR; michael@0: if (thename) { michael@0: bundle = ures_openDirect(thename, locale, &status); michael@0: } else { michael@0: bundle = ures_open(fromICUData ? 0 : inputDir, locale, &status); michael@0: } michael@0: if (status == U_ZERO_ERROR) { michael@0: UFILE *out = NULL; michael@0: michael@0: const char *filename = 0; michael@0: const char *ext = 0; michael@0: michael@0: if (!locale[0] || !tostdout) { michael@0: filename = uprv_strrchr(arg, U_FILE_SEP_CHAR); michael@0: michael@0: #if U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR michael@0: if (!filename) { michael@0: filename = uprv_strrchr(arg, U_FILE_ALT_SEP_CHAR); michael@0: } michael@0: #endif michael@0: if (!filename) { michael@0: filename = arg; michael@0: } else { michael@0: ++filename; michael@0: } michael@0: ext = uprv_strrchr(arg, '.'); michael@0: if (!ext) { michael@0: ext = filename + uprv_strlen(filename); michael@0: } michael@0: } michael@0: michael@0: if (tostdout) { michael@0: out = u_get_stdout(); michael@0: } else { michael@0: char thefile[4096], *tp; michael@0: int32_t len; michael@0: michael@0: if (outputDir) { michael@0: uprv_strcpy(thefile, outputDir); michael@0: uprv_strcat(thefile, U_FILE_SEP_STRING); michael@0: } else { michael@0: *thefile = 0; michael@0: } michael@0: uprv_strcat(thefile, filename); michael@0: tp = thefile + uprv_strlen(thefile); michael@0: len = (int32_t)uprv_strlen(ext); michael@0: if (len) { michael@0: tp -= len - 1; michael@0: } else { michael@0: *tp++ = '.'; michael@0: } michael@0: uprv_strcpy(tp, "txt"); michael@0: michael@0: out = u_fopen(thefile, "w", NULL, encoding); michael@0: if (!out) { michael@0: u_fprintf(ustderr, "%s: couldn't create %s\n", pname, thefile); michael@0: u_fclose(ustderr); michael@0: return 4; michael@0: } michael@0: } michael@0: michael@0: // now, set the callback. michael@0: ucnv_setFromUCallBack(u_fgetConverter(out), UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, 0, 0, &status); michael@0: if (U_FAILURE(status)) { michael@0: u_fprintf(ustderr, "%s: couldn't configure converter for encoding\n", pname); michael@0: u_fclose(ustderr); michael@0: if(!tostdout) { michael@0: u_fclose(out); michael@0: } michael@0: return 3; michael@0: } michael@0: michael@0: if (prbom) { /* XXX: Should be done only for UTFs */ michael@0: u_fputc(0xFEFF, out); michael@0: } michael@0: u_fprintf(out, "// -*- Coding: %s; -*-\n//\n", encoding ? encoding : getEncodingName(ucnv_getDefaultName())); michael@0: u_fprintf(out, "// This file was dumped by derb(8) from "); michael@0: if (thename) { michael@0: u_fprintf(out, "%s", thename); michael@0: } else if (fromICUData) { michael@0: u_fprintf(out, "the ICU internal %s locale", locale); michael@0: } michael@0: michael@0: u_fprintf(out, "\n// derb(8) by Vladimir Weinstein and Yves Arrouye\n\n"); michael@0: michael@0: if (locale[0]) { michael@0: u_fprintf(out, "%s", locale); michael@0: } else { michael@0: u_fprintf(out, "%.*s%.*S", (int32_t)(ext - filename), filename, (int32_t)(sizeof(sp)/sizeof(*sp)), sp); michael@0: } michael@0: printOutBundle(out, converter, bundle, 0, pname, &status); michael@0: michael@0: if (!tostdout) { michael@0: u_fclose(out); michael@0: } michael@0: } michael@0: else { michael@0: reportError(pname, &status, "opening resource file"); michael@0: } michael@0: michael@0: ures_close(bundle); michael@0: } michael@0: michael@0: ucnv_close(converter); michael@0: michael@0: return 0; michael@0: } michael@0: michael@0: static UChar *quotedString(const UChar *string) { michael@0: int len = u_strlen(string); michael@0: int alen = len; michael@0: const UChar *sp; michael@0: UChar *newstr, *np; michael@0: michael@0: for (sp = string; *sp; ++sp) { michael@0: switch (*sp) { michael@0: case '\n': michael@0: case 0x0022: michael@0: ++alen; michael@0: break; michael@0: } michael@0: } michael@0: michael@0: newstr = (UChar *) uprv_malloc((1 + alen) * sizeof(*newstr)); michael@0: for (sp = string, np = newstr; *sp; ++sp) { michael@0: switch (*sp) { michael@0: case '\n': michael@0: *np++ = 0x005C; michael@0: *np++ = 0x006E; michael@0: break; michael@0: michael@0: case 0x0022: michael@0: *np++ = 0x005C; michael@0: michael@0: default: michael@0: *np++ = *sp; michael@0: break; michael@0: } michael@0: } michael@0: *np = 0; michael@0: michael@0: return newstr; michael@0: } michael@0: michael@0: michael@0: static void printString(UFILE *out, UConverter *converter, const UChar *str, int32_t len) { michael@0: u_file_write(str, len, out); michael@0: } michael@0: michael@0: static void printCString(UFILE *out, UConverter *converter, const char *str, int32_t len) { michael@0: if(len==-1) { michael@0: u_fprintf(out, "%s", str); michael@0: } else { michael@0: u_fprintf(out, "%.*s", len, str); michael@0: } michael@0: } michael@0: michael@0: static void printIndent(UFILE *out, UConverter *converter, int32_t indent) { michael@0: UChar inchar[256]; michael@0: int32_t i = 0; michael@0: for(i = 0; i> 4]; michael@0: hex[1] = map[what & 0xf]; michael@0: michael@0: printString(out, converter, hex, (int32_t)(sizeof(hex)/sizeof(*hex))); michael@0: } michael@0: michael@0: static void printOutAlias(UFILE *out, UConverter *converter, UResourceBundle *parent, Resource r, const char *key, int32_t indent, const char *pname, UErrorCode *status) { michael@0: static const UChar cr[] = { '\n' }; michael@0: int32_t len = 0; michael@0: const UChar* thestr = res_getAlias(&(parent->fResData), r, &len); michael@0: UChar *string = quotedString(thestr); michael@0: if(opt_truncate && len > truncsize) { michael@0: char msg[128]; michael@0: printIndent(out, converter, indent); michael@0: sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", michael@0: (long)len, (long)truncsize/2); michael@0: printCString(out, converter, msg, -1); michael@0: len = truncsize; michael@0: } michael@0: if(U_SUCCESS(*status)) { michael@0: static const UChar openStr[] = { 0x003A, 0x0061, 0x006C, 0x0069, 0x0061, 0x0073, 0x0020, 0x007B, 0x0020, 0x0022 }; /* ":alias { \"" */ michael@0: static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D, 0x0020 }; /* "\" } " */ michael@0: printIndent(out, converter, indent); michael@0: if(key != NULL) { michael@0: printCString(out, converter, key, -1); michael@0: } michael@0: printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); michael@0: printString(out, converter, string, len); michael@0: printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); michael@0: if(verbose) { michael@0: printCString(out, converter, " // ALIAS", -1); michael@0: } michael@0: printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); michael@0: } else { michael@0: reportError(pname, status, "getting binary value"); michael@0: } michael@0: uprv_free(string); michael@0: } michael@0: michael@0: static void printOutBundle(UFILE *out, UConverter *converter, UResourceBundle *resource, int32_t indent, const char *pname, UErrorCode *status) michael@0: { michael@0: static const UChar cr[] = { '\n' }; michael@0: michael@0: /* int32_t noOfElements = ures_getSize(resource);*/ michael@0: int32_t i = 0; michael@0: const char *key = ures_getKey(resource); michael@0: michael@0: switch(ures_getType(resource)) { michael@0: case URES_STRING : michael@0: { michael@0: int32_t len=0; michael@0: const UChar* thestr = ures_getString(resource, &len, status); michael@0: UChar *string = quotedString(thestr); michael@0: michael@0: /* TODO: String truncation */ michael@0: if(opt_truncate && len > truncsize) { michael@0: char msg[128]; michael@0: printIndent(out, converter, indent); michael@0: sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", michael@0: (long)len, (long)(truncsize/2)); michael@0: printCString(out, converter, msg, -1); michael@0: len = truncsize/2; michael@0: } michael@0: printIndent(out, converter, indent); michael@0: if(key != NULL) { michael@0: static const UChar openStr[] = { 0x0020, 0x007B, 0x0020, 0x0022 }; /* " { \"" */ michael@0: static const UChar closeStr[] = { 0x0022, 0x0020, 0x007D }; /* "\" }" */ michael@0: printCString(out, converter, key, (int32_t)uprv_strlen(key)); michael@0: printString(out, converter, openStr, (int32_t)(sizeof(openStr)/sizeof(*openStr))); michael@0: printString(out, converter, string, len); michael@0: printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); michael@0: } else { michael@0: static const UChar openStr[] = { 0x0022 }; /* "\"" */ michael@0: static const UChar closeStr[] = { 0x0022, 0x002C }; /* "\"," */ michael@0: michael@0: printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); michael@0: printString(out, converter, string, (int32_t)(u_strlen(string))); michael@0: printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); michael@0: } michael@0: michael@0: if(verbose) { michael@0: printCString(out, converter, "// STRING", -1); michael@0: } michael@0: printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); michael@0: michael@0: uprv_free(string); michael@0: } michael@0: break; michael@0: michael@0: case URES_INT : michael@0: { michael@0: static const UChar openStr[] = { 0x003A, 0x0069, 0x006E, 0x0074, 0x0020, 0x007B, 0x0020 }; /* ":int { " */ michael@0: static const UChar closeStr[] = { 0x0020, 0x007D }; /* " }" */ michael@0: UChar num[20]; michael@0: michael@0: printIndent(out, converter, indent); michael@0: if(key != NULL) { michael@0: printCString(out, converter, key, -1); michael@0: } michael@0: printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); michael@0: uprv_itou(num, 20, ures_getInt(resource, status), 10, 0); michael@0: printString(out, converter, num, u_strlen(num)); michael@0: printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); michael@0: michael@0: if(verbose) { michael@0: printCString(out, converter, "// INT", -1); michael@0: } michael@0: printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); michael@0: break; michael@0: } michael@0: case URES_BINARY : michael@0: { michael@0: int32_t len = 0; michael@0: const int8_t *data = (const int8_t *)ures_getBinary(resource, &len, status); michael@0: if(opt_truncate && len > truncsize) { michael@0: char msg[128]; michael@0: printIndent(out, converter, indent); michael@0: sprintf(msg, "// WARNING: this resource, size %li is truncated to %li\n", michael@0: (long)len, (long)(truncsize/2)); michael@0: printCString(out, converter, msg, -1); michael@0: len = truncsize; michael@0: } michael@0: if(U_SUCCESS(*status)) { michael@0: static const UChar openStr[] = { 0x003A, 0x0062, 0x0069, 0x006E, 0x0061, 0x0072, 0x0079, 0x0020, 0x007B, 0x0020 }; /* ":binary { " */ michael@0: static const UChar closeStr[] = { 0x0020, 0x007D, 0x0020 }; /* " } " */ michael@0: printIndent(out, converter, indent); michael@0: if(key != NULL) { michael@0: printCString(out, converter, key, -1); michael@0: } michael@0: printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); michael@0: for(i = 0; i 0) { michael@0: uprv_itou(num, 20, data[len - 1], 10, 0); michael@0: printString(out, converter, num, u_strlen(num)); michael@0: } michael@0: printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); michael@0: if(verbose) { michael@0: printCString(out, converter, "// INTVECTOR", -1); michael@0: } michael@0: printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); michael@0: } else { michael@0: reportError(pname, status, "getting int vector"); michael@0: } michael@0: } michael@0: break; michael@0: case URES_TABLE : michael@0: case URES_ARRAY : michael@0: { michael@0: static const UChar openStr[] = { 0x007B }; /* "{" */ michael@0: static const UChar closeStr[] = { 0x007D, '\n' }; /* "}\n" */ michael@0: michael@0: UResourceBundle *t = NULL; michael@0: ures_resetIterator(resource); michael@0: printIndent(out, converter, indent); michael@0: if(key != NULL) { michael@0: printCString(out, converter, key, -1); michael@0: } michael@0: printString(out, converter, openStr, (int32_t)(sizeof(openStr) / sizeof(*openStr))); michael@0: if(verbose) { michael@0: if(ures_getType(resource) == URES_TABLE) { michael@0: printCString(out, converter, "// TABLE", -1); michael@0: } else { michael@0: printCString(out, converter, "// ARRAY", -1); michael@0: } michael@0: } michael@0: printString(out, converter, cr, (int32_t)(sizeof(cr) / sizeof(*cr))); michael@0: michael@0: if(suppressAliases == FALSE) { michael@0: while(U_SUCCESS(*status) && ures_hasNext(resource)) { michael@0: t = ures_getNextResource(resource, t, status); michael@0: if(U_SUCCESS(*status)) { michael@0: printOutBundle(out, converter, t, indent+indentsize, pname, status); michael@0: } else { michael@0: reportError(pname, status, "While processing table"); michael@0: *status = U_ZERO_ERROR; michael@0: } michael@0: } michael@0: } else { /* we have to use low level access to do this */ michael@0: Resource r; michael@0: int32_t resSize = ures_getSize(resource); michael@0: UBool isTable = (UBool)(ures_getType(resource) == URES_TABLE); michael@0: for(i = 0; i < resSize; i++) { michael@0: /* need to know if it's an alias */ michael@0: if(isTable) { michael@0: r = res_getTableItemByIndex(&resource->fResData, resource->fRes, i, &key); michael@0: } else { michael@0: r = res_getArrayItem(&resource->fResData, resource->fRes, i); michael@0: } michael@0: if(U_SUCCESS(*status)) { michael@0: if(res_getPublicType(r) == URES_ALIAS) { michael@0: printOutAlias(out, converter, resource, r, key, indent+indentsize, pname, status); michael@0: } else { michael@0: t = ures_getByIndex(resource, i, t, status); michael@0: printOutBundle(out, converter, t, indent+indentsize, pname, status); michael@0: } michael@0: } else { michael@0: reportError(pname, status, "While processing table"); michael@0: *status = U_ZERO_ERROR; michael@0: } michael@0: } michael@0: } michael@0: michael@0: printIndent(out, converter, indent); michael@0: printString(out, converter, closeStr, (int32_t)(sizeof(closeStr) / sizeof(*closeStr))); michael@0: ures_close(t); michael@0: } michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: michael@0: } michael@0: michael@0: static const char *getEncodingName(const char *encoding) { michael@0: UErrorCode err; michael@0: const char *enc; michael@0: michael@0: err = U_ZERO_ERROR; michael@0: if (!(enc = ucnv_getStandardName(encoding, "MIME", &err))) { michael@0: err = U_ZERO_ERROR; michael@0: if (!(enc = ucnv_getStandardName(encoding, "IANA", &err))) { michael@0: ; michael@0: } michael@0: } michael@0: michael@0: return enc; michael@0: } michael@0: michael@0: static void reportError(const char *pname, UErrorCode *status, const char *when) { michael@0: u_fprintf(ustderr, "%s: error %d while %s: %s\n", pname, *status, when, u_errorName(*status)); michael@0: } michael@0: michael@0: #else michael@0: extern int michael@0: main(int argc, char* argv[]) { michael@0: /* Changing stdio.h ustdio.h requires that formatting not be disabled. */ michael@0: return 3; michael@0: } michael@0: #endif /* !UCONFIG_NO_FORMATTING */ michael@0: michael@0: /* michael@0: * Local Variables: michael@0: * indent-tabs-mode: nil michael@0: * End: michael@0: */