From: simon Date: Tue, 13 Jun 2006 09:06:28 +0000 (+0000) Subject: I've apparently had this lying around for months but forgotten to X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/charset/commitdiff_plain/04b6f11105dd1f78a56a3b9de1b3e67e76035e0a I've apparently had this lying around for months but forgotten to commit it. Add `-i' option to cstable, which causes charset names to be output as CS_* constants where meaningful. (Doesn't apply to MBCS base charsets, because CS_* constants identify _encodings_.) git-svn-id: svn://svn.tartarus.org/sgt/charset@6728 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/cstable.c b/cstable.c index c8968bc..509923a 100644 --- a/cstable.c +++ b/cstable.c @@ -7,6 +7,9 @@ * libcharset _package_, using libcharset internals. */ +#include +#include + #include "charset.h" #include "internal.h" #include "sbcsdat.h" @@ -19,14 +22,25 @@ static charset_spec const *const cs_table[] = { #include "enum.c" #undef ENUM_CHARSET }; +static const char *const cs_names[] = { +#define ENUM_CHARSET(x) #x, +#include "enum.c" +#undef ENUM_CHARSET +}; int main(int argc, char **argv) { long int c; + int internal_names = FALSE; int verbose = FALSE; - if (argc > 1 && !strcmp(argv[1], "-v")) - verbose = TRUE; + while (--argc) { + char *p = *++argv; + if (!strcmp(p, "-i")) + internal_names = TRUE; + else if (!strcmp(p, "-v")) + verbose = TRUE; + } for (c = 0; c < 0x30000; c++) { int i, plane, row, col, chr; @@ -41,14 +55,18 @@ int main(int argc, char **argv) if (cs_table[i]->read == read_sbcs && (chr = sbcs_from_unicode(cs_table[i]->data, c)) != ERROR) { printf("%s %s", sep, - charset_to_localenc(cs_table[i]->charset)); + (internal_names ? cs_names[i] : + charset_to_localenc(cs_table[i]->charset))); if (verbose) printf("[%d]", chr); sep = ";"; } /* - * Look up individually in MBCS base charsets. + * Look up individually in MBCS base charsets. The + * `internal_names' flag does not affect these, because + * MBCS base charsets aren't directly encoded by CS_* + * constants. */ if (unicode_to_big5(c, &row, &col)) { printf("%s Big5", sep); @@ -56,6 +74,7 @@ int main(int argc, char **argv) printf("[%d,%d]", row, col); sep = ";"; } + if (unicode_to_gb2312(c, &row, &col)) { printf("%s GB2312", sep); if (verbose)