File: plotfont.c

package info (click to toggle)
plotutils 2.4.1-15
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 11,072 kB
  • ctags: 6,952
  • sloc: ansic: 76,305; cpp: 12,402; sh: 8,475; yacc: 2,604; makefile: 894; lex: 144
file content (618 lines) | stat: -rw-r--r-- 17,954 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/* This file is the driving routine for the GNU `plotfont' program.  It
   includes code to plot all characters in a specified font. */

/* Copyright (C) 1998 Free Software Foundation, Inc. */

#include "sys-defines.h"
#include "plot.h"
#include "getopt.h"

const char *progname = "plotfont"; /* name of this program */

const char *usage_appendage = " FONT...\n";

enum radix { DECIMAL, OCTAL, HEXADECIMAL };

/* Long options we recognize */

#define	ARG_NONE	0
#define	ARG_REQUIRED	1
#define	ARG_OPTIONAL	2

struct option long_options[] = 
{
  /* The most important option */
  { "display-type",	ARG_REQUIRED,	NULL, 'T'},
  /* Other frequently used options */
  { "box",		ARG_NONE,	NULL, 'b' << 8 },
  { "octal",		ARG_NONE,	NULL, 'o'},
  { "hexadecimal",	ARG_NONE,	NULL, 'x'},
  { "jis-page",		ARG_REQUIRED,	NULL, 'J'},
  { "jis-row",		ARG_REQUIRED,	NULL, 'j'},
  { "lower-half",	ARG_NONE,	NULL, '1'},
  { "upper-half",	ARG_NONE,	NULL, '2'},
  { "font-name",	ARG_REQUIRED,	NULL, 'F' }, /* hidden */
  /* Long options with no equivalent short option alias */
  { "numbering-font-name", ARG_REQUIRED, NULL, 'N' << 8 },
  { "title-font-name",	ARG_REQUIRED,	NULL, 'Z' << 8 },
  { "pen-color",	ARG_REQUIRED,	NULL, 'C' << 8 },
  { "bg-color",		ARG_REQUIRED,	NULL, 'q' << 8 },
  { "bitmap-size",	ARG_REQUIRED,	NULL, 'B' << 8 },
  { "emulate-color",	ARG_REQUIRED,	NULL, 'e' << 8},  
  { "page-size",	ARG_REQUIRED,	NULL, 'P' << 8 },
  { "rotation",		ARG_REQUIRED,	NULL, 'r' << 8},
  /* Options relevant only to raw plotfont (refers to metafile output) */
  { "portable-output",	ARG_NONE,	NULL, 'O' },
  /* Documentation options */
  { "help-fonts",	ARG_NONE,	NULL, 'f' << 8 },
  { "list-fonts",	ARG_NONE,	NULL, 'l' << 8 },
  { "version",		ARG_NONE,	NULL, 'V' << 8 },
  { "help",		ARG_NONE,	NULL, 'h' << 8 },
  { NULL,		0,		NULL,  0}
};
    
/* null-terminated list of options that we don't show to the user */
int hidden_options[] = { (int)'J', (int)'F', 0 };

/* forward references */
bool do_font ____P((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));
void write_three_bytes ____P((int charnum, char *numbuf, int radix));
void write_two_bytes ____P((int charnum, char *numbuf, int radix));

/* from libcommon */
extern int display_fonts ____P((const char *display_type, const char *progname));
extern int list_fonts ____P((const char *display_type, const char *progname));
extern void display_usage ____P((const char *progname, const int *omit_vals, const char *appendage, bool fonts));
extern void display_version ____P((const char *progname)); 
extern voidptr_t xcalloc ____P ((size_t nmemb, size_t size));
extern voidptr_t xmalloc ____P ((size_t size));
extern voidptr_t xrealloc ____P ((voidptr_t p, size_t length));
extern char *xstrdup ____P ((const char *s));


int
#ifdef _HAVE_PROTOS
main (int argc, char *argv[])
#else
main (argc, argv)
     int argc;
     char *argv[];
