1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
2: static char rcsid[]="$Header: b2mai.c,v 1.1 84/06/28 00:49:17 timo Exp $";
3:
4: /* B driver for interpreter */
5: #include "b.h"
6: #include <sys/types.h>
7:
8: #include "b1obj.h"
9: #include "b1mem.h"
10: #include "b2env.h"
11: #include "b2scr.h"
12: #include "b2err.h"
13: #include "b2fil.h"
14: #include "b2sig.h"
15: #include "b2syn.h"
16: #include "b2sem.h"
17: #include "b2sou.h"
18:
19: bool call_error, in_process;
20:
21: main(argc, argv) int argc; string argv[]; {
22: in_process= No; call_error= No;
23: call(argc, argv);
24: if (call_error) exit(-1);
25: in_process= Yes;
26: init();
27: call(argc, argv);
28: bye(0);
29: }
30:
31: #define Cllerr stderr
32:
33: string pname; /* program name */
34:
35: Hidden Procedure erm(m, n, argc, pargc, pargv) string m, n; int argc, pargc; string pargv[]; {
36: fprintf(Cllerr,
37: "*** There is something I don't quite get in your call of %s\n", pname);
38: show_call(argc, pargc, pargv);
39: fprintf(Cllerr, "*** The problem is: %s %s\n", m, n);
40: if (in_process) bye(-1);
41: call_error= Yes;
42: }
43:
44: Hidden Procedure call(pargc, pargv) int pargc; string pargv[]; {
45: int argc; string *argv;
46:
47: pname = pargv[0];
48: argc = pargc-1;
49: argv = pargv+1;
50: while (argc >= 0)
51: if (argc > 0 && argv[0][0] == '-' && argv[0][1] != '\0') {
52: if (argv[0][1] == 'q') { if (in_process) bye(0); }
53: else if (argv[0][1] == 'i') {
54: filtered= Yes;
55: cmd_prompt= "\001>";
56: eg_prompt= "\001E";
57: raw_prompt= "\001R";
58: qn_prompt= "\001Y";
59: } else erm("I never learned about the option", argv[0], argc, pargc, pargv);
60: argc -= 1;
61: argv += 1;
62: } else {
63: if (argc == 0 || (argv[0][0] == '-' && argv[0][1] == '\0')) {
64: release(iname);
65: iname = Vnil;
66: ifile = stdin;
67: } else {
68: release(iname);
69: iname = mk_text(*argv);
70: ifile = fopen(*argv, "r");
71: }
72: if (ifile != NULL) { if (in_process) process();
73: } else erm("can't open input file", *argv, argc, pargc, pargv);
74: if (ifile != NULL && ifile != stdin) fclose(ifile);
75: ++argv; --argc;
76: }
77: }
78:
79: Hidden Procedure show_call(eargc, pargc, pargv)
80: int eargc, pargc; string pargv[]; {
81: int argc= pargc; string *argv= pargv;
82: intlet p, pos= 4;
83: fprintf(Cllerr, " ");
84: while (argc > 0) {
85: fprintf(Cllerr, *argv);
86: pos+= strlen(*argv);
87: if (argc == eargc) p= pos-1;
88: ++argv; --argc;
89: if (argc > 0) {
90: putc(' ', Cllerr);
91: pos++;
92: }
93: }
94: putc('\n', Cllerr);
95: for (pos= 0; pos < p; pos++) putc(' ', Cllerr);
96: fprintf(Cllerr, "^\n");
97: }
98:
99: Hidden Procedure init() {
100: initmem();
101: initnum();
102: initenv();
103: inittors();
104: initsou();
105: initfprs();
106: inithow();
107: initscr();
108: setprmnv();
109: getprmnv();
110: inisigs();
111: }
112:
113: Visible Procedure process() {
114: re_screen();
115: alino= 0; Eof= Eof0= No;
116: xeq= Yes; skipping= No; cntxt= In_command;
117: if (setjmp(main_loop) != 0) /* long jump occurred */ {
118: re_files();
119: if (Eof) return;
120: xeq= interactive; skipping= !interactive;
121: /* skipping may be reset by command() */
122: }
123: inistreams();
124: re_env();
125: active_reads= 0;
126: while (!Eof) {
127: re_streams();
128: cntxt= In_command; resexp= Voi; lino= 0;
129: cur_ilev= 0;
130: terminated= No;
131: if (ilev(Yes) > 0) parerr("outer indentation not zero", "");
132: findceol(); command();
133: re_files();
134: }
135: }
Defined functions
call
defined in line
44; used 2 times
erm
defined in line
35; used 2 times
init
defined in line
99; used 1 times
main
defined in line
21;
never used
Defined variables
pname
defined in line
33; used 2 times
rcsid
defined in line
2;
never used
Defined macros