996
|
1 /*
|
|
2 * SYNOPSIS: ick_parseargs(argc,argv)
|
|
3 * FILE : ick_parseargs.c
|
|
4 * AUTHOR : Steve Swales
|
|
5 * DATE: October 7, 1990
|
|
6 * PURPOSE: Parse arguments for INTERCAL programs.
|
|
7 *
|
|
8 LICENSE TERMS
|
|
9 Copyright (C) 1996 Eric S. Raymond
|
|
10
|
|
11 This program is free software; you can redistribute it and/or modify
|
|
12 it under the terms of the GNU General Public License as published by
|
|
13 the Free Software Foundation; either version 2 of the License, or
|
|
14 (at your option) any later version.
|
|
15
|
|
16 This program is distributed in the hope that it will be useful,
|
|
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 GNU General Public License for more details.
|
|
20
|
|
21 You should have received a copy of the GNU General Public License
|
|
22 along with this program; if not, write to the Free Software
|
|
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
24 */
|
|
25 #include <stdio.h>
|
|
26 #include <stdlib.h>
|
|
27 #include <string.h>
|
|
28 #include <setjmp.h>
|
|
29 #include "config.h"
|
|
30 #include "abcess.h"
|
|
31 #include "ick_lose.h"
|
|
32
|
|
33 /*@-redef@*/ /* it's never the case that both are used at once */
|
|
34 int ick_traditional = 0;
|
|
35 /*@=redef@*/
|
|
36 int ick_wimp_mode = 0;
|
|
37 int ick_instapipe = 0; /* AIS */
|
|
38 int ick_printflow = 0; /* AIS */
|
|
39 int ick_mystery = 0; /* AIS */
|
|
40
|
|
41 unsigned long ick_mysteryc = 0; /* AIS */
|
|
42
|
|
43 void
|
|
44 ick_parseargs(int argc, char **argv)
|
|
45 {
|
|
46 register int i, j;
|
|
47 static int helpflag = -1;
|
|
48 static const char *flags[] = {
|
|
49 "help",
|
|
50 "wimpmode",
|
|
51 "traditional",
|
|
52 "instapipe", /* AIS */
|
|
53 "printflow", /* AIS */
|
|
54 "mystery", /* AIS */
|
|
55 };
|
|
56 static int *bools[] = {
|
|
57 &helpflag,
|
|
58 &ick_wimp_mode,
|
|
59 &ick_traditional,
|
|
60 &ick_instapipe, /* AIS */
|
|
61 &ick_printflow, /* AIS */
|
|
62 &ick_mystery, /* AIS */
|
|
63 };
|
|
64 static const int nflags = (int)(sizeof(flags)/sizeof(flags[0]));
|
|
65
|
|
66 for(i = 1;i < argc;i++) {
|
|
67 if(argv[i][0] != '+' && argv[i][0] != '-') {
|
|
68 break;
|
|
69 }
|
|
70 for(j = 0; j < nflags;j++) {
|
|
71 if(0 == strcmp(argv[i]+1,flags[j])) {
|
|
72 *(bools[j]) = (argv[i][0] == '+');
|
|
73 break;
|
|
74 }
|
|
75 }
|
|
76 if(j == nflags) {
|
|
77 fprintf(stderr,"%s: can't grok %s\n",argv[0],argv[i]);
|
|
78 helpflag = 1;
|
|
79 }
|
|
80 }
|
|
81 if(helpflag != -1) {
|
|
82 if(!helpflag) {
|
|
83 fprintf(stderr,
|
|
84 "Once you start messing with INTERCAL... \n");
|
|
85 fprintf(stderr,"\t\tthere is no help for you!\n\n");
|
|
86 }
|
|
87 fprintf(stderr,"Current flags (and current state) are:\n");
|
|
88 for(i = 0;i < nflags;i++) {
|
|
89 fprintf(stderr,"\t[+/-]%-20.20s\t(%s)\n",flags[i],
|
|
90 (*(bools[i]) == 1)?"ON":((*(bools[i]) == 0)?"OFF":"???"));
|
|
91 }
|
|
92 fprintf(stderr,"All flags must be preceded by either + or -, which\n");
|
|
93 fprintf(stderr," usually will mean turn on or turn off something,\n");
|
|
94 fprintf(stderr," but not always, and not all of them currently\n");
|
|
95 fprintf(stderr," do anything, but you can switch them on or off\n");
|
|
96 fprintf(stderr," if you like anyway. Isn't this helpful?\n\n");
|
|
97 (void) fflush(stderr);
|
|
98 ick_lose(IE778, 0, (const char *)NULL);
|
|
99 }
|
|
100 if(ick_wimp_mode) {
|
|
101 fprintf(stderr,"How sad... you have selected to run an INTERCAL\n");
|
|
102 fprintf(stderr,"program in WIMP MODE.\n\n");
|
|
103 fprintf(stderr,"This means that:\n");
|
|
104 fprintf(stderr," A) Rather than the nifty input like:\n");
|
|
105 fprintf(stderr,"\tONE NINER SEVEN TWO OH SIX THREE,\n");
|
|
106 fprintf(stderr," and even niftier output like:\n");
|
|
107 fprintf(stderr,"\t______\n");
|
|
108 fprintf(stderr,"\tMCMLXXMMLXIII,\n");
|
|
109 fprintf(stderr," you will have to settle for plain old number\n");
|
|
110 fprintf(stderr," representations like 1972063; and,\n");
|
|
111 fprintf(stderr," B) You are a WIMP!\n\n");
|
|
112 (void) fflush(stderr);
|
|
113 }
|
|
114 }
|