devcntl.c (4688B)
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(Biobuf *inp) { 55 56 char cmd[50], buf[256], str[MAXTOKENSIZE], *line; 57 int c, n; 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 t_charht(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 beginpath(buf, FALSE); 133 } else if (strncmp(str, "DrawPath", sizeof("DrawPath")-1) == 0) { 134 drawpath(buf, FALSE); 135 } else if (strncmp(str, "BeginObject", sizeof("BeginObject")-1) == 0) { 136 beginpath(buf, TRUE); 137 } else if (strncmp(str, "EndObject", sizeof("EndObject")-1) == 0) { 138 drawpath(buf, TRUE); 139 } else if (strncmp(str, "NewBaseline", sizeof("NewBaseline")-1) == 0) { 140 error(FATAL, "NewBaseline not implemented yet.\n"); 141 /* newbaseline(buf); */ 142 } else if (strncmp(str, "DrawText", sizeof("DrawText")-1) == 0) { 143 error(FATAL, "DrawText not implemented yet.\n"); 144 /* drawtext(buf); */ 145 } else if (strncmp(str, "SetText", sizeof("SetText")-1) == 0) { 146 error(FATAL, "SetText not implemented yet.\n"); 147 /* settext(buf); */ 148 } else if (strncmp(str, "SetColor", sizeof("SetColor")-1) == 0) { 149 error(FATAL, "SetColor not implemented yet.\n"); 150 /* newcolor(buf); */ 151 /* setcolor(); */ 152 } else if (strncmp(str, "INFO", sizeof("INFO")-1) == 0) { 153 error(FATAL, "INFO not implemented yet.\n"); 154 /* flushtext(); */ 155 /* Bprint(outp, "%%INFO%s", buf); */ 156 } else if (strncmp(str, "PS", sizeof("PS")-1) == 0 || strncmp(str, "PostScript", sizeof("PostScript")-1) == 0) { 157 if(pageon()) { 158 endstring(); 159 Bprint(Bstdout, "%s\n", buf); 160 } 161 } else if (strncmp(str, "ExportPS", sizeof("ExportPS")-1) == 0) { /* dangerous!! */ 162 error(FATAL, "ExportPS not implemented yet.\n"); 163 /* if (Bfildes(outp) == 1) { */ 164 /* restore(); */ 165 /* Bprint(outp, "%s", buf); */ 166 /* save(); */ 167 /* } */ 168 } 169 /* else 170 error(WARNING, "Unknown string <%s %s> after x X\n", str, buf); 171 */ 172 173 break; 174 } 175 while ((c = Bgetc(inp)) != '\n' && c != Beof); 176 inputlineno++; 177 }