From 7988979a722b4cdf287b2093956a76a3f19b9897 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Mon, 24 Oct 2016 20:22:12 +0200 Subject: add uClibc-ng test directory --- test/locale/show-ucs-data.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 test/locale/show-ucs-data.c (limited to 'test/locale/show-ucs-data.c') diff --git a/test/locale/show-ucs-data.c b/test/locale/show-ucs-data.c new file mode 100644 index 0000000..9992ece --- /dev/null +++ b/test/locale/show-ucs-data.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +int +main (int argc, char *argv[]) +{ + int n; + char *line = NULL; + size_t len = 0; + + for (n = 1; n < argc; ++n) + { + FILE *fp = fopen (argv[n], "r"); + if (fp == NULL) + continue; + + while (! feof (fp)) + { + ssize_t cnt = getline (&line, &len, fp); + char *runp; + if (cnt <= 0) + break; + + runp = line; + do + { + if (runp[0] == '<' && runp[1] == 'U' && isxdigit (runp[2]) + && isxdigit (runp[3]) && isxdigit (runp[4]) + && isxdigit (runp[5]) && runp[6] == '>') + { + unsigned int val = strtoul (runp + 2, NULL, 16); + + //putchar ('<'); + if (val < 128) + putchar (val); + else if (val < 0x800) + { + putchar (0xc0 | (val >> 6)); + putchar (0x80 | (val & 0x3f)); + } + else + { + putchar (0xe0 | (val >> 12)); + putchar (0x80 | ((val >> 6) & 0x3f)); + putchar (0x80 | (val & 0x3f)); + } + //putchar ('>'); + runp += 7; + } + else + putchar (*runp++); + } + while (runp < &line[cnt]); + } + + fclose (fp); + } + + return 0; +} -- cgit v1.2.3