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