GNU Unifont  15.1.01
Pan-Unicode font with complete Unicode Plane 0 coverage and partial coverage of higher planes
unijohab2html.c
Go to the documentation of this file.
1 /**
2  @file unijohab2html.c
3 
4  @brief Display overalpped Hangul letter combinations in a grid.
5 
6  This displays overlapped letters that form Unicode Hangul Syllables
7  combinations, as a tool to determine bounding boxes for all combinations.
8  It works with both modern and archaic Hangul letters.
9 
10  Input is a Unifont .hex file such as the "hangul-base.hex" file that
11  is part of the Unifont package. Glyphs are all processed as being
12  16 pixels wide and 16 pixels tall.
13 
14  Output is an HTML file containing 16 by 16 pixel grids shwoing
15  overlaps in table format, arranged by variation of the initial
16  consonant (choseong).
17 
18  Initial consonants (choseong) have 6 variations. In general, the
19  first three are for combining with vowels (jungseong) that are
20  vertical, horizontal, or vertical and horizontal, respectively;
21  the second set of three variations are for combinations with a final
22  consonant.
23 
24  The output HTML file can be viewed in a web browser.
25 
26  @author Paul Hardy
27 
28  @copyright Copyright © 2023 Paul Hardy
29 */
30 /*
31  LICENSE:
32 
33  This program is free software: you can redistribute it and/or modify
34  it under the terms of the GNU General Public License as published by
35  the Free Software Foundation, either version 2 of the License, or
36  (at your option) any later version.
37 
38  This program is distributed in the hope that it will be useful,
39  but WITHOUT ANY WARRANTY; without even the implied warranty of
40  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41  GNU General Public License for more details.
42 
43  You should have received a copy of the GNU General Public License
44  along with this program. If not, see <http://www.gnu.org/licenses/>.
45 */
46 
47 #include <stdio.h>
48 #include <stdlib.h>
49 #include <string.h>
50 #include "hangul.h"
51 
52 #define MAXFILENAME 1024
53 
54 #define START_JUNG 0 ///< Vowel index of first vowel with which to begin.
55 // #define START_JUNG 21 /* Use this #define for just ancient vowels */
56 
57 
58 /* (Red, Green, Blue) HTML color coordinates. */
59 #define RED 0xCC0000 ///< Color code for slightly unsaturated HTML red.
60 #define GREEN 0x00CC00 ///< Color code for slightly unsaturated HTML green.
61 #define BLUE 0x0000CC ///< Color code for slightly unsaturated HTML blue.
62 #define BLACK 0x000000 ///< Color code for HTML black.
63 #define WHITE 0xFFFFFF ///< Color code for HTML white.
64 
65 
66 /**
67  @brief The main function.
68 */
69 int
70 main (int argc, char *argv[]) {
71  int i, j; /* loop variables */
72  unsigned codept;
73  unsigned max_codept;
74  int modern_only = 0; /* To just use modern Hangul */
75  int group, consonant1, vowel, consonant2;
76  int vowel_variation;
77  unsigned glyph[MAX_GLYPHS][16];
78  unsigned tmp_glyph [16]; /* To build one combined glyph at a time. */
79  unsigned mask;
80  unsigned overlapped; /* To find overlaps */
81  int ancient_choseong; /* Flag when within ancient choseong range. */
82 
83  /*
84  16x16 pixel grid for each Choseong group, for:
85 
86  Group 0 to Group 5 with no Jongseong
87  Group 3 to Group 5 with Jongseong except Nieun
88  Group 3 to Group 5 with Jongseong Nieun
89 
90  12 grids total.
91 
92  Each grid cell will hold a 32-bit HTML RGB color.
93  */
94  unsigned grid[12][16][16];
95 
96  /*
97  Matrices to detect and report overlaps. Identify vowel
98  variations where an overlap occurred. For most vowel
99  variations, there will be no overlap. Then go through
100  choseong, and then jongseong to find the overlapping
101  combinations. This saves storage space as an alternative
102  to storing large 2- or 3-dimensional overlap matrices.
103  */
104  // jungcho: Jungseong overlap with Choseong
105  unsigned jungcho [TOTAL_JUNG * JUNG_VARIATIONS];
106  // jongjung: Jongseong overlap with Jungseong -- for future expansion
107  // unsigned jongjung [TOTAL_JUNG * JUNG_VARIATIONS];
108 
109  int glyphs_overlap; /* If glyph pair being considered overlap. */
110  int cho_overlaps = 0; /* Number of choseong+vowel overlaps. */
111  // int jongjung_overlaps = 0; /* Number of vowel+jongseong overlaps. */
112 
113  int inindex = 0;
114  int outindex = 0;
115  FILE *infp, *outfp; /* Input and output file pointers. */
116 
117  void parse_args (int argc, char *argv[], int *inindex, int *outindex,
118  int *modern_only);
119  int cho_variation (int cho, int jung, int jong);
120  unsigned hangul_read_base16 (FILE *infp, unsigned glyph[][16]);
121  int glyph_overlap (unsigned *glyph1, unsigned *glyph2);
122 
123  void combine_glyphs (unsigned *glyph1, unsigned *glyph2,
124  unsigned *combined_glyph);
125  void print_glyph_txt (FILE *fp, unsigned codept, unsigned *this_glyph);
126 
127 
128  /*
129  Parse command line arguments to open input & output files, if given.
130  */
131  if (argc > 1) {
132  parse_args (argc, argv, &inindex, &outindex, &modern_only);
133  }
134 
135  if (inindex == 0) {
136  infp = stdin;
137  }
138  else {
139  infp = fopen (argv[inindex], "r");
140  if (infp == NULL) {
141  fprintf (stderr, "\n*** ERROR: Cannot open %s for input.\n\n",
142  argv[inindex]);
143  exit (EXIT_FAILURE);
144  }
145  }
146  if (outindex == 0) {
147  outfp = stdout;
148  }
149  else {
150  outfp = fopen (argv[outindex], "w");
151  if (outfp == NULL) {
152  fprintf (stderr, "\n*** ERROR: Cannot open %s for output.\n\n",
153  argv[outindex]);
154  exit (EXIT_FAILURE);
155  }
156  }
157 
158  /*
159  Initialize glyph array to all zeroes.
160  */
161  for (codept = 0; codept < MAX_GLYPHS; codept++) {
162  for (i = 0; i < 16; i++) glyph[codept][i] = 0x0000;
163  }
164 
165  /*
166  Initialize overlap matrices to all zeroes.
167  */
168  for (i = 0; i < TOTAL_JUNG * JUNG_VARIATIONS; i++) {
169  jungcho [i] = 0;
170  }
171  // jongjung is reserved for expansion.
172  // for (i = 0; i < TOTAL_JONG * JONG_VARIATIONS; i++) {
173  // jongjung [i] = 0;
174  // }
175 
176  /*
177  Read Hangul base glyph file.
178  */
179  max_codept = hangul_read_base16 (infp, glyph);
180  if (max_codept > 0x8FF) {
181  fprintf (stderr, "\nWARNING: Hangul glyph range exceeds PUA space.\n\n");
182  }
183 
184  /*
185  If only examining modern Hangul, fill the ancient glyphs
186  with blanks to guarantee they won't overlap. This is
187  not as efficient as ending loops sooner, but is easier
188  to verify for correctness.
189  */
190  if (modern_only) {
191  for (i = 0x0073; i < JUNG_HEX; i++) {
192  for (j = 0; j < 16; j++) glyph[i][j] = 0x0000;
193  }
194  for (i = 0x027A; i < JONG_HEX; i++) {
195  for (j = 0; j < 16; j++) glyph[i][j] = 0x0000;
196  }
197  for (i = 0x032B; i < 0x0400; i++) {
198  for (j = 0; j < 16; j++) glyph[i][j] = 0x0000;
199  }
200  }
201 
202  /*
203  Initialize grids to all black (no color) for each of
204  the 12 Choseong groups.
205  */
206  for (group = 0; group < 12; group++) {
207  for (i = 0; i < 16; i++) {
208  for (j = 0; j < 16; j++) {
209  grid[group][i][j] = BLACK; /* No color at first */
210  }
211  }
212  }
213 
214  /*
215  Superimpose all Choseong glyphs according to group.
216  Each grid spot with choseong will be blue.
217  */
218  for (group = 0; group < 6; group++) {
219  for (consonant1 = CHO_HEX + group;
220  consonant1 < CHO_HEX +
221  CHO_VARIATIONS * TOTAL_CHO;
222  consonant1 += CHO_VARIATIONS) {
223  for (i = 0; i < 16; i++) { /* For each glyph row */
224  mask = 0x8000;
225  for (j = 0; j < 16; j++) {
226  if (glyph[consonant1][i] & mask) grid[group][i][j] |= BLUE;
227  mask >>= 1; /* Get next bit in glyph row */
228  }
229  }
230  }
231  }
232 
233  /*
234  Fill with Choseong (initial consonant) to prepare
235  for groups 3-5 with jongseong except niuen (group+3),
236  then for groups 3-5 with jongseong nieun (group+6).
237  */
238  for (group = 3; group < 6; group++) {
239  for (i = 0; i < 16; i++) {
240  for (j = 0; j < 16; j++) {
241  grid[group + 6][i][j] = grid[group + 3][i][j]
242  = grid[group][i][j];
243  }
244  }
245  }
246 
247  /*
248  For each Jungseong, superimpose first variation on
249  appropriate Choseong group for grids 0 to 5.
250  */
251  for (vowel = START_JUNG; vowel < TOTAL_JUNG; vowel++) {
252  group = cho_variation (-1, vowel, -1);
253  glyphs_overlap = 0; /* Assume the 2 glyphs do not overlap. */
254 
255  for (i = 0; i < 16; i++) { /* For each glyph row */
256  mask = 0x8000;
257  for (j = 0; j < 16; j++) {
258  if (glyph[JUNG_HEX + JUNG_VARIATIONS * vowel][i] & mask) {
259  /*
260  If there was already blue in this grid cell,
261  mark this vowel variation as having overlap
262  with choseong (initial consonant) letter(s).
263  */
264  if (grid[group][i][j] & BLUE) glyphs_overlap = 1;
265 
266  /* Add green to grid cell color. */
267  grid[group][i][j] |= GREEN;
268  }
269  mask >>= 1; /* Mask for next bit in glyph row */
270  } /* for j */
271  } /* for i */
272  if (glyphs_overlap) {
273  jungcho [JUNG_VARIATIONS * vowel] = 1;
274  cho_overlaps++;
275  }
276  } /* for each vowel */
277 
278  /*
279  For each Jungseong, superimpose second variation on
280  appropriate Choseong group for grids 6 to 8.
281  */
282  for (vowel = START_JUNG; vowel < TOTAL_JUNG; vowel++) {
283  /*
284  The second vowel variation is for combination with
285  a final consonant (Jongseong), with initial consonant
286  (Choseong) variations (or "groups") 3 to 5. Thus,
287  if the vowel type returns an initial Choseong group
288  of 0 to 2, add 3 to it.
289  */
290  group = cho_variation (-1, vowel, -1);
291  /*
292  Groups 0 to 2 don't use second vowel variation,
293  so increment if group is below 2.
294  */
295  if (group < 3) group += 3;
296  glyphs_overlap = 0; /* Assume the 2 glyphs do not overlap. */
297 
298  for (i = 0; i < 16; i++) { /* For each glyph row */
299  mask = 0x8000; /* Start mask at leftmost glyph bit */
300  for (j = 0; j < 16; j++) { /* For each column in this row */
301  /* "+ 1" is to get each vowel's second variation */
302  if (glyph [JUNG_HEX +
303  JUNG_VARIATIONS * vowel + 1][i] & mask) {
304  /* If this cell has blue already, mark as overlapped. */
305  if (grid [group + 3][i][j] & BLUE) glyphs_overlap = 1;
306 
307  /* Superimpose green on current cell color. */
308  grid [group + 3][i][j] |= GREEN;
309  }
310  mask >>= 1; /* Get next bit in glyph row */
311  } /* for j */
312  } /* for i */
313  if (glyphs_overlap) {
314  jungcho [JUNG_VARIATIONS * vowel + 1] = 1;
315  cho_overlaps++;
316  }
317  } /* for each vowel */
318 
319  /*
320  For each Jungseong, superimpose third variation on
321  appropriate Choseong group for grids 9 to 11 for
322  final consonant (Jongseong) of Nieun.
323  */
324  for (vowel = START_JUNG; vowel < TOTAL_JUNG; vowel++) {
325  group = cho_variation (-1, vowel, -1);
326  if (group < 3) group += 3;
327  glyphs_overlap = 0; /* Assume the 2 glyphs do not overlap. */
328 
329  for (i = 0; i < 16; i++) { /* For each glyph row */
330  mask = 0x8000;
331  for (j = 0; j < 16; j++) {
332  if (glyph[JUNG_HEX +
333  JUNG_VARIATIONS * vowel + 2][i] & mask) {
334  /* If this cell has blue already, mark as overlapped. */
335  if (grid[group + 6][i][j] & BLUE) glyphs_overlap = 1;
336 
337  grid[group + 6][i][j] |= GREEN;
338  }
339  mask >>= 1; /* Get next bit in glyph row */
340  } /* for j */
341  } /* for i */
342  if (glyphs_overlap) {
343  jungcho [JUNG_VARIATIONS * vowel + 2] = 1;
344  cho_overlaps++;
345  }
346  } /* for each vowel */
347 
348 
349  /*
350  Superimpose all final consonants except nieun for grids 6 to 8.
351  */
352  for (consonant2 = 0; consonant2 < TOTAL_JONG; consonant2++) {
353  /*
354  Skip over Jongseong Nieun, because it is covered in
355  grids 9 to 11 after this loop.
356  */
357  if (consonant2 == 3) consonant2++;
358 
359  glyphs_overlap = 0; /* Assume the 2 glyphs do not overlap. */
360  for (i = 0; i < 16; i++) { /* For each glyph row */
361  mask = 0x8000;
362  for (j = 0; j < 16; j++) {
363  if (glyph [JONG_HEX +
364  JONG_VARIATIONS * consonant2][i] & mask) {
365  if (grid[6][i][j] & GREEN ||
366  grid[7][i][j] & GREEN ||
367  grid[8][i][j] & GREEN) glyphs_overlap = 1;
368 
369  grid[6][i][j] |= RED;
370  grid[7][i][j] |= RED;
371  grid[8][i][j] |= RED;
372  }
373  mask >>= 1; /* Get next bit in glyph row */
374  } /* for j */
375  } /* for i */
376  // jongjung is for expansion
377  // if (glyphs_overlap) {
378  // jongjung [JONG_VARIATIONS * consonant2] = 1;
379  // jongjung_overlaps++;
380  // }
381  } /* for each final consonant except nieun */
382 
383  /*
384  Superimpose final consonant 3 (Jongseong Nieun) on
385  groups 9 to 11.
386  */
387  codept = JONG_HEX + 3 * JONG_VARIATIONS;
388 
389  for (i = 0; i < 16; i++) { /* For each glyph row */
390  mask = 0x8000;
391  for (j = 0; j < 16; j++) {
392  if (glyph[codept][i] & mask) {
393  grid[ 9][i][j] |= RED;
394  grid[10][i][j] |= RED;
395  grid[11][i][j] |= RED;
396  }
397  mask >>= 1; /* Get next bit in glyph row */
398  }
399  }
400 
401 
402  /*
403  Turn the black (uncolored) cells into white for better
404  visibility of grid when displayed.
405  */
406  for (group = 0; group < 12; group++) {
407  for (i = 0; i < 16; i++) {
408  for (j = 0; j < 16; j++) {
409  if (grid[group][i][j] == BLACK) grid[group][i][j] = WHITE;
410  }
411  }
412  }
413 
414 
415  /*
416  Generate HTML output.
417  */
418  fprintf (outfp, "<html>\n");
419  fprintf (outfp, "<head>\n");
420  fprintf (outfp, " <title>Johab 6/3/1 Overlaps</title>\n");
421  fprintf (outfp, "</head>\n");
422  fprintf (outfp, "<body bgcolor=\"#FFFFCC\">\n");
423 
424  fprintf (outfp, "<center>\n");
425  fprintf (outfp, " <h1>Unifont Hangul Jamo Syllable Components</h1>\n");
426  fprintf (outfp, " <h2>Johab 6/3/1 Overlap</h2><br><br>\n");
427 
428  /* Print the color code key for the table. */
429  fprintf (outfp, " <table border=\"1\" cellpadding=\"10\">\n");
430  fprintf (outfp, " <tr><th colspan=\"2\" align=\"center\" bgcolor=\"#FFCC80\">");
431  fprintf (outfp, "<font size=\"+1\">Key</font></th></tr>\n");
432  fprintf (outfp, " <tr>\n");
433  fprintf (outfp, " <th align=\"center\" bgcolor=\"#FFFF80\">Color</th>\n");
434  fprintf (outfp, " <th align=\"center\" bgcolor=\"#FFFF80\">Letter(s)</th>\n");
435  fprintf (outfp, " </tr>\n");
436 
437  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", BLUE);
438  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
439  fprintf (outfp, "<td>Choseong (Initial Consonant)</td></tr>\n");
440 
441  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", GREEN);
442  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
443  fprintf (outfp, "<td>Jungseong (Medial Vowel/Diphthong)</td></tr>\n");
444 
445  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", RED);
446  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
447  fprintf (outfp, "<td>Jongseong (Final Consonant)</td></tr>\n");
448 
449  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", BLUE | GREEN);
450  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
451  fprintf (outfp, "<td>Choseong + Jungseong Overlap</td></tr>\n");
452 
453  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", GREEN | RED);
454  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
455  fprintf (outfp, "<td>Jungseong + Jongseong Overlap</td></tr>\n");
456 
457  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", RED | BLUE);
458  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
459  fprintf (outfp, "<td>Choseong + Jongseong Overlap</td></tr>\n");
460 
461  fprintf (outfp, " <tr><td bgcolor=\"#%06X\">", RED | GREEN | BLUE);
462  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>");
463  fprintf (outfp, "<td>Choseong + Jungseong + Jongseong Overlap</td></tr>\n");
464 
465  fprintf (outfp, " </table>\n");
466  fprintf (outfp, " <br><br>\n");
467 
468 
469  for (group = 0; group < 12; group++) {
470  /* Arrange tables 3 across, 3 down. */
471  if ((group % 3) == 0) {
472  fprintf (outfp, " <table border=\"0\" cellpadding=\"10\">\n");
473  fprintf (outfp, " <tr>\n");
474  }
475 
476  fprintf (outfp, " <td>\n");
477  fprintf (outfp, " <table border=\"3\" cellpadding=\"2\">\n");
478  fprintf (outfp, " <tr><th colspan=\"16\" bgcolor=\"#FFFF80\">");
479  fprintf (outfp, "Choseong Group %d, %s %s</th></tr>\n",
480  group < 6 ? group : (group > 8 ? group - 6 : group - 3),
481  group < 6 ? (group < 3 ? "No" : "Without") : "With",
482  group < 9 ? "Jongseong" : "Nieun");
483 
484  for (i = 0; i < 16; i++) {
485  fprintf (outfp, " <tr>\n");
486  for (j = 0; j < 16; j++) {
487  fprintf (outfp, " <td bgcolor=\"#%06X\">",
488  grid[group][i][j]);
489  fprintf (outfp, "&nbsp;&nbsp;&nbsp;&nbsp;</td>\n");
490  }
491  fprintf (outfp, " </tr>\n");
492  }
493 
494  fprintf (outfp, " </td>\n");
495  fprintf (outfp, " </tr>\n");
496  fprintf (outfp, " </table>\n");
497  fprintf (outfp, " </td>\n");
498 
499  if ((group % 3) == 2) {
500  fprintf (outfp, " </tr>\n");
501  fprintf (outfp, " </table>\n </br>\n");
502  }
503  }
504 
505  /* Wrap up HTML table output. */
506  fprintf (outfp, "</center>\n");
507 
508  /*
509  Print overlapping initial consonant + vowel combinations.
510  */
511  fprintf (outfp, "<h2>%d Vowel Overlaps with Initial Consonants Found</h2>",
512  cho_overlaps);
513  fprintf (outfp, "<font size=\"+1\"><pre>\n");
514 
515  for (i = JUNG_HEX;
516  i < JUNG_HEX + TOTAL_JUNG * JUNG_VARIATIONS;
517  i++) {
518  /*
519  If this vowel variation (Jungseong) had overlaps
520  with one or more initial consonants (Choseong),
521  find and print them.
522  */
523  if (jungcho [i - JUNG_HEX]) {
524  ancient_choseong = 0; /* Not within ancient choseong range yet. */
525  fprintf (outfp, "<font color=\"#0000FF\"><b>");
526  if (i >= JUNG_ANCIENT_HEX) {
527  if (i >= JUNG_EXTB_HEX) fprintf (outfp, "Extended-B ");
528  fprintf (outfp, "Ancient ");
529  }
530  fprintf (outfp, "Vowel at 0x%04X and&hellip;</b>", i + PUA_START);
531  fprintf (outfp, "</font>\n\n");
532 
533  /*
534  Get current vowel number, 0 to (TOTAL_JUNG - 1), and
535  current vowel variation, 0 or 1, or 2 for final nieun.
536  */
537  vowel = (i - JUNG_HEX) / JUNG_VARIATIONS;
538  vowel_variation = (i - JUNG_HEX) % JUNG_VARIATIONS;
539 
540  /* Get first Choseong group for this vowel, 0 to 5. */
541  group = cho_variation (-1, vowel, -1);
542 
543  /*
544  If this vowel variation is used with a final consonant
545  (Jongseong) and the default initial consonant (Choseong)
546  group for this vowel is < 3, add 3 to current Chosenong
547  group.
548  */
549  if (vowel_variation > 0 && group < 3) group += 3;
550 
551  for (consonant1 = 0; consonant1 < TOTAL_CHO; consonant1++) {
552  overlapped = glyph_overlap (glyph [i],
553  glyph [consonant1 * CHO_VARIATIONS
554  + CHO_HEX + group]);
555 
556  /*
557  If we just entered ancient choseong range, flag it.
558  */
559  if (overlapped && consonant1 >= 19 && ancient_choseong == 0) {
560  fprintf (outfp, "<font color=\"#0000FF\"><b>");
561  fprintf (outfp, "&hellip;Ancient Choseong&hellip;</b></font>\n");
562  ancient_choseong = 1;
563  }
564  /*
565  If overlapping choseong found, print combined glyph.
566  */
567  if (overlapped != 0) {
568 
569  combine_glyphs (glyph [i],
570  glyph [consonant1 * CHO_VARIATIONS
571  + CHO_HEX + group],
572  tmp_glyph);
573 
574  print_glyph_txt (outfp,
575  PUA_START +
576  consonant1 * CHO_VARIATIONS +
577  CHO_HEX + group,
578  tmp_glyph);
579 
580  } /* If overlapping pixels found. */
581  } /* For each initial consonant (Choseong) */
582  } /* Find the initial consonant that overlapped this vowel variation. */
583  } /* For each variation of each vowel (Jungseong) */
584 
585  fputc ('\n', outfp);
586 
587  fprintf (outfp, "</pre></font>\n");
588  fprintf (outfp, "</body>\n");
589  fprintf (outfp, "</html>\n");
590 
591  fclose (infp);
592  fclose (outfp);
593 
594 
595  exit (EXIT_SUCCESS);
596 }
597 
598 
599 /**
600  @brief Parse command line arguments.
601 
602  @param[in] argc The argc parameter to the main function.
603  @param[in] argv The argv command line arguments to the main function.
604  @param[in,out] infile The input filename; defaults to NULL.
605  @param[in,out] outfile The output filename; defaults to NULL.
606 */
607 void
608 parse_args (int argc, char *argv[], int *inindex, int *outindex,
609  int *modern_only) {
610  int arg_count; /* Current index into argv[]. */
611 
612  int strncmp (const char *s1, const char *s2, size_t n);
613 
614 
615  arg_count = 1;
616 
617  while (arg_count < argc) {
618  /* If input file is specified, open it for read access. */
619  if (strncmp (argv [arg_count], "-i", 2) == 0) {
620  arg_count++;
621  if (arg_count < argc) {
622  *inindex = arg_count;
623  }
624  }
625  /* If only modern Hangul is desired, set modern_only flag. */
626  else if (strncmp (argv [arg_count], "-m", 2) == 0 ||
627  strncmp (argv [arg_count], "--modern", 8) == 0) {
628  *modern_only = 1;
629  }
630  /* If output file is specified, open it for write access. */
631  else if (strncmp (argv [arg_count], "-o", 2) == 0) {
632  arg_count++;
633  if (arg_count < argc) {
634  *outindex = arg_count;
635  }
636  }
637  /* If help is requested, print help message and exit. */
638  else if (strncmp (argv [arg_count], "-h", 2) == 0 ||
639  strncmp (argv [arg_count], "--help", 6) == 0) {
640  printf ("\nunijohab2html [options]\n\n");
641  printf (" Generates an HTML page of overlapping Hangul letters from an input\n");
642  printf (" Unifont .hex file encoded in Johab 6/3/1 format.\n\n");
643 
644  printf (" Option Parameters Function\n");
645  printf (" ------ ---------- --------\n");
646  printf (" -h, --help Print this message and exit.\n\n");
647  printf (" -i input_file Unifont hangul-base.hex formatted input file.\n\n");
648  printf (" -o output_file HTML output file showing overlapping letters.\n\n");
649  printf (" -m, --modern Only examine modern Hangul letters.\n\n");
650  printf (" Example:\n\n");
651  printf (" unijohab2html -i hangul-base.hex -o hangul-syllables.html\n\n");
652 
653  exit (EXIT_SUCCESS);
654  }
655 
656  arg_count++;
657  }
658 
659  return;
660 }
661 
Define constants and function prototypes for using Hangul glyphs.
#define CHO_VARIATIONS
6 choseong variations
Definition: hangul.h:88
#define JONG_VARIATIONS
1 jongseong variation
Definition: hangul.h:90
void print_glyph_txt(FILE *fp, unsigned codept, unsigned *this_glyph)
Print one glyph in Unifont hexdraw plain text style.
#define JUNG_HEX
Location of first jungseong (will be 0x2FB)
Definition: hangul.h:108
int glyph_overlap(unsigned *glyph1, unsigned *glyph2)
See if two glyphs overlap.
#define JUNG_ANCIENT_HEX
Location of first ancient jungseong.
Definition: hangul.h:111
#define JUNG_VARIATIONS
3 jungseong variations
Definition: hangul.h:89
void combine_glyphs(unsigned *glyph1, unsigned *glyph2, unsigned *combined_glyph)
Combine two glyphs into one glyph.
#define CHO_HEX
Location of first choseong (location 0x0000 is a blank glyph)
Definition: hangul.h:96
int cho_variation(int choseong, int jungseong, int jongseong)
Return the Johab 6/3/1 choseong variation for a syllable.
#define JUNG_EXTB_HEX
U+D7B0 Extended-B jungseong.
Definition: hangul.h:114
#define JONG_HEX
Location of first jongseong (will be 0x421)
Definition: hangul.h:120
unsigned hangul_read_base16(FILE *infp, unsigned base[][16])
Read hangul-base.hex file into a unsigned array.
#define MAX_GLYPHS
An OpenType font has at most 65536 glyphs.
Definition: hex2otf.c:85
int main(int argc, char *argv[])
The main function.
Definition: unijohab2html.c:70
#define START_JUNG
Vowel index of first vowel with which to begin.
Definition: unijohab2html.c:54
#define BLUE
Color code for slightly unsaturated HTML blue.
Definition: unijohab2html.c:61
#define BLACK
Color code for HTML black.
Definition: unijohab2html.c:62
#define WHITE
Color code for HTML white.
Definition: unijohab2html.c:63
#define RED
Color code for slightly unsaturated HTML red.
Definition: unijohab2html.c:59
#define GREEN
Color code for slightly unsaturated HTML green.
Definition: unijohab2html.c:60
void parse_args(int argc, char *argv[], int *inindex, int *outindex, int *modern_only)
Parse command line arguments.