1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 #include "../common/common.h" 5 #include "tr2post.h" 6 7 void 8 conv(Biobufhdr *Bp) { 9 long c, n; 10 int r; 11 char special[10]; 12 13 inputlineno = 1; 14 if (debug) Bprint(Bstderr, "conv(Biobufhdr *Bp=0x%x)\n", Bp); 15 while ((r = Bgetrune(Bp)) >= 0) { 16 /* Bprint(Bstderr, "r=<%c>,0x%x\n", r, r); */ 17 /* Bflush(Bstderr); */ 18 switch (r) { 19 case 's': /* set point size */ 20 Bgetfield(Bp, 'd', &fontsize, 0); 21 break; 22 case 'f': /* set font to postion */ 23 Bgetfield(Bp, 'd', &fontpos, 0); 24 settrfont(); 25 break; 26 case 'c': /* print rune */ 27 r = Bgetrune(Bp); 28 runeout(r); 29 break; 30 case 'C': /* print special character */ 31 Bgetfield(Bp, 's', special, 10); 32 specialout(special); 33 break; 34 case 'N': /* print character with numeric value from current font */ 35 Bgetfield(Bp, 'd', &n, 0); 36 break; 37 case 'H': /* go to absolute horizontal position */ 38 Bgetfield(Bp, 'd', &n, 0); 39 hgoto(n); 40 break; 41 case 'V': /* go to absolute vertical position */ 42 Bgetfield(Bp, 'd', &n, 0); 43 vgoto(n); 44 break; 45 case 'h': /* go to relative horizontal position */ 46 Bgetfield(Bp, 'd', &n, 0); 47 hmot(n); 48 break; 49 case 'v': /* go to relative vertical position */ 50 Bgetfield(Bp, 'd', &n, 0); 51 vmot(n); 52 break; 53 case '0': case '1': case '2': case '3': case '4': 54 case '5': case '6': case '7': case '8': case '9': 55 /* move right nn units, then print character c */ 56 n = (r - '0') * 10; 57 r = Bgetrune(Bp); 58 if (r < 0) 59 error(FATAL, "EOF or error reading input\n"); 60 else if (r < '0' || r > '9') 61 error(FATAL, "integer expected\n"); 62 n += r - '0'; 63 r = Bgetrune(Bp); 64 hmot(n); 65 runeout(r); 66 break; 67 case 'p': /* begin page */ 68 Bgetfield(Bp, 'd', &n, 0); 69 endpage(); 70 startpage(); 71 break; 72 case 'n': /* end of line (information only 'b a' follows) */ 73 Brdline(Bp, '\n'); /* toss rest of line */ 74 inputlineno++; 75 break; 76 case 'w': /* paddable word space (information only) */ 77 break; 78 case 'D': /* graphics function */ 79 draw(Bp); 80 break; 81 case 'x': /* device control functions */ 82 devcntl(Bp); 83 break; 84 case '#': /* comment */ 85 Brdline(Bp, '\n'); /* toss rest of line */ 86 case '\n': 87 inputlineno++; 88 break; 89 default: 90 error(WARNING, "unknown troff function <%c>\n", r); 91 break; 92 } 93 } 94 endpage(); 95 if (debug) Bprint(Bstderr, "r=0x%x\n", r); 96 if (debug) Bprint(Bstderr, "leaving conv\n"); 97 } 98