xref: /csrg-svn/old/tbl/t7.c (revision 11048)
1*11048Sshannon /*	t7.c	4.2	83/02/12	*/
211034Sshannon 
311034Sshannon  /* t7.c: control to write table entries */
411034Sshannon # include "t..c"
511034Sshannon # define realsplit ((ct=='a'||ct=='n') && table[ldata][c].rcol)
611034Sshannon runout()
711034Sshannon {
811034Sshannon int i;
911034Sshannon if (boxflg || allflg || dboxflg) need();
1011034Sshannon if (ctrflg)
1111034Sshannon 	{
1211034Sshannon 	fprintf(tabout, ".nr #I \\n(.i\n");
1311034Sshannon 	fprintf(tabout, ".in +(\\n(.lu-\\n(TWu-\\n(.iu)/2u\n");
1411034Sshannon 	}
1511034Sshannon fprintf(tabout, ".fc %c %c\n", F1, F2);
1611034Sshannon fprintf(tabout, ".nr #T 0-1\n");
1711034Sshannon deftail();
1811034Sshannon for(i=0; i<nlin; i++)
1911034Sshannon 	putline(i,i);
2011034Sshannon if (leftover)
2111034Sshannon 	yetmore();
2211034Sshannon fprintf(tabout, ".fc\n");
2311034Sshannon fprintf(tabout, ".nr T. 1\n");
2411034Sshannon fprintf(tabout, ".T# 1\n");
2511034Sshannon if (ctrflg)
2611034Sshannon 	fprintf(tabout, ".in \\n(#Iu\n");
2711034Sshannon }
2811034Sshannon runtabs(lform, ldata)
2911034Sshannon {
3011034Sshannon int c, ct, vforml, lf;
3111034Sshannon fprintf(tabout, ".ta ");
3211034Sshannon for(c=0; c<ncol; c++)
3311034Sshannon 	{
3411034Sshannon 	vforml=lform;
3511034Sshannon 	for(lf=prev(lform); lf>=0 && vspen(table[lf][c].col); lf=prev(lf))
3611034Sshannon 		vforml=lf;
3711034Sshannon 	if (fspan(vforml,c))
3811034Sshannon 		continue;
3911034Sshannon 	switch(ct=ctype(vforml,c))
4011034Sshannon 		{
4111034Sshannon 		case 'n':
4211034Sshannon 		case 'a':
4311034Sshannon 			if (table[ldata][c].rcol)
4411034Sshannon 			  if (lused[c]) /*Zero field width*/
4511034Sshannon 				fprintf(tabout, "\\n(%du ",c+CMID);
4611034Sshannon 		case 'c':
4711034Sshannon 		case 'l':
4811034Sshannon 		case 'r':
4911034Sshannon 		    if (realsplit? rused[c]: (used[c]+lused[c]))
5011034Sshannon 			fprintf(tabout, "\\n(%du ",c+CRIGHT);
5111034Sshannon 			continue;
5211034Sshannon 		case 's':
5311034Sshannon 			if (lspan(lform, c))
5411034Sshannon 				fprintf(tabout, "\\n(%du ", c+CRIGHT);
5511034Sshannon 			continue;
5611034Sshannon 		}
5711034Sshannon 	}
5811034Sshannon fprintf(tabout, "\n");
5911034Sshannon }
6011034Sshannon ifline(s)
6111034Sshannon 	char *s;
6211034Sshannon {
63*11048Sshannon if (!point(s)) return(0);
6411034Sshannon if (s[0] == '\\') s++;
6511034Sshannon if (s[1] ) return(0);
6611034Sshannon if (s[0] == '_') return('-');
6711034Sshannon if (s[0] == '=') return('=');
6811034Sshannon return(0);
6911034Sshannon }
7011034Sshannon need()
7111034Sshannon {
7211034Sshannon int texlin, horlin, i;
7311034Sshannon for(texlin=horlin=i=0; i<nlin; i++)
7411034Sshannon 	{
7511034Sshannon 	if (fullbot[i]!=0)
7611034Sshannon 		horlin++;
7711034Sshannon 	else
7811034Sshannon 	if (instead[i]!=0)
7911034Sshannon 		continue;
8011034Sshannon 	else
8111034Sshannon 		texlin++;
8211034Sshannon 	}
8311034Sshannon fprintf(tabout, ".ne %dv+%dp\n",texlin,2*horlin);
8411034Sshannon }
8511034Sshannon deftail()
8611034Sshannon {
8711034Sshannon int i, c, lf, lwid;
8811034Sshannon for(i=0; i<MAXHEAD; i++)
8911034Sshannon 	if (linestop[i])
9011034Sshannon 		fprintf(tabout, ".nr #%c 0-1\n", linestop[i]+'a'-1);
9111034Sshannon fprintf(tabout, ".nr #a 0-1\n");
9211034Sshannon fprintf(tabout, ".eo\n");
9311034Sshannon fprintf(tabout, ".de T#\n");
9411034Sshannon fprintf(tabout, ".ds #d .d\n");
9511034Sshannon fprintf(tabout, ".if \\(ts\\n(.z\\(ts\\(ts .ds #d nl\n");
9611034Sshannon 	fprintf(tabout, ".mk ##\n");
9711034Sshannon 	fprintf(tabout, ".nr ## -1v\n");
9811034Sshannon 	fprintf(tabout, ".ls 1\n");
9911034Sshannon 	for(i=0; i<MAXHEAD; i++)
10011034Sshannon 		if (linestop[i])
10111034Sshannon 			fprintf(tabout, ".if \\n(#T>=0 .nr #%c \\n(#T\n",linestop[i]+'a'-1);
10211034Sshannon if (boxflg || allflg || dboxflg) /* bottom of table line */
10311034Sshannon 	if (fullbot[nlin-1]==0)
10411034Sshannon 		{
10511034Sshannon 		if (!pr1403)
10611034Sshannon 			fprintf(tabout, ".if \\n(T. .vs \\n(.vu-\\n(.sp\n");
10711034Sshannon 		fprintf(tabout, ".if \\n(T. ");
10811034Sshannon 		drawline(nlin,0,ncol, dboxflg ? '=' : '-',1,0);
10911034Sshannon 		fprintf(tabout, "\n.if \\n(T. .vs\n");
11011034Sshannon 		/* T. is really an argument to a macro but because of
11111034Sshannon 		   eqn we don't dare pass it as an argument and reference by $1 */
11211034Sshannon 		}
11311034Sshannon 	for(c=0; c<ncol; c++)
11411034Sshannon 		{
11511034Sshannon 		if ((lf=left(nlin-1,c, &lwid))>=0)
11611034Sshannon 			{
11711034Sshannon 			fprintf(tabout, ".if \\n(#%c>=0 .sp -1\n",linestop[lf]+'a'-1);
11811034Sshannon 			fprintf(tabout, ".if \\n(#%c>=0 ", linestop[lf]+'a'-1);
11911034Sshannon 			tohcol(c);
12011034Sshannon 			drawvert(lf, nlin-1, c, lwid);
12111034Sshannon 			fprintf(tabout, "\\h'|\\n(TWu'\n");
12211034Sshannon 			}
12311034Sshannon 		}
12411034Sshannon 	if (boxflg || allflg || dboxflg) /* right hand line */
12511034Sshannon 		{
12611034Sshannon 		fprintf(tabout, ".if \\n(#a>=0 .sp -1\n");
12711034Sshannon 		fprintf(tabout, ".if \\n(#a>=0 \\h'|\\n(TWu'");
12811034Sshannon 		drawvert (0, nlin-1, ncol, dboxflg? 2 : 1);
12911034Sshannon 		fprintf(tabout, "\n");
13011034Sshannon 		}
13111034Sshannon fprintf(tabout, ".ls\n");
13211034Sshannon fprintf(tabout, "..\n");
13311034Sshannon fprintf(tabout, ".ec\n");
13411034Sshannon }
135