#endif
{
  plPlotter *plotter;
  plPlotterParams *plotter_params;
  bool bearings = false;	/* show sidebearings on characters? */
  bool do_jis_page = false;	/* show page of HersheyEUC in JIS encoding? */
  bool do_list_fonts = false;	/* show a list of fonts? */
  bool show_fonts = false;	/* supply help on fonts? */
  bool show_usage = false;	/* show usage message? */
  bool show_version = false;	/* show version message? */
  bool upper_half = false;	/* upper half of font, not lower? */
  char *display_type = (char *)"meta"; /* default libplot output format */
  char *numbering_font_name = NULL; /* numbering font name, NULL -> default */
  char *option_font_name = NULL; /* allows user to use -F */
  char *pen_color = NULL;	/* initial pen color, can be spec'd by user */
  char *title_font_name = NULL;	/* title font name, NULL -> current font */
  enum radix base = DECIMAL;
  int errcnt = 0;		/* errors encountered */
  int jis_page = 33;		/* page of HersheyEUC in JIS encoding */
  int opt_index;		/* long option index */
  int option;			/* option character */
  int retval;			/* return value */

  plotter_params = pl_newplparams ();
  while ((option = getopt_long (argc, argv, "12oxOj:J:F:T:", long_options, &opt_index)) != EOF)
    {
      if (option == 0)
	option = long_options[opt_index].val;
      
      switch (option) 
	{
	case 'T':		/* Display type, ARG REQUIRED      */
	  display_type = (char *)xmalloc (strlen (optarg) + 1);
	  strcpy (display_type, optarg);
	  break;
	case 'O':		/* Ascii output */
	  pl_setplparam (plotter_params, "META_PORTABLE", (char *)"yes");
	  break;
	case '1':		/* Lower half */
	  upper_half = false;
	  break;
	case '2':		/* Upper half */
	  upper_half = true;
	  break;
	case 'o':		/* Octal */
	  base = OCTAL;
	  break;
	case 'x':		/* Hexadecimal */
	  base = HEXADECIMAL;
	  break;
	case 'F':		/* set the initial font */
	  option_font_name = (char *)xmalloc (strlen (optarg) + 1);
	  strcpy (option_font_name, optarg);
	  break;
	case 'e' << 8:		/* Emulate color via grayscale */
	  pl_setplparam (plotter_params, "EMULATE_COLOR", (char *)optarg);
	  break;
	case 'N' << 8:		/* Numbering Font name, ARG REQUIRED */
	  numbering_font_name = xstrdup (optarg);
	  break;
	case 'Z' << 8:		/* Title Font name, ARG REQUIRED */
	  title_font_name = xstrdup (optarg);
	  break;
	case 'C' << 8:		/* set the initial pen color */
	  pen_color = (char *)xmalloc (strlen (optarg) + 1);
	  strcpy (pen_color, optarg);
	  break;
	case 'q' << 8:		/* set the initial background color */
	  pl_setplparam (plotter_params, "BG_COLOR", (voidptr_t)optarg);
	  break;
	case 'B' << 8:		/* Bitmap size */
	  pl_setplparam (plotter_params, "BITMAPSIZE", (voidptr_t)optarg);
	  break;
	case 'P' << 8:		/* Page size */
	  pl_setplparam (plotter_params, "PAGESIZE", (voidptr_t)optarg);
	  break;
	case 'r' << 8:		/* Rotation angle */
	  pl_setplparam (plotter_params, "ROTATION", (voidptr_t)optarg);
	  break;
	case 'b' << 8:		/* Bearings requested */
	  bearings = true;
	  break;
	case 'V' << 8:		/* Version */
	  show_version = true;
	  break;
	case 'f' << 8:		/* Fonts */
	  show_fonts = true;
	  break;
	case 'l' << 8:		/* Fonts */
	  do_list_fonts = true;
	  break;
	case 'J':		/* JIS page */
	  if (sscanf (optarg, "%d", &jis_page) <= 0
	      || (jis_page < 33) || (jis_page > 126))
	    {
	      fprintf (stderr,
		       "%s: bad JIS page, must be in the range 33..126\n",
		       progname);
	      errcnt++;
	    }
	  else
	    do_jis_page = true;
	  break;
	case 'j':		/* JIS row */
	  if (sscanf (optarg, "%d", &jis_page) <= 0
	      || (jis_page < 1) || (jis_page > 94))
	    {
	      fprintf (stderr,
		       "%s: bad JIS row, must be in the range 1..94\n",
		       progname);
	      errcnt++;
	    }
	  else
	    {
	      jis_page += 32;
	      do_jis_page = true;
	    }
	  break;
	case 'h' << 8:		/* Help */
	  show_usage = true;
	  break;

	default:
	  errcnt++;
	  break;
	}
    }

  if (errcnt > 0)
    {
      fprintf (stderr, "Try `%s --help' for more information\n", progname);
      return EXIT_FAILURE;
    }
  if (show_version)
    {
      display_version (progname);
      return EXIT_SUCCESS;
    }
  if (do_list_fonts)
    {
      int success;

      success = list_fonts (display_type, progname);
      if (success)
	return EXIT_SUCCESS;
      else
	return EXIT_FAILURE;
    }
  if (show_fonts)
    {
      int success;

      success = display_fonts (display_type, progname);
      if (success)
	return EXIT_SUCCESS;
      else
	return EXIT_FAILURE;
    }
  if (show_usage)
    {
      display_usage (progname, hidden_options, usage_appendage, true);
      return EXIT_SUCCESS;
    }

  if (option_font_name == NULL && optind >= argc)
    {
      fprintf (stderr, "%s: no font(s) specified \n", progname);
      return EXIT_FAILURE;
    }

  if (do_jis_page)
    {
      if ((!((option_font_name == NULL && optind == argc - 1)
	    || (option_font_name && optind >= argc)))
	  || (option_font_name && strcasecmp (option_font_name, "HersheyEUC") != 0)
	  || (!option_font_name && strcasecmp (argv[optind], "HersheyEUC") != 0))
	{
	  fprintf (stderr, "%s: JIS page can only be specified for HersheyEUC \n font", progname);
	  return EXIT_FAILURE;
	}	  
    }

  if ((plotter = pl_newpl_r (display_type, NULL, stdout, stderr, 
			     plotter_params)) == NULL)
    {
      fprintf (stderr, "%s: error: could not create plot device\n", progname);
      return EXIT_FAILURE;
    }

  if (option_font_name)
    /* user specifed a font with -F */
    {
      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)
	return EXIT_FAILURE;
    }
  
  if (optind < argc)
    /* 1 or more fonts named explicitly on command line */
    {
      for (; optind < argc; optind++)
	{
	  char *font_name;

	  font_name = argv[optind];
	  if (do_font (plotter, font_name, upper_half, pen_color, numbering_font_name, title_font_name, bearings, base, jis_page, do_jis_page) == false)
	    return EXIT_FAILURE;
	}
    }

  /* clean up */
  retval = EXIT_SUCCESS;
  if (pl_deletepl_r (plotter) < 0)
    {
      fprintf (stderr, "%s: error: could not delete plot device\n", progname);
      retval = EXIT_FAILURE;
    }
  pl_deleteplparams (plotter_params);

  return retval;
}

