summaryrefslogtreecommitdiff
path: root/strings/utr11-dump.c
diff options
context:
space:
mode:
authorunknown <bar@mysql.com>2004-08-25 10:15:46 +0500
committerunknown <bar@mysql.com>2004-08-25 10:15:46 +0500
commit51fd9ed41834c324b476e137dbdf34ed8c81983f (patch)
treea3ba6657bd53f12cd806d6f71c78bb5b6e01ab93 /strings/utr11-dump.c
parent340d40a77c87009d83fe360ca00bd5ef0f7b8792 (diff)
downloadmariadb-git-51fd9ed41834c324b476e137dbdf34ed8c81983f.tar.gz
utr11-dump.c:
new file
Diffstat (limited to 'strings/utr11-dump.c')
-rw-r--r--strings/utr11-dump.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/strings/utr11-dump.c b/strings/utr11-dump.c
new file mode 100644
index 00000000000..c1b5a923946
--- /dev/null
+++ b/strings/utr11-dump.c
@@ -0,0 +1,112 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/*
+ Dump an EastAsianWidth.txt file.
+ See http://www.unicode.org/reports/tr11/ for details.
+ Character types:
+ F - Full width = 1
+ H - Half width = 0
+ W - Wide = 1
+ Na - Narrow = 0
+ A - Ambiguous = 0
+ N - Neutral = 0
+*/
+
+
+int main(int ac, char **av)
+{
+ char str[128];
+ int errors= 0;
+ int plane[0x10000];
+ int page[256];
+ int i;
+
+ memset(plane, 0, sizeof(plane));
+ memset(page, 0, sizeof(page));
+
+ while (fgets(str, sizeof(str), stdin))
+ {
+ int code1, code2, width;
+ char *end;
+
+ if (str[0] == '#')
+ continue;
+ code1= strtol(str, &end, 16);
+ if (code1 < 0 || code1 > 0xFFFF)
+ continue;
+ if (end[0] == ';') /* One character */
+ {
+ code2= code1;
+ }
+ else if (end[0] == '.' && end[1] == '.') /* Range */
+ {
+ end+= 2;
+ code2= strtol(end, &end, 16);
+ if (code2 < 0 || code2 > 0xFFFF)
+ continue;
+ if (end[0] != ';')
+ {
+ errors++;
+ fprintf(stderr, "error: %s", str);
+ continue;
+ }
+ }
+ else
+ {
+ errors++;
+ fprintf(stderr, "error: %s", str);
+ continue;
+ }
+
+ end++;
+ width= (end[0] == 'F' || end[0] == 'W') ? 1 : 0;
+
+ for ( ; code1 <= code2; code1++)
+ {
+ plane[code1]= width;
+ }
+ }
+
+ if (errors)
+ return 1;
+
+ for (i=0; i < 256; i++)
+ {
+ int j;
+ int *p= plane + 256 * i;
+ page[i]= 0;
+ for (j=0; j < 256; j++)
+ {
+ page[i]+= p[j];
+ }
+ if (page[i] != 0 && page[i] != 256)
+ {
+ printf("static char pg%02X[256]=\n{\n", i);
+ for (j=0; j < 256; j++)
+ {
+ printf("%d%s%s", p[j], j < 255 ? "," : "", (j + 1) % 32 ? "" : "\n");
+ }
+ printf("};\n\n");
+ }
+ }
+
+ printf("static struct {int page; char *p;} utr11_data[256]=\n{\n");
+ for (i=0; i < 256; i++)
+ {
+ if (page[i] == 0 || page[i] == 256)
+ {
+ int width= (page[i] == 256) ? 1 : 0;
+ printf("{%d,NULL}", width);
+ }
+ else
+ {
+ printf("{0,pg%02X}", i);
+ }
+ printf("%s%s", i < 255 ? "," : "", (i+1) % 8 ? "" : "\n");
+ }
+ printf("};\n");
+ return 0;
+}