Annotation of researchv8dc/cmd/adb/format.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.