dpost.ps: increase linewidth to match groff
[troff.git] / tr2ps / readDESC.c
blobe890ae7e14d9623e2d6bdb1fba1c6ea2502f7a98
1 #include <ctype.h>
2 #include <fcntl.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <sys/stat.h>
7 #include "ustr.h"
8 #include "common.h"
9 #include "tr2ps.h"
10 #include "comments.h"
11 #include "path.h"
13 int devres;
14 int unitwidth;
15 static char encoding[256];
17 #define NDESCTOKS 9
19 static char *desctoks[NDESCTOKS] = {
20 "PDL",
21 "Encoding",
22 "fonts",
23 "sizes",
24 "res",
25 "hor",
26 "vert",
27 "unitwidth",
28 "charset"
31 char *spechar[MAXSPECHARS];
33 int hash(char *s, int l)
35 unsigned i;
37 for (i = 0; *s; s++)
38 i = i * 10 + *s;
39 return i % l;
42 int readDESC(void)
44 char token[MAXTOKENSIZE];
45 char descfilename[512];
46 int fd;
47 struct ustr *ustr;
48 int state = -1;
49 int fontindex = 0;
50 int i;
52 if (debug)
53 fprintf(ferr, "readDESC()\n");
54 sprintf(descfilename, "%s/dev%s/DESC", FONTDIR, devname);
55 if ((fd = open(descfilename, O_RDONLY)) < 0) {
56 error(WARNING, "cannot open file %s\n", descfilename);
57 return 0;
59 ustr = ustr_fill(fd);
61 while (ustr_str(ustr, token, MAXTOKENSIZE) > 0) {
62 for (i = 0; i < NDESCTOKS; i++) {
63 if (strcmp(desctoks[i], token) == 0) {
64 state = i;
65 break;
68 if (i < NDESCTOKS)
69 continue;
70 switch (state) {
71 case 0:
72 if (debug)
73 fprintf(ferr, "PDL %s\n", token);
74 break;
75 case 1:
76 strcpy(encoding, token);
77 setencoding(encoding);
78 if (debug)
79 fprintf(ferr, "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;
87 fontmnt = atoi(token) + 1;
88 for (i = 0; i < fontmnt; i++)
89 fontmtab[i][0] = 0;
90 fontindex = 0;
91 } else {
92 mountfont(++fontindex, token);
93 findtfn(token, TRUE);
95 break;
96 case 3:
97 /* I don't really care about sizes */
98 break;
99 case 4:
100 /* device resolution in dots per inch */
101 if (!isdigit(*token)) {
102 error(WARNING, "readdesc: expecting device resolution.\n");
103 return(FALSE);
105 devres = atoi(token);
106 if (debug)
107 fprintf(ferr, "res %d\n", devres);
108 break;
109 case 5:
110 /* I don't really care about horizontal motion resolution */
111 if (debug)
112 fprintf(ferr, "ignoring horizontal resolution\n");
113 break;
114 case 6:
115 /* I don't really care about vertical motion resolution */
116 if (debug)
117 fprintf(ferr, "ignoring vertical resolution\n");
118 break;
119 case 7:
120 /* unitwidth is the font size at which the character widths are 1:1 */
121 if (!isdigit(*token)) {
122 error(WARNING, "readdesc: expecting unitwidth.\n");
123 return FALSE;
125 unitwidth = atoi(token);
126 if (debug)
127 fprintf(ferr, "unitwidth %d\n", unitwidth);
128 break;
129 case 8:
130 /* I don't really care about this list of special characters */
131 if (debug)
132 fprintf(ferr, "ignoring special character <%s>\n", token);
133 break;
134 default:
135 if (*token == '#')
136 ustr_eol(ustr);
137 else
138 error(WARNING, "unknown token %s in DESC file.\n", token);
139 break;
142 ustr_free(ustr);
143 return 0;