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