xref: /csrg-svn/old/vpr/vtools/vwidth.c (revision 20204)
1*20204Sdist /*
2*20204Sdist  * Copyright (c) 1983 Regents of the University of California.
3*20204Sdist  * All rights reserved.  The Berkeley software License Agreement
4*20204Sdist  * specifies the terms and conditions for redistribution.
5*20204Sdist  */
6*20204Sdist 
713950Ssam #ifndef lint
8*20204Sdist static char sccsid[] = "@(#)vwidth.c	5.1 (Berkeley) 05/15/85";
9*20204Sdist #endif not lint
1013950Ssam 
1111452Sralph /*
1211452Sralph  *	Creates a width table for troff from a versatec font for a
1311452Sralph  *		normal font.
1411452Sralph  *	Usage: width font [ point_size ]
1511452Sralph  *		where font is the file name of the versatec font and
1611452Sralph  *		point_size is it point size.
1711452Sralph  *	If the point size is omitted it is taken from the suffix of
1811452Sralph  *	the font name, as bocklin.14 => 14 point.
1911452Sralph  *	It is better to use as large a point size font as possible
2011452Sralph  *	to avoid round off.
2111452Sralph  */
2211452Sralph 
2311452Sralph #include <stdio.h>
2411452Sralph 
2511452Sralph struct wtable {
2611452Sralph 	char	charloc;
2711452Sralph 	char	*name;
2811452Sralph } wtable[] = {
2911452Sralph 	'\214',	"space",
3011452Sralph 	'!',	"!",
3111452Sralph 	'"',	"\"",
3211452Sralph 	'#',	"#",
3311452Sralph 	'$',	"$",
3411452Sralph 	'%',	"%",
3511452Sralph 	'&',	"&",
3611452Sralph 	'\'',	"'",
3711452Sralph 	'(',	"(",
3811452Sralph 	')',	")",
3911452Sralph 	'*',	"*",
4011452Sralph 	'+',	"+",
4111452Sralph 	',',	",",
4211452Sralph 	'-',	"- hyphen",
4311452Sralph 	'.',	".",
4411452Sralph 	'/',	"/",
4511452Sralph 	'0',	"0",
4611452Sralph 	'1',	"1",
4711452Sralph 	'2',	"2",
4811452Sralph 	'3',	"3",
4911452Sralph 	'4',	"4",
5011452Sralph 	'5',	"5",
5111452Sralph 	'6',	"6",
5211452Sralph 	'7',	"7",
5311452Sralph 	'8',	"8",
5411452Sralph 	'9',	"9",
5511452Sralph 	':',	":",
5611452Sralph 	';',	";",
5711452Sralph 	'<',	"<",
5811452Sralph 	'=',	"=",
5911452Sralph 	'>',	">",
6011452Sralph 	'?',	"?",
6111452Sralph 	'@',	"@",
6211452Sralph 	'A',	"A",
6311452Sralph 	'B',	"B",
6411452Sralph 	'C',	"C",
6511452Sralph 	'D',	"D",
6611452Sralph 	'E',	"E",
6711452Sralph 	'F',	"F",
6811452Sralph 	'G',	"G",
6911452Sralph 	'H',	"H",
7011452Sralph 	'I',	"I",
7111452Sralph 	'J',	"J",
7211452Sralph 	'K',	"K",
7311452Sralph 	'L',	"L",
7411452Sralph 	'M',	"M",
7511452Sralph 	'N',	"N",
7611452Sralph 	'O',	"O",
7711452Sralph 	'P',	"P",
7811452Sralph 	'Q',	"Q",
7911452Sralph 	'R',	"R",
8011452Sralph 	'S',	"S",
8111452Sralph 	'T',	"T",
8211452Sralph 	'U',	"U",
8311452Sralph 	'V',	"V",
8411452Sralph 	'W',	"W",
8511452Sralph 	'X',	"X",
8611452Sralph 	'Y',	"Y",
8711452Sralph 	'Z',	"Z",
8811452Sralph 	'[',	"[",
8911452Sralph 	'\\',	"\\",
9011452Sralph 	']',	"]",
9111452Sralph 	'^',	"^",
9211452Sralph 	'_',	"_",
9311452Sralph 	'\`',	"\`",
9411452Sralph 	'a',	"a",
9511452Sralph 	'b',	"b",
9611452Sralph 	'c',	"c",
9711452Sralph 	'd',	"d",
9811452Sralph 	'e',	"e",
9911452Sralph 	'f',	"f",
10011452Sralph 	'g',	"g",
10111452Sralph 	'h',	"h",
10211452Sralph 	'i',	"i",
10311452Sralph 	'j',	"j",
10411452Sralph 	'k',	"k",
10511452Sralph 	'l',	"l",
10611452Sralph 	'm',	"m",
10711452Sralph 	'n',	"n",
10811452Sralph 	'o',	"o",
10911452Sralph 	'p',	"p",
11011452Sralph 	'q',	"q",
11111452Sralph 	'r',	"r",
11211452Sralph 	's',	"s",
11311452Sralph 	't',	"t",
11411452Sralph 	'u',	"u",
11511452Sralph 	'v',	"v",
11611452Sralph 	'w',	"w",
11711452Sralph 	'x',	"x",
11811452Sralph 	'y',	"y",
11911452Sralph 	'z',	"z",
12011452Sralph 	'{',	"{",
12111452Sralph 	'|',	"|",
12211452Sralph 	'}',	"}",
12311452Sralph 	'~',	"~",
12411452Sralph 	'\206',	"narrow space",
12511452Sralph 	'-',	"hyphen",
12611452Sralph 	'\07',	"bullet",
12711452Sralph 	'\010',	"square",
12811452Sralph 	'\06',	"3/4 em dash",
12911452Sralph 	'\05',	"rule",
13011452Sralph 	'\021',	"1/4",
13111452Sralph 	'\022',	"1/2",
13211452Sralph 	'\023',	"3/4",
13311452Sralph 	'\04',	"minus",
13411452Sralph 	'\01',	"fi",
13511452Sralph 	'\02',	"fl",
13611452Sralph 	'\03',	"ff",
13711452Sralph 	'\011',	"ffi",
13811452Sralph 	'\012',	"ffl",
13911452Sralph 	'\013',	"degree",
14011452Sralph 	'\014',	"dagger",
14111452Sralph 	'\200',	"section (unimplem)",
14211452Sralph 	'\015',	"foot mark",
14311452Sralph 	'\200',	"acute acc (unimplem)",
14411452Sralph 	'\200',	"grave acc (unimplem)",
14511452Sralph 	'\200',	"underrule (unimplem)",
14611452Sralph 	'\200',	"slash (unimplem)",
14711452Sralph 	'\203',	"half narrow space",
14811452Sralph 	'\200',	"null",
14911452Sralph 	'\200',	"null",
15011452Sralph 	'\200',	"null",
15111452Sralph 	'\200',	"null",
15211452Sralph 	'\200',	"null",
15311452Sralph 	'\200',	"null",
15411452Sralph 	'\200',	"null",
15511452Sralph 	'\200',	"null",
15611452Sralph 	'\200',	"null",
15711452Sralph 	'\200',	"null",
15811452Sralph 	'\200',	"null",
15911452Sralph 	'\200',	"null",
16011452Sralph 	'\200',	"null",
16111452Sralph 	'\200',	"null",
16211452Sralph 	'\200',	"null",
16311452Sralph 	'\200',	"null",
16411452Sralph 	'\200',	"null",
16511452Sralph 	'\200',	"null",
16611452Sralph 	'\200',	"null",
16711452Sralph 	'\200',	"null",
16811452Sralph 	'\200',	"null",
16911452Sralph 	'\200',	"null",
17011452Sralph 	'\200',	"null",
17111452Sralph 	'\200',	"null",
17211452Sralph 	'\200',	"null",
17311452Sralph 	'\200',	"null",
17411452Sralph 	'\200',	"null",
17511452Sralph 	'\200',	"null",
17611452Sralph 	'\200',	"null",
17711452Sralph 	'\200',	"null",
17811452Sralph 	'\200',	"null",
17911452Sralph 	'\200',	"null",
18011452Sralph 	'\200',	"null",
18111452Sralph 	'\200',	"null",
18211452Sralph 	'\200',	"null",
18311452Sralph 	'\200',	"null",
18411452Sralph 	'\200',	"null",
18511452Sralph 	'\200',	"null",
18611452Sralph 	'\200',	"null",
18711452Sralph 	'\200',	"null",
18811452Sralph 	'\200',	"null",
18911452Sralph 	'\200',	"null",
19011452Sralph 	'\200',	"null",
19111452Sralph 	'\200',	"null",
19211452Sralph 	'\200',	"null",
19311452Sralph 	'\200',	"null",
19411452Sralph 	'\200',	"null",
19511452Sralph 	'\200',	"null",
19611452Sralph 	'\200',	"null",
19711452Sralph 	'\200',	"null",
19811452Sralph 	'\200',	"null",
19911452Sralph 	'\200',	"null",
20011452Sralph 	'\200',	"null",
20111452Sralph 	'\200',	"null",
20211452Sralph 	'\200',	"null",
20311452Sralph 	'\200',	"null",
20411452Sralph 	'\200',	"null",
20511452Sralph 	'\200',	"null",
20611452Sralph 	'\200',	"null",
20711452Sralph 	'\200',	"null",
20811452Sralph 	'\200',	"null",
20911452Sralph 	'\200',	"null",
21011452Sralph 	'\200',	"null",
21111452Sralph 	'\200',	"null",
21211452Sralph 	'\200',	"null",
21311452Sralph 	'\200',	"null",
21411452Sralph 	'\200',	"null",
21511452Sralph 	'\200',	"null",
21611452Sralph 	'\200',	"null",
21711452Sralph 	'\200',	"null",
21811452Sralph 	'\200',	"null",
21911452Sralph 	'\017',	"registered",
22011452Sralph 	'\016',	"copyright",
22111452Sralph 	'\200',	"null",
22211452Sralph 	'\020',	"cent",
22311452Sralph 	0,	0
22411452Sralph };
22511452Sralph 
22611452Sralph struct desc {
22711452Sralph 	short	addr;
22811452Sralph 	short	nbytes;
22911452Sralph 	char	up;
23011452Sralph 	char	down;
23111452Sralph 	char	left;
23211452Sralph 	char	right;
23311452Sralph 	short	width;
23411452Sralph } desc[256];
23511452Sralph 
main(argc,argv)23611452Sralph main(argc, argv)
23711452Sralph 	int argc;
23811452Sralph 	char *argv[];
23911452Sralph {
24011452Sralph 	register int cl;
24111452Sralph 	register esc;
24211452Sralph 	register w;
24311452Sralph 	int i, psize;
24411452Sralph 	int fd, high;
24511452Sralph 
24611452Sralph 	if (argc != 3 && argc != 2) {
24711452Sralph 		printf("Usage: vwidth font [pointsize] > font.c\n");
24811452Sralph 		exit(1);
24911452Sralph 	}
25011452Sralph 	fd = open(argv[1], 0);
25111452Sralph 	if (argc == 3)
25211452Sralph 		psize = atoi(argv[2]);
25311452Sralph 	else {
25411452Sralph 		char *p;
25511452Sralph 		for (p = argv[1]; *p && *p != '.'; p++)
25611452Sralph 			;
25711452Sralph 		if (*p == 0) {
25811452Sralph 			psize = 10;
25911452Sralph 			fprintf(stderr, "Assuming %d point\n", psize);
26011452Sralph 		} else
26111452Sralph 			psize = atoi(p+1);
26211452Sralph 	}
26311452Sralph 	lseek(fd, 10L, 0);
26411452Sralph 	read(fd, desc, sizeof desc);
26511452Sralph 	high = desc['a'].up+1;
26611452Sralph 	printf("char XXw[256-32] = {\n");
26711452Sralph 	for (i = 0; wtable[i].charloc != 0; i++) {
26811452Sralph 		cl = wtable[i].charloc & 0377;
26911452Sralph 		if (cl & 0200)
27011452Sralph 			w = cl & 0177;
27111452Sralph 		else
27211452Sralph 			w = desc[cl].width*(54./25.)*(6./psize)+.5;
27311452Sralph 		esc = 0;
27411452Sralph 		if ((cl >= '0' && cl <= '9') || (cl >= 'A' && cl <= 'Z') ||
27511452Sralph 		    (cl >= 'a' && cl <= 'z')) {
27611452Sralph 			if (desc[cl].up > high)
27711452Sralph 				esc |= 0200;
27811452Sralph 			if (desc[cl].down > 0)
27911452Sralph 				esc |= 0100;
28011452Sralph 		}
28111452Sralph 		if (esc)
28211452Sralph 			printf("%d+0%o,\t/* %s */\n", w, esc, wtable[i].name);
28311452Sralph 		else
28411452Sralph 			printf("%d,\t\t/* %s */\n", w, wtable[i].name);
28511452Sralph 	}
28611452Sralph 	printf("};\n");
28711452Sralph }
288