Annotation of embedaddon/libiconv/tools/cjk_variants.c, revision 1.1.1.2

1.1.1.2 ! misho       1: /* Copyright (C) 1999-2002, 2012, 2018 Free Software Foundation, Inc.
1.1       misho       2:    This file is part of the GNU LIBICONV Tools.
                      3: 
                      4:    This program is free software: you can redistribute it and/or modify
                      5:    it under the terms of the GNU General Public License as published by
                      6:    the Free Software Foundation; either version 3 of the License, or
                      7:    (at your option) any later version.
                      8: 
                      9:    This program is distributed in the hope that it will be useful,
                     10:    but WITHOUT ANY WARRANTY; without even the implied warranty of
                     11:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     12:    GNU General Public License for more details.
                     13: 
                     14:    You should have received a copy of the GNU General Public License
1.1.1.2 ! misho      15:    along with this program; if not, see <https://www.gnu.org/licenses/>.  */
1.1       misho      16: 
                     17: /*
                     18:  * Generates Unicode variants table from Koichi Yasuoka's UniVariants file.
                     19:  */
                     20: 
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: 
                     24: #define ENTRIES  8176  /* number of lines in UniVariants file */
                     25: #define MAX_PER_ENTRY  10  /* max number of entries per line in file */
                     26: 
                     27: int main (int argc, char *argv[])
                     28: {
                     29:   int variants[MAX_PER_ENTRY*ENTRIES];
                     30:   int uni2index[0x10000];
                     31:   int index;
                     32: 
                     33:   if (argc != 1)
                     34:     exit(1);
                     35: 
                     36:   printf("/*\n");
                     37:   printf(" * Copyright (C) 1999-2002 Free Software Foundation, Inc.\n");
                     38:   printf(" * This file is part of the GNU LIBICONV Library.\n");
                     39:   printf(" *\n");
                     40:   printf(" * The GNU LIBICONV Library is free software; you can redistribute it\n");
                     41:   printf(" * and/or modify it under the terms of the GNU Library General Public\n");
                     42:   printf(" * License as published by the Free Software Foundation; either version 2\n");
                     43:   printf(" * of the License, or (at your option) any later version.\n");
                     44:   printf(" *\n");
                     45:   printf(" * The GNU LIBICONV Library is distributed in the hope that it will be\n");
                     46:   printf(" * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
                     47:   printf(" * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n");
                     48:   printf(" * Library General Public License for more details.\n");
                     49:   printf(" *\n");
                     50:   printf(" * You should have received a copy of the GNU Library General Public\n");
                     51:   printf(" * License along with the GNU LIBICONV Library; see the file COPYING.LIB.\n");
1.1.1.2 ! misho      52:   printf(" * If not, see <https://www.gnu.org/licenses/>.\n");
1.1       misho      53:   printf(" */\n");
                     54:   printf("\n");
                     55:   printf("/*\n");
                     56:   printf(" * CJK variants table\n");
                     57:   printf(" */\n");
                     58:   printf("\n");
                     59:   {
                     60:     int c;
                     61:     int j;
                     62:     for (j = 0; j < 0x10000; j++)
                     63:       uni2index[j] = -1;
                     64:     index = 0;
                     65:     for (;;) {
                     66:       c = getc(stdin);
                     67:       if (c == EOF)
                     68:         break;
                     69:       if (c == '#') {
                     70:         do { c = getc(stdin); } while (!(c == EOF || c == '\n'));
                     71:         continue;
                     72:       }
                     73:       ungetc(c,stdin);
                     74:       if (scanf("%x",&j) != 1)
                     75:         exit(1);
                     76:       c = getc(stdin);
                     77:       if (c != '\t')
                     78:         exit(1);
                     79:       uni2index[j] = index;
                     80:       for (;;) {
                     81:         int i;
                     82:         if (scanf("%x",&i) != 1)
                     83:           exit(1);
                     84:         if (!(i >= 0x3000 && i < 0x3000+0x8000))
                     85:           exit(1);
                     86:         variants[index++] = i-0x3000;
                     87:         c = getc(stdin);
                     88:         if (c != ' ')
                     89:           break;
                     90:       }
                     91:       variants[index-1] |= 0x8000; /* end of list marker */
                     92:       if (c != '\n')
                     93:         exit(1);
                     94:     }
                     95:   }
                     96:   printf("static const unsigned short cjk_variants[%d] = {",index);
                     97:   {
                     98:     int i;
                     99:     for (i = 0; i < index; i++) {
                    100:       if ((i % 8) == 0)
                    101:         printf("\n ");
                    102:       printf(" 0x%04x,",variants[i]);
                    103:     }
                    104:     printf("\n};\n");
                    105:   }
                    106:   printf("\n");
                    107:   printf("static const short cjk_variants_indx[0x5200] = {\n");
                    108:   {
                    109:     int j;
                    110:     for (j = 0x4e00; j < 0xa000; j++) {
                    111:       if ((j % 0x100) == 0)
                    112:         printf("  /* 0x%04x */\n", j);
                    113:       if ((j % 8) == 0)
                    114:         printf(" ");
                    115:       printf(" %5d,",uni2index[j]);
                    116:       if ((j % 8) == 7)
                    117:         printf("\n");
                    118:     }
                    119:     printf("};\n");
                    120:   }
                    121:   printf("\n");
                    122: 
                    123:   return 0;
                    124: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>