plotfont.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /* This file is part of the GNU plotutils package. Copyright (C) 1995,
  2. 1996, 1997, 1998, 1999, 2000, 2005, 2008, 2009, Free Software
  3. Foundation, Inc.
  4. The GNU plotutils package is free software. You may redistribute it
  5. and/or modify it under the terms of the GNU General Public License as
  6. published by the Free Software foundation; either version 2, or (at your
  7. option) any later version.
  8. The GNU plotutils package is distributed in the hope that it will be
  9. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License along
  13. with the GNU plotutils package; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor,
  15. Boston, MA 02110-1301, USA. */
  16. /* This file is the driving routine for the GNU `plotfont' program. It
  17. includes code to plot all characters in a specified font. */
  18. #include "sys-defines.h"
  19. #include "libcommon.h"
  20. #include "getopt.h"
  21. #include "fontlist.h"
  22. #include "plot.h"
  23. const char *progname = "plotfont"; /* name of this program */
  24. const char *written = "Written by Robert S. Maier.";
  25. const char *copyright = "Copyright (C) 2009 Free Software Foundation, Inc.";
  26. const char *usage_appendage = " FONT...\n";
  27. enum radix { DECIMAL, OCTAL, HEXADECIMAL };
  28. /* options */
  29. #define ARG_NONE 0
  30. #define ARG_REQUIRED 1
  31. #define ARG_OPTIONAL 2
  32. const char *optstring = "12oxOj:J:F:T:";
  33. struct option long_options[] =
  34. {
  35. /* The most important option ("--display-type" is an obsolete variant) */
  36. { "output-format", ARG_REQUIRED, NULL, 'T'},
  37. { "display-type", ARG_REQUIRED, NULL, 'T' << 8 }, /* hidden */
  38. /* Other frequently used options */
  39. { "box", ARG_NONE, NULL, 'b' << 8 },
  40. { "octal", ARG_NONE, NULL, 'o'},
  41. { "hexadecimal", ARG_NONE, NULL, 'x'},
  42. { "jis-page", ARG_REQUIRED, NULL, 'J'},
  43. { "jis-row", ARG_REQUIRED, NULL, 'j'},
  44. { "lower-half", ARG_NONE, NULL, '1'},
  45. { "upper-half", ARG_NONE, NULL, '2'},
  46. { "font-name", ARG_REQUIRED, NULL, 'F' }, /* hidden */
  47. /* Long options with no equivalent short option alias */
  48. { "numbering-font-name", ARG_REQUIRED, NULL, 'N' << 8 },
  49. { "title-font-name", ARG_REQUIRED, NULL, 'Z' << 8 },
  50. { "pen-color", ARG_REQUIRED, NULL, 'C' << 8 },
  51. { "bg-color", ARG_REQUIRED, NULL, 'q' << 8 },
  52. { "bitmap-size", ARG_REQUIRED, NULL, 'B' << 8 },
  53. { "emulate-color", ARG_REQUIRED, NULL, 'e' << 8 },
  54. { "page-size", ARG_REQUIRED, NULL, 'P' << 8 },
  55. { "rotation", ARG_REQUIRED, NULL, 'r' << 8 },
  56. /* Options relevant only to raw plotfont (refers to metafile output) */
  57. { "portable-output", ARG_NONE, NULL, 'O' },
  58. /* Documentation options */
  59. { "help-fonts", ARG_NONE, NULL, 'f' << 8 },
  60. { "list-fonts", ARG_NONE, NULL, 'l' << 8 },
  61. { "version", ARG_NONE, NULL, 'V' << 8 },
  62. { "help", ARG_NONE, NULL, 'h' << 8 },
  63. { NULL, 0, NULL, 0}
  64. };
  65. /* null-terminated list of options, such as obsolete-but-still-maintained
  66. options or undocumented options, which we don't show to the user */
  67. const int hidden_options[] = { (int)'J', (int)'F', (int)('T' << 8), 0 };
  68. /* forward references */
  69. bool do_font (plPlotter *plotter, const char *name, bool upper_half, char *pen_color_name, char *numbering_font_name, char *title_font_name, bool bearings, enum radix base, int jis_page, bool do_jis_page);
  70. void write_three_bytes (int charnum, char *numbuf, int radix);
  71. void write_two_bytes (int charnum, char *numbuf, int radix);
  72. int
  73. main (int argc, char *argv[])
  74. {
  75. plPlotter *plotter;
  76. plPlotterParams *plotter_params;
  77. bool bearings = false; /* show sidebearings on characters? */
  78. bool do_jis_page = false; /* show page of HersheyEUC in JIS encoding? */
  79. bool do_list_fonts = false; /* show a list of fonts? */
  80. bool show_fonts = false; /* supply help on fonts? */
  81. bool show_usage = false; /* show usage message? */
  82. bool show_version = false; /* show version message? */
  83. bool upper_half = false; /* upper half of font, not lower? */
  84. char *output_format = (char *)"meta"; /* default libplot output format */
  85. char *numbering_font_name = NULL; /* numbering font name, NULL -> default */
  86. char *option_font_name = NULL; /* allows user to use -F */
  87. char *pen_color = NULL; /* initial pen color, can be spec'd by user */
  88. char *title_font_name = NULL; /* title font name, NULL -> current font */
  89. enum radix base = DECIMAL;
  90. int errcnt = 0; /* errors encountered */
  91. int jis_page = 33; /* page of HersheyEUC in JIS encoding */
  92. int opt_index; /* long option index */
  93. int option; /* option character */
  94. int retval; /* return value */
  95. plotter_params = pl_newplparams ();
  96. while ((option = getopt_long (argc, argv, optstring, long_options, &opt_index)) != EOF)
  97. {
  98. if (option == 0)
  99. option = long_options[opt_index].val;
  100. switch (option)
  101. {
  102. case 'T': /* Output format, ARG REQUIRED */
  103. case 'T' << 8:
  104. output_format = (char *)xmalloc (strlen (optarg) + 1);
  105. strcpy (output_format, optarg);
  106. break;
  107. case 'O': /* Ascii output */
  108. pl_setplparam (plotter_params, "META_PORTABLE", (char *)"yes");
  109. break;
  110. case '1': /* Lower half */
  111. upper_half = false;
  112. break;
  113. case '2': /* Upper half */
  114. upper_half = true;
  115. break;
  116. case 'o': /* Octal */
  117. base = OCTAL;
  118. break;
  119. case 'x': /* Hexadecimal */
  120. base = HEXADECIMAL;
  121. break;
  122. case 'F': /* set the initial font */
  123. option_font_name = (char *)xmalloc (strlen (optarg) + 1);
  124. strcpy (option_font_name, optarg);
  125. break;
  126. case 'e' << 8: /* Emulate color via grayscale */
  127. pl_setplparam (plotter_params, "EMULATE_COLOR", (char *)optarg);
  128. break;
  129. case 'N' << 8: /* Numbering Font name, ARG REQUIRED */
  130. numbering_font_name = xstrdup (optarg);
  131. break;
  132. case 'Z' << 8: /* Title Font name, ARG REQUIRED */
  133. title_font_name = xstrdup (optarg);
  134. break;
  135. case 'C' << 8: /* set the initial pen color */
  136. pen_color = (char *)xmalloc (strlen (optarg) + 1);
  137. strcpy (pen_color, optarg);
  138. break;
  139. case 'q' << 8: /* set the initial background color */
  140. pl_setplparam (plotter_params, "BG_COLOR", (void *)optarg);
  141. break;
  142. case 'B' << 8: /* Bitmap size */
  143. pl_setplparam (plotter_params, "BITMAPSIZE", (void *)optarg);
  144. break;
  145. case 'P' << 8: /* Page size */
  146. pl_setplparam (plotter_params, "PAGESIZE", (void *)optarg);
  147. break;
  148. case 'r' << 8: /* Rotation angle */
  149. pl_setplparam (plotter_params, "ROTATION", (void *)optarg);
  150. break;
  151. case 'b' << 8: /* Bearings requested */
  152. bearings = true;
  153. break;
  154. case 'V' << 8: /* Version */
  155. show_version = true;
  156. break;
  157. case 'f' << 8: /* Fonts */
  158. show_fonts = true;
  159. break;
  160. case 'l' << 8: /* Fonts */
  161. do_list_fonts = true;
  162. break;
  163. case 'J': /* JIS page */
  164. if (sscanf (optarg, "%d", &jis_page) <= 0
  165. || (jis_page < 33) || (jis_page > 126))
  166. {
  167. fprintf (stderr,
  168. "%s: the JIS page number is bad (it should be in the range 33..126)\n",
  169. progname);
  170. errcnt++;
  171. }
  172. else
  173. do_jis_page = true;
  174. break;
  175. case 'j': /* JIS row */
  176. if (sscanf (optarg, "%d", &jis_page) <= 0
  177. || (jis_page < 1) || (jis_page > 94))
  178. {
  179. fprintf (stderr,
  180. "%s: the JIS row number is bad (it should be in the range 1..94)\n",
  181. progname);
  182. errcnt++;
  183. }
  184. else
  185. {
  186. jis_page += 32;
  187. do_jis_page = true;
  188. }
  189. break;
  190. case 'h' << 8: /* Help */
  191. show_usage = true;
  192. break;
  193. default:
  194. errcnt++;
  195. break;
  196. }
  197. }
  198. if (errcnt > 0)
  199. {
  200. fprintf (stderr, "Try `%s --help' for more information\n", progname);
  201. return EXIT_FAILURE;
  202. }
  203. if (show_version)
  204. {
  205. display_version (progname, written, copyright);
  206. return EXIT_SUCCESS;
  207. }
  208. if (do_list_fonts)
  209. {
  210. int success;
  211. success = list_fonts (output_format, progname);
  212. if (success)
  213. return EXIT_SUCCESS;
  214. else
  215. return EXIT_FAILURE;
  216. }
  217. if (show_fonts)
  218. {
  219. int success;
  220. success = display_fonts (output_format, progname);
  221. if (success)
  222. return EXIT_SUCCESS;
  223. else
  224. return EXIT_FAILURE;
  225. }
  226. if (show_usage)
  227. {
  228. display_usage (progname, hidden_options, usage_appendage, 2);
  229. return EXIT_SUCCESS;
  230. }
  231. if (option_font_name == NULL && optind >= argc)
  232. {
  233. fprintf (stderr, "%s: no font or fonts are specified\n", progname);
  234. return EXIT_FAILURE;
  235. }
  236. if (do_jis_page)
  237. {
  238. if ((!((option_font_name == NULL && optind == argc - 1)
  239. || (option_font_name && optind >= argc)))
  240. || (option_font_name && strcasecmp (option_font_name, "HersheyEUC") != 0)
  241. || (!option_font_name && strcasecmp (argv[optind], "HersheyEUC") != 0))
  242. {
  243. fprintf (stderr, "%s: a JIS page can only be specified for the HersheyEUC font\n", progname);
  244. return EXIT_FAILURE;
  245. }
  246. }
  247. if ((plotter = pl_newpl_r (output_format, NULL, stdout, stderr,
  248. plotter_params)) == NULL)
  249. {
  250. fprintf (stderr, "%s: error: the plot device could not be created\n", progname);
  251. return EXIT_FAILURE;
  252. }
  253. if (option_font_name)
  254. /* user specifed a font with -F */
  255. {
  256. if (do_font (plotter, option_font_name, upper_half, pen_color, numbering_font_name, title_font_name, bearings, base, jis_page, do_jis_page) == false)
  257. return EXIT_FAILURE;
  258. }
  259. if (optind < argc)
  260. /* 1 or more fonts named explicitly on command line */
  261. {
  262. for (; optind < argc; optind++)
  263. {
  264. char *font_name;
  265. font_name = argv[optind];
  266. if (do_font (plotter, font_name, upper_half, pen_color, numbering_font_name, title_font_name, bearings, base, jis_page, do_jis_page) == false)
  267. return EXIT_FAILURE;
  268. }
  269. }
  270. /* clean up */
  271. retval = EXIT_SUCCESS;
  272. if (pl_deletepl_r (plotter) < 0)
  273. {
  274. fprintf (stderr, "%s: error: the plot device could not be deleted\n", progname);
  275. retval = EXIT_FAILURE;
  276. }
  277. pl_deleteplparams (plotter_params);
  278. return retval;
  279. }
  280. #define NUM_ROWS 12
  281. #define SIZE 1.0
  282. #define MAX_TITLE_LENGTH 0.9
  283. #define HSPACING 0.1 /* must have 8*HSPACING < SIZE */
  284. #define VSPACING 0.06 /* must have 12*VSPACING < SIZE-LINE_VOFFSET */
  285. #define LINE_HOFFSET (0.5 * ((SIZE) - 8 * (HSPACING)))
  286. #define LINE_VOFFSET 0.15 /* top line down from top of display by this */
  287. #define CHAR_HOFFSET ((LINE_HOFFSET) + 0.5 * (HSPACING))
  288. #define CHAR_VOFFSET ((LINE_VOFFSET) + 0.5 * (VSPACING))
  289. #define TOP (SIZE - (LINE_VOFFSET))
  290. #define BOTTOM ((SIZE - (LINE_VOFFSET)) - 12 * (VSPACING))
  291. #define LEFT (LINE_HOFFSET)
  292. #define RIGHT (LINE_HOFFSET + 8 * HSPACING)
  293. #define FONT_SIZE 0.04
  294. #define TITLE_FONT_SIZE 0.045
  295. #define NUMBERING_FONT_SIZE 0.015
  296. /* shifts of numbers in grid cells leftward and upward */
  297. #define N_X_SHIFT 0.015
  298. #define N_Y_SHIFT 0.05
  299. bool
  300. do_font (plPlotter *plotter, const char *name, bool upper_half, char *pen_color_name, char *numbering_font_name, char *title_font_name, bool bearings, enum radix base, int jis_page, bool do_jis_page)
  301. {
  302. char buf[16];
  303. char numbuf[16];
  304. char suffixbuf[16];
  305. char *titlebuf;
  306. const char *suffix;
  307. double title_width;
  308. int i, j, bottom_octet, top_octet;
  309. if (do_jis_page)
  310. {
  311. switch (base)
  312. {
  313. case DECIMAL:
  314. default:
  315. sprintf (suffixbuf, " (row %d)", jis_page - 32);
  316. break;
  317. case OCTAL:
  318. sprintf (suffixbuf, " (row 0%o)", jis_page - 32);
  319. break;
  320. case HEXADECIMAL:
  321. sprintf (suffixbuf, " (row 0x%X)", jis_page - 32);
  322. break;
  323. }
  324. suffix = suffixbuf;
  325. }
  326. else
  327. suffix = upper_half ? " (upper half)" : " (lower half)";
  328. titlebuf = (char *)xmalloc (strlen (name) + strlen (suffix) + 1);
  329. strcpy (titlebuf, name);
  330. strcat (titlebuf, suffix);
  331. if (pl_openpl_r (plotter) < 0)
  332. {
  333. fprintf (stderr, "%s: error: the plot device could not be opened\n", progname);
  334. return false;
  335. }
  336. pl_fspace_r (plotter, 0.0, 0.0, (double)SIZE, (double)SIZE);
  337. pl_erase_r (plotter);
  338. if (pen_color_name)
  339. pl_pencolorname_r (plotter, pen_color_name);
  340. pl_fmove_r (plotter, 0.5 * SIZE, 0.5 * (SIZE + TOP));
  341. if (title_font_name)
  342. pl_fontname_r (plotter, title_font_name);
  343. else
  344. pl_fontname_r (plotter, name);
  345. pl_ffontsize_r (plotter, (double)(TITLE_FONT_SIZE));
  346. title_width = pl_flabelwidth_r (plotter, titlebuf);
  347. if (title_width > MAX_TITLE_LENGTH)
  348. /* squeeze title to fit */
  349. pl_ffontsize_r (plotter,
  350. (double)(TITLE_FONT_SIZE) * (MAX_TITLE_LENGTH / title_width));
  351. /* print title */
  352. pl_alabel_r (plotter, 'c', 'c', titlebuf);
  353. if (do_jis_page)
  354. bottom_octet = 4;
  355. else /* ordinary map */
  356. {
  357. if (upper_half)
  358. bottom_octet = 20;
  359. else
  360. bottom_octet = 4;
  361. }
  362. top_octet = bottom_octet + NUM_ROWS - 1;
  363. /* draw grid */
  364. pl_linemod_r (plotter, "solid");
  365. pl_fbox_r (plotter, LEFT, BOTTOM, RIGHT, TOP);
  366. for (i = 1; i <= 7; i++)
  367. /* boustrophedon */
  368. {
  369. if (i % 2)
  370. pl_fline_r (plotter,
  371. LINE_HOFFSET + i * HSPACING, BOTTOM,
  372. LINE_HOFFSET + i * HSPACING, TOP);
  373. else
  374. pl_fline_r (plotter,
  375. LINE_HOFFSET + i * HSPACING, TOP,
  376. LINE_HOFFSET + i * HSPACING, BOTTOM);
  377. }
  378. for (j = 1; j <= 11; j++)
  379. /* boustrophedon */
  380. {
  381. if (j % 2)
  382. pl_fline_r (plotter,
  383. RIGHT, TOP - j * VSPACING,
  384. LEFT, TOP - j * VSPACING);
  385. else
  386. pl_fline_r (plotter,
  387. LEFT, TOP - j * VSPACING,
  388. RIGHT, TOP - j * VSPACING);
  389. }
  390. /* number grid cells */
  391. if (numbering_font_name)
  392. pl_fontname_r (plotter, numbering_font_name);
  393. else /* select default font */
  394. pl_fontname_r (plotter, "");
  395. pl_ffontsize_r (plotter, (double)(NUMBERING_FONT_SIZE));
  396. if (bearings)
  397. pl_linemod_r (plotter, "dotted");
  398. for (i = bottom_octet; i <= top_octet; i++)
  399. for (j = 0; j < 8; j++)
  400. {
  401. int row, column, charnum;
  402. row = i - bottom_octet; /* row, 0..11 */
  403. column = j; /* column, 0..7 */
  404. charnum = (unsigned char)(8 * i + j);
  405. if (charnum == 127) /* 0xff not a legitimate glyph */
  406. continue;
  407. if (do_jis_page && charnum == 32)
  408. continue; /* 0x20 not legitimate for JIS */
  409. switch (base)
  410. {
  411. case HEXADECIMAL:
  412. write_two_bytes (charnum - (do_jis_page ? 32 : 0), numbuf, 16);
  413. break;
  414. case DECIMAL:
  415. default:
  416. write_three_bytes (charnum - (do_jis_page ? 32 : 0), numbuf, 10);
  417. break;
  418. case OCTAL:
  419. write_three_bytes (charnum - (do_jis_page ? 32 : 0), numbuf, 8);
  420. break;
  421. }
  422. pl_fmove_r (plotter,
  423. (double)(LINE_HOFFSET + HSPACING * (column + 1 - N_X_SHIFT)),
  424. (double)(SIZE - (LINE_VOFFSET + VSPACING * (row + 1 - N_Y_SHIFT))));
  425. pl_alabel_r (plotter, 'r', 'x', numbuf);
  426. }
  427. /* fill grid cells with characters */
  428. pl_fontname_r (plotter, name);
  429. pl_ffontsize_r (plotter, (double)(FONT_SIZE));
  430. for (i = bottom_octet; i <= top_octet; i++)
  431. for (j = 0; j < 8; j++)
  432. {
  433. int row, column, charnum;
  434. row = i - bottom_octet; /* row, 0..11 */
  435. column = j; /* column, 0..7 */
  436. charnum = (unsigned char)(8 * i + j);
  437. if (charnum == 127) /* 0xff not a legitimate glyph */
  438. continue;
  439. if (do_jis_page && charnum == 32)
  440. continue; /* 0x20 not legitimate for JIS */
  441. if (!do_jis_page)
  442. {
  443. buf[0] = charnum;
  444. buf[1] = '\0';
  445. }
  446. else /* do JIS page */
  447. {
  448. /* two bytes, set high bits on both page and character */
  449. buf[0] = jis_page + 0x80;
  450. buf[1] = charnum + 0x80;
  451. buf[2] = '\0';
  452. }
  453. pl_fmove_r (plotter,
  454. (double)(LINE_HOFFSET + HSPACING * (column + 0.5)),
  455. (double)(SIZE - (LINE_VOFFSET + VSPACING * (row + 0.5))));
  456. /* place glyph on page */
  457. pl_alabel_r (plotter, 'c', 'c', (char *)buf);
  458. if (bearings)
  459. {
  460. double halfwidth;
  461. /* compute glyph width */
  462. halfwidth = 0.5 * pl_flabelwidth_r (plotter, (char *)buf);
  463. if (halfwidth == 0.0)
  464. /* empty glyph, draw only one vertical dotted line */
  465. pl_fline_r (plotter,
  466. (double)(CHAR_HOFFSET + HSPACING * column),
  467. (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row - 0.5))),
  468. (double)(CHAR_HOFFSET + HSPACING * column),
  469. (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row + 0.5))));
  470. else
  471. /* draw vertical dotted lines to either side of glyph */
  472. {
  473. pl_fline_r (plotter,
  474. (double)(CHAR_HOFFSET + HSPACING * column - halfwidth),
  475. (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row - 0.5))),
  476. (double)(CHAR_HOFFSET + HSPACING * column - halfwidth),
  477. (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row + 0.5))));
  478. pl_fline_r (plotter,
  479. (double)(CHAR_HOFFSET + HSPACING * column + halfwidth),
  480. (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row - 0.5))),
  481. (double)(CHAR_HOFFSET + HSPACING * column + halfwidth),
  482. (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row + 0.5))));
  483. }
  484. }
  485. }
  486. if (pl_closepl_r (plotter) < 0)
  487. {
  488. fprintf (stderr, "%s: error: the plot device could not be closed\n", progname);
  489. return false;
  490. }
  491. return true;
  492. }
  493. /* Write an integer that is < (radix)**4 as three ascii bytes with respect
  494. to the specified radix. Initial zeroes are converted to spaces. */
  495. void
  496. write_three_bytes (int charnum, char *numbuf, int radix)
  497. {
  498. int i;
  499. numbuf[0] = charnum / (radix * radix);
  500. numbuf[1] = (charnum - (radix * radix) * (charnum / (radix * radix))) / radix;
  501. numbuf[2] = charnum % radix;
  502. numbuf[3] = '\0';
  503. for (i = 0 ; i <= 2 ; i++)
  504. {
  505. if (numbuf[i] >= 10)
  506. numbuf[i] += ('A' - 10);
  507. else
  508. numbuf[i] += '0';
  509. }
  510. if (numbuf[0] == '0')
  511. {
  512. numbuf[0] = ' ';
  513. if (numbuf[1] == '0')
  514. numbuf[1] = ' ';
  515. }
  516. }
  517. /* Write an integer that is < (radix)**3 as two ascii bytes with respect to
  518. the specified radix. Initial zeroes are converted are not changed. */
  519. void
  520. write_two_bytes (int charnum, char *numbuf, int radix)
  521. {
  522. int i;
  523. numbuf[0] = charnum / radix;
  524. numbuf[1] = charnum % radix;
  525. numbuf[2] = '\0';
  526. for (i = 0 ; i <= 1 ; i++)
  527. {
  528. if (numbuf[i] >= 10)
  529. numbuf[i] += ('A' - 10);
  530. else
  531. numbuf[i] += '0';
  532. }
  533. }