xref: /plan9-contrib/sys/src/cmd/postscript/tr2post/devcntl.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <stdio.h>
5 #include "../common/common.h"
6 #include "tr2post.h"
7 
8 char devname[20] = { 'u', 't', 'f', '\0' };
9 int resolution;
10 int minx, miny;
11 
12 struct sjt {
13 	char *str;
14 	void (*func)(void *);
15 };
16 
17 /* I won't need this if getfields can replace sscanf
18 
19 extern void picture(Biobufhdr *);
20 extern void notavail(char *);
21 
22 void
23 PSInclude(Biobufhdr *inp) {
24 	char buf[256];
25 
26 	Bgetfield(inp, 's', buf, 256);
27 	if(pageon()) {
28 		endstring();
29 		Bprint(Bstdout, "%s\n", buf);
30 	}
31 }
32 
33 struct sjt specialjumptable[] = {
34 	{"PI", picture},
35 	{"PictureInclusion", picture},
36 	{"InlinePicture", NULL},
37 	{"BeginPath", NULL},
38 	{"DrawPath", NULL},
39 	{"BeginObject", NULL},
40 	{"EndObject", NULL},
41 	{"NewBaseline", NULL},
42 	{"DrawText", NULL},
43 	{"SetText", NULL},
44 	{"SetColor", NULL},
45 	{"INFO", NULL},
46 	{"PS", PSInclude},
47 	{"Postscript", PSInclude},
48 	{"ExportPS", notavail("ExportPS")},
49 	{NULL, NULL}
50 };
51 */
52 
53 void
54 devcntl(Biobufhdr *inp) {
55 
56 	char cmd[50], buf[256], str[MAXTOKENSIZE], *line;
57 	int c, n, linelen;
58 
59 /*
60  *
61  * Interpret device control commands, ignoring any we don't recognize. The
62  * "x X ..." commands are a device dependent collection generated by troff's
63  * \X'...' request.
64  *
65  */
66 
67 	Bgetfield(inp, 's', cmd, 50);
68 	if (debug) Bprint(Bstderr, "devcntl(cmd=%s)\n", cmd);
69 	switch (cmd[0]) {
70 	case 'f':		/* mount font in a position */
71 		Bgetfield(inp, 'd', &n, 0);
72 		Bgetfield(inp, 's', str, 100);
73 		mountfont(n, str);
74 		break;
75 
76 	case 'i':			/* initialize */
77 		initialize();
78 		break;
79 
80 	case 'p':			/* pause */
81 		break;
82 
83 	case 'r':			/* resolution assumed when prepared */
84 		Bgetfield(inp, 'd', &resolution, 0);
85 		Bgetfield(inp, 'd', &minx, 0);
86 		Bgetfield(inp, 'd', &miny, 0);
87 		break;
88 
89 	case 's':			/* stop */
90 	case 't':			/* trailer */
91 		/* flushtext(); */
92 		break;
93 
94 	case 'H':			/* char height */
95 		Bgetfield(inp, 'd', &n, 0);
96 		/* charhgt(n); */
97 		break;
98 
99 	case 'S':			/* slant */
100 		Bgetfield(inp, 'd', &n, 0);
101 		/* t_slant(n); */
102 		break;
103 
104 	case 'T':			/* device name */
105 		Bgetfield(inp, 's', &devname, 16);
106 		if (debug) Bprint(Bstderr, "devname=%s\n", devname);
107 		break;
108 
109 	case 'E':			/* input encoding - not in troff yet */
110 		Bgetfield(inp, 's', &str, 100);
111 /*		if ( strcmp(str, "UTF") == 0 )
112 		    reading = UTFENCODING;
113 		else reading = ONEBYTE;
114   */
115 		break;
116 
117 	case 'X':			/* copy through - from troff */
118 		if (Bgetfield(inp, 's', str, MAXTOKENSIZE-1) <= 0)
119 			error(FATAL, "incomplete devcntl line\n");
120 		if ((line = Brdline(inp, '\n')) == 0)
121 			error(FATAL, "incomplete devcntl line\n");
122 		strncpy(buf, line, Blinelen(inp)-1);
123 		buf[Blinelen(inp)-1] = '\0';
124 		Bungetc(inp);
125 
126 		if (strncmp(str, "PI", sizeof("PI")-1) == 0 || strncmp(str, "PictureInclusion", sizeof("PictureInclusion")-1) == 0) {
127 			picture(inp, str);
128 		} else if (strncmp(str, "InlinePicture", sizeof("InlinePicture")-1) == 0) {
129 			error(FATAL, "InlinePicture not implemented yet.\n");
130 /*			inlinepic(inp, buf);			*/
131 		} else if (strncmp(str, "BeginPath", sizeof("BeginPath")-1) == 0) {
132 			error(FATAL, "BeginPath not implemented yet.\n");
133 /*			beginpath(buf, FALSE);		*/
134 		} else if (strncmp(str, "DrawPath", sizeof("DrawPath")-1) == 0) {
135 			error(FATAL, "DrawPath not implemented yet.\n");
136 /*			drawpath(buf, FALSE);		*/
137 		} else if (strncmp(str, "BeginObject", sizeof("BeginObject")-1) == 0) {
138 			error(FATAL, "BeginObject not implemented yet.\n");
139 /*			beginpath(buf, TRUE);		*/
140 		} else if (strncmp(str, "EndObject", sizeof("EndObject")-1) == 0) {
141 			error(FATAL, "EndObject not implemented yet.\n");
142 /*			drawpath(buf, TRUE);		*/
143 		} else if (strncmp(str, "NewBaseline", sizeof("NewBaseline")-1) == 0) {
144 			error(FATAL, "NewBaseline not implemented yet.\n");
145 /*			newbaseline(buf);			*/
146 		} else if (strncmp(str, "DrawText", sizeof("DrawText")-1) == 0) {
147 			error(FATAL, "DrawText not implemented yet.\n");
148 /*			drawtext(buf);				*/
149 		} else if (strncmp(str, "SetText", sizeof("SetText")-1) == 0) {
150 			error(FATAL, "SetText not implemented yet.\n");
151 /*			settext(buf);				*/
152 		} else if (strncmp(str, "SetColor", sizeof("SetColor")-1) == 0) {
153 			error(FATAL, "SetColor not implemented yet.\n");
154 /*			newcolor(buf);				*/
155 /*			setcolor();					*/
156 		} else if (strncmp(str, "INFO", sizeof("INFO")-1) == 0) {
157 			error(FATAL, "INFO not implemented yet.\n");
158 /*			flushtext();				*/
159 /*			Bprint(outp, "%%INFO%s", buf);	*/
160 		} else if (strncmp(str, "PS", sizeof("PS")-1) == 0 || strncmp(str, "PostScript", sizeof("PostScript")-1) == 0) {
161 			if(pageon()) {
162 				endstring();
163 				Bprint(Bstdout, "%s\n", buf);
164 			}
165 		} else if (strncmp(str, "ExportPS", sizeof("ExportPS")-1) == 0) {	/* dangerous!! */
166 			error(FATAL, "ExportPS not implemented yet.\n");
167 /*			if (Bfildes(outp) == 1) {		*/
168 /*				restore();				*/
169 /*				Bprint(outp, "%s", buf);	*/
170 /*				save();				*/
171 /*			}						*/
172 		}
173 /*		 else
174 			error(WARNING, "Unknown string <%s %s> after x X\n", str, buf);
175 */
176 
177 		break;
178 	}
179 	while ((c = Bgetc(inp)) != '\n' && c != Beof);
180 	inputlineno++;
181 }
182 
183