Annotation of cci/usr/src/bin/adb/format.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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