|
|
1.1 root 1: /*
2: *
3: * UNIX debugger
4: *
5: */
6:
7: #include "defs.h"
8: #include "space.h"
9:
10: extern char lastc, peekc;
11:
12: scanform(icount,ifp,itype,ptype)
13: WORD icount;
14: char *ifp;
15: {
16: register char *fp;
17: register char c;
18: register int fcount;
19: ADDR savdot;
20:
21: while (icount) {
22: fp=ifp;
23: savdot=dot;
24: /*now loop over format*/
25: while (*fp && errflg==0) {
26: if (!isdigit(*fp))
27: fcount = 1;
28: else {
29: fcount = 0;
30: while (isdigit(c = *fp++)) {
31: fcount *= 10;
32: fcount += c-'0';
33: }
34: fp--;
35: }
36: if (*fp==0)
37: break;
38: fp=exform(fcount,fp,itype,ptype);
39: }
40: dotinc=dot-savdot;
41: dot=savdot;
42: if (errflg) {
43: if (icount<0) {
44: errflg=0;
45: break;
46: }
47: else
48: error(errflg);
49: }
50: if (--icount)
51: dot=inkdot(dotinc);
52: if (mkfault)
53: error(NULL);
54: }
55: }
56:
57: char *
58: exform(fcount,ifp,itype,ptype)
59: int fcount;
60: char *ifp;
61: {
62: /* execute single format item `fcount' times
63: * sets `dotinc' and moves `dot'
64: * returns address of next format item
65: */
66: register WORD w;
67: ADDR savdot;
68: register char *fp;
69: register char c, modifier;
70: union {
71: TFLOAT s;
72: TDOUBLE d;
73: } fl;
74:
75: while (fcount > 0) {
76: fp = ifp;
77: c = *fp;
78: modifier = *fp++;
79: if (charpos()==0 && modifier!='a')
80: printf("%16m");
81: switch(modifier) {
82:
83: case SPC:
84: case TB:
85: break;
86:
87: case 't':
88: case 'T':
89: printf("%T", fcount);
90: return(fp);
91:
92: case 'a':
93: psymoff((WORD)dot, ptype, itype & SYMF ?"?%16t":"/%16t");
94: dotinc = 0;
95: break;
96:
97: case 'p':
98: w = atow(aget(dot, itype));
99: if (errflg)
100: return (fp);
101: if (mkfault)
102: return (0);
103: psymoff(w, ptype, "%16t");
104: dotinc = SZADDR;
105: break;
106:
107: case 'u':
108: case 'r':
109: case 'd':
110: case 'x':
111: case 'o':
112: case 'q':
113: w = stow(sget(dot, itype));
114: if (errflg)
115: return (fp);
116: if (mkfault)
117: return (0);
118: dotinc = SZSHORT;
119: if (c == 'u')
120: printf("%-8U", w);
121: else if (c == 'r')
122: printf("%-8R", w);
123: else if (c == 'd')
124: printf("%-8D", w);
125: else if (c == 'x')
126: printf("%-8X", w);
127: else if (c == 'o')
128: printf("%-8O", w);
129: else if (c == 'q')
130: printf("%-8Q", w);
131: break;
132:
133: case 'U':
134: case 'R':
135: case 'D':
136: case 'X':
137: case 'O':
138: case 'Q':
139: w = ltow(lget(dot, itype));
140: if (errflg)
141: return (fp);
142: if (mkfault)
143: return (0);
144: dotinc = SZLONG;
145: if (c == 'U')
146: printf("%-16U", w);
147: else if (c == 'R')
148: printf("%-16R", w);
149: else if (c == 'D')
150: printf("%-16D", w);
151: else if (c == 'X')
152: printf("%-16X", w);
153: else if (c == 'O')
154: printf("%-16O", w);
155: else if (c == 'Q')
156: printf("%-16Q", w);
157: break;
158:
159: case 'b':
160: case 'B':
161: case 'c':
162: case 'C':
163: w = ctow(cget(dot, itype));
164: if (errflg)
165: return (fp);
166: if (mkfault)
167: return (0);
168: if (modifier == 'C')
169: printesc((char)w);
170: else if (modifier == 'B' || modifier == 'b')
171: printf("%-8O", w);
172: else
173: printc((char)w);
174: dotinc = SZCHAR;
175: break;
176:
177: case 's':
178: case 'S':
179: savdot=dot;
180: dotinc=SZCHAR;
181: while ((w=ctow(cget(dot,itype))) && errflg==0) {
182: dot=inkdot((WORD)SZCHAR);
183: if (modifier == 'S')
184: printesc((char)w);
185: else
186: printc((char)w);
187: endline();
188: }
189: dotinc=(dot-savdot+1) * SZCHAR;
190: dot=savdot;
191: break;
192:
193: case 'Y':
194: printf("%-24Y", (long)ltow(lget(dot, itype)));
195: break;
196:
197: case 'i':
198: printins(itype);
199: printc(EOR);
200: break;
201:
202: case 'f':
203: if (fget(dot, itype, (char *)&fl.s, SZFLOAT) == 0)
204: return (fp);
205: if (mkfault)
206: return (0);
207: dotinc = SZFLOAT;
208: fpout('f', (char *)&fl.s);
209: break;
210:
211: case 'F':
212: if (fget(dot, itype, (char *)&fl.d, SZDOUBLE) == 0)
213: return (fp);
214: if (mkfault)
215: return (0);
216: dotinc = SZDOUBLE;
217: fpout('F', (char *)&fl.d);
218: break;
219:
220: case 'n':
221: case 'N':
222: printc('\n');
223: dotinc=0;
224: break;
225:
226: case '"':
227: dotinc=0;
228: while (*fp != '"' && *fp)
229: printc(*fp++);
230: if (*fp)
231: fp++;
232: break;
233:
234: case '^':
235: dot=inkdot(-dotinc*fcount);
236: return(fp);
237:
238: case '+':
239: dot=inkdot((WORD)fcount);
240: return(fp);
241:
242: case '-':
243: dot=inkdot(-(WORD)fcount);
244: return(fp);
245:
246: default:
247: error("bad modifier");
248: }
249: if ((itype & SPTYPE) != NOSP)
250: dot=inkdot(dotinc);
251: fcount--;
252: endline();
253: }
254:
255: return(fp);
256: }
257:
258: printesc(c)
259: {
260: c &= STRIP;
261: if (c == 0177)
262: printf("^?");
263: else if (c < SPC)
264: printf("^%c", c + '@');
265: else
266: printc(c);
267: }
268:
269: ADDR
270: inkdot(incr)
271: WORD incr;
272: {
273: ADDR newdot;
274:
275: newdot=dot+incr;
276: if ((incr >= 0 && newdot < dot)
277: || (incr < 0 && newdot > dot))
278: error("address wraparound");
279: return(newdot);
280: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.