cjk_variants.c
Upload User: yingmei828
Upload Date: 2007-01-01
Package Size: 1646k
Code Size: 2k
Development Platform:

Unix_Linux

  1. /*
  2.  * Generates Unicode variants table from Koichi Yasuoka's UniVariants file.
  3.  */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #define ENTRIES  8176  /* number of lines in UniVariants file */
  7. #define MAX_PER_ENTRY  10  /* max number of entries per line in file */
  8. int main (int argc, char *argv[])
  9. {
  10.   int variants[MAX_PER_ENTRY*ENTRIES];
  11.   int uni2index[0x10000];
  12.   int index;
  13.   if (argc != 1)
  14.     exit(1);
  15.   printf("n");
  16.   printf("/*n");
  17.   printf(" * CJK variants tablen");
  18.   printf(" */n");
  19.   printf("n");
  20.   {
  21.     int c;
  22.     int j;
  23.     for (j = 0; j < 0x10000; j++)
  24.       uni2index[j] = -1;
  25.     index = 0;
  26.     for (;;) {
  27.       c = getc(stdin);
  28.       if (c == EOF)
  29.         break;
  30.       if (c == '#') {
  31.         do { c = getc(stdin); } while (!(c == EOF || c == 'n'));
  32.         continue;
  33.       }
  34.       ungetc(c,stdin);
  35.       if (scanf("%x",&j) != 1)
  36.         exit(1);
  37.       c = getc(stdin);
  38.       if (c != 't')
  39.         exit(1);
  40.       uni2index[j] = index;
  41.       for (;;) {
  42.         int i;
  43.         if (scanf("%x",&i) != 1)
  44.           exit(1);
  45.         if (!(i >= 0x3000 && i < 0x3000+0x8000))
  46.           exit(1);
  47.         variants[index++] = i-0x3000;
  48.         c = getc(stdin);
  49.         if (c != ' ')
  50.           break;
  51.       }
  52.       variants[index-1] |= 0x8000; /* end of list marker */
  53.       if (c != 'n')
  54.         exit(1);
  55.     }
  56.   }
  57.   printf("static const unsigned short cjk_variants[%d] = {",index);
  58.   {
  59.     int i;
  60.     for (i = 0; i < index; i++) {
  61.       if ((i % 8) == 0)
  62.         printf("n ");
  63.       printf(" 0x%04x,",variants[i]);
  64.     }
  65.     printf("n};n");
  66.   }
  67.   printf("n");
  68.   printf("static const short cjk_variants_indx[0x5200] = {n");
  69.   {
  70.     int j;
  71.     for (j = 0x4e00; j < 0xa000; j++) {
  72.       if ((j % 0x100) == 0)
  73.         printf("  /* 0x%04x */n", j);
  74.       if ((j % 8) == 0)
  75.         printf(" ");
  76.       printf(" %5d,",uni2index[j]);
  77.       if ((j % 8) == 7)
  78.         printf("n");
  79.     }
  80.     printf("};n");
  81.   }
  82.   printf("n");
  83.   return 0;
  84. }