t8.c 9.2 KB

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