xref: /illumos-gate/usr/src/cmd/tbl/t3.c (revision 2a8bcb4e)
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 
157c478bd9Sstevel@tonic-gate  /* t3.c: interpret commands affecting whole table */
167c478bd9Sstevel@tonic-gate # include "t..c"
17*b5514887Smuffin #include <string.h>
18*b5514887Smuffin 
197c478bd9Sstevel@tonic-gate struct optstr {char *optnam; int *optadd;} options [] = {
207c478bd9Sstevel@tonic-gate 	"expand", &expflg,
217c478bd9Sstevel@tonic-gate 	"EXPAND", &expflg,
227c478bd9Sstevel@tonic-gate 	"center", &ctrflg,
237c478bd9Sstevel@tonic-gate 	"CENTER", &ctrflg,
247c478bd9Sstevel@tonic-gate 	"box", &boxflg,
257c478bd9Sstevel@tonic-gate 	"BOX", &boxflg,
267c478bd9Sstevel@tonic-gate 	"allbox", &allflg,
277c478bd9Sstevel@tonic-gate 	"ALLBOX", &allflg,
287c478bd9Sstevel@tonic-gate 	"doublebox", &dboxflg,
297c478bd9Sstevel@tonic-gate 	"DOUBLEBOX", &dboxflg,
307c478bd9Sstevel@tonic-gate 	"frame", &boxflg,
317c478bd9Sstevel@tonic-gate 	"FRAME", &boxflg,
327c478bd9Sstevel@tonic-gate 	"doubleframe", &dboxflg,
337c478bd9Sstevel@tonic-gate 	"DOUBLEFRAME", &dboxflg,
347c478bd9Sstevel@tonic-gate 	"tab", &tab,
357c478bd9Sstevel@tonic-gate 	"TAB", &tab,
367c478bd9Sstevel@tonic-gate 	"linesize", &linsize,
377c478bd9Sstevel@tonic-gate 	"LINESIZE", &linsize,
387c478bd9Sstevel@tonic-gate 	"delim", &delim1,
397c478bd9Sstevel@tonic-gate 	"DELIM", &delim1,
407c478bd9Sstevel@tonic-gate 	0,0};
41*b5514887Smuffin 
42*b5514887Smuffin void	backrest(char *);
43*b5514887Smuffin 
44*b5514887Smuffin void
getcomm(void)45*b5514887Smuffin getcomm(void)
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate char line[200], *cp, nb[25], *t;
487c478bd9Sstevel@tonic-gate struct optstr *lp;
497c478bd9Sstevel@tonic-gate int c, ci, found;
507c478bd9Sstevel@tonic-gate for(lp= options; lp->optnam; lp++)
517c478bd9Sstevel@tonic-gate 	*(lp->optadd) = 0;
527c478bd9Sstevel@tonic-gate texname = texstr[texct=0];
537c478bd9Sstevel@tonic-gate tab = '\t';
547c478bd9Sstevel@tonic-gate printf(".nr %d \\n(.s\n", LSIZE);
557c478bd9Sstevel@tonic-gate gets1(line, sizeof line);
567c478bd9Sstevel@tonic-gate /* see if this is a command line */
577c478bd9Sstevel@tonic-gate if (strchr(line,';') == NULL)
587c478bd9Sstevel@tonic-gate 	{
597c478bd9Sstevel@tonic-gate 	backrest(line);
607c478bd9Sstevel@tonic-gate 	return;
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate for(cp=line; (c = *cp) != ';'; cp++)
637c478bd9Sstevel@tonic-gate 	{
647c478bd9Sstevel@tonic-gate 	if (!letter(c)) continue;
657c478bd9Sstevel@tonic-gate 	found=0;
667c478bd9Sstevel@tonic-gate 	for(lp= options; lp->optadd; lp++)
677c478bd9Sstevel@tonic-gate 		{
687c478bd9Sstevel@tonic-gate 		if (prefix(lp->optnam, cp))
697c478bd9Sstevel@tonic-gate 			{
707c478bd9Sstevel@tonic-gate 			*(lp->optadd) = 1;
717c478bd9Sstevel@tonic-gate 			cp += strlen(lp->optnam);
727c478bd9Sstevel@tonic-gate 			if (letter(*cp))
737c478bd9Sstevel@tonic-gate 				error(gettext("Misspelled global option"));
747c478bd9Sstevel@tonic-gate 			while (*cp==' ')cp++;
757c478bd9Sstevel@tonic-gate 			t=nb;
767c478bd9Sstevel@tonic-gate 			if ( *cp == '(')
777c478bd9Sstevel@tonic-gate 				while ((ci= *++cp) != ')')
787c478bd9Sstevel@tonic-gate 					*t++ = ci;
797c478bd9Sstevel@tonic-gate 			else cp--;
807c478bd9Sstevel@tonic-gate 			*t++ = 0; *t=0;
817c478bd9Sstevel@tonic-gate 			if (lp->optadd == &tab)
827c478bd9Sstevel@tonic-gate 				{
837c478bd9Sstevel@tonic-gate 				if (nb[0])
847c478bd9Sstevel@tonic-gate 					*(lp->optadd) = nb[0];
857c478bd9Sstevel@tonic-gate 				}
867c478bd9Sstevel@tonic-gate 			if (lp->optadd == &linsize)
877c478bd9Sstevel@tonic-gate 				printf(".nr %d %s\n", LSIZE, nb);
887c478bd9Sstevel@tonic-gate 			if (lp->optadd == &delim1)
897c478bd9Sstevel@tonic-gate 				{
907c478bd9Sstevel@tonic-gate 				delim1 = nb[0];
917c478bd9Sstevel@tonic-gate 				delim2 = nb[1];
927c478bd9Sstevel@tonic-gate 				}
937c478bd9Sstevel@tonic-gate 			found=1;
947c478bd9Sstevel@tonic-gate 			break;
957c478bd9Sstevel@tonic-gate 			}
967c478bd9Sstevel@tonic-gate 		}
977c478bd9Sstevel@tonic-gate 	if (!found)
987c478bd9Sstevel@tonic-gate 		error(gettext("Illegal option"));
997c478bd9Sstevel@tonic-gate 	}
1007c478bd9Sstevel@tonic-gate cp++;
1017c478bd9Sstevel@tonic-gate backrest(cp);
1027c478bd9Sstevel@tonic-gate return;
1037c478bd9Sstevel@tonic-gate }
104*b5514887Smuffin 
105*b5514887Smuffin void
backrest(char * cp)106*b5514887Smuffin backrest(char *cp)
1077c478bd9Sstevel@tonic-gate {
1087c478bd9Sstevel@tonic-gate char *s;
1097c478bd9Sstevel@tonic-gate for(s=cp; *s; s++);
1107c478bd9Sstevel@tonic-gate un1getc('\n');
1117c478bd9Sstevel@tonic-gate while (s>cp)
1127c478bd9Sstevel@tonic-gate 	un1getc(*--s);
1137c478bd9Sstevel@tonic-gate return;
1147c478bd9Sstevel@tonic-gate }
115