1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ctype.h>
5 #include "common.h"
6 #include "tr2post.h"
7 #include "comments.h"
8 #include "path.h"
9
10 char *printdesclang = 0;
11 char *encoding = 0;
12 int devres;
13 int unitwidth;
14 int nspechars = 0;
15 struct charent spechars[MAXSPECHARS];
16
17 #define NDESCTOKS 9
18 static char *desctoks[NDESCTOKS] = {
19 "PDL",
20 "Encoding",
21 "fonts",
22 "sizes",
23 "res",
24 "hor",
25 "vert",
26 "unitwidth",
27 "charset"
28 };
29
30 char *spechar[MAXSPECHARS];
31
32 int
hash(char * s,int l)33 hash(char *s, int l) {
34 unsigned i;
35
36 for (i=0; *s; s++)
37 i = i*10 + *s;
38 return(i % l);
39 }
40
41 BOOLEAN
readDESC(void)42 readDESC(void)
43 {
44 char token[MAXTOKENSIZE];
45 char *descnameformat = "%s/dev%s/DESC";
46 char *descfilename = 0;
47 Biobuf *bfd;
48 Biobufhdr *Bfd;
49 int i, state = -1;
50 int fontindex = 0;
51
52 if (debug) Bprint(Bstderr, "readDESC()\n");
53 descfilename = galloc(descfilename, strlen(descnameformat)+strlen(FONTDIR)
54 +strlen(devname), "readdesc");
55 sprint(descfilename, descnameformat, FONTDIR, devname);
56 if ((bfd = Bopen(descfilename, OREAD)) == 0) {
57 error(WARNING, "cannot open file %s\n", descfilename);
58 return 0;
59 }
60 Bfd = &(bfd->Biobufhdr);
61
62 while (Bgetfield(Bfd, 's', token, MAXTOKENSIZE) > 0) {
63 for (i=0; i<NDESCTOKS; i++) {
64 if (strcmp(desctoks[i], token) == 0) {
65 state = i;
66 break;
67 }
68 }
69 if (i<NDESCTOKS) continue;
70 switch (state) {
71 case 0:
72 printdesclang=galloc(printdesclang, strlen(token)+1, "readdesc:");
73 strcpy(printdesclang, token);
74 if (debug) Bprint(Bstderr, "PDL %s\n", token);
75 break;
76 case 1:
77 encoding=galloc(encoding, strlen(token)+1, "readdesc:");
78 strcpy(encoding, token);
79 if (debug) Bprint(Bstderr, "encoding %s\n", token);
80 break;
81 case 2:
82 if (fontmnt <=0) {
83 if (!isdigit(*token)) {
84 error(WARNING, "readdesc: expecting number of fonts in mount table.\n");
85 return FALSE;
86 }
87 fontmnt = atoi(token) + 1;
88 fontmtab = galloc(fontmtab, fontmnt*sizeof(char *), "readdesc:");
89
90 for (i=0; i<fontmnt; i++)
91 fontmtab[i] = 0;
92 fontindex = 0;
93 } else {
94 mountfont(++fontindex, token);
95 findtfn(token, TRUE);
96 }
97 break;
98 case 3:
99 /* I don't really care about sizes */
100 break;
101 case 4:
102 /* device resolution in dots per inch */
103 if (!isdigit(*token)) {
104 error(WARNING, "readdesc: expecting device resolution.\n");
105 return FALSE;
106 }
107 devres = atoi(token);
108 if (debug) Bprint(Bstderr, "res %d\n", devres);
109 break;
110 case 5:
111 /* I don't really care about horizontal motion resolution */
112 if (debug) Bprint(Bstderr, "ignoring horizontal resolution\n");
113 break;
114 case 6:
115 /* I don't really care about vertical motion resolution */
116 if (debug) Bprint(Bstderr, "ignoring vertical resolution\n");
117 break;
118 case 7:
119 /* unitwidth is the font size at which the character widths are 1:1 */
120 if (!isdigit(*token)) {
121 error(WARNING, "readdesc: expecting unitwidth.\n");
122 return(FALSE);
123 }
124 unitwidth = atoi(token);
125 if (debug) Bprint(Bstderr, "unitwidth %d\n", unitwidth);
126 break;
127 case 8:
128 /* I don't really care about this list of special characters */
129 if (debug) Bprint(Bstderr, "ignoring special character <%s>\n", token);
130 break;
131 default:
132 if (*token == '#')
133 Brdline(Bfd, '\n');
134 else
135 error(WARNING, "unknown token %s in DESC file.\n", token);
136 break;
137 }
138 }
139 Bterm(Bfd);
140 return 0;
141 }
142