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