Commit | Line | Data |
---|---|---|
d94e2462 M |
1 | # |
2 | /* | |
3 | * | |
4 | * UNIX debugger | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "defs.h" | |
9 | ||
10 | ||
11 | MSG BADMOD; | |
12 | MSG NOFORK; | |
13 | MSG ADWRAP; | |
14 | ||
15 | SYMTAB symbol; | |
16 | ||
17 | INT mkfault; | |
18 | CHAR *lp; | |
19 | INT maxoff; | |
20 | INT sigint; | |
21 | INT sigqit; | |
22 | STRING errflg; | |
23 | CHAR lastc; | |
24 | L_INT dot; | |
25 | INT dotinc; | |
26 | L_INT var[]; | |
27 | ||
28 | ||
29 | scanform(icount,ifp,itype,ptype) | |
30 | L_INT icount; | |
31 | STRING ifp; | |
32 | { | |
33 | STRING fp; | |
34 | CHAR modifier; | |
35 | INT fcount, init=1; | |
36 | L_INT savdot; | |
37 | ||
38 | WHILE icount | |
39 | DO fp=ifp; | |
40 | IF init==0 ANDF findsym(shorten(dot),ptype)==0 ANDF maxoff | |
41 | THEN printf("\n%.8s:%16t",symbol.symc); | |
42 | FI | |
43 | savdot=dot; init=0; | |
44 | ||
45 | /*now loop over format*/ | |
46 | WHILE *fp ANDF errflg==0 | |
47 | DO IF digit(modifier = *fp) | |
48 | THEN fcount=0; | |
49 | WHILE digit(modifier = *fp++) | |
50 | DO fcount *= 10; | |
51 | fcount += modifier-'0'; | |
52 | OD | |
53 | fp--; | |
54 | ELSE fcount=1; | |
55 | FI | |
56 | ||
57 | IF *fp==0 THEN break; FI | |
58 | fp=exform(fcount,fp,itype,ptype); | |
59 | OD | |
60 | dotinc=dot-savdot; | |
61 | dot=savdot; | |
62 | ||
63 | IF errflg | |
64 | THEN IF icount<0 | |
65 | THEN errflg=0; break; | |
66 | ELSE error(errflg); | |
67 | FI | |
68 | FI | |
69 | IF --icount | |
70 | THEN dot=inkdot(dotinc); | |
71 | FI | |
72 | IF mkfault THEN error(0); FI | |
73 | OD | |
74 | } | |
75 | ||
76 | STRING exform(fcount,ifp,itype,ptype) | |
77 | INT fcount; | |
78 | STRING ifp; | |
79 | { | |
80 | /* execute single format item `fcount' times | |
81 | * sets `dotinc' and moves `dot' | |
82 | * returns address of next format item | |
83 | */ | |
84 | POS w; | |
85 | L_INT savdot, wx; | |
86 | STRING fp; | |
87 | CHAR c, modifier, longpr; | |
88 | L_REAL fw; | |
89 | struct{ | |
90 | L_INT sa; | |
91 | INT sb,sc; | |
92 | }; | |
93 | ||
94 | WHILE fcount>0 | |
95 | DO fp = ifp; c = *fp; | |
96 | longpr=(c>='A')&(c<='Z')|(c=='f'); | |
97 | IF itype==NSP ORF *fp=='a' | |
98 | THEN wx=dot; w=dot; | |
99 | ELSE w=get(dot,itype); | |
100 | IF longpr | |
101 | THEN wx=itol(w,get(inkdot(2),itype)); | |
102 | ELSE wx=w; | |
103 | FI | |
104 | FI | |
105 | IF c=='F' | |
106 | THEN fw.sb=get(inkdot(4),itype); | |
107 | fw.sc=get(inkdot(6),itype); | |
108 | FI | |
109 | IF errflg THEN return(fp); FI | |
110 | IF mkfault THEN error(0); FI | |
111 | var[0]=wx; | |
112 | modifier = *fp++; | |
113 | dotinc=(longpr?4:2);; | |
114 | ||
115 | IF charpos()==0 ANDF modifier!='a' THEN printf("%16m"); FI | |
116 | ||
117 | switch(modifier) { | |
118 | ||
119 | case SP: case TB: | |
120 | break; | |
121 | ||
122 | case 't': case 'T': | |
123 | printf("%T",fcount); return(fp); | |
124 | ||
125 | case 'r': case 'R': | |
126 | printf("%M",fcount); return(fp); | |
127 | ||
128 | case 'a': | |
129 | psymoff(dot,ptype,":%16t"); dotinc=0; break; | |
130 | ||
131 | case 'p': | |
132 | psymoff(var[0],ptype,"%16t"); break; | |
133 | ||
134 | case 'u': | |
135 | printf("%-8u",w); break; | |
136 | ||
137 | case 'U': | |
138 | printf("%-16U",wx); break; | |
139 | ||
140 | case 'c': case 'C': | |
141 | IF modifier=='C' | |
142 | THEN printesc(w&LOBYTE); | |
143 | ELSE printc(w&LOBYTE); | |
144 | FI | |
145 | dotinc=1; break; | |
146 | ||
147 | case 'b': case 'B': | |
148 | printf("%-8o", w&LOBYTE); dotinc=1; break; | |
149 | ||
150 | case 's': case 'S': | |
151 | savdot=dot; dotinc=1; | |
152 | WHILE (c=get(dot,itype)&LOBYTE) ANDF errflg==0 | |
153 | DO dot=inkdot(1); | |
154 | IF modifier == 'S' | |
155 | THEN printesc(c); | |
156 | ELSE printc(c); | |
157 | FI | |
158 | endline(); | |
159 | OD | |
160 | dotinc=dot-savdot+1; dot=savdot; break; | |
161 | ||
162 | case 'x': | |
163 | printf("%-8x",w); break; | |
164 | ||
165 | case 'X': | |
166 | printf("%-16X", wx); break; | |
167 | ||
168 | case 'Y': | |
169 | printf("%-24Y", wx); break; | |
170 | ||
171 | case 'q': | |
172 | printf("%-8q", w); break; | |
173 | ||
174 | case 'Q': | |
175 | printf("%-16Q", wx); break; | |
176 | ||
177 | case 'o': | |
178 | case 'w': | |
179 | printf("%-8o", w); break; | |
180 | ||
181 | case 'O': | |
182 | case 'W': | |
183 | printf("%-16O", wx); break; | |
184 | ||
185 | case 'i': | |
186 | printins(0,itype,w); printc(EOR); break; | |
187 | ||
188 | case 'd': | |
189 | printf("%-8d", w); break; | |
190 | ||
191 | case 'D': | |
192 | printf("%-16D", wx); break; | |
193 | ||
194 | case 'f': | |
195 | fw = 0; | |
196 | fw.sa = wx; | |
197 | printf("%-16.9f", fw); | |
198 | dotinc=4; break; | |
199 | ||
200 | case 'F': | |
201 | fw.sa = wx; | |
202 | printf("%-32.18F", fw); | |
203 | dotinc=8; break; | |
204 | ||
205 | case 'n': case 'N': | |
206 | printc('\n'); dotinc=0; break; | |
207 | ||
208 | case '"': | |
209 | dotinc=0; | |
210 | WHILE *fp != '"' ANDF *fp | |
211 | DO printc(*fp++); OD | |
212 | IF *fp THEN fp++; FI | |
213 | break; | |
214 | ||
215 | case '^': | |
216 | dot=inkdot(-dotinc*fcount); return(fp); | |
217 | ||
218 | case '+': | |
219 | dot=inkdot(fcount); return(fp); | |
220 | ||
221 | case '-': | |
222 | dot=inkdot(-fcount); return(fp); | |
223 | ||
224 | default: error(BADMOD); | |
225 | } | |
226 | IF itype!=NSP | |
227 | THEN dot=inkdot(dotinc); | |
228 | FI | |
229 | fcount--; endline(); | |
230 | OD | |
231 | ||
232 | return(fp); | |
233 | } | |
234 | ||
235 | unox() | |
236 | { | |
237 | INT rc, status, unixpid; | |
238 | STRING argp lp; | |
239 | ||
240 | WHILE lastc!=EOR DO rdc(); OD | |
241 | IF (unixpid=fork())==0 | |
242 | THEN signal(SIGINT,sigint); signal(SIGQUIT,sigqit); | |
243 | *lp=0; execl("/bin/sh", "sh", "-c", argp, 0); | |
244 | exit(16); | |
245 | ELIF unixpid == -1 | |
246 | THEN error(NOFORK); | |
247 | ELSE signal(SIGINT,1); | |
248 | WHILE (rc = wait(&status)) != unixpid ANDF rc != -1 DONE | |
249 | signal(SIGINT,sigint); | |
250 | prints("!"); lp--; | |
251 | FI | |
252 | } | |
253 | ||
254 | ||
255 | printesc(c) | |
256 | { | |
257 | c &= STRIP; | |
258 | IF c<SP ORF c>'~' ORF c=='@' | |
259 | THEN printf("@%c",(c=='@' ? '@' : c^0140)); | |
260 | ELSE printc(c); | |
261 | FI | |
262 | } | |
263 | ||
264 | L_INT inkdot(incr) | |
265 | { | |
266 | L_INT newdot; | |
267 | ||
268 | newdot=dot+incr; | |
269 | IF (dot NEQ newdot) >> 24 THEN error(ADWRAP); FI | |
270 | return(newdot); | |
271 | } |