Header And Logo

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

win1251.c

Go to the documentation of this file.
00001 /*
00002  * make KOI8->CP1251(win-1251) and CP1251(win-1251)->KOI8 translation table
00003  * from koi-win.tab.
00004  *
00005  * Tatsuo Ishii
00006  *
00007  * src/backend/utils/mb/win1251.c
00008  */
00009 
00010 #include <stdio.h>
00011 
00012 
00013 main()
00014 {
00015     int         i;
00016     char        koitab[128],
00017                 wintab[128];
00018     char        buf[4096];
00019     int         koi,
00020                 win;
00021 
00022     for (i = 0; i < 128; i++)
00023         koitab[i] = wintab[i] = 0;
00024 
00025     while (fgets(buf, sizeof(buf), stdin) != NULL)
00026     {
00027         if (*buf == '#')
00028             continue;
00029         sscanf(buf, "%d %d", &koi, &win);
00030         if (koi < 128 || koi > 255 || win < 128 || win > 255)
00031         {
00032             fprintf(stderr, "invalid value %d\n", koi);
00033             exit(1);
00034         }
00035         koitab[koi - 128] = win;
00036         wintab[win - 128] = koi;
00037     }
00038 
00039     i = 0;
00040     printf("static char koi2win[] = {\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 win2koi[] = {\n");
00059     while (i < 128)
00060     {
00061         int         j = 0;
00062 
00063         while (j < 8)
00064         {
00065             printf("0x%02x", wintab[i++]);
00066             j++;
00067             if (i >= 128)
00068                 break;
00069             printf(", ");
00070         }
00071         printf("\n");
00072     }
00073     printf("};\n");
00074 }