post: print a help message when unknown options are given
[neatpost.git] / dev.c
blobad4dd241428041f36f1505c2ef23b5609c50fab5
1 #include <ctype.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include "post.h"
7 char dev_dir[PATHLEN]; /* device directory */
8 char dev_dev[PATHLEN]; /* output device name */
9 int dev_res; /* device resolution */
10 int dev_uwid; /* device unitwidth */
11 int dev_hor; /* minimum horizontal movement */
12 int dev_ver; /* minimum vertical movement */
14 /* mounted fonts */
15 static char fn_name[NFONTS][FNLEN]; /* font names */
16 static struct font *fn_font[NFONTS]; /* font structs */
17 static int fn_n; /* number of mounted fonts */
19 static void skipline(FILE* filp)
21 int c;
22 do {
23 c = getc(filp);
24 } while (c != '\n' && c != EOF);
27 int dev_mnt(int pos, char *id, char *name)
29 char path[PATHLEN];
30 struct font *fn;
31 sprintf(path, "%s/dev%s/%s", dev_dir, dev_dev, name);
32 fn = font_open(path);
33 if (!fn)
34 return -1;
35 if (fn_font[pos])
36 font_close(fn_font[pos]);
37 if (fn_name[pos] != name) /* ignore if fn_name[pos] is passed */
38 strcpy(fn_name[pos], id);
39 fn_font[pos] = fn;
40 return pos;
43 int dev_open(char *dir, char *dev)
45 char path[PATHLEN];
46 char tok[ILNLEN];
47 int i;
48 FILE *desc;
49 strcpy(dev_dir, dir);
50 strcpy(dev_dev, dev);
51 sprintf(path, "%s/dev%s/DESC", dir, dev);
52 desc = fopen(path, "r");
53 if (!desc)
54 return 1;
55 while (fscanf(desc, "%s", tok) == 1) {
56 if (tok[0] == '#') {
57 skipline(desc);
58 continue;
60 if (!strcmp("fonts", tok)) {
61 fscanf(desc, "%d", &fn_n);
62 for (i = 0; i < fn_n; i++)
63 fscanf(desc, "%s", fn_name[i + 1]);
64 fn_n++;
65 continue;
67 if (!strcmp("sizes", tok)) {
68 while (fscanf(desc, "%s", tok) == 1)
69 if (!strcmp("0", tok))
70 break;
71 continue;
73 if (!strcmp("res", tok)) {
74 fscanf(desc, "%d", &dev_res);
75 continue;
77 if (!strcmp("unitwidth", tok)) {
78 fscanf(desc, "%d", &dev_uwid);
79 continue;
81 if (!strcmp("hor", tok)) {
82 fscanf(desc, "%d", &dev_hor);
83 continue;
85 if (!strcmp("ver", tok)) {
86 fscanf(desc, "%d", &dev_ver);
87 continue;
89 if (!strcmp("charset", tok))
90 break;
91 skipline(desc);
93 fclose(desc);
94 return 0;
97 void dev_close(void)
99 int i;
100 for (i = 0; i < fn_n; i++) {
101 if (fn_font[i])
102 font_close(fn_font[i]);
103 fn_font[i] = NULL;
107 struct glyph *dev_glyph(char *c, int fn)
109 struct glyph *g;
110 int i;
111 g = font_find(fn_font[fn], c);
112 if (g)
113 return g;
114 for (i = 0; i < fn_n; i++)
115 if (fn_font[i] && fn_font[i]->special)
116 if ((g = font_find(fn_font[i], c)))
117 return g;
118 return NULL;
121 struct glyph *dev_glyph_byid(char *id, int fn)
123 return font_glyph(fn_font[fn], id);
126 int dev_kernpair(char *c1, char *c2)
128 return 0;
131 /* return the font struct at pos */
132 struct font *dev_font(int pos)
134 return pos >= 0 && pos < fn_n ? fn_font[pos] : NULL;
137 int charwid(int wid, int sz)
139 /* the original troff rounds the widths up */
140 return (wid * sz + dev_uwid / 2) / dev_uwid;
143 int dev_fontid(struct font *fn)
145 int i;
146 for (i = 0; i < fn_n; i++)
147 if (fn_font[i] == fn)
148 return i;
149 return 0;