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