PostgreSQL Source Code  git master
iso.c
Go to the documentation of this file.
1 /*
2  * make KOI8->ISO8859-5 and ISO8859-5->KOI8 translation table
3  * from koi-iso.tab.
4  *
5  * Tatsuo Ishii
6  *
7  * src/backend/utils/mb/iso.c
8  */
9 
10 #include <stdio.h>
11 
12 
14 {
15  int i;
16  char koitab[128],
17  isotab[128];
18  char buf[4096];
19  int koi,
20  iso;
21 
22  for (i = 0; i < 128; i++)
23  koitab[i] = isotab[i] = 0;
24 
25  while (fgets(buf, sizeof(buf), stdin) != NULL)
26  {
27  if (*buf == '#')
28  continue;
29  sscanf(buf, "%d %x", &koi, &iso);
30  if (koi < 128 || koi > 255 || iso < 128 || iso > 255)
31  {
32  fprintf(stderr, "invalid value %d\n", koi);
33  exit(1);
34  }
35  koitab[koi - 128] = iso;
36  isotab[iso - 128] = koi;
37  }
38 
39  i = 0;
40  printf("static char koi2iso[] = {\n");
41  while (i < 128)
42  {
43  int j = 0;
44 
45  while (j < 8)
46  {
47  printf("0x%02x", koitab[i++]);
48  j++;
49  if (i >= 128)
50  break;
51  printf(", ");
52  }
53  printf("\n");
54  }
55  printf("};\n");
56 
57  i = 0;
58  printf("static char iso2koi[] = {\n");
59  while (i < 128)
60  {
61  int j = 0;
62 
63  while (j < 8)
64  {
65  printf("0x%02x", isotab[i++]);
66  j++;
67  if (i >= 128)
68  break;
69  printf(", ");
70  }
71  printf("\n");
72  }
73  printf("};\n");
74 }
int j
Definition: isn.c:74
int i
Definition: isn.c:73
main()
Definition: iso.c:13
exit(1)
static char * buf
Definition: pg_test_fsync.c:73
#define fprintf
Definition: port.h:242
#define printf(...)
Definition: port.h:244