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