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