ascii-jtex/Mojikyo/mksample.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. parse_args
  2. main

   1 /*
   2  *  mksample.c
   3  *    Make list of all characters of Mojikyo font in LaTeX form.
   4  *  
   5  *
   6  *  How to use this program:
   7  *
   8  *  1. Compile this program.
   9  *         % gcc -o mksample mksample.c
  10  *  2. Run this program to generate (huge) LaTeX input file.
  11  *         % ./mksample  > sample.tex
  12  *  3. Run pLaTeX to generate DVI file.
  13  *         % platex sample.tex
  14  *  4. View/Print it. For example, 
  15  *         % xgdvi sample.dvi 
  16  *
  17  */
  18  
  19 #include <stdio.h>
  20 
  21 #define MINCHAR        1
  22 #define MAXCHAR   115000
  23 #define NCHLINE       20
  24 #define SIZECMD  "normalsize"
  25 
  26 
  27 int    ku_from, ku_to, nchline, title;
  28 char  *sizecmd;
  29 int    mtype;
  30 
  31 
  32 #define  TYPE_TTF    1
  33 #define  TYPE_TYPE1  2
  34 
  35 
  36 void
  37 parse_args(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  38 {
  39   if (argc == 1)
  40     return;
  41 
  42   mtype = TYPE_TTF;
  43   title = 1;
  44   argc--;
  45   while (argc > 0){
  46     if (strcmp(*argv, "-f") == 0){
  47       argc--; argv++;
  48       ku_from = atoi(*argv) / 100;      
  49     } else if (strcmp(*argv, "-t") == 0){
  50       argc--; argv++;
  51       ku_to = atoi(*argv) / 100;      
  52     } else if (strcmp(*argv, "-n") == 0){
  53       argc--; argv++;
  54       if ((nchline = atoi(*argv)) < 1){
  55         fprintf(stderr, "-n option: value must be positive.\n");
  56       }
  57     } else if (strcmp(*argv, "-s") == 0){
  58       argc--; argv++;
  59       sizecmd = *argv;
  60     } else if (strcmp(*argv, "-ttf") == 0){
  61       mtype = TYPE_TTF;
  62     } else if (strcmp(*argv, "-type1") == 0){
  63       mtype = TYPE_TYPE1;
  64     } else if ((strcmp(*argv, "-h") == 0)
  65                || (strcmp(*argv, "-help") == 0)
  66                || (strcmp(*argv, "--help") == 0)){
  67       fprintf(stderr, 
  68               "Usage: mksample  [-ttf] [-type1] "
  69               "[-f FROM_CODE] [-t TO_CODE] [-n LINE_NCHARS] [-s SIZE_CMD]\n");
  70       fprintf(stderr, "Default Values:\n");
  71       fprintf(stderr, "  FROM_CODE = %d\n", MINCHAR);
  72       fprintf(stderr, "  TO_CODE = %d\n", MAXCHAR);
  73       fprintf(stderr, "  LINE_NCHARS = %d\n", NCHLINE);
  74       fprintf(stderr, "  SIZE_CMD = %s\n", SIZECMD);
  75       exit(0);
  76     }
  77     argc--; argv++;
  78   }
  79 }
  80 
  81 
  82 int
  83 main(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  84 {
  85   int  ku, ten, i;
  86 
  87 
  88   ku_from = MINCHAR/100;
  89   ku_to   = (MAXCHAR+99)/100;
  90   title   = 0;
  91   nchline = NCHLINE;
  92   sizecmd = SIZECMD;
  93 
  94   parse_args(argc, argv);
  95 
  96   printf("\\documentclass[a4paper]{jarticle}\n");
  97   printf("\\setlength{\\topmargin}{-25mm}\n");
  98   printf("\\setlength{\\evensidemargin}{-10mm}\n");
  99   printf("\\setlength{\\oddsidemargin}{-10mm}\n");
 100   printf("\\setlength{\\textwidth}{180mm}\n");
 101   printf("\\setlength{\\textheight}{263mm}\n");
 102   printf("\\usepackage{mojikyo}\n");
 103   printf("\\usepackage{array}\n");
 104   printf("\\renewcommand{\\arraystretch}{0.9}\n");
 105 #if 1
 106   printf("\\def\\CH#1{#1}\n");
 107 #else
 108   printf("\\def\\CH#1{\\mbox{#1}}\n");
 109 #endif
 110   printf("\\begin{document}\n");
 111   if (title == 0){
 112     printf("\\begin{center}\n");
 113     printf("\\textsf{\\textbf{\\LARGE 「文字鏡」 \\quad 文字一覧}}\n");
 114     printf("\\end{center}\n");
 115     printf("\\vskip 3em\n");
 116   }
 117   printf("\\%s\n", sizecmd);
 118 
 119 
 120   for (ku = ku_from; ku <= ku_to; ku++){
 121 
 122     printf("\\vskip 1.2em\n");
 123     printf("\\vbox{\n");
 124     printf("\\noindent\\textsf{\\textbf{%06d}}\\par\n", ku*100 + 1);
 125     printf("\\begin{center}");
 126     printf("\\begin{tabular}{|r|");
 127     for (i = 0; i < nchline; i++)
 128       printf("c");
 129     printf("|}\n");
 130     printf("\\hline\n");
 131     printf(" \n");
 132     for (i = 0; i < nchline; i++)
 133       printf("&\\texttt{%02d}", i+1);
 134     printf("\\\\\n");
 135     printf("\\hline\n");
 136     for (ten = 1; ten <= 100; ten++){
 137       if ((ten % nchline) == 1){
 138         if (ten > 1)
 139           printf("\\\\\n");
 140         printf("\\texttt{%06d}\n", ku*100 + ten);
 141       }
 142       if (mtype == TYPE_TTF){
 143         printf(" &\\CH{\\TMO{%06d}}\n", ku*100 + ten);
 144       } else {
 145         printf(" &\\CH{\\PMO{%06d}}\n", ku*100 + ten);
 146       }
 147     }
 148     while ((ten % nchline) != 1){
 149       printf(" &\n");
 150       ten++;
 151     }
 152     printf("\\\\\n");
 153     printf("\\hline\n");
 154     printf("\\end{tabular}\n");
 155     printf("\\end{center}");
 156     printf("}\n");
 157     printf("\n");
 158   }
 159 
 160   printf("\\end{document}\n");
 161   
 162   return 0;
 163 }

/* [<][>][^][v][top][bottom][index][help] */