Annotation of 43BSDTahoe/bin/adb/adb.tahoe/output.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)output.c   1.2 (Berkeley) 10/22/87";
        !             3: #endif
        !             4: /*
        !             5:  *
        !             6:  *     UNIX debugger
        !             7:  *
        !             8:  */
        !             9: 
        !            10: #include "defs.h"
        !            11: 
        !            12: INT            mkfault;
        !            13: INT            infile;
        !            14: INT            outfile = 1;
        !            15: L_INT          maxpos;
        !            16: ADDR           maxoff;
        !            17: INT            radix = 16;
        !            18: 
        !            19: CHAR           printbuf[MAXLIN];
        !            20: CHAR           *printptr = printbuf;
        !            21: CHAR           *digitptr;
        !            22: MSG            TOODEEP;
        !            23: 
        !            24: printc(c)
        !            25:        CHAR            c;
        !            26: {
        !            27:        CHAR            d;
        !            28:        REG     STRING  q;
        !            29:        REG             posn, tabs, p;
        !            30: 
        !            31:        IF mkfault
        !            32:        THEN    return;
        !            33:        ELIF (*printptr=c)==EOR
        !            34:        THEN tabs=0; posn=0; q=printbuf;
        !            35:             FOR p=0; p<printptr-printbuf; p++
        !            36:             DO d=printbuf[p];
        !            37:                IF (p&7)==0 ANDF posn
        !            38:                THEN tabs++; posn=0;
        !            39:                FI
        !            40:                IF d==SP
        !            41:                THEN posn++;
        !            42:                ELSE WHILE tabs>0 DO *q++=TB; tabs--; OD
        !            43:                     WHILE posn>0 DO *q++=SP; posn--; OD
        !            44:                     *q++=d;
        !            45:                FI
        !            46:             OD
        !            47:             *q++=EOR;
        !            48: #ifdef EDDT
        !            49:                printptr=printbuf; do putchar(*printptr++); while (printptr<q);
        !            50: #else
        !            51:             write(outfile,printbuf,q-printbuf);
        !            52: #endif
        !            53:             printptr=printbuf;
        !            54:        ELIF c==TB
        !            55:        THEN *printptr++=SP;
        !            56:             WHILE (printptr-printbuf)&7 DO *printptr++=SP; OD
        !            57:        ELIF c
        !            58:        THEN printptr++;
        !            59:        FI
        !            60:        IF printptr >= &printbuf[MAXLIN-9] THEN
        !            61:                write(outfile, printbuf, printptr - printbuf);
        !            62:                printptr = printbuf;
        !            63:        FI
        !            64: }
        !            65: 
        !            66: charpos()
        !            67: {      return(printptr-printbuf);
        !            68: }
        !            69: 
        !            70: flushbuf()
        !            71: {      IF printptr!=printbuf
        !            72:        THEN printc(EOR);
        !            73:        FI
        !            74: }
        !            75: 
        !            76: /* VARARGS1 */
        !            77: printf(fmat,a1)
        !            78:        STRING          fmat;
        !            79:        STRING          a1;
        !            80: {
        !            81:        STRING  fptr;
        !            82:        REG     STRING  s;
        !            83:        REG     L_INT   *dptr;
        !            84:        L_REAL          *rptr;
        !            85:        REG             width, prec;
        !            86:        CHAR            c, adj;
        !            87:        INT             x, n;
        !            88:        REG     L_INT   lx;
        !            89:        CHAR            digits[64];
        !            90: 
        !            91:        fptr = fmat; dptr = (L_INT *)&a1;
        !            92: 
        !            93:        WHILE c = *fptr++
        !            94:        DO  IF c!='%'
        !            95:            THEN printc(c);
        !            96:            ELSE IF *fptr=='-' THEN adj='l'; fptr++; ELSE adj='r'; FI
        !            97:                 width=convert(&fptr);
        !            98:                 IF *fptr=='.' THEN fptr++; prec=convert(&fptr); ELSE prec = -1; FI
        !            99:                 digitptr=digits;
        !           100:                 rptr=(L_REAL *)dptr; x = lx = *dptr++;
        !           101:                 s=0;
        !           102:                 switch (c = *fptr++) {
        !           103: 
        !           104:                    case 'd':
        !           105:                        printnum(x, -10); break;
        !           106:                    case 'u':
        !           107:                        printnum((unsigned short)x, 10); break;
        !           108:                    case 'o':
        !           109:                        printnum((unsigned short)x, 8); break;
        !           110:                    case 'q':
        !           111:                        printnum(x, -8); break;
        !           112:                    case 'x':
        !           113:                        printnum((unsigned short)x, 16); break;
        !           114:                    case 'z':
        !           115:                        printnum((unsigned short)x, -16); break;
        !           116:                    case 'R':
        !           117:                        printnum(lx, radix); break;
        !           118:                    case 'Y':
        !           119:                        printdate(lx); break;
        !           120:                    case 'D':
        !           121:                        printnum(lx, -10); break;
        !           122:                    case 'U':
        !           123:                        printnum(lx, 10); break;
        !           124:                    case 'O':
        !           125:                        printnum(lx, 8); break;
        !           126:                    case 'Q':
        !           127:                        printnum(lx, -8); break;
        !           128:                    case 'X':
        !           129:                        printnum(lx, 16); break;
        !           130:                    case 'Z':
        !           131:                        printnum(lx, -16); break;
        !           132:                    case 'c':
        !           133:                        printc(x); break;
        !           134:                    case 's':
        !           135:                        s=(STRING)lx; break;
        !           136: #ifndef EDDT
        !           137:                    case 'f':
        !           138:                    case 'F':
        !           139:                        dptr++;
        !           140:                        (void)sprintf(s=digits, "%*.*f", width, prec, *rptr); prec= -1; break;
        !           141: #endif
        !           142:                    case 'm':
        !           143:                        break;
        !           144:                    case 'M':
        !           145:                        width=x; break;
        !           146:                    case 'T':
        !           147:                    case 't':
        !           148:                        IF c=='T'
        !           149:                        THEN width=x;
        !           150:                        ELSE dptr--;
        !           151:                        FI
        !           152:                        IF width
        !           153:                        THEN width -= charpos()%width;
        !           154:                        FI
        !           155:                        break;
        !           156:                    default:
        !           157:                        printc(c); dptr--;
        !           158:                }
        !           159: 
        !           160:                IF s==0
        !           161:                THEN *digitptr=0; s=digits;
        !           162:                FI
        !           163:                n=strlen(s);
        !           164:                n=(prec<n ANDF prec>=0 ? prec : n);
        !           165:                width -= n;
        !           166:                IF adj=='r'
        !           167:                THEN WHILE width-- > 0
        !           168:                     DO printc(SP); OD
        !           169:                FI
        !           170:                WHILE n-- DO printc(*s++); OD
        !           171:                WHILE width-- > 0 DO printc(SP); OD
        !           172:                digitptr=digits;
        !           173:            FI
        !           174:        OD
        !           175: }
        !           176: 
        !           177: printdate(tvec)
        !           178:        L_INT           tvec;
        !           179: {
        !           180:        REG             i;
        !           181:        REG STRING      timeptr;
        !           182:        STRING          ctime();
        !           183: 
        !           184: #ifndef EDDT
        !           185:        timeptr = ctime(&tvec);
        !           186: #else
        !           187:        timeptr="????????????????????????";
        !           188: #endif
        !           189:        FOR i=20; i<24; i++ DO *digitptr++ = *(timeptr+i); OD
        !           190:        FOR i=3; i<19; i++ DO *digitptr++ = *(timeptr+i); OD
        !           191: } /*printdate*/
        !           192: 
        !           193: convert(cp)
        !           194: REG STRING     *cp;
        !           195: {
        !           196:        REG CHAR        c;
        !           197:        INT             n;
        !           198:        n=0;
        !           199:        WHILE ((c = *(*cp)++)>='0') ANDF (c<='9') DO n=n*10+c-'0'; OD
        !           200:        (*cp)--;
        !           201:        return(n);
        !           202: }
        !           203: 
        !           204: printnum(n, base)
        !           205:        REG POS         n;
        !           206: {
        !           207:        REG CHAR        *dptr;
        !           208:        CHAR            digs[15];
        !           209:        dptr=digs;
        !           210:        IF base<0 THEN base = -base;
        !           211:                IF (L_INT)n<0 THEN n = -n; *digitptr++ = '-'; FI
        !           212:        FI
        !           213:        WHILE n
        !           214:        DO  *dptr++ = n%base;
        !           215:            n /= base;
        !           216:        OD
        !           217:        IF dptr==digs THEN *dptr++=0; FI
        !           218:        WHILE dptr!=digs
        !           219:        DO  n = *--dptr;
        !           220:            *digitptr++ = (n+(n<=9 ? '0' : 'a'-10));
        !           221:        OD
        !           222: }
        !           223: 
        !           224: #define        MAXIFD  5
        !           225: struct {
        !           226:        int     fd;
        !           227:        int     r9;
        !           228: } istack[MAXIFD];
        !           229: int    ifiledepth;
        !           230: 
        !           231: iclose(stack, err)
        !           232: {
        !           233:        IF err
        !           234:        THEN    IF infile
        !           235:                THEN    close(infile); infile=0;
        !           236:                FI
        !           237:                WHILE --ifiledepth >= 0
        !           238:                DO      IF istack[ifiledepth].fd
        !           239:                        THEN    close(istack[ifiledepth].fd);
        !           240:                        FI
        !           241:                OD
        !           242:                ifiledepth = 0;
        !           243:        ELIF stack == 0
        !           244:        THEN    IF infile
        !           245:                THEN    close(infile); infile=0;
        !           246:                FI
        !           247:        ELIF stack > 0
        !           248:        THEN    IF ifiledepth >= MAXIFD
        !           249:                THEN    error(TOODEEP);
        !           250:                FI
        !           251:                istack[ifiledepth].fd = infile;
        !           252:                istack[ifiledepth].r9 = var[9];
        !           253:                ifiledepth++;
        !           254:                infile = 0;
        !           255:        ELSE    IF infile
        !           256:                THEN    close(infile); infile=0;
        !           257:                FI
        !           258:                IF ifiledepth > 0
        !           259:                THEN    infile = istack[--ifiledepth].fd;
        !           260:                        var[9] = istack[ifiledepth].r9;
        !           261:                FI
        !           262:        FI
        !           263: }
        !           264: 
        !           265: oclose()
        !           266: {
        !           267:        IF outfile!=1
        !           268:        THEN    flushbuf(); close(outfile); outfile=1;
        !           269:        FI
        !           270: }
        !           271: 
        !           272: endline()
        !           273: {
        !           274: 
        !           275:        if (maxpos <= charpos())
        !           276:                printf("\n");
        !           277: }

unix.superglobalmegacorp.com

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