Sync to latest upstream
[pcsx_rearmed.git] / deps / flac-1.3.2 / src / share / utf8 / makemap.c
CommitLineData
ce188d4d 1/*
2 * Copyright (C) 2001 Edmund Grimley Evans <edmundo@rano.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#endif
22
23#include <errno.h>
24#include <iconv.h>
25#include <stdio.h>
26
27int main(int argc, char *argv[])
28{
29 iconv_t cd;
30 const char *ib;
31 char *ob;
32 size_t ibl, obl, k;
33 unsigned char c, buf[4];
34 int i, wc;
35
36 if (argc != 2) {
37 printf("Usage: %s ENCODING\n", argv[0]);
38 printf("Output a charset map for the 8-bit ENCODING.\n");
39 return 1;
40 }
41
42 cd = iconv_open("UCS-4", argv[1]);
43 if (cd == (iconv_t)(-1)) {
44 perror("iconv_open");
45 return 1;
46 }
47
48 for (i = 0; i < 256; i++) {
49 c = i;
50 ib = &c;
51 ibl = 1;
52 ob = buf;
53 obl = 4;
54 k = iconv(cd, &ib, &ibl, &ob, &obl);
55 if (!k && !ibl && !obl) {
56 wc = (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
57 if (wc >= 0xffff) {
58 printf("Dodgy value.\n");
59 return 1;
60 }
61 }
62 else if (k == (size_t)(-1) && errno == EILSEQ)
63 wc = 0xffff;
64 else {
65 printf("Non-standard iconv.\n");
66 return 1;
67 }
68
69 if (i % 8 == 0)
70 printf(" ");
71 printf("0x%04x", wc);
72 if (i == 255)
73 printf("\n");
74 else if (i % 8 == 7)
75 printf(",\n");
76 else
77 printf(", ");
78 }
79
80 return 0;
81}