Header And Logo

PostgreSQL
| The world's most advanced open source database.

win866.c

Go to the documentation of this file.
00001 /*
00002  * make KOI8->CP866(ALT) and CP866(ALT)->KOI8 translation table
00003  * from koi-alt.tab.
00004  *
00005  * Tatsuo Ishii
00006  *
00007  * src/backend/utils/mb/win866.c
00008  */
00009 
00010 #include <stdio.h>
00011 
00012 
00013 main()
00014 {
00015     int         i;
00016     char        koitab[128],
00017                 alttab[128];
00018     char        buf[4096];
00019     int         koi,
00020                 alt;
00021 
00022     for (i = 0; i < 128; i++)
00023         koitab[i] = alttab[i] = 0;
00024 
00025     while (fgets(buf, sizeof(buf), stdin) != NULL)
00026     {
00027         if (*buf == '#')
00028             continue;
00029         sscanf(buf, "%d %d", &koi, &alt);
00030         if (koi < 128 || koi > 255 || alt < 128 || alt > 255)
00031         {
00032             fprintf(stderr, "invalid value %d\n", koi);
00033             exit(1);
00034         }
00035         koitab[koi - 128] = alt;
00036         alttab[alt - 128] = koi;
00037     }
00038 
00039     i = 0;
00040     printf("static char koi2alt[] = {\n");
00041     while (i < 128)
00042     {
00043         int         j = 0;
00044 
00045         while (j < 8)
00046         {
00047             printf("0x%02x", koitab[i++]);
00048             j++;
00049             if (i >= 128)
00050                 break;
00051             printf(", ");
00052         }
00053         printf("\n");
00054     }
00055     printf("};\n");
00056 
00057     i = 0;
00058     printf("static char alt2koi[] = {\n");
00059     while (i < 128)
00060     {
00061         int         j = 0;
00062 
00063         while (j < 8)
00064         {
00065             printf("0x%02x", alttab[i++]);
00066             j++;
00067             if (i >= 128)
00068                 break;
00069             printf(", ");
00070         }
00071         printf("\n");
00072     }
00073     printf("};\n");
00074 }