#define NUM_ROWS 12

#define SIZE 1.0
#define MAX_TITLE_LENGTH 0.9

#define HSPACING 0.1	/* must have 8*HSPACING < SIZE */
#define VSPACING 0.06	/* must have 12*VSPACING < SIZE-LINE_VOFFSET */

#define LINE_HOFFSET (0.5 * ((SIZE) - 8 * (HSPACING)))
#define LINE_VOFFSET 0.15	/* top line down from top of display by this */
#define CHAR_HOFFSET ((LINE_HOFFSET) + 0.5 * (HSPACING))
#define CHAR_VOFFSET ((LINE_VOFFSET) + 0.5 * (VSPACING))

#define TOP (SIZE - (LINE_VOFFSET))
#define BOTTOM ((SIZE - (LINE_VOFFSET)) - 12 * (VSPACING))
#define LEFT (LINE_HOFFSET)
#define RIGHT (LINE_HOFFSET + 8 * HSPACING)

#define FONT_SIZE 0.04
#define TITLE_FONT_SIZE 0.045
#define NUMBERING_FONT_SIZE 0.015

/* shifts of numbers in grid cells leftward and upward */
#define N_X_SHIFT 0.015
#define N_Y_SHIFT 0.05

bool
#ifdef _HAVE_PROTOS
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)
#else
do_font (plotter, name, upper_half, pen_color_name, numbering_font_name, title_font_name, bearings, base, jis_page, do_jis_page)
     plPlotter *plotter;
     const unsigned 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;
