conv.c 2.7 KB

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