void devcntl(Biobufhdr *inp) { char cmd[50], buf[256], str[MAXTOKENSIZE], *line; int c, n; /* * * Interpret device control commands, ignoring any we don't recognize. The * "x X ..." commands are a device dependent collection generated by troff's * \X'...' request. * */ Bgetfield(inp, 's', cmd, 50); if (debug) Bprint(Bstderr, "devcntl(cmd=%s)\n", cmd); switch (cmd[0]) { case 'f': /* mount font in a position */ Bgetfield(inp, 'd', &n, 0); Bgetfield(inp, 's', str, 100); mountfont(n, str); break; case 'i': /* initialize */ initialize(); break; case 'p': /* pause */ break; case 'r': /* resolution assumed when prepared */ Bgetfield(inp, 'd', &resolution, 0); Bgetfield(inp, 'd', &minx, 0); Bgetfield(inp, 'd', &miny, 0); break; case 's': /* stop */ case 't': /* trailer */ /* flushtext(); */ break; case 'H': /* char height */ Bgetfield(inp, 'd', &n, 0); t_charht(n); break; case 'S': /* slant */ Bgetfield(inp, 'd', &n, 0); t_slant(n); break; case 'T': /* device name */ Bgetfield(inp, 's', devname, 16); if (debug) Bprint(Bstderr, "devname=%s\n", devname); break; case 'E': /* input encoding - not in troff yet */ Bgetfield(inp, 's', str, 100); /* if (strcmp(str, "UTF") == 0) reading = UTFENCODING; else reading = ONEBYTE; */ break; case 'X': /* copy through - from troff */ if (Bgetfield(inp, 's', str, MAXTOKENSIZE-1) <= 0) error(FATAL, "incomplete devcntl line\n"); if ((line = Brdline(inp, '\n')) == 0) error(FATAL, "incomplete devcntl line\n"); strncpy(buf, line, Blinelen(inp)-1); buf[Blinelen(inp)-1] = '\0'; Bungetc(inp); if (strncmp(str, "PI", sizeof("PI")-1) == 0 || strncmp(str, "PictureInclusion", sizeof("PictureInclusion")-1) == 0) { picture(inp, str); } else if (strncmp(str, "InlinePicture", sizeof("InlinePicture")-1) == 0) { error(FATAL, "InlinePicture not implemented yet.\n"); /* inlinepic(inp, buf); */ } else if (strncmp(str, "BeginPath", sizeof("BeginPath")-1) == 0) { beginpath(buf, FALSE); } else if (strncmp(str, "DrawPath", sizeof("DrawPath")-1) == 0) { drawpath(buf, FALSE); } else if (strncmp(str, "BeginObject", sizeof("BeginObject")-1) == 0) { beginpath(buf, TRUE); } else if (strncmp(str, "EndObject", sizeof("EndObject")-1) == 0) { drawpath(buf, TRUE); } else if (strncmp(str, "NewBaseline", sizeof("NewBaseline")-1) == 0) { error(FATAL, "NewBaseline not implemented yet.\n"); /* newbaseline(buf); */ } else if (strncmp(str, "DrawText", sizeof("DrawText")-1) == 0) { error(FATAL, "DrawText not implemented yet.\n"); /* drawtext(buf); */ } else if (strncmp(str, "SetText", sizeof("SetText")-1) == 0) { error(FATAL, "SetText not implemented yet.\n"); /* settext(buf); */ } else if (strncmp(str, "SetColor", sizeof("SetColor")-1) == 0) { error(FATAL, "SetColor not implemented yet.\n"); /* newcolor(buf); */ /* setcolor(); */ } else if (strncmp(str, "INFO", sizeof("INFO")-1) == 0) { error(FATAL, "INFO not implemented yet.\n"); /* flushtext(); */ /* Bprint(outp, "%%INFO%s", buf); */ } else if (strncmp(str, "PS", sizeof("PS")-1) == 0 || strncmp(str, "PostScript", sizeof("PostScript")-1) == 0) { if(pageon()) { endstring(); Bprint(Bstdout, "%s\n", buf); } } else if (strncmp(str, "ExportPS", sizeof("ExportPS")-1) == 0) { /* dangerous!! */ error(FATAL, "ExportPS not implemented yet.\n"); /* if (Bfildes(outp) == 1) { */ /* restore(); */ /* Bprint(outp, "%s", buf); */ /* save(); */ /* } */ } /* else error(WARNING, "Unknown string <%s %s> after x X\n", str, buf); */ break; } while ((c = Bgetc(inp)) != '\n' && c != Beof); inputlineno++; }
void xcmd(Biobuf *b) { char *p, *fld[16], buf[1024]; int i, nfld; p = getline(b); if(p == nil) sysfatal("xcmd error: %r"); if(debug) fprint(2, "x command '%s'\n", p); nfld = tokenize(p, fld, nelem(fld)); if(nfld == 0) return; switch(fld[0][0]){ case 'f': /* mount font */ if(nfld != 3) break; i = atoi(fld[1]); if(i<0 || Nfont<=i) sysfatal("font %d out of range at %s:#%d", i, filename, cno); mountfont(i, fld[2]); return; case 'i': /* init */ return; case 'r': if(nfld<2 || atoi(fld[1])!=res) sysfatal("typesetter has unexpected resolution %s", fld[1]? fld[1] : "<unspecified>"); return; case 's': /* stop */ return; case 't': /* trailer */ return; case 'T': if(nfld!=2 || strcmp(fld[1], "utf")!=0) sysfatal("output for unknown typesetter type %s", fld[1]); return; case 'X': if(nfld<3 || strcmp(fld[1], "html")!=0) break; /* is it a man reference of the form cp(1)? */ /* X manref start/end cp (1) */ if(nfld==6 && strcmp(fld[2], "manref")==0){ /* was the right macro; is it the right form? */ if(strlen(fld[5])>=3 && fld[5][0]=='(' && fld[5][2]==')' && '0'<=fld[5][1] && fld[5][1]<='9'){ if(strcmp(fld[3], "start") == 0){ /* set anchor attribute and remember string */ attr |= (1<<Anchor); snprint(buf, sizeof buf, "<a href=\"/magic/man2html/%c/%s\">", fld[5][1], fld[4]); nanchors++; anchors = erealloc(anchors, nanchors*sizeof(char*)); anchors[nanchors-1] = estrdup(buf); }else if(strcmp(fld[3], "end") == 0) attr &= ~(1<<Anchor); } }else if(strcmp(fld[2], "manPP") == 0){ didP = 1; emitchar(Epp); }else if(nfld<4 || strcmp(fld[2], "manref")!=0){ if(nfld>2 && strcmp(fld[2], "<P>")==0){ /* avoid triggering extra <br> */ didP = 1; /* clear all font attributes before paragraph */ emitchar(' ' | (attr & ~(0xFFFF|((1<<Italic)|(1<<Bold)|(1<<CW))))); emitstr("<P>"); /* next emittec char will turn font attributes back on */ }else if(nfld>2 && strcmp(fld[2], "<H4>")==0) attr |= (1<<Heading); else if(nfld>2 && strcmp(fld[2], "</H4>")==0) attr &= ~(1<<Heading); else if(debug) fprint(2, "unknown in-line html %s... at %s:%#d\n", fld[2], filename, cno); } return; } if(debug) fprint(2, "unknown or badly formatted x command %s\n", fld[0]); }
BOOLEAN readDESC(void) { char token[MAXTOKENSIZE]; char *descnameformat = "%s/dev%s/DESC"; char *descfilename = 0; Biobuf *bfd; Biobufhdr *Bfd; int i, state = -1; int fontindex = 0; if (debug) Bprint(Bstderr, "readDESC()\n"); descfilename = galloc(descfilename, strlen(descnameformat)+strlen(FONTDIR) +strlen(devname), "readdesc"); sprint(descfilename, descnameformat, FONTDIR, devname); if ((bfd = Bopen(descfilename, OREAD)) == 0) { error(WARNING, "cannot open file %s\n", descfilename); return 0; } Bfd = &(bfd->Biobufhdr); while (Bgetfield(Bfd, 's', token, MAXTOKENSIZE) > 0) { for (i=0; i<NDESCTOKS; i++) { if (strcmp(desctoks[i], token) == 0) { state = i; break; } } if (i<NDESCTOKS) continue; switch (state) { case 0: printdesclang=galloc(printdesclang, strlen(token)+1, "readdesc:"); strcpy(printdesclang, token); if (debug) Bprint(Bstderr, "PDL %s\n", token); break; case 1: encoding=galloc(encoding, strlen(token)+1, "readdesc:"); strcpy(encoding, token); if (debug) Bprint(Bstderr, "encoding %s\n", token); break; case 2: if (fontmnt <=0) { if (!isdigit(*token)) { error(WARNING, "readdesc: expecting number of fonts in mount table.\n"); return FALSE; } fontmnt = atoi(token) + 1; fontmtab = galloc(fontmtab, fontmnt*sizeof(char *), "readdesc:"); for (i=0; i<fontmnt; i++) fontmtab[i] = 0; fontindex = 0; } else { mountfont(++fontindex, token); findtfn(token, TRUE); } break; case 3: /* I don't really care about sizes */ break; case 4: /* device resolution in dots per inch */ if (!isdigit(*token)) { error(WARNING, "readdesc: expecting device resolution.\n"); return FALSE; } devres = atoi(token); if (debug) Bprint(Bstderr, "res %d\n", devres); break; case 5: /* I don't really care about horizontal motion resolution */ if (debug) Bprint(Bstderr, "ignoring horizontal resolution\n"); break; case 6: /* I don't really care about vertical motion resolution */ if (debug) Bprint(Bstderr, "ignoring vertical resolution\n"); break; case 7: /* unitwidth is the font size at which the character widths are 1:1 */ if (!isdigit(*token)) { error(WARNING, "readdesc: expecting unitwidth.\n"); return(FALSE); } unitwidth = atoi(token); if (debug) Bprint(Bstderr, "unitwidth %d\n", unitwidth); break; case 8: /* I don't really care about this list of special characters */ if (debug) Bprint(Bstderr, "ignoring special character <%s>\n", token); break; default: if (*token == '#') Brdline(Bfd, '\n'); else error(WARNING, "unknown token %s in DESC file.\n", token); break; } } Bterm(Bfd); return 0; }