Annotation of researchv10no/cmd/adb/comm/format.c, revision 1.1

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:                        printdate((long)ltow(lget(dot, itype)));
        !           195:                        dotinc = SZLONG;
        !           196:                        break;
        !           197: 
        !           198:                case 'i':
        !           199:                        printins(itype);
        !           200:                        printc(EOR);
        !           201:                        break;
        !           202: 
        !           203:                case 'f':
        !           204:                        if (fget(dot, itype, (char *)&fl.s, SZFLOAT) == 0)
        !           205:                                return (fp);
        !           206:                        if (mkfault)
        !           207:                                return (0);
        !           208:                        dotinc = SZFLOAT;
        !           209:                        fpout('f', (char *)&fl.s);
        !           210:                        break;
        !           211: 
        !           212:                case 'F':
        !           213:                        if (fget(dot, itype, (char *)&fl.d, SZDOUBLE) == 0)
        !           214:                                return (fp);
        !           215:                        if (mkfault)
        !           216:                                return (0);
        !           217:                        dotinc = SZDOUBLE;
        !           218:                        fpout('F', (char *)&fl.d);
        !           219:                        break;
        !           220: 
        !           221:                case 'n':
        !           222:                case 'N':
        !           223:                        printc('\n');
        !           224:                        dotinc=0;
        !           225:                        break;
        !           226: 
        !           227:                case '"':
        !           228:                        dotinc=0;
        !           229:                        while (*fp != '"' && *fp)
        !           230:                                printc(*fp++);
        !           231:                        if (*fp)
        !           232:                                fp++;
        !           233:                        break;
        !           234: 
        !           235:                case '^':
        !           236:                        dot=inkdot(-dotinc*fcount);
        !           237:                        return(fp);
        !           238: 
        !           239:                case '+':
        !           240:                        dot=inkdot((WORD)fcount);
        !           241:                        return(fp);
        !           242: 
        !           243:                case '-':
        !           244:                        dot=inkdot(-(WORD)fcount);
        !           245:                        return(fp);
        !           246: 
        !           247:                default:
        !           248:                        error("bad modifier");
        !           249:                }
        !           250:                if ((itype & SPTYPE) != NOSP)
        !           251:                        dot=inkdot(dotinc);
        !           252:                fcount--;
        !           253:                endline();
        !           254:        }
        !           255: 
        !           256:        return(fp);
        !           257: }
        !           258: 
        !           259: printesc(c)
        !           260: {
        !           261:        c &= STRIP;
        !           262:        if (c == 0177)
        !           263:                printf("^?");
        !           264:        else if (c < SPC)
        !           265:                printf("^%c", c + '@');
        !           266:        else
        !           267:                printc(c);
        !           268: }
        !           269: 
        !           270: ADDR
        !           271: inkdot(incr)
        !           272: WORD incr;
        !           273: {
        !           274:        ADDR    newdot;
        !           275: 
        !           276:        newdot=dot+incr;
        !           277:        if ((incr >= 0 && newdot < dot)
        !           278:        ||  (incr < 0 && newdot > dot))
        !           279:                error("address wraparound");
        !           280:        return(newdot);
        !           281: }

unix.superglobalmegacorp.com

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