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