~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/utils/mb/alt.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * make KOI8->CP866(ALT) and CP866(ALT)->KOI8 translation table
 
3
 * from koi-alt.tab.
 
4
 *
 
5
 * Tatsuo Ishii
 
6
 *
 
7
 * $PostgreSQL: pgsql/src/backend/utils/mb/alt.c,v 1.4 2003-11-29 22:39:59 pgsql Exp $
 
8
 */
 
9
 
 
10
#include <stdio.h>
 
11
 
 
12
 
 
13
main()
 
14
{
 
15
        int                     i;
 
16
        char            koitab[128],
 
17
                                alttab[128];
 
18
        char            buf[4096];
 
19
        int                     koi,
 
20
                                alt;
 
21
 
 
22
        for (i = 0; i < 128; i++)
 
23
                koitab[i] = alttab[i] = 0;
 
24
 
 
25
        while (fgets(buf, sizeof(buf), stdin) != NULL)
 
26
        {
 
27
                if (*buf == '#')
 
28
                        continue;
 
29
                sscanf(buf, "%d %d", &koi, &alt);
 
30
                if (koi < 128 || koi > 255 || alt < 128 || alt > 255)
 
31
                {
 
32
                        fprintf(stderr, "invalid value %d\n", koi);
 
33
                        exit(1);
 
34
                }
 
35
                koitab[koi - 128] = alt;
 
36
                alttab[alt - 128] = koi;
 
37
        }
 
38
 
 
39
        i = 0;
 
40
        printf("static char koi2alt[] = {\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 alt2koi[] = {\n");
 
59
        while (i < 128)
 
60
        {
 
61
                int                     j = 0;
 
62
 
 
63
                while (j < 8)
 
64
                {
 
65
                        printf("0x%02x", alttab[i++]);
 
66
                        j++;
 
67
                        if (i >= 128)
 
68
                                break;
 
69
                        printf(", ");
 
70
                }
 
71
                printf("\n");
 
72
        }
 
73
        printf("};\n");
 
74
}