Commit | Line | Data |
---|---|---|
505bf312 | 1 | /*- |
e0f0d8c7 KB |
2 | * Copyright (c) 1980, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
505bf312 KB |
4 | * |
5 | * %sccs.include.redist.c% | |
a3e21f40 DF |
6 | */ |
7 | ||
8 | #ifndef lint | |
e0f0d8c7 KB |
9 | static char copyright[] = |
10 | "@(#) Copyright (c) 1980, 1993\n\ | |
11 | The Regents of the University of California. All rights reserved.\n"; | |
505bf312 | 12 | #endif /* not lint */ |
dad19963 | 13 | |
a3e21f40 | 14 | #ifndef lint |
e0f0d8c7 | 15 | static char sccsid[] = "@(#)main.c 8.1 (Berkeley) %G%"; |
505bf312 | 16 | #endif /* not lint */ |
dad19963 ML |
17 | |
18 | /* | |
19 | * Debugger main routine. | |
20 | */ | |
21 | ||
22 | #include "defs.h" | |
23 | #include <setjmp.h> | |
24 | #include <signal.h> | |
25 | #include "main.h" | |
26 | #include "command.h" | |
27 | #include "process.h" | |
28 | #include "object.h" | |
29 | ||
76eb7cef | 30 | #define FIRST_TIME 0 /* initial value setjmp returns */ |
dad19963 | 31 | |
b7eb7857 | 32 | LOCAL int firstarg; |
dad19963 ML |
33 | LOCAL jmp_buf env; |
34 | LOCAL catchintr(); | |
35 | ||
36 | main(argc, argv) | |
37 | int argc; | |
38 | char **argv; | |
39 | { | |
76eb7cef ML |
40 | FILE *fp; |
41 | int i; | |
42 | ||
82d3cd01 KM |
43 | #ifdef lint |
44 | syserr(); | |
45 | #endif | |
76eb7cef ML |
46 | catchsigs(); |
47 | scanargs(argc, argv); | |
48 | cmdname = argv[0]; | |
49 | if ((fp = fopen(objname, "r")) == NIL) { | |
50 | panic("can't read %s", objname); | |
51 | } else { | |
52 | fclose(fp); | |
53 | } | |
54 | if (option('r')) { | |
55 | if (setjmp(env) == FIRST_TIME) { | |
56 | arginit(); | |
57 | for (i = firstarg; i < argc; i++) { | |
58 | newarg(argv[i]); | |
59 | } | |
60 | run(); | |
61 | /* NOTREACHED */ | |
dad19963 | 62 | } else { |
76eb7cef | 63 | option('r') = FALSE; |
dad19963 | 64 | } |
76eb7cef ML |
65 | } else { |
66 | initstart(); | |
67 | prompt(); | |
68 | init(); | |
69 | } | |
70 | setjmp(env); | |
71 | signal(SIGINT, catchintr); | |
72 | yyparse(); | |
73 | putchar('\n'); | |
74 | quit(0); | |
dad19963 ML |
75 | } |
76 | ||
77 | /* | |
78 | * Initialize the world, including setting initial input file | |
79 | * if the file exists. | |
80 | */ | |
81 | ||
82 | init() | |
83 | { | |
76eb7cef ML |
84 | initinput(); |
85 | readobj(objname); | |
86 | lexinit(); | |
dad19963 ML |
87 | } |
88 | ||
89 | /* | |
90 | * After a non-fatal error we jump back to command parsing. | |
91 | */ | |
92 | ||
93 | erecover() | |
94 | { | |
76eb7cef ML |
95 | gobble(); |
96 | prompt(); | |
97 | longjmp(env, 1); | |
dad19963 ML |
98 | } |
99 | ||
100 | /* | |
101 | * This routine is called when an interrupt occurs. | |
102 | */ | |
103 | ||
104 | LOCAL catchintr() | |
105 | { | |
76eb7cef ML |
106 | putchar('\n'); |
107 | prompt(); | |
108 | longjmp(env, 1); | |
dad19963 ML |
109 | } |
110 | ||
111 | /* | |
112 | * scan the argument list | |
113 | */ | |
114 | ||
115 | LOCAL scanargs(argc, argv) | |
116 | int argc; | |
117 | char **argv; | |
118 | { | |
76eb7cef ML |
119 | register int i, j; |
120 | BOOLEAN done; | |
121 | ||
122 | if (streq(argv[0], "pxhdr") || streq(argv[0], "pix")) { | |
123 | objname = argv[1]; | |
124 | option('r') = TRUE; | |
125 | option('t') = TRUE; | |
126 | if (streq(argv[0], "pxhdr")) { | |
127 | setargs("pdx", argv[2]); | |
128 | firstarg = 3; | |
b7eb7857 | 129 | } else { |
76eb7cef ML |
130 | setargs("pix", NIL); |
131 | firstarg = 2; | |
132 | } | |
133 | argv[0] = "pdx"; | |
134 | } else { | |
135 | done = FALSE; | |
136 | i = 1; | |
137 | while (i < argc && !done) { | |
138 | if (argv[i][0] == '-') { | |
139 | for (j = 1; argv[i][j] != '\0'; j++) { | |
140 | switch (argv[i][j]) { | |
141 | case 'r': /* run program before accepting commands */ | |
142 | case 'i': /* assume input is a terminal */ | |
143 | case 'b': /* (internal) trace breakpoints */ | |
144 | case 'e': /* (internal) trace execution */ | |
145 | case 'h': /* (internal) display header information */ | |
146 | option(argv[i][j]) = TRUE; | |
147 | break; | |
148 | ||
149 | default: | |
150 | panic("bad option \"%c\"", argv[i]); | |
151 | } | |
b7eb7857 | 152 | } |
76eb7cef ML |
153 | } else { |
154 | objname = argv[i]; | |
155 | done = TRUE; | |
156 | } | |
157 | i++; | |
dad19963 | 158 | } |
76eb7cef ML |
159 | firstarg = i; |
160 | setargs("pdx", objname); | |
161 | } | |
dad19963 ML |
162 | } |
163 | ||
164 | /* | |
b7eb7857 ML |
165 | * Terminate program. In the case of the -t option, we must remove |
166 | * the object file because it's a tmp file. | |
dad19963 ML |
167 | */ |
168 | ||
b7eb7857 ML |
169 | quit(r) |
170 | int r; | |
dad19963 | 171 | { |
76eb7cef ML |
172 | if (option('t')) { |
173 | unlink(objname); | |
174 | } | |
175 | exit(r); | |
b7eb7857 ML |
176 | } |
177 | ||
178 | LOCAL catchsigs() | |
179 | { | |
76eb7cef ML |
180 | signal(SIGHUP, quit); |
181 | signal(SIGQUIT, quit); | |
dad19963 | 182 | } |