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