File: gentable.c

package info (click to toggle)
libydpdict 1.0.4-2
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd
  • size: 200 kB
  • ctags: 74
  • sloc: ansic: 848; makefile: 31; python: 19; sh: 12
file content (58 lines) | stat: -rw-r--r-- 944 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * gentable.c
 *
 * Generates windows-1250 to utf-8 conversion table with iconv. Character
 * "ď" from the resulting table has to be modified to "ï" (used in the word
 * "naïve") and "ŕ" to "à" (in "à propos").
 *
 * $Id$
 */

#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int main(void)
{
	iconv_t cd;
	int i;

	cd = iconv_open("utf-8", "windows-1250");

	if (cd == (iconv_t)(-1)) {
		perror("iconv_open");
		exit(1);
	}

	for (i = 128; i < 256; i++) {
		char inbuf[2], outbuf[16], *in, *out;
		size_t inbytes, outbytes, res;

		inbuf[0] = i;
		inbuf[1] = 0;
		inbytes = 1;
		in = inbuf;

		outbuf[0] = 0;
		outbytes = sizeof(outbuf) - 1;
		out = outbuf;

		res = iconv(cd, &in, &inbytes, &out, &outbytes);
		*out = 0;

		if ((i % 8) == 0)
			printf("\t");
		
		if (res == (size_t)(-1))
			printf("\"?\", ");
		else
			printf("\"%s\", ", outbuf);

		if ((i % 8) == 7)
			printf("\n");
	}

	iconv_close(cd);

	return 0;
}