plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

t7.c (3413B)


      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) {
     13 		Bprint(&tabout, ".nr #I \\n(.i\n");
     14 		Bprint(&tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
     15 	}
     16 	Bprint(&tabout, ".fc %c %c\n", F1, F2);
     17 	Bprint(&tabout, ".nr #T 0-1\n");
     18 	deftail();
     19 	for (i = 0; i < nlin; i++)
     20 		putline(i, i);
     21 	if (leftover)
     22 		yetmore();
     23 	Bprint(&tabout, ".fc\n");
     24 	Bprint(&tabout, ".nr T. 1\n");
     25 	Bprint(&tabout, ".T# 1\n");
     26 	if (ctrflg)
     27 		Bprint(&tabout, ".in \\n(#Iu\n");
     28 }
     29 
     30 
     31 void
     32 runtabs(int lform, int ldata)
     33 {
     34 	int	c, ct, vforml, lf;
     35 
     36 	Bprint(&tabout, ".ta ");
     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*/
     48 					Bprint(&tabout, "\\n(%2su ", reg(c, CMID));
     49 		case 'c':
     50 		case 'l':
     51 		case 'r':
     52 			if (realsplit ? rused[c] : (used[c] + lused[c]))
     53 				Bprint(&tabout, "\\n(%2su ", reg(c, CRIGHT));
     54 			continue;
     55 		case 's':
     56 			if (lspan(lform, c))
     57 				Bprint(&tabout, "\\n(%2su ", reg(c, CRIGHT));
     58 			continue;
     59 		}
     60 	}
     61 	Bprint(&tabout, "\n");
     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 	}
     95 	Bprint(&tabout, ".ne %dv+%dp\n", texlin, 2 * horlin);
     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])
    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");
    116 	for (i = 0; i < MAXHEAD; i++)
    117 		if (linestop[i])
    118 			Bprint(&tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",
    119 			     linestop[i] + 'a' - 1);
    120 	if (boxflg || allflg || dboxflg) /* bottom of table line */
    121 		if (fullbot[nlin-1] == 0) {
    122 			if (!pr1403)
    123 				Bprint(&tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
    124 			Bprint(&tabout, ".if \\n(T. ");
    125 			drawline(nlin, 0, ncol, dboxflg ? '=' : '-', 1, 0);
    126 			Bprint(&tabout, "\n.if \\n(T. .vs\n");
    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) {
    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);
    134 			tohcol(c);
    135 			drawvert(lf, nlin - 1, c, lwid);
    136 			Bprint(&tabout, "\\h'|\\n(TWu'\n");
    137 		}
    138 	}
    139 	if (boxflg || allflg || dboxflg) /* right hand line */ {
    140 		Bprint(&tabout, ".if \\n(#a>=0 .sp -1\n");
    141 		Bprint(&tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
    142 		drawvert (0, nlin - 1, ncol, dboxflg ? 2 : 1);
    143 		Bprint(&tabout, "\n");
    144 	}
    145 	Bprint(&tabout, ".ls\n");
    146 	Bprint(&tabout, "..\n");
    147 	Bprint(&tabout, ".ec\n");
    148 }