clean up awk syntax
[unix-history] / usr / src / old / adb / adb.tahoe / main.c
CommitLineData
d74a6b29
SL
1#ifndef lint
2static char sccsid[] = "@(#)main.c 1.1 (Berkeley) %G%";
3#endif
4/*
5 * adb - main command loop and error/interrupt handling
6 */
7#include "defs.h"
8
9MSG NOEOR;
10
11INT mkfault;
12INT executing;
13INT infile;
14CHAR *lp;
15L_INT maxpos;
16SIG sigint;
17SIG sigqit;
18INT wtflag;
19L_INT maxfile;
20STRING errflg;
21L_INT exitflg;
22
23CHAR lastc;
24INT eof;
25
26INT lastcom;
27
28ADDR maxoff = MAXOFF;
29L_INT maxpos = MAXPOS;
30char *Ipath = "/usr/lib/adb";
31
32main(argc, argv)
33 register char **argv;
34 int argc;
35{
36
37 mkioptab();
38another:
39 if (argc>1) {
40 if (eqstr("-w", argv[1])) {
41 wtflag = 2; /* suitable for open() */
42 argc--, argv++;
43 goto another;
44 }
45 if (eqstr("-k", argv[1])) {
46 kernel = 1;
47 argc--, argv++;
48 goto another;
49 }
50 if (argv[1][0] == '-' && argv[1][1] == 'I') {
51 Ipath = argv[1]+2;
52 argc--, argv++;
53 }
54 }
55 if (argc > 1)
56 symfil = argv[1];
57 if (argc > 2)
58 corfil = argv[2];
59 xargc = argc;
60 setsym(); setcor(); setvar();
61
62 if ((sigint=signal(SIGINT,SIG_IGN)) != SIG_IGN) {
63 sigint = fault;
64 signal(SIGINT, fault);
65 }
66 sigqit = signal(SIGQUIT, SIG_IGN);
67 setexit();
68 if (executing)
69 delbp();
70 executing = 0;
71 for (;;) {
72 flushbuf();
73 if (errflg) {
74 printf("%s\n", errflg);
75 exitflg = 1;
76 errflg = 0;
77 }
78 if (mkfault) {
79 mkfault=0;
80 printc('\n');
81 printf(DBNAME);
82 }
83 lp=0; rdc(); lp--;
84 if (eof) {
85 if (infile) {
86 iclose(-1, 0); eof=0; reset();
87 } else
88 done();
89 } else
90 exitflg = 0;
91 command(0, lastcom);
92 if (lp && lastc!='\n')
93 error(NOEOR);
94 }
95}
96
97done()
98{
99 endpcs();
100 exit(exitflg);
101}
102
103L_INT
104round(a,b)
105REG L_INT a, b;
106{
107 REG L_INT w;
108 w = (a/b)*b;
109 IF a!=w THEN w += b; FI
110 return(w);
111}
112
113/*
114 * If there has been an error or a fault, take the error.
115 */
116chkerr()
117{
118 if (errflg || mkfault)
119 error(errflg);
120}
121
122/*
123 * An error occurred; save the message for later printing,
124 * close open files, and reset to main command loop.
125 */
126error(n)
127 char *n;
128{
129 errflg = n;
130 iclose(0, 1); oclose();
131 reset();
132}
133
134/*
135 * An interrupt occurred; reset the interrupt
136 * catch, seek to the end of the current file
137 * and remember that there was a fault.
138 */
139fault(a)
140{
141 signal(a, fault);
142 lseek(infile, 0L, 2);
143 mkfault++;
144}