date and time created 82/01/18 19:20:28 by linton
authorMark Linton <linton@ucbvax.Berkeley.EDU>
Tue, 19 Jan 1982 11:20:28 +0000 (03:20 -0800)
committerMark Linton <linton@ucbvax.Berkeley.EDU>
Tue, 19 Jan 1982 11:20:28 +0000 (03:20 -0800)
SCCS-vsn: usr.bin/pascal/pdx/main/main.c 1.1

usr/src/usr.bin/pascal/pdx/main/main.c [new file with mode: 0644]

diff --git a/usr/src/usr.bin/pascal/pdx/main/main.c b/usr/src/usr.bin/pascal/pdx/main/main.c
new file mode 100644 (file)
index 0000000..9da513f
--- /dev/null
@@ -0,0 +1,136 @@
+/* Copyright (c) 1982 Regents of the University of California */
+
+static char sccsid[] = "@(#)main.c 1.1 %G%";
+
+/*
+ * Debugger main routine.
+ */
+
+#include "defs.h"
+#include <setjmp.h>
+#include <signal.h>
+#include "main.h"
+#include "command.h"
+#include "process.h"
+#include "object.h"
+
+#define FIRST_TIME 0           /* initial value setjmp returns */
+#define isinteractive()                (isatty(fileno(stdin)))
+
+LOCAL jmp_buf env;
+LOCAL catchintr();
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+       FILE *fp;
+
+       cmdname = argv[0];
+       catcherrs();
+       scanargs(argc, argv);
+       if ((fp = fopen(objname, "r")) == NIL) {
+               panic("can't read %s", objname);
+       } else {
+               fclose(fp);
+       }
+       if (option('r')) {
+               if (setjmp(env) == FIRST_TIME) {
+                       arginit();
+                       run();
+                       /* NOTREACHED */
+               } else {
+                       option('r') = FALSE;
+                       if (isinteractive()) {
+                               printf("> ");
+                               fflush(stdout);
+                       }
+               }
+       } else {
+               start(NIL, NIL, NIL);
+               prompt();
+               init();
+       }
+       setjmp(env);
+       signal(SIGINT, &catchintr);
+       yyparse();
+       putchar('\n');
+}
+
+/*
+ * Initialize the world, including setting initial input file
+ * if the file exists.
+ */
+
+init()
+{
+       initinput();
+       readobj(objname);
+       lexinit();
+}
+
+/*
+ * After a non-fatal error we jump back to command parsing.
+ */
+
+erecover()
+{
+       gobble();
+       prompt();
+       longjmp(env, 1);
+}
+
+/*
+ * This routine is called when an interrupt occurs.
+ */
+
+LOCAL catchintr()
+{
+       putchar('\n');
+       prompt();
+       longjmp(env, 1);
+}
+
+/*
+ * scan the argument list
+ */
+
+LOCAL scanargs(argc, argv)
+int argc;
+char **argv;
+{
+       register int i, j;
+       BOOLEAN foundfile;
+
+       foundfile = FALSE;
+       for (i = 1; i < argc; i++) {
+               if (argv[i][0] == '-') {
+                       for (j = 1; argv[i][j] != '\0'; j++) {
+                               setoption(argv[i][j]);
+                       }
+               } else if (!foundfile) {
+                       objname = argv[i];
+               } else {
+                       panic("extraneous argument %s", argv[i]);
+               }
+       }
+}
+
+/*
+ * take appropriate action for recognized command argument
+ */
+
+LOCAL setoption(c)
+register char c;
+{
+       switch(c) {
+               case 'r':       /* run program before accepting commands */
+               case 'b':       /* trace internal breakpoints (for debugging) */
+               case 'e':       /* trace execution (for debugging) */
+                       option(c) = TRUE;
+                       break;
+
+               default:
+                       panic("unknown option '%c'", c);
+       }
+}