Annotation of cci/sys/stand/prf.c, revision 1.1.1.2

1.1       root        1: /*     prf.c   4.3     81/05/05        */
                      2: 
                      3: #include "../h/param.h"
                      4: #include "../machine/mtpr.h"
                      5: #include "../h/cp.h"
                      6: #ifdef NOIO
                      7: #define CINADR 0xf0000         /* Dummy keyboard (memory mapped) */
                      8: #define COUTADR        0xf1000         /* Dummy screen         -,,-      */
                      9: #endif
                     10: 
1.1.1.2 ! root       11: int    wait_for_char = 1;
        !            12: 
1.1       root       13: /*
                     14:  * Scaled down version of C Library printf.
                     15:  * Used to print diagnostic information directly on console tty.
                     16:  * Since it is not interrupt driven, all system activities are
                     17:  * suspended.  Printf should not be used for chit-chat.
                     18:  *
                     19:  * One additional format: %b is supported to decode error registers.
                     20:  * Usage is:
                     21:  *     printf("reg=%b\n", regval, "<base><arg>*");
                     22:  * Where <base> is the output base expressed as a control character,
                     23:  * e.g. \10 gives octal; \20 gives hex.  Each arg is a sequence of
                     24:  * characters, the first of which gives the bit number to be inspected
                     25:  * (origin 1), and the next characters (up to a control character, i.e.
                     26:  * a character <= 32), give the name of the register.  Thus
                     27:  *     printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
                     28:  * would produce output:
                     29:  *     reg=2<BITTWO,BITONE>
                     30:  */
                     31: /*VARARGS1*/
                     32: printf(fmt, x1)
                     33:        char *fmt;
                     34:        unsigned x1;
                     35: {
                     36: 
                     37:        prf(fmt, &x1);
                     38: }
                     39: 
                     40: prf(fmt, adx)
                     41:        register char *fmt;
                     42:        register u_int *adx;
                     43: {
                     44:        register int b, c, i;
                     45:        char *s;
                     46:        int any;
                     47: 
                     48: loop:
                     49:        while ((c = *fmt++) != '%') {
                     50:                if(c == '\0')
                     51:                        return;
                     52:                putchar(c);
                     53:        }
                     54: again:
                     55:        c = *fmt++;
                     56:        /* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */
                     57:        switch (c) {
                     58: 
                     59:        case 'l':
                     60:                goto again;
                     61:        case 'x': case 'X':
                     62:                b = 16;
                     63:                goto number;
                     64:        case 'd': case 'D':
                     65:        case 'u':               /* what a joke */
                     66:                b = 10;
                     67:                goto number;
                     68:        case 'o': case 'O':
                     69:                b = 8;
                     70: number:
                     71:                printn((u_long)*adx, b);
                     72:                break;
                     73:        case 'c':
                     74:                b = *adx;
                     75:                for (i = 24; i >= 0; i -= 8)
                     76:                        if (c = (b >> i) & 0x7f)
                     77:                                putchar(c);
                     78:                break;
                     79:        case 'b':
                     80:                b = *adx++;
                     81:                s = (char *)*adx;
                     82:                printn((u_long)b, *s++);
                     83:                any = 0;
                     84:                if (b) {
                     85:                        putchar('<');
                     86:                        while (i = *s++) {
                     87:                                if (b & (1 << (i-1))) {
                     88:                                        if (any)
                     89:                                                putchar(',');
                     90:                                        any = 1;
                     91:                                        for (; (c = *s) > 32; s++)
                     92:                                                putchar(c);
                     93:                                } else
                     94:                                        for (; *s > 32; s++)
                     95:                                                ;
                     96:                        }
                     97:                        putchar('>');
                     98:                }
                     99:                break;
                    100: 
                    101:        case 's':
                    102:                s = (char *)*adx;
                    103:                while (c = *s++)
                    104:                        putchar(c);
                    105:                break;
                    106:        }
                    107:        adx++;
                    108:        goto loop;
                    109: }
                    110: 
                    111: /*
                    112:  * Printn prints a number n in base b.
                    113:  * We don't use recursion to avoid deep kernel stacks.
                    114:  */
                    115: printn(n, b)
                    116:        u_long n;
                    117: {
                    118:        char prbuf[11];
                    119:        register char *cp;
                    120: 
                    121:        if (b == 10 && (int)n < 0) {
                    122:                putchar('-');
                    123:                n = (unsigned)(-(int)n);
                    124:        }
                    125:        cp = prbuf;
                    126:        do {
                    127:                *cp++ = "0123456789abcdef"[n%b];
                    128:                n /= b;
                    129:        } while (n);
                    130:        do
                    131:                putchar(*--cp);
                    132:        while (cp > prbuf);
                    133: }
                    134: 
                    135: /*
                    136:  * Print a character on console.
                    137:  * Attempts to save and restore device
                    138:  * status.
                    139:  *
                    140:  * Whether or not printing is inhibited,
                    141:  * the last MSGBUFS characters
                    142:  * are saved in msgbuf for inspection later.
                    143:  */
                    144: #ifdef NOIO
                    145: char   *coutadr=(char *)COUTADR;
                    146: putchar(c)
                    147:        register c;
                    148: {
                    149:        *coutadr++ = c;
                    150: }
                    151: 
                    152: char   *cinadr=(char *)CINADR;
                    153: getchar()
                    154: {
                    155:        return( *cinadr++ );
                    156: }
                    157: 
                    158: #else
                    159: struct cpdcb_o cpout;
                    160: struct cpdcb_i cpin;
                    161: 
                    162: /* console requires even parity */
                    163: #define EVENP
                    164: putchar(c)
                    165: char c;
                    166: {
                    167:        int time;
                    168: #ifdef EVENP
                    169:        register mask, par;
                    170: 
                    171:        for(par=0, mask=1; mask!=0200; mask<<=1, par<<=1)
                    172:                par ^= c&mask;
                    173:        c |= par;
                    174: #endif EVENP
                    175:        cpout.cp_hdr.cp_unit = CPCONS;  /* Resets done bit */
                    176:        cpout.cp_hdr.cp_comm = CPWRITE;
                    177:        cpout.cp_hdr.cp_count = 1;
                    178:        cpout.cp_buf[0] = c;
                    179:        mtpr(&cpout, CPMDCB);
                    180: #ifdef SIMIO
                    181:        simout(&cpout);
                    182: #endif
                    183:        time = 100000;                          /* Delay loop */
                    184:        while (time--) {
                    185:                uncache (&cpout.cp_hdr.cp_unit) ;
                    186:                if (cpout.cp_hdr.cp_unit & CPDONE) break;
                    187:        }
                    188:        if (c == '\n') putchar ('\r');
                    189: }
                    190: 
                    191: #ifdef SIMIO
                    192: simout(addr)
                    193: {
                    194:        asm(".byte 0x4");
                    195: }
                    196: simin(addr)
                    197: {
                    198:        asm(".byte 0x3");
                    199: }
                    200: #endif
                    201: 
                    202: getchar()
                    203: {
1.1.1.2 ! root      204:        static  char_read = 0;
1.1       root      205:        char    c;
                    206: 
1.1.1.2 ! root      207:        if(!char_read) {
        !           208:                char_read = 1;
        !           209:                cpin.cp_hdr.cp_unit = CPCONS;   /* Resets done bit */
        !           210:                cpin.cp_hdr.cp_comm = CPREAD;
        !           211:                cpin.cp_hdr.cp_count = 1;
        !           212:                mtpr(&cpin, CPMDCB);
1.1       root      213: #ifdef SIMIO
1.1.1.2 ! root      214:                simin(&cpin);
1.1       root      215: #endif
1.1.1.2 ! root      216:        }
        !           217:        uncache (&cpin.cp_hdr.cp_unit);
        !           218:        if(wait_for_char) {
        !           219:                while ((cpin.cp_hdr.cp_unit & CPDONE) == 0) 
        !           220:                        uncache (&cpin.cp_hdr.cp_unit);
        !           221:        }
        !           222:        else {
        !           223:                if((cpin.cp_hdr.cp_unit & CPDONE) == 0)
        !           224:                        return 0;
        !           225:        }
1.1       root      226:        uncache (&cpin.cpi_buf[0]);
                    227:        c = cpin.cpi_buf[0] & 0x7f;
1.1.1.2 ! root      228:        char_read = 0;
1.1       root      229:        if (c == '\r')  c = '\n';
1.1.1.2 ! root      230:        if(c != '\b')
        !           231:                putchar(c);
1.1       root      232:        return(c);
                    233: }
                    234: #endif
                    235: 
                    236: 
                    237: gets(buf)
                    238:        char *buf;
                    239: {
1.1.1.2 ! root      240:        static char     line[256];
        !           241:        static char     *lp = line;
        !           242:        register        c;
1.1       root      243: 
1.1.1.2 ! root      244:        *buf = '\0';
1.1       root      245:        for (;;) {
                    246:        store:
1.1.1.2 ! root      247:                c = getchar() & 0177;
1.1       root      248:                switch(c) {
1.1.1.2 ! root      249:                case '\0' :
        !           250:                        if(!wait_for_char)
        !           251:                                return;
        !           252:                        break;
1.1       root      253:                case '\n':
                    254:                case '\r':
                    255:                        c = '\n';
1.1.1.2 ! root      256:                        *lp = '\0';
        !           257:                        strcpy(buf, line);
        !           258:                        lp = line;
1.1       root      259:                        return;
                    260:                case '\b':
1.1.1.2 ! root      261:                        if (lp > line)
        !           262:                                putchar('\b');
1.1       root      263:                case '#':
                    264:                        lp--;
1.1.1.2 ! root      265:                        if (lp < line)
        !           266:                                lp = line;
1.1       root      267:                        continue;
                    268:                case '@':
                    269:                case 'u'&037:
1.1.1.2 ! root      270:                        lp = line;
1.1       root      271:                        putchar('\n');
                    272:                        continue;
                    273:                default:
1.1.1.2 ! root      274:                        if((lp - line) < 256)
        !           275:                                *lp++ = c;
1.1       root      276:                }
                    277:        }
                    278: }

unix.superglobalmegacorp.com

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