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