xref: /csrg-svn/usr.bin/struct/struct/0.args.c (revision 10941)
1*10941Srrh #ifndef lint
2*10941Srrh static char sccsid[] = "@(#)0.args.c	4.1	(Berkeley)	02/11/83";
3*10941Srrh #endif not lint
4*10941Srrh 
5*10941Srrh #include <stdio.h>
6*10941Srrh #
7*10941Srrh #include "def.h"
8*10941Srrh int errflag;
9*10941Srrh FILE *infd;
10*10941Srrh 
11*10941Srrh 
12*10941Srrh int intcase=1, arbcase=0;
13*10941Srrh int exitsize=0;			/* max number of nodes to be left in loop without iterating */
14*10941Srrh int maxnode=400;	/* max number of nodes */
15*10941Srrh int maxhash=347;	/* prime number = size of hash table */
16*10941Srrh int progress=0;		/* if not 0, print line number every n lines, n = progress */
17*10941Srrh int labinit=10;			/* labels generated starting with labinit */
18*10941Srrh int labinc=10;			/* labels increase by labinc */
19*10941Srrh int inputform=0;		/* = 0 if freeform input, 1 if standard form input */
20*10941Srrh int debug=0;
21*10941Srrh int levbrk=1;	/* true implies multilevel breaks; false implies single-level breaks only */
22*10941Srrh int levnxt=1;	/* true implies multilevel nexts; false implies single-level nexts only */
23*10941Srrh 
24*10941Srrh 
25*10941Srrh int maxprogsw=12;		/* number of program switches which can be set */
26*10941Srrh char *progsw[]		= {"i", "a",
27*10941Srrh 			"e", "m",
28*10941Srrh 			"h", "p",
29*10941Srrh 			"t", "c",
30*10941Srrh 			"s", "d",
31*10941Srrh 			"b", "n"
32*10941Srrh 			};
33*10941Srrh 
34*10941Srrh 
35*10941Srrh int *swval[]		= {&intcase, &arbcase,
36*10941Srrh 			&exitsize, &maxnode,
37*10941Srrh 			&maxhash, &progress,
38*10941Srrh 			&labinit, &labinc,
39*10941Srrh 			&inputform, &debug,
40*10941Srrh 			&levbrk, &levnxt
41*10941Srrh 			};
42*10941Srrh 
43*10941Srrh 
44*10941Srrh char *getargs(argc, argv)
45*10941Srrh int argc; char *argv[];
46*10941Srrh 	{
47*10941Srrh 	int n, infile;
48*10941Srrh 	infile = 0;
49*10941Srrh 
50*10941Srrh 	for (n = 1; n < argc; ++n)
51*10941Srrh 		{
52*10941Srrh 		if (argv[n][0] == '-')
53*10941Srrh 			setsw(&argv[n][1]);
54*10941Srrh 		else
55*10941Srrh 			{
56*10941Srrh 			if (infile != 0)
57*10941Srrh 				error("multiple input files - using first one: ", argv[infile],"");
58*10941Srrh 			else
59*10941Srrh 				infile = n;
60*10941Srrh 			}
61*10941Srrh 		}
62*10941Srrh 	if (errflag)
63*10941Srrh 		exit(1);
64*10941Srrh 	if (!infile) faterr("no input file","","");
65*10941Srrh 	infd = fopen(argv[infile],"r");
66*10941Srrh 	if (infd == NULL)
67*10941Srrh 		faterr("can't open input file:",argv[infile],"");
68*10941Srrh 	return;
69*10941Srrh 	}
70*10941Srrh 
71*10941Srrh setsw(str)
72*10941Srrh char *str;
73*10941Srrh 	{
74*10941Srrh 	int i, val, swnum;
75*10941Srrh #define maxtemp 15
76*10941Srrh 	char temp[maxtemp];
77*10941Srrh 	for (i = 0; 'a' <= str[i] && str[i] <= 'z'; ++i)
78*10941Srrh 		{
79*10941Srrh 		if (i >= maxtemp)
80*10941Srrh 			{
81*10941Srrh 			error("invalid switch:",str,"");
82*10941Srrh 			errflag = 1;
83*10941Srrh 			}
84*10941Srrh 		temp[i] = str[i];
85*10941Srrh 		}
86*10941Srrh 	temp[i] = '\0';
87*10941Srrh 
88*10941Srrh 	swnum = find(temp,progsw,maxprogsw);
89*10941Srrh 	if (swnum == -1)
90*10941Srrh 		{
91*10941Srrh 		error("invalid switch:", str,"");
92*10941Srrh 		errflag = 1;
93*10941Srrh 		return;
94*10941Srrh 		}
95*10941Srrh 	if (str[i] == '\0')
96*10941Srrh 		*(swval[swnum]) = !*(swval[swnum]);
97*10941Srrh 	else
98*10941Srrh 		{
99*10941Srrh 		sscanf(&str[i],"%d",&val);
100*10941Srrh 		*(swval[swnum]) = val;
101*10941Srrh 		}
102*10941Srrh 	}
103