Header And Logo

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

Functions

win866.c File Reference

#include <stdio.h>
Include dependency graph for win866.c:

Go to the source code of this file.

Functions

 main ()

Function Documentation

main ( void   ) 

Definition at line 13 of file win866.c.

References buf, i, and NULL.

{
    int         i;
    char        koitab[128],
                alttab[128];
    char        buf[4096];
    int         koi,
                alt;

    for (i = 0; i < 128; i++)
        koitab[i] = alttab[i] = 0;

    while (fgets(buf, sizeof(buf), stdin) != NULL)
    {
        if (*buf == '#')
            continue;
        sscanf(buf, "%d %d", &koi, &alt);
        if (koi < 128 || koi > 255 || alt < 128 || alt > 255)
        {
            fprintf(stderr, "invalid value %d\n", koi);
            exit(1);
        }
        koitab[koi - 128] = alt;
        alttab[alt - 128] = koi;
    }

    i = 0;
    printf("static char koi2alt[] = {\n");
    while (i < 128)
    {
        int         j = 0;

        while (j < 8)
        {
            printf("0x%02x", koitab[i++]);
            j++;
            if (i >= 128)
                break;
            printf(", ");
        }
        printf("\n");
    }
    printf("};\n");

    i = 0;
    printf("static char alt2koi[] = {\n");
    while (i < 128)
    {
        int         j = 0;

        while (j < 8)
        {
            printf("0x%02x", alttab[i++]);
            j++;
            if (i >= 128)
                break;
            printf(", ");
        }
        printf("\n");
    }
    printf("};\n");
}