xref: /illumos-gate/usr/src/cmd/tbl/t3.c (revision b55148877d473978f0b46d593fd6213fa526fcc5)
1*b5514887Smuffin /*
2*b5514887Smuffin  * Copyright 1991 Sun Microsystems, Inc.  All rights reserved.
3*b5514887Smuffin  * Use is subject to license terms.
4*b5514887Smuffin  */
5*b5514887Smuffin 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
15*b5514887Smuffin #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate  /* t3.c: interpret commands affecting whole table */
187c478bd9Sstevel@tonic-gate # include "t..c"
19*b5514887Smuffin #include <string.h>
20*b5514887Smuffin 
217c478bd9Sstevel@tonic-gate struct optstr {char *optnam; int *optadd;} options [] = {
227c478bd9Sstevel@tonic-gate 	"expand", &expflg,
237c478bd9Sstevel@tonic-gate 	"EXPAND", &expflg,
247c478bd9Sstevel@tonic-gate 	"center", &ctrflg,
257c478bd9Sstevel@tonic-gate 	"CENTER", &ctrflg,
267c478bd9Sstevel@tonic-gate 	"box", &boxflg,
277c478bd9Sstevel@tonic-gate 	"BOX", &boxflg,
287c478bd9Sstevel@tonic-gate 	"allbox", &allflg,
297c478bd9Sstevel@tonic-gate 	"ALLBOX", &allflg,
307c478bd9Sstevel@tonic-gate 	"doublebox", &dboxflg,
317c478bd9Sstevel@tonic-gate 	"DOUBLEBOX", &dboxflg,
327c478bd9Sstevel@tonic-gate 	"frame", &boxflg,
337c478bd9Sstevel@tonic-gate 	"FRAME", &boxflg,
347c478bd9Sstevel@tonic-gate 	"doubleframe", &dboxflg,
357c478bd9Sstevel@tonic-gate 	"DOUBLEFRAME", &dboxflg,
367c478bd9Sstevel@tonic-gate 	"tab", &tab,
377c478bd9Sstevel@tonic-gate 	"TAB", &tab,
387c478bd9Sstevel@tonic-gate 	"linesize", &linsize,
397c478bd9Sstevel@tonic-gate 	"LINESIZE", &linsize,
407c478bd9Sstevel@tonic-gate 	"delim", &delim1,
417c478bd9Sstevel@tonic-gate 	"DELIM", &delim1,
427c478bd9Sstevel@tonic-gate 	0,0};
43*b5514887Smuffin 
44*b5514887Smuffin void	backrest(char *);
45*b5514887Smuffin 
46*b5514887Smuffin void
47*b5514887Smuffin getcomm(void)
487c478bd9Sstevel@tonic-gate {
497c478bd9Sstevel@tonic-gate char line[200], *cp, nb[25], *t;
507c478bd9Sstevel@tonic-gate struct optstr *lp;
517c478bd9Sstevel@tonic-gate int c, ci, found;
527c478bd9Sstevel@tonic-gate for(lp= options; lp->optnam; lp++)
537c478bd9Sstevel@tonic-gate 	*(lp->optadd) = 0;
547c478bd9Sstevel@tonic-gate texname = texstr[texct=0];
557c478bd9Sstevel@tonic-gate tab = '\t';
567c478bd9Sstevel@tonic-gate printf(".nr %d \\n(.s\n", LSIZE);
577c478bd9Sstevel@tonic-gate gets1(line, sizeof line);
587c478bd9Sstevel@tonic-gate /* see if this is a command line */
597c478bd9Sstevel@tonic-gate if (strchr(line,';') == NULL)
607c478bd9Sstevel@tonic-gate 	{
617c478bd9Sstevel@tonic-gate 	backrest(line);
627c478bd9Sstevel@tonic-gate 	return;
637c478bd9Sstevel@tonic-gate 	}
647c478bd9Sstevel@tonic-gate for(cp=line; (c = *cp) != ';'; cp++)
657c478bd9Sstevel@tonic-gate 	{
667c478bd9Sstevel@tonic-gate 	if (!letter(c)) continue;
677c478bd9Sstevel@tonic-gate 	found=0;
687c478bd9Sstevel@tonic-gate 	for(lp= options; lp->optadd; lp++)
697c478bd9Sstevel@tonic-gate 		{
707c478bd9Sstevel@tonic-gate 		if (prefix(lp->optnam, cp))
717c478bd9Sstevel@tonic-gate 			{
727c478bd9Sstevel@tonic-gate 			*(lp->optadd) = 1;
737c478bd9Sstevel@tonic-gate 			cp += strlen(lp->optnam);
747c478bd9Sstevel@tonic-gate 			if (letter(*cp))
757c478bd9Sstevel@tonic-gate 				error(gettext("Misspelled global option"));
767c478bd9Sstevel@tonic-gate 			while (*cp==' ')cp++;
777c478bd9Sstevel@tonic-gate 			t=nb;
787c478bd9Sstevel@tonic-gate 			if ( *cp == '(')
797c478bd9Sstevel@tonic-gate 				while ((ci= *++cp) != ')')
807c478bd9Sstevel@tonic-gate 					*t++ = ci;
817c478bd9Sstevel@tonic-gate 			else cp--;
827c478bd9Sstevel@tonic-gate 			*t++ = 0; *t=0;
837c478bd9Sstevel@tonic-gate 			if (lp->optadd == &tab)
847c478bd9Sstevel@tonic-gate 				{
857c478bd9Sstevel@tonic-gate 				if (nb[0])
867c478bd9Sstevel@tonic-gate 					*(lp->optadd) = nb[0];
877c478bd9Sstevel@tonic-gate 				}
887c478bd9Sstevel@tonic-gate 			if (lp->optadd == &linsize)
897c478bd9Sstevel@tonic-gate 				printf(".nr %d %s\n", LSIZE, nb);
907c478bd9Sstevel@tonic-gate 			if (lp->optadd == &delim1)
917c478bd9Sstevel@tonic-gate 				{
927c478bd9Sstevel@tonic-gate 				delim1 = nb[0];
937c478bd9Sstevel@tonic-gate 				delim2 = nb[1];
947c478bd9Sstevel@tonic-gate 				}
957c478bd9Sstevel@tonic-gate 			found=1;
967c478bd9Sstevel@tonic-gate 			break;
977c478bd9Sstevel@tonic-gate 			}
987c478bd9Sstevel@tonic-gate 		}
997c478bd9Sstevel@tonic-gate 	if (!found)
1007c478bd9Sstevel@tonic-gate 		error(gettext("Illegal option"));
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate cp++;
1037c478bd9Sstevel@tonic-gate backrest(cp);
1047c478bd9Sstevel@tonic-gate return;
1057c478bd9Sstevel@tonic-gate }
106*b5514887Smuffin 
107*b5514887Smuffin void
108*b5514887Smuffin backrest(char *cp)
1097c478bd9Sstevel@tonic-gate {
1107c478bd9Sstevel@tonic-gate char *s;
1117c478bd9Sstevel@tonic-gate for(s=cp; *s; s++);
1127c478bd9Sstevel@tonic-gate un1getc('\n');
1137c478bd9Sstevel@tonic-gate while (s>cp)
1147c478bd9Sstevel@tonic-gate 	un1getc(*--s);
1157c478bd9Sstevel@tonic-gate return;
1167c478bd9Sstevel@tonic-gate }
117