home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / j_tools.zip / jchar.c next >
C/C++ Source or Header  |  1998-01-14  |  37KB  |  1,027 lines

  1. /*
  2. Program: jchar.c
  3. Version: 3.0
  4. Date:    July 1, 1993
  5. Author:  Ken R. Lunde, Adobe Systems Incorporated
  6.   EMAIL: lunde@mv.us.adobe.com
  7.   MAIL : 1585 Charleston Road, P.O. Box 7900, Mountain View, CA 94039-7900
  8. Type:    A tool for generating various Japanese character sets.
  9. Code:    ANSI C (portable)
  10.  
  11. PORTABILITY:
  12. This source code was written so that it would be portable on C compilers which
  13. conform to the ANSI C standard. It has been tested on a variety of compilers.
  14.  
  15. I used THINK C and GNU C as my development platforms. I left in the Macintosh-
  16. specific lines of code so that it would be easier to enhance/debug this tool
  17. later. For those of you who wish to use this tool on the Macintosh, simply
  18. add the ANSI library to the THINK C project, and then build the application.
  19. Be sure that THINK_C has been defined, though, as the conditional compilation
  20. depends on it. You then have a double-clickable application, which when
  21. launched, will greet you with a Macintosh-style interface.
  22.  
  23. DISTRIBUTION AND RESTRICTIONS ON USAGE:
  24.  1) Please give this source code away to your friends at no charge.
  25.  2) Please try to compile this source code on various platforms to check for
  26.     portablity, and please report back to me with any results be they good or
  27.     bad. Suggestions are always welcome.
  28.  3) This source code or a compiled version may be bundled with commercial
  29.     software as long as the author is notified beforehand. The author's name
  30.     should also be mentioned in the credits.
  31.  4) Feel free to use any of the algorithms for your own work. Many of them are
  32.     being used in other tools I have written.
  33.  5) The most current version can be obtained by requesting a copy directly
  34.     from me.
  35.  
  36. DESCRIPTION:
  37.  1) Supports Shift-JIS, EUC, New-JIS, Old-JIS, and NEC-JIS codes for output.
  38.  2) This tool generates half-width katakana in both Shift-JIS and EUC codes.
  39.  3) The printable ASCII character set, the 1945 Joyo Kanji, the 284
  40.     Jinmei-yo Kanji, and the 1006 Gakushu Kanji can be generated.
  41.  4) In the case of JIS X 0208-1990, the row number is given before the row.
  42.  5) In the case of Gakushu Kanji, the list is separated into the 6 grade
  43.     levels.
  44.  6) One can choose whether to have the text wrap, and at how many columns.
  45. */
  46.  
  47. #ifdef THINK_C
  48. #include <console.h>
  49. #include <stdlib.h>
  50. #endif
  51. #include <stdio.h>
  52. #include <string.h>
  53. #include <ctype.h>
  54.  
  55. #define NOTSET           0
  56. #define FALSE            0
  57. #define TRUE             1
  58. #define NEW              1
  59. #define OLD              2
  60. #define NEC              3
  61. #define EUC              4
  62. #define SJIS             5
  63. #define ASCII            6
  64. #define KUTEN_OFFSET     32
  65. #define ASCII_ZERO       48
  66. #define JIS_START        33
  67. #define JIS_END          126
  68. #define ASCII_START      33
  69. #define ASCII_END        126
  70. #define HW_KANA_START    161
  71. #define HW_KANA_END      223
  72. #define EUC_START        161
  73. #define EUC_END          254
  74. #define JOYO_TOTAL       1945
  75. #define JINMEIYO_TOTAL   284
  76. #define GAKUSHU_TOTAL    1006
  77. #define DEFAULT_MAX      78
  78. #define FIRSTBYTE(val)   (((val) / 100) + KUTEN_OFFSET)
  79. #define SECONDBYTE(val)  (((val) % 100) + KUTEN_OFFSET)
  80. #define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
  81. /* The following 3 lines of code are used to establish the default output codes
  82.  * when using the "-o[CODE]" option. They are self-explanatory, and easy to
  83.  * change.
  84.  */
  85. #define DEFAULT          SJIS     /* default output code */
  86. #define DEFAULT_KI       ""       /* default kanji-in code */
  87. #define DEFAULT_KO       ""       /* default kanji-out code */
  88.  
  89. void printASCII(FILE *out,int wrap,int max,int suppress);
  90. void printJIS(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress);
  91. void printEUC(FILE *out,int wrap,int max,int suppress);
  92. void printSJIS(FILE *out,int wrap,int max,int suppress);
  93. void printJOYO(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress);
  94. void printJINMEI(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress);
  95. void printGAKUSHU(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress);
  96. void jis2sjis(int *p1,int *p2);
  97. void dohelp(char toolname[]);
  98. int toup(int data);
  99. int getoutcode(int data,char ki[],char ko[]);
  100. #ifdef THINK_C
  101. int ccommand(char ***p);
  102. #endif
  103.  
  104. void main(int argc,char **argv)
  105. {
  106.   FILE *out;
  107.   int y,max,suppress = FALSE;
  108.   int makejinmei = FALSE,makejis = FALSE,makeascii = FALSE,makejoyo = FALSE;
  109.   int usersetcol = FALSE,wrap = FALSE,outcode = NOTSET,select = FALSE,makegakushu = FALSE;
  110.   char outfilename[100],ki[10],ko[10],toolname[100];
  111.  
  112. #ifdef THINK_C
  113.   argc = ccommand(&argv);
  114. #endif
  115.  
  116.   strcpy(toolname,*argv);
  117.   while (--argc > 0 && (*++argv)[0] == '-')
  118.     switch (toup(*++argv[0])) {
  119.       case 'A' :
  120.         makeascii = select = TRUE;
  121.         break;
  122.       case 'G' :
  123.         makegakushu = select = TRUE;
  124.         break;
  125.       case 'H' :
  126.         dohelp(toolname);
  127.         break;
  128.       case 'J' :
  129.         makejoyo = select = TRUE;
  130.         break;
  131.       case 'K' :
  132.         makejis = select = TRUE;
  133.         break;
  134.       case 'O' :
  135.         outcode = getoutcode(toup(*++argv[0]),ki,ko);
  136.         break;
  137.       case 'P' :
  138.         makejinmei = select = TRUE;
  139.         break;
  140.       case 'S' :
  141.         suppress = TRUE;
  142.         break;
  143.       case 'W' :
  144.         max = y = 0;
  145.         wrap = TRUE;
  146.         if (*++argv[0] != '\0') {
  147.           usersetcol = TRUE;
  148.           while (argv[0][y] != '\0' && argv[0][y] >= '0' && argv[0][y] <= '9')
  149.             max = (max * 10) + (argv[0][y++] - ASCII_ZERO);
  150.         }
  151.         break;
  152.       default :
  153.         fprintf(stderr,"Illegal option \"-%c\"! Try using the \"-h\" option for help.\n",*argv[0]);
  154.         fprintf(stderr,"Usage: %s [-options] [outfile]\nExiting...\n",toolname);
  155.         exit(1);
  156.         break;
  157.     }
  158.   if (outcode == NOTSET) {
  159.     strcpy(ki,DEFAULT_KI);
  160.     strcpy(ko,DEFAULT_KO);
  161.     outcode = DEFAULT;
  162.   }
  163.   if (!select)
  164.     makejis = TRUE;
  165.   if (wrap && !usersetcol)
  166.     max = DEFAULT_MAX;
  167.   if (argc == 0)
  168.     out = stdout;
  169.   else if (argc > 0) {
  170.     strcpy(outfilename,*argv);
  171.     if ((out = fopen(outfilename,"w")) == NULL) {
  172.       fprintf(stderr,"Cannot open %s! Exiting...\n",outfilename);
  173.       exit(1);
  174.     }
  175.   }
  176.   if (makeascii)
  177.     printASCII(out,wrap,max,suppress);
  178.   if (makejinmei)
  179.     printJINMEI(out,outcode,wrap,max,ki,ko,suppress);
  180.   if (makejoyo)
  181.     printJOYO(out,outcode,wrap,max,ki,ko,suppress);
  182.   if (makegakushu)
  183.     printGAKUSHU(out,outcode,wrap,max,ki,ko,suppress);
  184.   if (makejis) {
  185.     if (!suppress)
  186.       fprintf(out,"JIS X 0208-1990\n\n");
  187.     switch (outcode) {
  188.       case NEW :
  189.       case OLD :
  190.       case NEC :
  191.         printJIS(out,outcode,wrap,max,ki,ko,suppress);
  192.         break;
  193.       case EUC :
  194.         printEUC(out,wrap,max,suppress);
  195.         break;
  196.       case SJIS :
  197.         printSJIS(out,wrap,max,suppress);
  198.         break;
  199.     }
  200.   }
  201.   exit(0);
  202. }
  203.  
  204. int toup(int data)
  205. {
  206.   if (islower(data))
  207.     return (toupper(data));
  208.   else
  209.     return data;
  210. }
  211.  
  212. int getoutcode(int data,char ki[],char ko[])
  213. {
  214.   if (data == 'E')
  215.     return EUC;
  216.   else if (data == 'S')
  217.     return SJIS;
  218.   else if (data == 'J') {
  219.     strcpy(ki,"\033$B");
  220.     strcpy(ko,"\033(J");
  221.     return NEW;
  222.   }
  223.   else if (data == 'O') {
  224.     strcpy(ki,"\033$@");
  225.     strcpy(ko,"\033(J");
  226.     return OLD;
  227.   }
  228.   else if (data == 'N') {
  229.     strcpy(ki,"\033K");
  230.     strcpy(ko,"\033H");
  231.     return NEC;
  232.   }
  233.   else
  234.     return NOTSET;
  235. }
  236.  
  237. void dohelp(char toolname[])
  238. {
  239.   printf("** %s v3.0 (July 1, 1993) **\n\n",toolname);
  240.   printf("Written by Ken R. Lunde, Adobe Systems Incorporated\nlunde@mv.us.adobe.com\n\n");
  241.   printf("Usage: %s [-options] [outfile]\n\n",toolname);
  242.   printf("Tool description: This tool is a utility for generating various Japanese\n");
  243.   printf("character sets in any code. This includes all the characters specified in\n");
  244.   printf("JIS X 0208-1990, half-width katakana (EUC and Shift-JIS output only), the\n");
  245.   printf("94 printable ASCII/JIS-Roman characters, the 1945 Joyo Kanji, the 284\n");
  246.   printf("Jinmei-yo Kanji, and the 1006 Gakushu Kanji.\n\n");
  247.   printf("Options include:\n\n");
  248.   printf("  -a        Builds an ASCII/JIS-Roman list (printable characters only)\n");
  249.   printf("  -g        Builds the Gakushu Kanji list\n");
  250.   printf("  -h        Displays this help page, then exits\n");
  251.   printf("  -j        Builds the Joyo Kanji list\n");
  252.   printf("  -k        Builds the JIS X 0208-1990 list\n");
  253.   printf("  -o[CODE]  Builds lists in CODE format (default is Shift-JIS if this option\n");
  254.   printf("            is not specified, if CODE is not specified, or if CODE is invalid)\n");
  255.   printf("  -p        Builds the Jinmei-yo Kanji list\n");
  256.   printf("  -s        Suppresses headers and row number information\n");
  257.   printf("  -w[NUM]   Wraps output lines at NUM columns (if NUM is not specified, 78\n");
  258.   printf("            is used as the default value)\n\n");
  259.   printf("NOTE: CODE has five possible values: \"e\" = EUC; \"s\" = Shift-JIS;\n");
  260.   printf("      \"j\" = New-JIS; \"o\" = Old-JIS; and \"n\" = NEC-JIS\n\n");
  261.   exit(0);
  262. }
  263.  
  264. void printASCII(FILE *out,int wrap,int max,int suppress)
  265. {
  266.   int i,column = 0;
  267.  
  268.   if (!suppress)
  269.     fprintf(out,"ASCII/JIS-Roman\n\n");
  270.   for (i = ASCII_START;i <= ASCII_END;fprintf(out,"%c",i),column++,i++)
  271.     if (wrap)
  272.       if (column >= max) {
  273.         fprintf(out,"\n");
  274.         column = 0;
  275.       }
  276.   fprintf(out,"\n");
  277. }
  278.  
  279. void printJIS(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress)
  280. {
  281.   int i,j,column = 0;
  282.  
  283.   for (i = JIS_START;i <= JIS_END;i++) {
  284.     if (i == JIS_START && !suppress)
  285.       fprintf(out,"Row number %1d:\n",(i - KUTEN_OFFSET));
  286.     else if (i > JIS_START && !suppress)
  287.       fprintf(out,"\nRow number %1d:\n",(i - KUTEN_OFFSET));
  288.     if (!suppress || i == JIS_START)
  289.       switch (outcode) {
  290.         case NEW :
  291.         case OLD :
  292.         case NEC :
  293.           fprintf(out,"%s",ki);
  294.           break;
  295.         default :
  296.           break;
  297.       }
  298.     for (j = JIS_START;j <= JIS_END;fprintf(out,"%c%c",i,j),column += 2,j++) {
  299.       if (wrap)
  300.         if (column >= max) {
  301.           switch (outcode) {
  302.             case NEW :
  303.             case OLD :
  304.             case NEC :
  305.               fprintf(out,"%s\n%s",ko,ki);
  306.               break;
  307.             default :
  308.               break;
  309.           }
  310.           column = 0;
  311.         }
  312.     }
  313.     if (!suppress) {
  314.       switch (outcode) {
  315.         case NEW :
  316.         case OLD :
  317.         case NEC :
  318.          fprintf(out,"%s",ko);
  319.          break;
  320.         default :
  321.          break;
  322.       }
  323.       column = 0;
  324.     }
  325.   }
  326.   if (suppress)
  327.     fprintf(out,"%s\n",ko);
  328.   else
  329.     fprintf(out,"\n");
  330. }
  331.  
  332. void printEUC(FILE *out,int wrap,int max,int suppress)
  333. {
  334.   int i,j,column = 0;
  335.  
  336.   for (i = EUC_START;i <= EUC_END;i++) {
  337.     if (i > EUC_START && !suppress)
  338.       fprintf(out,"\n");
  339.     if (!suppress)
  340.       fprintf(out,"Row number %1d:\n",(i - 160));
  341.     for (j = EUC_START;j <= EUC_END;fprintf(out,"%c%c",i,j),column += 2,j++)
  342.       if (wrap)
  343.         if (column >= max) {
  344.           fprintf(out,"\n");
  345.           column = 0;
  346.         }
  347.     if (!suppress)
  348.       column = 0;
  349.   }
  350.   column = 0;
  351.   fprintf(out,"\n");
  352.   if (!suppress)
  353.     fprintf(out,"Half-width katakana:\n");
  354.   for (i = HW_KANA_START;i <= HW_KANA_END;fprintf(out,"%c%c",142,i),column++,i++)
  355.     if (wrap)
  356.       if (column >= max) {
  357.         fprintf(out,"\n");
  358.         column = 0;
  359.       }
  360.   fprintf(out,"\n");
  361. }
  362.  
  363. void printSJIS(FILE *out,int wrap,int max,int suppress)
  364. {
  365.   int i,j = 64,count = 1,column = 0;
  366.  
  367.   if (!suppress)
  368.     fprintf(out,"Row number %1d:\n",count);
  369.   for (i = 129;i <= 159;i++) {
  370.     for (j = 64;j <= 252;j++) {
  371.       if (j != 127) {
  372.         fprintf(out,"%c%c",i,j);
  373.         column += 2;
  374.         if (wrap)
  375.           if (column >= max) {
  376.             fprintf(out,"\n");
  377.             column = 0;
  378.           }
  379.       }
  380.       if (j == 158 || j == 252) {
  381.         count++;
  382.         if (!suppress) {
  383.           column = 0;
  384.           fprintf(out,"\nRow number %1d:\n",count);
  385.         }
  386.       }
  387.     }
  388.     if (!suppress)
  389.       column = 0;
  390.   }
  391.   j = 64;
  392.   for (i = 224;i <= 239;i++) {
  393.     for (j = 64;j <= 252;j++) {
  394.       if (j != 127) {
  395.         fprintf(out,"%c%c",i,j);
  396.         column += 2;
  397.         if (wrap)
  398.           if (column >= max) {
  399.             fprintf(out,"\n");
  400.             column = 0;
  401.           }
  402.       }
  403.       if (j == 158 || j == 252) {
  404.         count++;
  405.         if (count <= 94 && !suppress) {
  406.           column = 0;
  407.           fprintf(out,"\nRow number %1d:\n",count);
  408.         }
  409.       }
  410.     }
  411.     if (!suppress)
  412.       column = 0;
  413.   }
  414.   column = 0;
  415.   fprintf(out,"\n");
  416.   if (!suppress)
  417.     fprintf(out,"Half-width katakana:\n");
  418.   for (i = HW_KANA_START;i <= HW_KANA_END;fprintf(out,"%c",i),column++,i++)
  419.     if (wrap)
  420.       if (column >= max) {
  421.         fprintf(out,"\n");
  422.         column = 0;
  423.       }
  424.   fprintf(out,"\n");
  425. }
  426.  
  427. void printJINMEI(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress)
  428. {
  429.   int p1,p2,i,column = 0;
  430.   static unsigned short pk[] = {
  431.     1604,1610,1611,1615,1616,1620,1628,1629,1630,1641,
  432.     1643,1652,1671,1674,1675,1684,1693,1712,1715,1720,
  433.     1735,1745,1780,1781,1787,1802,1832,1837,1856,1866,
  434.     1901,1914,1930,1980,1982,1989,1993,2006,2048,2064,
  435.     2076,2082,2103,2109,2121,2135,2139,2144,2192,2209,
  436.     2212,2238,2245,2251,2253,2254,2260,2262,2274,2275,
  437.     2280,2307,2310,2322,2329,2337,2343,2393,2430,2453,
  438.     2455,2464,2467,2472,2474,2481,2486,2508,2516,2523,
  439.     2524,2532,2541,2567,2623,2627,2628,2632,2640,2651,
  440.     2667,2683,2691,2709,2724,2804,2812,2814,2815,2837,
  441.     2851,2907,2952,2955,2956,2957,2963,2970,2976,2977,
  442.     2990,3017,3025,3027,3031,3052,3054,3071,3087,3124,
  443.     3126,3133,3160,3173,3180,3183,3187,3257,3354,3358,
  444.     3378,3379,3383,3433,3467,3468,3475,3479,3486,3494,
  445.     3504,3507,3522,3541,3550,3586,3610,3619,3639,3648,
  446.     3653,3656,3661,3665,3680,3685,3687,3746,3803,3820,
  447.     3823,3850,3851,3855,3856,3864,3865,3868,3872,3879,
  448.     3890,3921,3923,3935,3975,4005,4023,4027,4069,4076,
  449.     4093,4102,4107,4118,4123,4143,4171,4186,4189,4243,
  450.     4267,4269,4294,4308,4317,4318,4351,4374,4379,4382,
  451.     4391,4406,4413,4426,4450,4473,4474,4477,4479,4487,
  452.     4504,4508,4514,4515,4520,4524,4544,4552,4554,4558,
  453.     4582,4585,4586,4591,4592,4594,4628,4631,4638,4639,
  454.     4642,4643,4654,4659,4660,4666,4670,4671,4672,4701,
  455.     4704,4729,4733,4743,4850,5006,5287,5437,5534,5869,
  456.     5871,5879,5880,5886,5957,6031,6160,6211,6213,6270,
  457.     6291,6326,6389,6402,6486,6611,6640,6789,6926,6937,
  458.     7038,7091,7193,7229,7233,7546,7557,7666,7776,8083,
  459.     8105,8353,8405,8406 };
  460.  
  461.   if (JINMEIYO_TOTAL != ARRAYSIZE(pk)) {
  462.     fprintf(stderr,"Incomplete data structure for Jinmei-yo Kanji list! Exiting...\n");
  463.     exit(1);
  464.   }
  465.   if (!suppress) {
  466.     fprintf(out,"MACHINE-READABLE JINMEI-YO KANJI LIST (in JIS order)\n");
  467.     fprintf(out,"NOTE: the last two kanji are unique to JIS X 0208-1990, and thus\n");
  468.     fprintf(out,"      may not display properly on all systems\n\n");
  469.   }
  470.   for (i = 0;i < JINMEIYO_TOTAL;i++) {
  471.     if (column == 0)
  472.       switch (outcode) {
  473.         case NEW :
  474.         case OLD :
  475.         case NEC :
  476.           fprintf(out,"%s",ki);
  477.           break;
  478.         default :
  479.           break;
  480.       }
  481.     if (wrap && column >= max) {
  482.       switch (outcode) {
  483.         case NEW :
  484.         case OLD :
  485.         case NEC :
  486.           fprintf(out,"%s\n%s",ko,ki);
  487.           break;
  488.         case EUC :
  489.         case SJIS :
  490.           fprintf(out,"\n");
  491.           break;
  492.         default :
  493.           break;
  494.       }
  495.       column = 0;
  496.     }
  497.     switch (outcode) {
  498.       case NEW :
  499.       case OLD :
  500.       case NEC :
  501.         fprintf(out,"%c%c",FIRSTBYTE(pk[i]), SECONDBYTE(pk[i]));
  502.         column += 2;
  503.         break;
  504.       case EUC :
  505.         fprintf(out,"%c%c",FIRSTBYTE(pk[i]) + 128, SECONDBYTE(pk[i]) + 128);
  506.         column += 2;
  507.         break;
  508.       case SJIS :
  509.         p1 = FIRSTBYTE(pk[i]);
  510.         p2 = SECONDBYTE(pk[i]);
  511.         jis2sjis(&p1,&p2);
  512.         fprintf(out,"%c%c",p1,p2);
  513.         column += 2;
  514.         break;
  515.       default :
  516.         break;
  517.     }
  518.   }
  519.   switch (outcode) {
  520.     case NEW :
  521.     case OLD :
  522.     case NEC :
  523.       fprintf(out,"%s\n",ko);
  524.       break;
  525.     case EUC :
  526.     case SJIS :
  527.       fprintf(out,"\n");
  528.       break;
  529.     default :
  530.       break;
  531.   }
  532. }
  533.  
  534. void printGAKUSHU(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress)
  535. {
  536.   int p1,p2,i,column = 0;
  537.   static unsigned short gk[] = {
  538.     1676,1706,1711,1763,1806,1827,1828,1848,1854,1913,
  539.     1956,2104,2157,2244,2266,2269,2285,2378,2404,2411,
  540.     2462,2493,2527,2624,2716,2719,2745,2750,2769,2790,
  541.     2810,2823,2854,2874,2929,2948,2987,3014,3069,3125,
  542.     3145,3169,3221,3224,3236,3248,3254,3272,3273,3278,
  543.     3365,3380,3413,3428,3471,3543,3561,3570,3578,3614,
  544.     3723,3736,3758,3883,3892,3894,3915,3982,4012,4120,
  545.     4224,4360,4430,4458,4460,4528,4609,4647,4651,4727,
  546.     1690,1709,1732,1764,1783,1811,1831,1838,1840,1842,
  547.     1846,1872,1881,1883,1904,1908,1916,1949,1958,1972,
  548.     2054,2061,2068,2073,2102,2105,2113,2161,2177,2191,
  549.     2194,2215,2221,2265,2327,2333,2355,2421,2422,2432,
  550.     2437,2445,2465,2469,2476,2482,2487,2488,2509,2513,
  551.     2545,2552,2566,2571,2581,2585,2603,2645,2657,2678,
  552.     2727,2748,2752,2755,2763,2770,2791,2794,2811,2828,
  553.     2850,2869,2883,2909,2921,2953,2981,3015,3076,3107,
  554.     3109,3120,3123,3138,3162,3184,3217,3218,3228,3230,
  555.     3258,3267,3294,3305,3316,3340,3386,3431,3432,3446,
  556.     3470,3511,3546,3547,3551,3567,3575,3611,3625,3627,
  557.     3630,3644,3679,3725,3732,3737,3763,3765,3776,3786,
  558.     3790,3812,3817,3827,3841,3866,3878,3889,3947,3967,
  559.     3968,3994,4030,4054,4167,4187,4212,4225,4238,4266,
  560.     4276,4293,4344,4369,4372,4392,4432,4436,4451,4471,
  561.     4475,4478,4480,4507,4543,4549,4572,4593,4604,4735,
  562.     1613,1634,1637,1649,1653,1669,1673,1687,1691,1701,
  563.     1731,1743,1756,1803,1816,1825,1829,1857,1906,1911,
  564.     1912,2008,2022,2033,2059,2063,2092,2115,2150,2160,
  565.     2162,2169,2170,2173,2178,2222,2240,2241,2242,2268,
  566.     2272,2276,2281,2315,2324,2358,2372,2376,2406,2409,
  567.     2443,2448,2494,2512,2533,2570,2612,2655,2668,2714,
  568.     2737,2740,2747,2756,2764,2777,2785,2786,2793,2801,
  569.     2816,2834,2844,2852,2871,2872,2873,2882,2885,2903,
  570.     2906,2910,2912,2924,2927,2937,2941,2974,2975,2985,
  571.     3001,3006,3028,3035,3047,3072,3102,3128,3129,3131,
  572.     3132,3140,3142,3204,3216,3246,3320,3359,3374,3387,
  573.     3409,3414,3418,3430,3439,3448,3452,3469,3472,3474,
  574.     3526,3527,3544,3569,3576,3577,3590,3602,3620,3641,
  575.     3674,3677,3711,3720,3730,3748,3752,3757,3771,3774,
  576.     3782,3789,3806,3816,3824,3932,3940,3959,3960,4002,
  577.     4010,4015,4031,4036,4065,4073,4094,4101,4114,4125,
  578.     4129,4134,4135,4142,4155,4173,4184,4194,4201,4210,
  579.     4231,4254,4257,4292,4403,4431,4444,4468,4482,4484,
  580.     4493,4513,4519,4523,4529,4545,4546,4551,4553,4559,
  581.     4578,4614,4625,4630,4648,4673,4683,4693,4709,4734,
  582.     1606,1638,1642,1644,1647,1663,1665,1685,1741,1749,
  583.     1786,1791,1815,1835,1844,1861,1863,1874,1894,1903,
  584.     1918,1925,1938,1948,2016,2017,2041,2049,2056,2074,
  585.     2078,2079,2085,2090,2101,2108,2110,2136,2163,2165,
  586.     2167,2175,2183,2189,2205,2206,2208,2232,2243,2317,
  587.     2319,2320,2331,2334,2342,2361,2371,2375,2382,2390,
  588.     2419,2439,2485,2489,2505,2515,2550,2580,2625,2639,
  589.     2658,2664,2682,2694,2701,2705,2706,2718,2722,2726,
  590.     2736,2742,2743,2746,2765,2778,2789,2803,2813,2826,
  591.     2858,2879,2894,2943,2971,2973,3007,3030,3038,3040,
  592.     3042,3048,3061,3062,3114,3135,3214,3222,3237,3242,
  593.     3249,3262,3265,3266,3279,3285,3310,3319,3350,3367,
  594.     3372,3406,3411,3419,3420,3425,3451,3466,3503,3517,
  595.     3554,3571,3589,3591,3618,3667,3668,3676,3710,3721,
  596.     3733,3744,3756,3784,3815,3818,3832,3835,3839,3914,
  597.     3916,3952,3963,3978,4051,4081,4084,4112,4124,4128,
  598.     4152,4153,4160,4191,4220,4228,4244,4249,4253,4256,
  599.     4281,4301,4330,4350,4386,4394,4404,4414,4417,4421,
  600.     4483,4506,4555,4560,4565,4588,4606,4633,4641,4644,
  601.     4656,4664,4665,4667,4668,4682,4702,4711,4723,4731,
  602.     1621,1655,1660,1688,1736,1742,1750,1753,1755,1773,
  603.     1793,1794,1824,1830,1833,1836,1847,1865,1876,1882,
  604.     1887,1942,1946,1959,2009,2020,2023,2067,2080,2083,
  605.     2112,2127,2133,2153,2155,2176,2179,2186,2213,2229,
  606.     2249,2256,2271,2318,2348,2373,2379,2384,2401,2417,
  607.     2426,2429,2434,2436,2446,2478,2490,2492,2529,2544,
  608.     2554,2559,2614,2626,2638,2642,2646,2650,2661,2663,
  609.     2665,2666,2689,2708,2731,2732,2753,2754,2757,2762,
  610.     2781,2784,2787,2808,2817,2833,2843,2853,2888,2904,
  611.     2949,2950,2964,2988,3021,3023,3058,3079,3080,3082,
  612.     3085,3105,3106,3209,3210,3213,3215,3226,3229,3239,
  613.     3251,3253,3260,3263,3268,3269,3312,3336,3339,3377,
  614.     3392,3393,3404,3407,3412,3416,3427,3454,3463,3464,
  615.     3536,3539,3559,3605,3683,3688,3708,3712,3793,3819,
  616.     3828,3833,3840,3904,3919,3929,3943,4029,4039,4040,
  617.     4070,4078,4083,4087,4122,4130,4147,4156,4157,4159,
  618.     4180,4192,4203,4209,4252,4259,4261,4272,4283,4313,
  619.     4329,4339,4341,4419,4420,4434,4442,4502,4530,4534,
  620.     4538,4608,4612,4617,4646,1659,1668,1672,1707,1739,
  621.     1768,1772,1870,1905,1940,1953,1955,1968,1984,2012,
  622.     2019,2039,2042,2077,2088,2089,2114,2131,2159,2201,
  623.     2227,2231,2248,2258,2341,2347,2357,2364,2367,2374,
  624.     2391,2402,2408,2423,2427,2438,2442,2477,2501,2507,
  625.     2536,2540,2561,2563,2579,2582,2592,2604,2629,2634,
  626.     2649,2659,2686,2693,2729,2749,2768,2774,2775,2776,
  627.     2779,2807,2845,2846,2860,2867,2889,2893,2901,2902,
  628.     2916,2930,2936,2944,2947,2967,2972,2980,2984,2992,
  629.     2993,3013,3067,3075,3088,3143,3146,3166,3168,3203,
  630.     3225,3227,3231,3275,3276,3284,3286,3287,3317,3347,
  631.     3353,3356,3364,3375,3385,3401,3402,3424,3426,3480,
  632.     3520,3521,3534,3540,3542,3545,3572,3573,3588,3603,
  633.     3612,3626,3634,3643,3724,3762,3792,3804,3847,3881,
  634.     3893,3907,3928,3930,3941,3948,3950,3956,3957,4041,
  635.     4053,4061,4067,4075,4202,4219,4234,4236,4237,4250,
  636.     4268,4275,4285,4312,4320,4326,4332,4371,4375,4409,
  637.     4433,4447,4485,4505,4525,4536,4563,4566,4580,4581,
  638.     4587,4602,4607,4655,4715,4732 };
  639.  
  640.   if (GAKUSHU_TOTAL != ARRAYSIZE(gk)) {
  641.     fprintf(stderr,"Incomplete data structure for Gakushu Kanji list! Exiting...\n");
  642.     exit(1);
  643.   }
  644.   if (!suppress)
  645.     fprintf(out,"MACHINE-READABLE GAKUSHU KANJI LIST (by grade level in JIS order)\n\n");
  646.   for (i = 0;i < GAKUSHU_TOTAL;i++) {
  647.     if (!suppress && i == 0)
  648.       fprintf(out,"Grade Level 1 (80 kanji):\n");
  649.     if (!suppress && (i == 80 || i == 240 || i == 440 || i == 640 || i == 825)) {
  650.       column = 0;
  651.       switch (outcode) {
  652.         case NEW :
  653.         case OLD :
  654.         case NEC :
  655.           fprintf(out,"%s\n",ko);
  656.           break;
  657.         case EUC :
  658.         case SJIS :
  659.           fprintf(out,"\n");
  660.           break;
  661.         default :
  662.           break;
  663.       }
  664.       switch (i) {
  665.         case 80 :
  666.           fprintf(out,"Grade Level 2 (160 kanji):\n");
  667.           break;
  668.         case 240 :
  669.           fprintf(out,"Grade Level 3 (200 kanji):\n");
  670.           break;
  671.         case 440 :
  672.           fprintf(out,"Grade Level 4 (200 kanji):\n");
  673.           break;
  674.         case 640 :
  675.           fprintf(out,"Grade Level 5 (185 kanji):\n");
  676.           break;
  677.         case 825 :
  678.           fprintf(out,"Grade Level 6 (181 kanji):\n");
  679.           break;
  680.         default :
  681.           break;
  682.       }
  683.     }
  684.     if (column == 0)
  685.       switch (outcode) {
  686.         case NEW :
  687.         case OLD :
  688.         case NEC :
  689.           fprintf(out,"%s",ki);
  690.           break;
  691.         default :
  692.           break;
  693.       }
  694.     if (wrap && column >= max) {
  695.       switch (outcode) {
  696.         case NEW :
  697.         case OLD :
  698.         case NEC :
  699.           fprintf(out,"%s\n%s",ko,ki);
  700.           break;
  701.         case EUC :
  702.         case SJIS :
  703.           fprintf(out,"\n");
  704.           break;
  705.         default :
  706.           break;
  707.       }
  708.       column = 0;
  709.     }
  710.     switch (outcode) {
  711.       case NEW :
  712.       case OLD :
  713.       case NEC :
  714.         fprintf(out,"%c%c",FIRSTBYTE(gk[i]), SECONDBYTE(gk[i]));
  715.         column += 2;
  716.         break;
  717.       case EUC :
  718.         fprintf(out,"%c%c",FIRSTBYTE(gk[i]) + 128, SECONDBYTE(gk[i]) + 128);
  719.         column += 2;
  720.         break;
  721.       case SJIS :
  722.         p1 = FIRSTBYTE(gk[i]);
  723.         p2 = SECONDBYTE(gk[i]);
  724.         jis2sjis(&p1,&p2);
  725.         fprintf(out,"%c%c",p1,p2);
  726.         column += 2;
  727.         break;
  728.       default :
  729.         break;
  730.     }
  731.   }
  732.   switch (outcode) {
  733.     case NEW :
  734.     case OLD :
  735.     case NEC :
  736.       fprintf(out,"%s\n",ko);
  737.       break;
  738.     case EUC :
  739.     case SJIS :
  740.       fprintf(out,"\n");
  741.       break;
  742.     default :
  743.       break;
  744.   }
  745. }
  746.  
  747. void printJOYO(FILE *out,int outcode,int wrap,int max,char ki[],char ko[],int suppress)
  748. {
  749.   int p1,p2,i,column = 0;
  750.   static unsigned short jk[] = {
  751.     1601,1605,1606,1613,1614,1621,1623,1634,1637,1638,
  752.     1642,1644,1645,1646,1647,1649,1650,1651,1653,1654,
  753.     1655,1657,1659,1660,1661,1662,1663,1665,1667,1668,
  754.     1669,1670,1672,1673,1676,1677,1679,1680,1682,1685,
  755.     1687,1688,1689,1690,1691,1701,1702,1703,1704,1706,
  756.     1707,1709,1711,1718,1726,1731,1732,1736,1738,1739,
  757.     1741,1742,1743,1749,1750,1751,1752,1753,1754,1755,
  758.     1756,1757,1758,1759,1760,1763,1764,1767,1768,1771,
  759.     1772,1773,1774,1776,1778,1779,1783,1784,1786,1788,
  760.     1790,1791,1792,1793,1794,1801,1803,1804,1805,1806,
  761.     1807,1811,1813,1815,1816,1817,1821,1823,1824,1825,
  762.     1826,1827,1828,1829,1830,1831,1833,1834,1835,1836,
  763.     1838,1839,1840,1841,1842,1843,1844,1845,1846,1847,
  764.     1848,1850,1852,1853,1854,1857,1858,1859,1861,1863,
  765.     1865,1867,1870,1872,1874,1876,1877,1878,1880,1881,
  766.     1882,1883,1884,1885,1887,1888,1889,1891,1892,1893,
  767.     1894,1903,1904,1905,1906,1907,1908,1911,1912,1913,
  768.     1915,1916,1918,1920,1921,1922,1925,1926,1932,1937,
  769.     1938,1940,1942,1943,1944,1945,1946,1947,1948,1949,
  770.     1951,1952,1953,1954,1955,1956,1957,1958,1959,1961,
  771.     1967,1968,1969,1971,1972,1973,1974,1976,1977,1978,
  772.     1984,2002,2005,2007,2008,2009,2010,2011,2012,2013,
  773.     2014,2016,2017,2018,2019,2020,2021,2022,2023,2024,
  774.     2025,2026,2029,2030,2031,2032,2033,2036,2037,2038,
  775.     2039,2041,2042,2043,2044,2046,2047,2049,2051,2052,
  776.     2053,2054,2055,2056,2057,2059,2061,2062,2063,2067,
  777.     2068,2072,2073,2074,2075,2077,2078,2079,2080,2081,
  778.     2083,2084,2085,2086,2087,2088,2089,2090,2091,2092,
  779.     2093,2094,2101,2102,2104,2105,2107,2108,2110,2112,
  780.     2113,2114,2115,2116,2117,2118,2119,2120,2122,2123,
  781.     2125,2126,2127,2128,2129,2130,2131,2133,2136,2138,
  782.     2140,2142,2145,2149,2150,2151,2152,2153,2154,2155,
  783.     2157,2158,2159,2160,2161,2162,2163,2164,2165,2167,
  784.     2169,2170,2171,2173,2174,2175,2176,2177,2178,2179,
  785.     2180,2181,2182,2183,2185,2186,2187,2189,2191,2193,
  786.     2194,2201,2205,2206,2207,2208,2211,2213,2214,2215,
  787.     2218,2219,2220,2221,2222,2223,2224,2225,2226,2227,
  788.     2228,2229,2231,2232,2233,2235,2236,2237,2239,2240,
  789.     2241,2242,2243,2244,2248,2249,2252,2255,2256,2258,
  790.     2259,2261,2263,2264,2265,2266,2267,2268,2269,2271,
  791.     2272,2276,2278,2281,2282,2283,2285,2286,2288,2289,
  792.     2294,2301,2304,2311,2312,2314,2315,2316,2317,2318,
  793.     2319,2320,2324,2325,2326,2327,2328,2331,2332,2333,
  794.     2334,2335,2336,2338,2339,2340,2341,2342,2344,2347,
  795.     2348,2349,2352,2354,2355,2357,2358,2360,2361,2362,
  796.     2363,2364,2366,2367,2370,2371,2372,2373,2374,2375,
  797.     2376,2378,2379,2380,2382,2383,2384,2385,2387,2388,
  798.     2389,2390,2391,2392,2401,2402,2404,2405,2406,2408,
  799.     2409,2410,2411,2412,2413,2414,2415,2417,2418,2419,
  800.     2421,2422,2423,2424,2425,2426,2427,2428,2429,2432,
  801.     2434,2436,2437,2438,2439,2441,2442,2443,2444,2445,
  802.     2446,2447,2448,2456,2459,2460,2461,2462,2463,2465,
  803.     2466,2468,2469,2470,2471,2475,2476,2477,2478,2482,
  804.     2484,2485,2487,2488,2489,2490,2492,2493,2494,2501,
  805.     2503,2505,2506,2507,2509,2510,2512,2513,2515,2517,
  806.     2518,2519,2520,2521,2522,2525,2527,2529,2530,2531,
  807.     2533,2534,2535,2536,2537,2538,2540,2542,2543,2544,
  808.     2545,2546,2550,2551,2552,2553,2554,2555,2556,2557,
  809.     2558,2559,2561,2563,2564,2565,2566,2568,2570,2571,
  810.     2573,2575,2578,2579,2580,2581,2582,2583,2585,2586,
  811.     2588,2592,2594,2603,2604,2606,2607,2608,2609,2611,
  812.     2612,2614,2616,2618,2620,2622,2624,2625,2626,2629,
  813.     2630,2631,2634,2636,2637,2638,2639,2642,2643,2644,
  814.     2645,2646,2647,2648,2649,2650,2653,2655,2656,2657,
  815.     2658,2659,2660,2661,2662,2663,2664,2665,2666,2668,
  816.     2673,2674,2678,2679,2681,2682,2686,2687,2688,2689,
  817.     2693,2694,2701,2703,2704,2705,2706,2708,2714,2716,
  818.     2717,2718,2719,2720,2722,2723,2726,2727,2729,2731,
  819.     2732,2735,2736,2737,2739,2740,2741,2742,2743,2744,
  820.     2745,2746,2747,2748,2749,2750,2752,2753,2754,2755,
  821.     2756,2757,2760,2761,2762,2763,2764,2765,2767,2768,
  822.     2769,2770,2771,2772,2773,2774,2775,2776,2777,2778,
  823.     2779,2780,2781,2782,2783,2784,2785,2786,2787,2788,
  824.     2789,2790,2791,2792,2793,2794,2801,2802,2803,2805,
  825.     2807,2808,2810,2811,2813,2816,2817,2820,2823,2825,
  826.     2826,2828,2830,2831,2832,2833,2834,2839,2843,2844,
  827.     2845,2846,2847,2848,2849,2850,2852,2853,2854,2855,
  828.     2856,2857,2858,2859,2860,2863,2864,2865,2867,2868,
  829.     2869,2871,2872,2873,2874,2875,2876,2877,2878,2879,
  830.     2881,2882,2883,2884,2885,2887,2888,2889,2891,2892,
  831.     2893,2894,2901,2902,2903,2904,2905,2906,2908,2909,
  832.     2910,2912,2913,2914,2916,2917,2921,2923,2924,2925,
  833.     2927,2928,2929,2930,2932,2933,2934,2935,2936,2937,
  834.     2938,2939,2941,2942,2943,2944,2945,2946,2947,2948,
  835.     2949,2950,2951,2953,2954,2958,2959,2960,2962,2964,
  836.     2965,2966,2967,2968,2969,2971,2972,2973,2974,2975,
  837.     2978,2979,2980,2981,2984,2985,2986,2987,2988,2989,
  838.     2992,2993,2994,3001,3002,3003,3004,3006,3007,3009,
  839.     3012,3013,3014,3015,3016,3018,3020,3021,3022,3023,
  840.     3024,3026,3028,3029,3030,3034,3035,3036,3038,3039,
  841.     3040,3041,3042,3043,3044,3045,3046,3047,3048,3049,
  842.     3050,3051,3055,3057,3058,3059,3060,3061,3062,3066,
  843.     3067,3069,3070,3072,3073,3074,3075,3076,3077,3078,
  844.     3079,3080,3082,3084,3085,3086,3088,3089,3090,3091,
  845.     3092,3094,3102,3103,3105,3106,3107,3108,3109,3111,
  846.     3113,3114,3115,3116,3117,3118,3119,3120,3121,3122,
  847.     3123,3125,3127,3128,3129,3131,3132,3134,3135,3137,
  848.     3138,3139,3140,3141,3142,3143,3144,3145,3146,3147,
  849.     3150,3151,3152,3155,3156,3161,3162,3165,3166,3167,
  850.     3168,3169,3170,3171,3172,3174,3175,3176,3178,3179,
  851.     3181,3182,3184,3185,3188,3189,3201,3203,3204,3205,
  852.     3206,3207,3209,3210,3211,3212,3213,3214,3215,3216,
  853.     3217,3218,3221,3222,3223,3224,3225,3226,3227,3228,
  854.     3229,3230,3231,3232,3233,3234,3236,3237,3238,3239,
  855.     3241,3242,3243,3245,3246,3247,3248,3249,3250,3251,
  856.     3253,3254,3255,3258,3259,3260,3261,3262,3263,3264,
  857.     3265,3266,3267,3268,3269,3271,3272,3273,3274,3275,
  858.     3276,3278,3279,3280,3282,3284,3285,3286,3287,3288,
  859.     3291,3294,3301,3305,3306,3309,3310,3311,3312,3313,
  860.     3315,3316,3317,3318,3319,3320,3321,3322,3326,3328,
  861.     3334,3335,3336,3337,3338,3339,3340,3342,3343,3346,
  862.     3347,3348,3350,3351,3352,3353,3356,3359,3360,3361,
  863.     3362,3364,3365,3366,3367,3369,3371,3372,3374,3375,
  864.     3377,3380,3381,3382,3384,3385,3386,3387,3388,3390,
  865.     3391,3392,3393,3394,3401,3402,3403,3404,3405,3406,
  866.     3407,3408,3409,3411,3412,3413,3414,3415,3416,3417,
  867.     3418,3419,3420,3424,3425,3426,3427,3428,3430,3431,
  868.     3432,3436,3437,3438,3439,3444,3446,3448,3449,3451,
  869.     3452,3453,3454,3456,3457,3458,3459,3462,3463,3464,
  870.     3465,3466,3469,3470,3471,3472,3474,3476,3478,3480,
  871.     3482,3483,3484,3485,3487,3489,3490,3502,3503,3505,
  872.     3506,3510,3511,3516,3517,3518,3520,3521,3524,3526,
  873.     3527,3528,3532,3534,3535,3536,3537,3538,3539,3540,
  874.     3542,3543,3544,3545,3546,3547,3549,3551,3552,3553,
  875.     3554,3555,3557,3559,3560,3561,3563,3564,3565,3566,
  876.     3567,3568,3569,3570,3571,3572,3573,3574,3575,3576,
  877.     3577,3578,3579,3582,3583,3588,3589,3590,3591,3602,
  878.     3603,3604,3605,3606,3607,3608,3609,3611,3612,3614,
  879.     3615,3616,3617,3618,3620,3622,3623,3625,3626,3627,
  880.     3628,3630,3631,3632,3633,3634,3635,3636,3637,3638,
  881.     3641,3643,3644,3645,3650,3658,3664,3666,3667,3668,
  882.     3669,3671,3672,3673,3674,3675,3676,3677,3678,3679,
  883.     3681,3683,3688,3689,3690,3691,3694,3701,3705,3706,
  884.     3708,3709,3710,3711,3712,3715,3716,3717,3719,3720,
  885.     3721,3723,3724,3725,3726,3730,3732,3733,3734,3736,
  886.     3737,3739,3741,3744,3745,3747,3748,3751,3752,3756,
  887.     3757,3758,3759,3760,3761,3762,3763,3764,3765,3766,
  888.     3767,3771,3773,3774,3775,3776,3777,3779,3780,3782,
  889.     3784,3786,3787,3789,3790,3791,3792,3793,3794,3804,
  890.     3805,3806,3807,3808,3809,3811,3812,3813,3814,3815,
  891.     3816,3817,3818,3819,3822,3824,3825,3827,3828,3829,
  892.     3831,3832,3833,3835,3836,3838,3839,3840,3841,3844,
  893.     3845,3847,3854,3858,3862,3863,3866,3876,3878,3880,
  894.     3881,3883,3884,3885,3889,3892,3893,3894,3901,3902,
  895.     3904,3905,3906,3907,3911,3913,3914,3915,3916,3919,
  896.     3920,3926,3927,3928,3929,3930,3932,3936,3938,3940,
  897.     3941,3943,3944,3947,3948,3949,3950,3951,3952,3953,
  898.     3956,3957,3958,3959,3960,3961,3962,3963,3967,3968,
  899.     3969,3970,3976,3978,3979,3981,3982,3985,3986,3987,
  900.     3989,3990,3991,3994,4002,4009,4010,4012,4013,4015,
  901.     4017,4018,4019,4020,4022,4028,4029,4030,4031,4033,
  902.     4034,4036,4039,4040,4041,4042,4043,4044,4045,4046,
  903.     4047,4049,4050,4051,4053,4054,4055,4058,4060,4061,
  904.     4062,4064,4065,4066,4067,4068,4070,4071,4072,4073,
  905.     4074,4075,4077,4078,4079,4081,4082,4083,4084,4087,
  906.     4088,4089,4094,4101,4104,4112,4114,4117,4120,4122,
  907.     4124,4125,4126,4128,4129,4130,4133,4134,4135,4136,
  908.     4142,4145,4147,4148,4149,4150,4151,4152,4153,4155,
  909.     4156,4157,4159,4160,4161,4162,4163,4165,4166,4167,
  910.     4168,4169,4170,4172,4173,4174,4175,4177,4178,4180,
  911.     4181,4184,4185,4187,4190,4191,4192,4193,4194,4201,
  912.     4202,4203,4204,4207,4208,4209,4210,4212,4214,4215,
  913.     4216,4219,4220,4222,4223,4224,4225,4226,4227,4228,
  914.     4229,4230,4231,4232,4233,4234,4236,4237,4238,4241,
  915.     4242,4244,4248,4249,4250,4252,4253,4254,4255,4256,
  916.     4257,4259,4261,4262,4265,4266,4268,4270,4271,4272,
  917.     4273,4275,4276,4277,4279,4280,4281,4283,4284,4285,
  918.     4286,4288,4290,4292,4293,4301,4302,4304,4305,4306,
  919.     4307,4311,4312,4313,4314,4316,4319,4320,4321,4322,
  920.     4323,4324,4325,4326,4327,4328,4329,4330,4331,4332,
  921.     4333,4334,4335,4336,4337,4339,4341,4344,4345,4347,
  922.     4348,4349,4350,4355,4357,4359,4360,4361,4362,4363,
  923.     4364,4365,4366,4367,4368,4369,4371,4372,4375,4376,
  924.     4384,4385,4386,4390,4392,4393,4394,4401,4403,4404,
  925.     4405,4408,4409,4414,4415,4417,4418,4419,4420,4421,
  926.     4423,4424,4427,4428,4430,4431,4432,4433,4434,4435,
  927.     4436,4439,4440,4442,4444,4447,4448,4449,4451,4452,
  928.     4453,4454,4455,4458,4459,4460,4465,4468,4470,4471,
  929.     4472,4475,4478,4480,4481,4482,4483,4484,4485,4486,
  930.     4488,4491,4493,4494,4501,4502,4503,4505,4506,4507,
  931.     4509,4510,4511,4513,4517,4519,4521,4522,4523,4525,
  932.     4526,4527,4528,4529,4530,4531,4532,4534,4536,4538,
  933.     4539,4540,4541,4542,4543,4545,4546,4547,4549,4550,
  934.     4551,4553,4555,4556,4557,4559,4560,4562,4563,4565,
  935.     4566,4567,4569,4571,4572,4574,4575,4577,4578,4579,
  936.     4580,4581,4583,4584,4587,4588,4589,4590,4593,4601,
  937.     4602,4604,4605,4606,4607,4608,4609,4612,4614,4617,
  938.     4618,4619,4620,4621,4624,4625,4626,4627,4629,4630,
  939.     4632,4633,4635,4636,4637,4640,4641,4644,4645,4646,
  940.     4647,4648,4649,4650,4651,4655,4656,4657,4661,4662,
  941.     4663,4664,4665,4667,4668,4669,4673,4675,4676,4677,
  942.     4678,4679,4680,4681,4682,4683,4684,4685,4686,4687,
  943.     4688,4693,4702,4703,4707,4709,4710,4711,4713,4715,
  944.     4716,4718,4719,4723,4726,4727,4731,4732,4734,4735,
  945.     4737,4739,4740,4749,4751 };
  946.  
  947.   if (JOYO_TOTAL != ARRAYSIZE(jk)) {
  948.     fprintf(stderr,"Incomplete data structure for Joyo Kanji list! Exiting...\n");
  949.     exit(1);
  950.   }
  951.   if (!suppress)
  952.     fprintf(out,"MACHINE-READABLE JOYO KANJI LIST (in JIS order)\n\n");
  953.   for (i = 0;i < JOYO_TOTAL;i++) {
  954.     if (column == 0)
  955.       switch (outcode) {
  956.         case NEW :
  957.         case OLD :
  958.         case NEC :
  959.           fprintf(out,"%s",ki);
  960.           break;
  961.         default :
  962.           break;
  963.       }
  964.     if (wrap && column >= max) {
  965.       switch (outcode) {
  966.         case NEW :
  967.         case OLD :
  968.         case NEC :
  969.           fprintf(out,"%s\n%s",ko,ki);
  970.           break;
  971.         case EUC :
  972.         case SJIS :
  973.           fprintf(out,"\n");
  974.           break;
  975.         default :
  976.           break;
  977.       }
  978.       column = 0;
  979.     }
  980.     switch (outcode) {
  981.       case NEW :
  982.       case OLD :
  983.       case NEC :
  984.         fprintf(out,"%c%c",FIRSTBYTE(jk[i]), SECONDBYTE(jk[i]));
  985.         column += 2;
  986.         break;
  987.       case EUC :
  988.         fprintf(out,"%c%c",FIRSTBYTE(jk[i]) + 128, SECONDBYTE(jk[i]) + 128);
  989.         column += 2;
  990.         break;
  991.       case SJIS :
  992.         p1 = FIRSTBYTE(jk[i]);
  993.         p2 = SECONDBYTE(jk[i]);
  994.         jis2sjis(&p1,&p2);
  995.         fprintf(out,"%c%c",p1,p2);
  996.         column += 2;
  997.         break;
  998.       default :
  999.         break;
  1000.     }
  1001.   }
  1002.   switch (outcode) {
  1003.     case NEW :
  1004.     case OLD :
  1005.     case NEC :
  1006.       fprintf(out,"%s\n",ko);
  1007.       break;
  1008.     case EUC :
  1009.     case SJIS :
  1010.       fprintf(out,"\n");
  1011.       break;
  1012.     default :
  1013.       break;
  1014.   }
  1015. }
  1016.  
  1017. void jis2sjis(int *p1, int *p2)
  1018. {
  1019.   unsigned char c1 = *p1;
  1020.   unsigned char c2 = *p2;
  1021.   int rowOffset = c1 < 95 ? 112 : 176;
  1022.   int cellOffset = c1 % 2 ? (c2 > 95 ? 32 : 31) : 126;
  1023.  
  1024.   *p1 = ((c1 + 1) >> 1) + rowOffset;
  1025.   *p2 += cellOffset;
  1026. }
  1027.