[BZ #4745]
[glibc.git] / localedata / show-ucs-data.c
blob9992ece427dbd2638584d698837db4bf59827fc4
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/types.h>
6 int
7 main (int argc, char *argv[])
9 int n;
10 char *line = NULL;
11 size_t len = 0;
13 for (n = 1; n < argc; ++n)
15 FILE *fp = fopen (argv[n], "r");
16 if (fp == NULL)
17 continue;
19 while (! feof (fp))
21 ssize_t cnt = getline (&line, &len, fp);
22 char *runp;
23 if (cnt <= 0)
24 break;
26 runp = line;
29 if (runp[0] == '<' && runp[1] == 'U' && isxdigit (runp[2])
30 && isxdigit (runp[3]) && isxdigit (runp[4])
31 && isxdigit (runp[5]) && runp[6] == '>')
33 unsigned int val = strtoul (runp + 2, NULL, 16);
35 //putchar ('<');
36 if (val < 128)
37 putchar (val);
38 else if (val < 0x800)
40 putchar (0xc0 | (val >> 6));
41 putchar (0x80 | (val & 0x3f));
43 else
45 putchar (0xe0 | (val >> 12));
46 putchar (0x80 | ((val >> 6) & 0x3f));
47 putchar (0x80 | (val & 0x3f));
49 //putchar ('>');
50 runp += 7;
52 else
53 putchar (*runp++);
55 while (runp < &line[cnt]);
58 fclose (fp);
61 return 0;