~mdw
/
sgt
/
charset
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
I've apparently had this lying around for months but forgotten to
[sgt/charset]
/
cstable.c
diff --git
a/cstable.c
b/cstable.c
index
29deceb
..
509923a
100644
(file)
--- a/
cstable.c
+++ b/
cstable.c
@@
-7,6
+7,9
@@
* libcharset _package_, using libcharset internals.
*/
* libcharset _package_, using libcharset internals.
*/
+#include <stdio.h>
+#include <string.h>
+
#include "charset.h"
#include "internal.h"
#include "sbcsdat.h"
#include "charset.h"
#include "internal.h"
#include "sbcsdat.h"
@@
-19,13
+22,28
@@
static charset_spec const *const cs_table[] = {
#include "enum.c"
#undef ENUM_CHARSET
};
#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(
void
)
+int main(
int argc, char **argv
)
{
long int c;
{
long int c;
+ int internal_names = FALSE;
+ int verbose = FALSE;
+
+ 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++) {
for (c = 0; c < 0x30000; c++) {
- int i, plane, row, col;
+ int i, plane, row, col
, chr
;
char const *sep = "";
printf("U+%04x:", c);
char const *sep = "";
printf("U+%04x:", c);
@@
-35,41
+53,60
@@
int main(void)
*/
for (i = 0; i < lenof(cs_table); i++)
if (cs_table[i]->read == read_sbcs &&
*/
for (i = 0; i < lenof(cs_table); i++)
if (cs_table[i]->read == read_sbcs &&
-
sbcs_from_unicode(cs_table[i]->data, c
) != ERROR) {
+
(chr = sbcs_from_unicode(cs_table[i]->data, c)
) != ERROR) {
printf("%s %s", sep,
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 = ";";
}
/*
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);
*/
if (unicode_to_big5(c, &row, &col)) {
printf("%s Big5", sep);
+ if (verbose)
+ printf("[%d,%d]", row, col);
sep = ";";
}
sep = ";";
}
+
if (unicode_to_gb2312(c, &row, &col)) {
printf("%s GB2312", sep);
if (unicode_to_gb2312(c, &row, &col)) {
printf("%s GB2312", sep);
+ if (verbose)
+ printf("[%d,%d]", row, col);
sep = ";";
}
if (unicode_to_jisx0208(c, &row, &col)) {
printf("%s JIS X 0208", sep);
sep = ";";
}
if (unicode_to_jisx0208(c, &row, &col)) {
printf("%s JIS X 0208", sep);
+ if (verbose)
+ printf("[%d,%d]", row, col);
sep = ";";
}
if (unicode_to_ksx1001(c, &row, &col)) {
printf("%s KS X 1001", sep);
sep = ";";
}
if (unicode_to_ksx1001(c, &row, &col)) {
printf("%s KS X 1001", sep);
+ if (verbose)
+ printf("[%d,%d]", row, col);
sep = ";";
}
if (unicode_to_cp949(c, &row, &col)) {
printf("%s CP949", sep);
sep = ";";
}
if (unicode_to_cp949(c, &row, &col)) {
printf("%s CP949", sep);
+ if (verbose)
+ printf("[%d,%d]", row, col);
sep = ";";
}
if (unicode_to_cns11643(c, &plane, &row, &col)) {
printf("%s CNS11643", sep);
sep = ";";
}
if (unicode_to_cns11643(c, &plane, &row, &col)) {
printf("%s CNS11643", sep);
+ if (verbose)
+ printf("[%d,%d,%d]", plane, row, col);
sep = ";";
}
sep = ";";
}