t8.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /* t8.c: write out one line of output table */
  2. # include "t.h"
  3. # define realsplit ((ct=='a'||ct=='n') && table[nl][c].rcol)
  4. int watchout;
  5. int once;
  6. void
  7. putline(int i, int nl)
  8. /* i is line number for deciding format */
  9. /* nl is line number for finding data usually identical */
  10. {
  11. int c, s, lf, ct, form, lwid, vspf, ip, cmidx, exvspen, vforml;
  12. int vct, chfont, uphalf;
  13. char *ss, *size, *fn, *rct;
  14. cmidx = watchout = vspf = exvspen = 0;
  15. if (i == 0)
  16. once = 0;
  17. if (i == 0 && ( allflg || boxflg || dboxflg))
  18. fullwide(0, dboxflg ? '=' : '-');
  19. if (instead[nl] == 0 && fullbot[nl] == 0)
  20. for (c = 0; c < ncol; c++) {
  21. ss = table[nl][c].col;
  22. if (ss == 0)
  23. continue;
  24. if (vspen(ss)) {
  25. for (ip = nl; ip < nlin; ip = next(ip)){
  26. ss = table[ip][c].col;
  27. if (!vspen(ss))
  28. break;
  29. }
  30. s = (int)(uintptr)ss;
  31. if (s > 0 && s < 128)
  32. Bprint(&tabout, ".ne \\n(%c|u+\\n(.Vu\n", s);
  33. continue;
  34. }
  35. if (point(ss))
  36. continue;
  37. s = (int)(uintptr)ss;
  38. Bprint(&tabout, ".ne \\n(%c|u+\\n(.Vu\n", s);
  39. watchout = 1;
  40. }
  41. if (linestop[nl])
  42. Bprint(&tabout, ".mk #%c\n", linestop[nl] + 'a' - 1);
  43. lf = prev(nl);
  44. if (instead[nl]) {
  45. Bprint(&tabout, "%s\n", instead[nl]);
  46. return;
  47. }
  48. if (fullbot[nl]) {
  49. switch (ct = fullbot[nl]) {
  50. case '=':
  51. case '-':
  52. fullwide(nl, ct);
  53. }
  54. return;
  55. }
  56. for (c = 0; c < ncol; c++) {
  57. if (instead[nl] == 0 && fullbot[nl] == 0)
  58. if (vspen(table[nl][c].col))
  59. vspf = 1;
  60. if (lf >= 0)
  61. if (vspen(table[lf][c].col))
  62. vspf = 1;
  63. }
  64. if (vspf) {
  65. Bprint(&tabout, ".nr #^ \\n(\\*(#du\n");
  66. Bprint(&tabout, ".nr #- \\n(#^\n"); /* current line position relative to bottom */
  67. }
  68. vspf = 0;
  69. chfont = 0;
  70. for (c = 0; c < ncol; c++) {
  71. ss = table[nl][c].col;
  72. if (ss == 0)
  73. continue;
  74. if(font[c][stynum[nl]])
  75. chfont = 1;
  76. if (point(ss) )
  77. continue;
  78. s = (int)(uintptr)ss;
  79. lf = prev(nl);
  80. if (lf >= 0 && vspen(table[lf][c].col))
  81. Bprint(&tabout,
  82. ".if (\\n(%c|+\\n(^%c-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(^%c-\\n(#--1v)\n",
  83. s, 'a' + c, s, 'a' + c);
  84. else
  85. Bprint(&tabout,
  86. ".if (\\n(%c|+\\n(#^-1v)>\\n(#- .nr #- +(\\n(%c|+\\n(#^-\\n(#--1v)\n",
  87. s, s);
  88. }
  89. if (allflg && once > 0 )
  90. fullwide(i, '-');
  91. once = 1;
  92. runtabs(i, nl);
  93. if (allh(i) && !pr1403) {
  94. Bprint(&tabout, ".nr %d \\n(.v\n", SVS);
  95. Bprint(&tabout, ".vs \\n(.vu-\\n(.sp\n");
  96. Bprint(&tabout, ".nr 35 \\n(.vu\n");
  97. } else
  98. Bprint(&tabout, ".nr 35 1m\n");
  99. if (chfont)
  100. Bprint(&tabout, ".nr %2d \\n(.f\n", S1);
  101. Bprint(&tabout, "\\&");
  102. vct = 0;
  103. for (c = 0; c < ncol; c++) {
  104. uphalf = 0;
  105. if (watchout == 0 && i + 1 < nlin && (lf = left(i, c, &lwid)) >= 0) {
  106. tohcol(c);
  107. drawvert(lf, i, c, lwid);
  108. vct += 2;
  109. }
  110. if (rightl && c + 1 == ncol)
  111. continue;
  112. vforml = i;
  113. for (lf = prev(nl); lf >= 0 && vspen(table[lf][c].col); lf = prev(lf))
  114. vforml = lf;
  115. form = ctype(vforml, c);
  116. if (form != 's') {
  117. rct = reg(c, CLEFT);
  118. if (form == 'a')
  119. rct = reg(c, CMID);
  120. if (form == 'n' && table[nl][c].rcol && lused[c] == 0)
  121. rct = reg(c, CMID);
  122. Bprint(&tabout, "\\h'|\\n(%2su'", rct);
  123. }
  124. ss = table[nl][c].col;
  125. fn = font[c][stynum[vforml]];
  126. size = csize[c][stynum[vforml]];
  127. if (*size == 0)
  128. size = 0;
  129. if ((flags[c][stynum[nl]] & HALFUP) != 0 && pr1403 == 0)
  130. uphalf = 1;
  131. switch (ct = ctype(vforml, c)) {
  132. case 'n':
  133. case 'a':
  134. if (table[nl][c].rcol) {
  135. if (lused[c]) /*Zero field width*/ {
  136. ip = prev(nl);
  137. if (ip >= 0)
  138. if (vspen(table[ip][c].col)) {
  139. if (exvspen == 0) {
  140. Bprint(&tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c + 'a');
  141. if (cmidx)
  142. /* code folded from here */
  143. Bprint(&tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c + 'a');
  144. /* unfolding */
  145. vct++;
  146. if (pr1403) /* must round to whole lines */
  147. /* code folded from here */
  148. Bprint(&tabout, "/1v*1v");
  149. /* unfolding */
  150. Bprint(&tabout, "'");
  151. exvspen = 1;
  152. }
  153. }
  154. Bprint(&tabout, "%c%c", F1, F2);
  155. if (uphalf)
  156. Bprint(&tabout, "\\u");
  157. puttext(ss, fn, size);
  158. if (uphalf)
  159. Bprint(&tabout, "\\d");
  160. Bprint(&tabout, "%c", F1);
  161. }
  162. ss = table[nl][c].rcol;
  163. form = 1;
  164. break;
  165. }
  166. case 'c':
  167. form = 3;
  168. break;
  169. case 'r':
  170. form = 2;
  171. break;
  172. case 'l':
  173. form = 1;
  174. break;
  175. case '-':
  176. case '=':
  177. if (real(table[nl][c].col))
  178. fprint(2, "%s: line %d: Data ignored on table line %d\n", ifile, iline - 1, i + 1);
  179. makeline(i, c, ct);
  180. continue;
  181. default:
  182. continue;
  183. }
  184. if (realsplit ? rused[c] : used[c]) /*Zero field width*/ {
  185. /* form: 1 left, 2 right, 3 center adjust */
  186. if (ifline(ss)) {
  187. makeline(i, c, ifline(ss));
  188. continue;
  189. }
  190. if (filler(ss)) {
  191. Bprint(&tabout, "\\l'|\\n(%2su\\&%s'", reg(c, CRIGHT), ss + 2);
  192. continue;
  193. }
  194. ip = prev(nl);
  195. cmidx = (flags[c][stynum[nl]] & (CTOP | CDOWN)) == 0;
  196. if (ip >= 0)
  197. if (vspen(table[ip][c].col)) {
  198. if (exvspen == 0) {
  199. Bprint(&tabout, "\\v'-(\\n(\\*(#du-\\n(^%cu", c + 'a');
  200. if (cmidx)
  201. Bprint(&tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c + 'a');
  202. vct++;
  203. if (pr1403) /* round to whole lines */
  204. Bprint(&tabout, "/1v*1v");
  205. Bprint(&tabout, "'");
  206. }
  207. }
  208. Bprint(&tabout, "%c", F1);
  209. if (form != 1)
  210. Bprint(&tabout, "%c", F2);
  211. if (vspen(ss))
  212. vspf = 1;
  213. else
  214. {
  215. if (uphalf)
  216. Bprint(&tabout, "\\u");
  217. puttext(ss, fn, size);
  218. if (uphalf)
  219. Bprint(&tabout, "\\d");
  220. }
  221. if (form != 2)
  222. Bprint(&tabout, "%c", F2);
  223. Bprint(&tabout, "%c", F1);
  224. }
  225. ip = prev(nl);
  226. if (ip >= 0)
  227. if (vspen(table[ip][c].col)) {
  228. exvspen = (c + 1 < ncol) && vspen(table[ip][c+1].col) &&
  229. (topat[c] == topat[c+1]) &&
  230. (cmidx == (flags[c+1] [stynum[nl]] & (CTOP | CDOWN) == 0))
  231. && (left(i, c + 1, &lwid) < 0);
  232. if (exvspen == 0) {
  233. Bprint(&tabout, "\\v'(\\n(\\*(#du-\\n(^%cu", c + 'a');
  234. if (cmidx)
  235. Bprint(&tabout, "-((\\n(#-u-\\n(^%cu)/2u)", c + 'a');
  236. vct++;
  237. if (pr1403) /* round to whole lines */
  238. Bprint(&tabout, "/1v*1v");
  239. Bprint(&tabout, "'");
  240. }
  241. }
  242. else
  243. exvspen = 0;
  244. /* if lines need to be split for gcos here is the place for a backslash */
  245. if (vct > 7 && c < ncol) {
  246. Bprint(&tabout, "\n.sp-1\n\\&");
  247. vct = 0;
  248. }
  249. }
  250. Bprint(&tabout, "\n");
  251. if (allh(i) && !pr1403)
  252. Bprint(&tabout, ".vs \\n(%du\n", SVS);
  253. if (watchout)
  254. funnies(i, nl);
  255. if (vspf) {
  256. for (c = 0; c < ncol; c++)
  257. if (vspen(table[nl][c].col) && (nl == 0 || (lf = prev(nl)) < 0 ||
  258. !vspen(table[lf][c].col))) {
  259. Bprint(&tabout, ".nr ^%c \\n(#^u\n", 'a' + c);
  260. topat[c] = nl;
  261. }
  262. }
  263. }
  264. void
  265. puttext(char *s, char *fn, char *size)
  266. {
  267. if (point(s)) {
  268. putfont(fn);
  269. putsize(size);
  270. Bprint(&tabout, "%s", s);
  271. if (*fn > 0)
  272. Bprint(&tabout, "\\f\\n(%2d", S1);
  273. if (size != 0)
  274. putsize("0");
  275. }
  276. }
  277. void
  278. funnies(int stl, int lin)
  279. {
  280. /* write out funny diverted things */
  281. int c, s, pl, lwid, dv, lf, ct;
  282. char *fn, *ss;
  283. Bprint(&tabout, ".mk ##\n"); /* rmember current vertical position */
  284. Bprint(&tabout, ".nr %d \\n(##\n", S1); /* bottom position */
  285. for (c = 0; c < ncol; c++) {
  286. ss = table[lin][c].col;
  287. if (point(ss))
  288. continue;
  289. if (ss == 0)
  290. continue;
  291. s = (int)(uintptr)ss;
  292. Bprint(&tabout, ".sp |\\n(##u-1v\n");
  293. Bprint(&tabout, ".nr %d ", SIND);
  294. ct = 0;
  295. for (pl = stl; pl >= 0 && !isalpha(ct = ctype(pl, c)); pl = prev(pl))
  296. ;
  297. switch (ct) {
  298. case 'n':
  299. case 'c':
  300. Bprint(&tabout, "(\\n(%2su+\\n(%2su-\\n(%c-u)/2u\n", reg(c, CLEFT),
  301. reg(c - 1 + ctspan(lin, c), CRIGHT),
  302. s);
  303. break;
  304. case 'l':
  305. Bprint(&tabout, "\\n(%2su\n", reg(c, CLEFT));
  306. break;
  307. case 'a':
  308. Bprint(&tabout, "\\n(%2su\n", reg(c, CMID));
  309. break;
  310. case 'r':
  311. Bprint(&tabout, "\\n(%2su-\\n(%c-u\n", reg(c, CRIGHT), s);
  312. break;
  313. }
  314. Bprint(&tabout, ".in +\\n(%du\n", SIND);
  315. fn = font[c][stynum[stl]];
  316. putfont(fn);
  317. pl = prev(stl);
  318. if (stl > 0 && pl >= 0 && vspen(table[pl][c].col)) {
  319. Bprint(&tabout, ".sp |\\n(^%cu\n", 'a' + c);
  320. if ((flags[c][stynum[stl]] & (CTOP | CDOWN)) == 0) {
  321. Bprint(&tabout, ".nr %d \\n(#-u-\\n(^%c-\\n(%c|+1v\n",
  322. TMP, 'a' + c, s);
  323. Bprint(&tabout, ".if \\n(%d>0 .sp \\n(%du/2u", TMP, TMP);
  324. if (pr1403) /* round */
  325. Bprint(&tabout, "/1v*1v");
  326. Bprint(&tabout, "\n");
  327. }
  328. }
  329. Bprint(&tabout, ".%c+\n", s);
  330. Bprint(&tabout, ".in -\\n(%du\n", SIND);
  331. if (*fn > 0)
  332. putfont("P");
  333. Bprint(&tabout, ".mk %d\n", S2);
  334. Bprint(&tabout, ".if \\n(%d>\\n(%d .nr %d \\n(%d\n", S2, S1, S1, S2);
  335. }
  336. Bprint(&tabout, ".sp |\\n(%du\n", S1);
  337. for (c = dv = 0; c < ncol; c++) {
  338. if (stl + 1 < nlin && (lf = left(stl, c, &lwid)) >= 0) {
  339. if (dv++ == 0)
  340. Bprint(&tabout, ".sp -1\n");
  341. tohcol(c);
  342. dv++;
  343. drawvert(lf, stl, c, lwid);
  344. }
  345. }
  346. if (dv)
  347. Bprint(&tabout, "\n");
  348. }
  349. void
  350. putfont(char *fn)
  351. {
  352. if (fn && *fn)
  353. Bprint(&tabout, fn[1] ? "\\f(%.2s" : "\\f%.2s", fn);
  354. }
  355. void
  356. putsize(char *s)
  357. {
  358. if (s && *s)
  359. Bprint(&tabout, "\\s%s", s);
  360. }