#endif
{
  char buf[16];
  char numbuf[16];
  char suffixbuf[16];
  char *titlebuf;
  const char *suffix;
  double title_width;
  int i, j, bottom_octet, top_octet;

  if (do_jis_page)
    {
      switch (base)
	{
	case DECIMAL:
	default:
	  sprintf (suffixbuf, " (row %d)", jis_page - 32);
	  break;
	case OCTAL:
	  sprintf (suffixbuf, " (row 0%o)", jis_page - 32);
	  break;
	case HEXADECIMAL:
	  sprintf (suffixbuf, " (row 0x%X)", jis_page - 32);
	  break;
	}
      suffix = suffixbuf;
    }
  else
    suffix = upper_half ? " (upper half)" : " (lower half)";
  titlebuf = (char *)xmalloc (strlen (name) + strlen (suffix) + 1);
  strcpy (titlebuf, name);
  strcat (titlebuf, suffix);

  if (pl_openpl_r (plotter) < 0)
    {
      fprintf (stderr, "%s: error: could not open plot device\n", progname);
      return false;
    }

  pl_fspace_r (plotter, 0.0, 0.0, (double)SIZE, (double)SIZE);
  pl_erase_r (plotter);
  if (pen_color_name)
    pl_pencolorname_r (plotter, pen_color_name);
  
  pl_fmove_r (plotter, 0.5 * SIZE, 0.5 * (SIZE + TOP));
  if (title_font_name)
    pl_fontname_r (plotter, title_font_name);
  else
    pl_fontname_r (plotter, name);
  pl_ffontsize_r (plotter, (double)(TITLE_FONT_SIZE));

  title_width = pl_flabelwidth_r (plotter, titlebuf);
  if (title_width > MAX_TITLE_LENGTH)
    /* squeeze title to fit */
    pl_ffontsize_r (plotter, 
		    (double)(TITLE_FONT_SIZE) * (MAX_TITLE_LENGTH / title_width));

  /* print title */
  pl_alabel_r (plotter, 'c', 'c', titlebuf);

  if (do_jis_page)
    bottom_octet = 4;
  else			/* ordinary map */
    {
      if (upper_half)
	bottom_octet = 20;
      else
	bottom_octet = 4;
    }
  top_octet = bottom_octet + NUM_ROWS - 1;

  /* draw grid */

  pl_linemod_r (plotter, "solid");
  pl_fbox_r (plotter, LEFT, BOTTOM, RIGHT, TOP);
  for (i = 1; i <= 7; i++)
    /* boustrophedon */
    {
      if (i % 2)
	pl_fline_r (plotter, 
		    LINE_HOFFSET + i * HSPACING, BOTTOM, 
		    LINE_HOFFSET + i * HSPACING, TOP);
      else
	pl_fline_r (plotter, 
		    LINE_HOFFSET + i * HSPACING, TOP,
		    LINE_HOFFSET + i * HSPACING, BOTTOM);
    }      
  for (j = 1; j <= 11; j++)
    /* boustrophedon */
    {
      if (j % 2)
	pl_fline_r (plotter, 
		    RIGHT, TOP - j * VSPACING,
		    LEFT, TOP - j * VSPACING);
      else
	pl_fline_r (plotter,  
		    LEFT, TOP - j * VSPACING,
		    RIGHT, TOP - j * VSPACING);
    }

  /* number grid cells */

  if (numbering_font_name)
    pl_fontname_r (plotter, numbering_font_name);
  else				/* select default font */
    pl_fontname_r (plotter, "");
  pl_ffontsize_r (plotter, (double)(NUMBERING_FONT_SIZE));
  if (bearings)
    pl_linemod_r (plotter, "dotted");
  for (i = bottom_octet; i <= top_octet; i++)
    for (j = 0; j < 8; j++)
      {
	int row, column, charnum;

	row = i - bottom_octet;	/* row, 0..11 */
	column = j;		/* column, 0..7 */

	charnum = (unsigned char)(8 * i + j);
	if (charnum == 127)	/* 0xff not a legitimate glyph */
	  continue;
	if (do_jis_page && charnum == 32)
	  continue;		/* 0x20 not legitimate for JIS */

	switch (base)
	  {
	  case HEXADECIMAL:
	    write_two_bytes (charnum - (do_jis_page ? 32 : 0), numbuf, 16);
	    break;
	  case DECIMAL:
	  default:
	    write_three_bytes (charnum - (do_jis_page ? 32 : 0), numbuf, 10);
	    break;
	  case OCTAL:
	    write_three_bytes (charnum - (do_jis_page ? 32 : 0), numbuf, 8);
	    break;
	  }
	
	pl_fmove_r (plotter,
		    (double)(LINE_HOFFSET + HSPACING * (column + 1 - N_X_SHIFT)),
		    (double)(SIZE - (LINE_VOFFSET + VSPACING * (row + 1 - N_Y_SHIFT))));
	pl_alabel_r (plotter, 'r', 'x', numbuf);
      }

  /* fill grid cells with characters */

  pl_fontname_r (plotter, name);
  pl_ffontsize_r (plotter, (double)(FONT_SIZE));
  for (i = bottom_octet; i <= top_octet; i++)
    for (j = 0; j < 8; j++)
      {
	int row, column, charnum;

	row = i - bottom_octet;	/* row, 0..11 */
	column = j;		/* column, 0..7 */
	
	charnum = (unsigned char)(8 * i + j);
	if (charnum == 127)	/* 0xff not a legitimate glyph */
	  continue;
	if (do_jis_page && charnum == 32)
	  continue;		/* 0x20 not legitimate for JIS */

	if (!do_jis_page)
	  {
	    buf[0] = charnum;
	    buf[1] = '\0';
	  }
	else			/* do JIS page */
	  {
	    /* two bytes, set high bits on both page and character */
	    buf[0] = jis_page + 0x80;
	    buf[1] = charnum + 0x80;
	    buf[2] = '\0';
	  }

	pl_fmove_r (plotter, 
		    (double)(LINE_HOFFSET + HSPACING * (column + 0.5)),
		    (double)(SIZE - (LINE_VOFFSET + VSPACING * (row + 0.5))));
	/* place glyph on page */
	pl_alabel_r (plotter, 'c', 'c', (char *)buf);
	if (bearings)
	  {
	    double halfwidth;

	    /* compute glyph width */
	    halfwidth = 0.5 * pl_flabelwidth_r (plotter, (char *)buf);
	    if (halfwidth == 0.0)
	      /* empty glyph, draw only one vertical dotted line */
	      pl_fline_r (plotter,
			  (double)(CHAR_HOFFSET + HSPACING * column),
			  (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row - 0.5))),
			  (double)(CHAR_HOFFSET + HSPACING * column),
			  (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row + 0.5))));
	    else
	      /* draw vertical dotted lines to either side of glyph */
	      {
		pl_fline_r (plotter, 
			    (double)(CHAR_HOFFSET + HSPACING * column - halfwidth),
			    (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row - 0.5))),
			    (double)(CHAR_HOFFSET + HSPACING * column - halfwidth),
			    (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row + 0.5))));
		pl_fline_r (plotter, 
			    (double)(CHAR_HOFFSET + HSPACING * column + halfwidth),
			    (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row - 0.5))),
			    (double)(CHAR_HOFFSET + HSPACING * column + halfwidth),
			    (double)(SIZE - (CHAR_VOFFSET + VSPACING * (row + 0.5))));
	      }
	  }
      }
  
  if (pl_closepl_r (plotter) < 0)
    {
      fprintf (stderr, "%s: error: could not close plot device\n", progname);
      return false;
    }
  return true;
}

