148123Sbostic /*-
248123Sbostic * %sccs.include.proprietary.c%
348123Sbostic */
448123Sbostic
510941Srrh #ifndef lint
6*62264Sbostic static char sccsid[] = "@(#)0.args.c 8.1 (Berkeley) 06/06/93";
748123Sbostic #endif /* not lint */
810941Srrh
910941Srrh #include <stdio.h>
1010941Srrh #
1110941Srrh #include "def.h"
1210941Srrh int errflag;
1310941Srrh FILE *infd;
1410941Srrh
1510941Srrh
1610941Srrh int intcase=1, arbcase=0;
1710941Srrh int exitsize=0; /* max number of nodes to be left in loop without iterating */
1810941Srrh int maxnode=400; /* max number of nodes */
1910941Srrh int maxhash=347; /* prime number = size of hash table */
2010941Srrh int progress=0; /* if not 0, print line number every n lines, n = progress */
2110941Srrh int labinit=10; /* labels generated starting with labinit */
2210941Srrh int labinc=10; /* labels increase by labinc */
2310941Srrh int inputform=0; /* = 0 if freeform input, 1 if standard form input */
2410941Srrh int debug=0;
2510941Srrh int levbrk=1; /* true implies multilevel breaks; false implies single-level breaks only */
2610941Srrh int levnxt=1; /* true implies multilevel nexts; false implies single-level nexts only */
2710941Srrh
2810941Srrh
2910941Srrh int maxprogsw=12; /* number of program switches which can be set */
3010941Srrh char *progsw[] = {"i", "a",
3110941Srrh "e", "m",
3210941Srrh "h", "p",
3310941Srrh "t", "c",
3410941Srrh "s", "d",
3510941Srrh "b", "n"
3610941Srrh };
3710941Srrh
3810941Srrh
3910941Srrh int *swval[] = {&intcase, &arbcase,
4010941Srrh &exitsize, &maxnode,
4110941Srrh &maxhash, &progress,
4210941Srrh &labinit, &labinc,
4310941Srrh &inputform, &debug,
4410941Srrh &levbrk, &levnxt
4510941Srrh };
4610941Srrh
4710941Srrh
getargs(argc,argv)4810941Srrh char *getargs(argc, argv)
4910941Srrh int argc; char *argv[];
5010941Srrh {
5110941Srrh int n, infile;
5210941Srrh infile = 0;
5310941Srrh
5410941Srrh for (n = 1; n < argc; ++n)
5510941Srrh {
5610941Srrh if (argv[n][0] == '-')
5710941Srrh setsw(&argv[n][1]);
5810941Srrh else
5910941Srrh {
6010941Srrh if (infile != 0)
6110941Srrh error("multiple input files - using first one: ", argv[infile],"");
6210941Srrh else
6310941Srrh infile = n;
6410941Srrh }
6510941Srrh }
6610941Srrh if (errflag)
6710941Srrh exit(1);
6810941Srrh if (!infile) faterr("no input file","","");
6910941Srrh infd = fopen(argv[infile],"r");
7010941Srrh if (infd == NULL)
7110941Srrh faterr("can't open input file:",argv[infile],"");
7210941Srrh return;
7310941Srrh }
7410941Srrh
setsw(str)7510941Srrh setsw(str)
7610941Srrh char *str;
7710941Srrh {
7810941Srrh int i, val, swnum;
7910941Srrh #define maxtemp 15
8010941Srrh char temp[maxtemp];
8110941Srrh for (i = 0; 'a' <= str[i] && str[i] <= 'z'; ++i)
8210941Srrh {
8310941Srrh if (i >= maxtemp)
8410941Srrh {
8510941Srrh error("invalid switch:",str,"");
8610941Srrh errflag = 1;
8710941Srrh }
8810941Srrh temp[i] = str[i];
8910941Srrh }
9010941Srrh temp[i] = '\0';
9110941Srrh
9210941Srrh swnum = find(temp,progsw,maxprogsw);
9310941Srrh if (swnum == -1)
9410941Srrh {
9510941Srrh error("invalid switch:", str,"");
9610941Srrh errflag = 1;
9710941Srrh return;
9810941Srrh }
9910941Srrh if (str[i] == '\0')
10010941Srrh *(swval[swnum]) = !*(swval[swnum]);
10110941Srrh else
10210941Srrh {
10310941Srrh sscanf(&str[i],"%d",&val);
10410941Srrh *(swval[swnum]) = val;
10510941Srrh }
10610941Srrh }
107