aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/tbl/tg.c
blob: 3afc88c688965e62c8ea9812285d3afcb70ae691 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* tg.c: process included text blocks */
# include "t.h"

int
gettext(char *sp, int ilin, int icol, char *fn, char *sz)
{
					/* get a section of text */
	char	line[4096];
	int	oname, startline;
	char	*vs;

	startline = iline;
	if (texname == 0) 
		error("Too many text block diversions");
	if (textflg == 0) {
		Bprint(&tabout, ".nr %d \\n(.lu\n", SL); /* remember old line length */
		textflg = 1;
	}
	Bprint(&tabout, ".eo\n");
	Bprint(&tabout, ".am %s\n", reg(icol, CRIGHT));
	Bprint(&tabout, ".br\n");
	Bprint(&tabout, ".di %c+\n", texname);
	rstofill();
	if (fn && *fn) 
		Bprint(&tabout, ".nr %d \\n(.f\n.ft %s\n", S1, fn);
	Bprint(&tabout, ".ft \\n(.f\n"); /* protect font */
	vs = vsize[icol][stynum[ilin]];
	if ((sz && *sz) || (vs && *vs)) {
		Bprint(&tabout, ".nr %d \\n(.v\n", S9);
		if (vs == 0 || *vs == 0) 
			vs = "\\n(.s+2";
		if (sz && *sz)
			Bprint(&tabout, ".ps %s\n", sz);
		Bprint(&tabout, ".vs %s\n", vs);
		Bprint(&tabout, ".if \\n(%du>\\n(.vu .sp \\n(%du-\\n(.vu\n", S9, S9);
	}
	if (cll[icol][0])
		Bprint(&tabout, ".ll %sn\n", cll[icol]);
	else
		Bprint(&tabout, ".ll \\n(%du*%du/%du\n", SL, ctspan(ilin, icol), ncol + 1);
	Bprint(&tabout, ".if \\n(.l<\\n(%2s .ll \\n(%2su\n", reg(icol, CRIGHT),
	     reg(icol, CRIGHT));
	if (ctype(ilin, icol) == 'a')
		Bprint(&tabout, ".ll -2n\n");
	Bprint(&tabout, ".in 0\n");
	for (;;) {
		if (gets1(line, sizeof(line)) == nil) {
			iline = startline;
			error("missing closing T}");
		}
		if (line[0] == 'T' && line[1] == '}' && line[2] == tab) 
			break;
		if (match("T}", line)) 
			break;
		Bprint(&tabout, "%s\n", line);
	}
	if (fn && *fn) 
		Bprint(&tabout, ".ft \\n(%d\n", S1);
	if (sz && *sz) 
		Bprint(&tabout, ".br\n.ps\n.vs\n");
	Bprint(&tabout, ".br\n");
	Bprint(&tabout, ".di\n");
	Bprint(&tabout, ".nr %c| \\n(dn\n", texname);
	Bprint(&tabout, ".nr %c- \\n(dl\n", texname);
	Bprint(&tabout, "..\n");
	Bprint(&tabout, ".ec \\\n");
	/* copy remainder of line */
	if (line[2])
		tcopy (sp, line + 3);
	else
		*sp = 0;
	oname = texname;
	texname = texstr[++texct];
	return(oname);
}


void
untext(void)
{
	rstofill();
	Bprint(&tabout, ".nf\n");
	Bprint(&tabout, ".ll \\n(%du\n", SL);
}