t7.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /* t7.c: control to write table entries */
  2. # include "t.h"
  3. # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
  4. void
  5. runout(void)
  6. {
  7. int i;
  8. if (boxflg || allflg || dboxflg)
  9. need();
  10. if (ctrflg) {
  11. Bprint(&tabout, ".nr #I \\n(.i\n");
  12. Bprint(&tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
  13. }
  14. Bprint(&tabout, ".fc %c %c\n", F1, F2);
  15. Bprint(&tabout, ".nr #T 0-1\n");
  16. deftail();
  17. for (i = 0; i < nlin; i++)
  18. putline(i, i);
  19. if (leftover)
  20. yetmore();
  21. Bprint(&tabout, ".fc\n");
  22. Bprint(&tabout, ".nr T. 1\n");
  23. Bprint(&tabout, ".T# 1\n");
  24. if (ctrflg)
  25. Bprint(&tabout, ".in \\n(#Iu\n");
  26. }
  27. void
  28. runtabs(int lform, int ldata)
  29. {
  30. int c, ct, vforml, lf;
  31. Bprint(&tabout, ".ta ");
  32. for (c = 0; c < ncol; c++) {
  33. vforml = lform;
  34. for (lf = prev(lform); lf >= 0 && vspen(table[lf][c].col); lf = prev(lf))
  35. vforml = lf;
  36. if (fspan(vforml, c))
  37. continue;
  38. switch (ct = ctype(vforml, c)) {
  39. case 'n':
  40. case 'a':
  41. if (table[ldata][c].rcol)
  42. if (lused[c]) /*Zero field width*/
  43. Bprint(&tabout, "\\n(%2su ", reg(c, CMID));
  44. case 'c':
  45. case 'l':
  46. case 'r':
  47. if (realsplit ? rused[c] : (used[c] + lused[c]))
  48. Bprint(&tabout, "\\n(%2su ", reg(c, CRIGHT));
  49. continue;
  50. case 's':
  51. if (lspan(lform, c))
  52. Bprint(&tabout, "\\n(%2su ", reg(c, CRIGHT));
  53. continue;
  54. }
  55. }
  56. Bprint(&tabout, "\n");
  57. }
  58. int
  59. ifline(char *s)
  60. {
  61. if (!point(s))
  62. return(0);
  63. if (s[0] == '\\')
  64. s++;
  65. if (s[1] )
  66. return(0);
  67. if (s[0] == '_')
  68. return('-');
  69. if (s[0] == '=')
  70. return('=');
  71. return(0);
  72. }
  73. void
  74. need(void)
  75. {
  76. int texlin, horlin, i;
  77. for (texlin = horlin = i = 0; i < nlin; i++) {
  78. if (fullbot[i] != 0)
  79. horlin++;
  80. else if (instead[i] != 0)
  81. continue;
  82. else
  83. texlin++;
  84. }
  85. Bprint(&tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
  86. }
  87. void
  88. deftail(void)
  89. {
  90. int i, c, lf, lwid;
  91. for (i = 0; i < MAXHEAD; i++)
  92. if (linestop[i])
  93. Bprint(&tabout, ".nr #%c 0-1\n", linestop[i] + 'a' - 1);
  94. Bprint(&tabout, ".nr #a 0-1\n");
  95. Bprint(&tabout, ".eo\n");
  96. Bprint(&tabout, ".de T#\n");
  97. Bprint(&tabout, ".nr 35 1m\n");
  98. Bprint(&tabout, ".ds #d .d\n");
  99. Bprint(&tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
  100. Bprint(&tabout, ".mk ##\n");
  101. Bprint(&tabout, ".nr ## -1v\n");
  102. Bprint(&tabout, ".ls 1\n");
  103. for (i = 0; i < MAXHEAD; i++)
  104. if (linestop[i])
  105. Bprint(&tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",
  106. linestop[i] + 'a' - 1);
  107. if (boxflg || allflg || dboxflg) /* bottom of table line */
  108. if (fullbot[nlin-1] == 0) {
  109. if (!pr1403)
  110. Bprint(&tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
  111. Bprint(&tabout, ".if \\n(T. ");
  112. drawline(nlin, 0, ncol, dboxflg ? '=' : '-', 1, 0);
  113. Bprint(&tabout, "\n.if \\n(T. .vs\n");
  114. /* T. is really an argument to a macro but because of
  115. eqn we don't dare pass it as an argument and reference by $1 */
  116. }
  117. for (c = 0; c < ncol; c++) {
  118. if ((lf = left(nlin - 1, c, &lwid)) >= 0) {
  119. Bprint(&tabout, ".if \\n(#%c>=0 .sp -1\n", linestop[lf] + 'a' - 1);
  120. Bprint(&tabout, ".if \\n(#%c>=0 ", linestop[lf] + 'a' - 1);
  121. tohcol(c);
  122. drawvert(lf, nlin - 1, c, lwid);
  123. Bprint(&tabout, "\\h'|\\n(TWu'\n");
  124. }
  125. }
  126. if (boxflg || allflg || dboxflg) /* right hand line */ {
  127. Bprint(&tabout, ".if \\n(#a>=0 .sp -1\n");
  128. Bprint(&tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
  129. drawvert (0, nlin - 1, ncol, dboxflg ? 2 : 1);
  130. Bprint(&tabout, "\n");
  131. }
  132. Bprint(&tabout, ".ls\n");
  133. Bprint(&tabout, "..\n");
  134. Bprint(&tabout, ".ec\n");
  135. }