1
0

tg.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /* tg.c: process included text blocks */
  10. # include "t.h"
  11. int
  12. gettext(char *sp, int ilin, int icol, char *fn, char *sz)
  13. {
  14. /* get a section of text */
  15. char line[4096];
  16. int oname, startline;
  17. char *vs;
  18. startline = iline;
  19. if (texname == 0)
  20. error("Too many text block diversions");
  21. if (textflg == 0) {
  22. Bprint(&tabout, ".nr %d \\n(.lu\n", SL); /* remember old line length */
  23. textflg = 1;
  24. }
  25. Bprint(&tabout, ".eo\n");
  26. Bprint(&tabout, ".am %s\n", reg(icol, CRIGHT));
  27. Bprint(&tabout, ".br\n");
  28. Bprint(&tabout, ".di %c+\n", texname);
  29. rstofill();
  30. if (fn && *fn)
  31. Bprint(&tabout, ".nr %d \\n(.f\n.ft %s\n", S1, fn);
  32. Bprint(&tabout, ".ft \\n(.f\n"); /* protect font */
  33. vs = vsize[icol][stynum[ilin]];
  34. if ((sz && *sz) || (vs && *vs)) {
  35. Bprint(&tabout, ".nr %d \\n(.v\n", S9);
  36. if (vs == 0 || *vs == 0)
  37. vs = "\\n(.s+2";
  38. if (sz && *sz)
  39. Bprint(&tabout, ".ps %s\n", sz);
  40. Bprint(&tabout, ".vs %s\n", vs);
  41. Bprint(&tabout, ".if \\n(%du>\\n(.vu .sp \\n(%du-\\n(.vu\n", S9, S9);
  42. }
  43. if (cll[icol][0])
  44. Bprint(&tabout, ".ll %sn\n", cll[icol]);
  45. else
  46. Bprint(&tabout, ".ll \\n(%du*%du/%du\n", SL, ctspan(ilin, icol), ncol + 1);
  47. Bprint(&tabout, ".if \\n(.l<\\n(%2s .ll \\n(%2su\n", reg(icol, CRIGHT),
  48. reg(icol, CRIGHT));
  49. if (ctype(ilin, icol) == 'a')
  50. Bprint(&tabout, ".ll -2n\n");
  51. Bprint(&tabout, ".in 0\n");
  52. for (;;) {
  53. if (gets1(line, sizeof(line)) == nil) {
  54. iline = startline;
  55. error("missing closing T}");
  56. }
  57. if (line[0] == 'T' && line[1] == '}' && line[2] == tab)
  58. break;
  59. if (match("T}", line))
  60. break;
  61. Bprint(&tabout, "%s\n", line);
  62. }
  63. if (fn && *fn)
  64. Bprint(&tabout, ".ft \\n(%d\n", S1);
  65. if (sz && *sz)
  66. Bprint(&tabout, ".br\n.ps\n.vs\n");
  67. Bprint(&tabout, ".br\n");
  68. Bprint(&tabout, ".di\n");
  69. Bprint(&tabout, ".nr %c| \\n(dn\n", texname);
  70. Bprint(&tabout, ".nr %c- \\n(dl\n", texname);
  71. Bprint(&tabout, "..\n");
  72. Bprint(&tabout, ".ec \\\n");
  73. /* copy remainder of line */
  74. if (line[2])
  75. tcopy (sp, line + 3);
  76. else
  77. *sp = 0;
  78. oname = texname;
  79. texname = texstr[++texct];
  80. return(oname);
  81. }
  82. void
  83. untext(void)
  84. {
  85. rstofill();
  86. Bprint(&tabout, ".nf\n");
  87. Bprint(&tabout, ".ll \\n(%du\n", SL);
  88. }