125077Sjaap #ifndef lint
2*25093Sjaap static char sccsid[] = "@(#)textblocks.c	1.2 (CWI) 85/10/02";
325077Sjaap #endif lint
425077Sjaap 
525077Sjaap #include "defs.h"
625077Sjaap #include "ext.h"
725077Sjaap 
825077Sjaap /*
925077Sjaap  * Get a section of text
10*25093Sjaap  *
11*25093Sjaap  * Note that this doen't work after MAXLIN lines (see over200.c)
12*25093Sjaap  *
1325077Sjaap  */
1425077Sjaap 
1525077Sjaap /*
1625077Sjaap  * This returns an int with the name of the diversion,
1725077Sjaap  * in maktab we test later in wide() whether the table entry is a
1825077Sjaap  * pointer to a string, or a character.
1925077Sjaap  * If it is a character, we now it is a diversion, and know it its width
2025077Sjaap  * to be in <diversionname>-
2125077Sjaap  *
2225077Sjaap  * Very ugly, (looks like we need unions in declaration of structure colstr ?)
2325077Sjaap  */
2425077Sjaap 
gettext(sp,ilin,icol,fn,sz)2525077Sjaap gettext(sp, ilin, icol, fn, sz)
2625077Sjaap char *sp, *fn, *sz;
2725077Sjaap {
2825077Sjaap 	char line[BUFSIZ];
2925077Sjaap 	char *vs;
3025077Sjaap 	int oname;
3125077Sjaap 
32*25093Sjaap 	dprint(".\\\" -- gettext\n");
3325077Sjaap 	if(texname == 0)
3425077Sjaap 		error("Too many text block diversions");
3525077Sjaap 	if(textflg == 0){
3625077Sjaap 		printf(".nr %d \\n(.lu\n", SL);
3725077Sjaap  		/*
3825077Sjaap 		 * remember old line length
3925077Sjaap 		 */
4025077Sjaap 		textflg = 1;
4125077Sjaap 	}
4225077Sjaap 	printf(".eo\n");
4325077Sjaap 	printf(".am %2s\n", reg(icol, CRIGHT));
4425077Sjaap 	printf(".br\n");
4525077Sjaap 	printf(".di %c+\n", texname);
4625077Sjaap 	rstofill();
4725077Sjaap 	if(fn && *fn)
4825077Sjaap 		printf(".nr %d \\n(.f\n.ft %s\n", S1, fn);
4925077Sjaap 	/*
5025077Sjaap 	 * protect font
5125077Sjaap 	 */
5225077Sjaap 	printf(".ft \\n(.f\n");
5325077Sjaap 	vs = vsize[stynum[ilin]][icol];
5425077Sjaap 	if((sz && *sz) || (vs && *vs)){
5525077Sjaap 		printf(".nr %d \\n(.v\n", S2);
5625077Sjaap 		if(vs == 0 || *vs == 0)
5725077Sjaap 			vs = "\\n(.s+2";
5825077Sjaap 		if(sz && *sz)
5925077Sjaap 			printf(".ps %s\n", sz);
6025077Sjaap 		printf(".vs %s\n", vs);
6125077Sjaap 		printf(".if \\n(%du>\\n(.vu .sp \\n(%du-\\n(.vu\n",
6225077Sjaap 									S2, S2);
6325077Sjaap 	}
6425077Sjaap 	if(cll[icol][0])
6525077Sjaap 		printf(".ll %sn\n", cll[icol]);
6625077Sjaap 	else
6725077Sjaap 		printf(".ll \\n(%du*%du/%du\n", SL, ctspan(ilin, icol),
6825077Sjaap 								ncol + 1);
6925077Sjaap 	printf(".if \\n(.l<\\n(%2s .ll \\n(%2su\n", reg(icol, CRIGHT),
7025077Sjaap 							reg(icol, CRIGHT));
7125077Sjaap 	if(ctype(ilin, icol) == 'a')
7225077Sjaap 		printf(".ll -2n\n");
7325077Sjaap 	printf(".in 0\n");
7425077Sjaap 	while(gets1(line)){
7525077Sjaap 		if(line[0] == 'T' && line[1] == '}' && line[2] == tab)
7625077Sjaap 			break;
7725077Sjaap 		if(strcmp("T}", line) == 0)
7825077Sjaap 			break;
7925077Sjaap 		printf("%s\n", line);
8025077Sjaap 	}
8125077Sjaap 	if(fn && *fn)
8225077Sjaap 		printf(".ft \\n(%d\n", S1);
8325077Sjaap 	if(sz && *sz)
8425077Sjaap 		printf(".br\n.ps\n.vs\n");
8525077Sjaap 	printf(".br\n");
8625077Sjaap 	printf(".di\n");
8725077Sjaap 	/*
8825077Sjaap 	 * Height of last complete diversion in register <diversionname>|
8925077Sjaap 	 */
9025077Sjaap 	printf(".nr %c| \\n(dn\n", texname);
9125077Sjaap 	/*
9225077Sjaap 	 * width of last complete diversion in register <diversionname>-
9325077Sjaap 	 */
9425077Sjaap 	printf(".nr %c- \\n(dl\n", texname);
9525077Sjaap 	printf("..\n");
9625077Sjaap 	printf(".ec \\\n");
9725077Sjaap 	/*
9825077Sjaap 	 * copy remainder of line
9925077Sjaap 	 */
10025077Sjaap 	if(line[2])
10125077Sjaap 		strcpy(sp, line + 3);
10225077Sjaap 	else
10325077Sjaap 		*sp = 0;
10425077Sjaap 	oname = texname;
10525077Sjaap 	texname = texstr[++texct];
10625077Sjaap 	return(oname);
10725077Sjaap }
10825077Sjaap 
untext()10925077Sjaap untext(){
11025077Sjaap 	rstofill();
11125077Sjaap 	printf(".nf\n");
11225077Sjaap 	printf(".ll \\n(%du\n", SL);
11325077Sjaap }
114