/* Write an integer that is < (radix)**4 as three ascii bytes with respect
   to the specified radix.  Initial zeroes are converted to spaces. */
void 
#ifdef _HAVE_PROTOS
write_three_bytes (int charnum, char *numbuf, int radix)
#else
write_three_bytes (charnum, numbuf, radix)
     int charnum;
     char *numbuf;
     int radix;
#endif
{
  int i;

  numbuf[0] = charnum / (radix * radix);
  numbuf[1] = (charnum - (radix * radix) * (charnum / (radix * radix))) / radix;
  numbuf[2] = charnum % radix;
  numbuf[3] = '\0';

  for (i = 0 ; i <= 2 ; i++)
    {
      if (numbuf[i] >= 10)
	numbuf[i] += ('A' - 10);
      else 
	numbuf[i] += '0';
    }
  if (numbuf[0] == '0')
    {
      numbuf[0] = ' ';
      if (numbuf[1] == '0')
	numbuf[1] = ' ';
    }
}

/* Write an integer that is < (radix)**3 as two ascii bytes with respect to
   the specified radix.  Initial zeroes are converted are not changed. */
void 
#ifdef _HAVE_PROTOS
write_two_bytes (int charnum, char *numbuf, int radix)
#else
write_two_bytes (charnum, numbuf, radix)
     int charnum;
     char *numbuf;
     int radix;
#endif
{
  int i;

  numbuf[0] = charnum / radix;
  numbuf[1] = charnum % radix;
  numbuf[2] = '\0';

  for (i = 0 ; i <= 1 ; i++)
    {
      if (numbuf[i] >= 10)
	numbuf[i] += ('A' - 10);
      else 
	numbuf[i] += '0';
    }
}