4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / pascal / pdx / main / main.c
CommitLineData
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
9static 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 15static 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 32LOCAL int firstarg;
dad19963
ML
33LOCAL jmp_buf env;
34LOCAL catchintr();
35
36main(argc, argv)
37int argc;
38char **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
82init()
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
93erecover()
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
104LOCAL 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
115LOCAL scanargs(argc, argv)
116int argc;
117char **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
169quit(r)
170int r;
dad19963 171{
76eb7cef
ML
172 if (option('t')) {
173 unlink(objname);
174 }
175 exit(r);
b7eb7857
ML
176}
177
178LOCAL catchsigs()
179{
76eb7cef
ML
180 signal(SIGHUP, quit);
181 signal(SIGQUIT, quit);
dad19963 182}