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