Commit | Line | Data |
---|---|---|
bb223121 | 1 | static char *sccsid = "@(#)vfontinfo.c 4.2 (Berkeley) 81/02/28"; |
98086f73 BJ |
2 | /* Font Information for VCat-style fonts |
3 | * AJH 4/79 | |
4 | * | |
5 | * Modified to print Ascii chars 1/80 by Mark Horton | |
bb223121 BJ |
6 | * Modified to use ,'| 1/81 by Mark Horton using an idea |
7 | * from Eric Scott of CalTech. | |
98086f73 BJ |
8 | */ |
9 | #include <stdio.h> | |
10 | #include <ctype.h> | |
11 | #include <vfont.h> | |
12 | ||
13 | struct header FontHeader; | |
14 | struct dispatch disptable[256] ; | |
15 | ||
16 | char IName[100]; | |
17 | char * rdchar(); | |
18 | long fbase; | |
19 | ||
20 | char defascii[256]; | |
21 | char *charswanted = defascii; | |
22 | int verbose; | |
23 | char charbits[4000]; | |
24 | int H, W, WB; | |
25 | ||
26 | main(argc,argv) | |
27 | int argc; | |
28 | char **argv; | |
29 | ||
30 | { | |
31 | int FID,i,j; | |
32 | ||
33 | if (argc > 1 && argv[1][0] == '-') { | |
34 | switch(argv[1][1]) { | |
35 | case 'v': | |
36 | verbose++; | |
37 | break; | |
38 | default: | |
39 | printf("Bad flag: %s\n", argv[1]); | |
40 | } | |
41 | argc--; argv++; | |
42 | } | |
43 | if (argc < 2) { | |
44 | fprintf(stderr,"Usage: %s filename", argv[0]); | |
45 | exit(2); | |
46 | } | |
47 | ||
48 | for (i=0; i<128; i++) | |
49 | defascii[i] = i; | |
50 | if (argc >= 3) | |
51 | charswanted = argv[2]; | |
52 | ||
53 | sprintf(IName,"/usr/lib/vfont/%s",argv[1]); | |
54 | if ((FID = open(argv[1],0)) < 0) | |
55 | if ((FID = open(IName,0)) < 0) { | |
56 | printf("Can't find %s\n",argv[1]); | |
57 | exit(8); | |
58 | }; | |
59 | ||
60 | if (read(FID,&FontHeader,sizeof FontHeader) != sizeof FontHeader) | |
61 | error("Bad header in Font file."); | |
62 | ||
63 | if (read(FID,&disptable[0],sizeof disptable) != sizeof disptable) | |
64 | error("Bad dispatch table in Font file"); | |
65 | ||
66 | fbase = sizeof FontHeader + sizeof disptable; | |
67 | ||
68 | if (FontHeader.magic != 0436) | |
69 | printf("Magic number %o wrong\n", FontHeader.magic); | |
70 | printf("Font %s, ",argv[1]); | |
71 | printf("raster size %d, ",FontHeader.size); | |
72 | printf("max width %d, max height %d, xtend %d\n", | |
73 | FontHeader.maxx, FontHeader.maxy,FontHeader.xtend); | |
bb223121 BJ |
74 | if (!verbose) |
75 | printf("\n ASCII offset size left right up down width \n"); | |
98086f73 BJ |
76 | |
77 | for (i=0; i<256; i++) { | |
78 | j = charswanted[i]; | |
79 | if (i>0 && j==0) | |
80 | break; | |
81 | if (disptable[j].nbytes != 0) { | |
bb223121 BJ |
82 | printf(!verbose ? |
83 | " %3o %2s %4d %4d %4d %4d %4d %4d %5d\n" : | |
84 | " %3o %2s a=%d, n=%d, l=%d, r=%d, u=%d, d=%d, w=%d\n", | |
98086f73 BJ |
85 | j, rdchar(j), |
86 | disptable[j].addr, | |
87 | disptable[j].nbytes, | |
88 | disptable[j].left, | |
89 | disptable[j].right, | |
90 | disptable[j].up, | |
91 | disptable[j].down, | |
92 | disptable[j].width); | |
93 | if (verbose) { | |
94 | int len = disptable[j].nbytes; | |
95 | int k, l, last; | |
96 | ||
97 | lseek(FID, fbase+disptable[j].addr, 0); | |
98 | read(FID, charbits, len); | |
99 | H = (disptable[j].up) + (disptable[j].down); | |
100 | W = (disptable[j].left) + (disptable[j].right); | |
101 | WB = (W+7)/8; | |
bb223121 | 102 | for (k=0; k<H; k+=2) { |
98086f73 BJ |
103 | for (last=W-1; last >= 0; last--) |
104 | if (fbit(k, last)) | |
105 | break; | |
106 | for (l=0; l<=last; l++) { | |
bb223121 | 107 | printf("%c", " ',|"[fbit(k,l)+2*fbit(k+1,l)]); |
98086f73 BJ |
108 | } |
109 | printf("\n"); | |
110 | } | |
111 | printf("\n"); | |
112 | } | |
113 | } | |
114 | }; | |
115 | } | |
116 | ||
117 | error(string) | |
118 | char *string; | |
119 | ||
120 | { | |
121 | printf("\nvfontinfo: %s\n",string); | |
122 | exit(8); | |
123 | }; | |
124 | ||
125 | char *rdchar(c) | |
126 | char c; | |
127 | { | |
128 | static char ret[3]; | |
129 | ret[0] = isprint(c) ? ' ' : '^'; | |
130 | ret[1] = isprint(c) ? c : c^0100; | |
131 | ret[2] = 0; | |
132 | return (ret); | |
133 | } | |
134 | ||
135 | int | |
136 | fbit(row, col) | |
137 | int row, col; | |
138 | { | |
139 | int thisbyte, thisbit, ret; | |
140 | ||
bb223121 BJ |
141 | if (row >= H) |
142 | return 0; | |
98086f73 BJ |
143 | thisbyte = charbits[row*WB + (col>>3)] & 0xff; |
144 | thisbit = 0x80 >> (col&7); | |
145 | ret = thisbyte & thisbit; | |
146 | return (ret != 0); | |
147 | } |