|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1982, 1986, 1990 The Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution is only permitted until one year after the first shipment ! 6: * of 4.4BSD by the Regents. Otherwise, redistribution and use in source and ! 7: * binary forms are permitted provided that: (1) source distributions retain ! 8: * this entire copyright notice and comment, and (2) distributions including ! 9: * binaries display the following acknowledgement: This product includes ! 10: * software developed by the University of California, Berkeley and its ! 11: * contributors'' in the documentation or other materials provided with the ! 12: * distribution and in all advertising materials mentioning features or use ! 13: * of this software. Neither the name of the University nor the names of ! 14: * its contributors may be used to endorse or promote products derived from ! 15: * this software without specific prior written permission. ! 16: * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 17: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 18: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 19: * ! 20: * @(#)prf.c 7.2 (Berkeley) 6/24/90 ! 21: */ ! 22: ! 23: #include "param.h" ! 24: ! 25: /* ! 26: * Scaled down version of C Library printf. ! 27: * Used to print diagnostic information directly on console tty. ! 28: * Since it is not interrupt driven, all system activities are ! 29: * suspended. Printf should not be used for chit-chat. ! 30: * ! 31: * One additional format: %b is supported to decode error registers. ! 32: * Usage is: ! 33: * printf("reg=%b\n", regval, "<base><arg>*"); ! 34: * Where <base> is the output base expressed as a control character, ! 35: * e.g. \10 gives octal; \20 gives hex. Each arg is a sequence of ! 36: * characters, the first of which gives the bit number to be inspected ! 37: * (origin 1), and the next characters (up to a control character, i.e. ! 38: * a character <= 32), give the name of the register. Thus ! 39: * printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); ! 40: * would produce output: ! 41: * reg=2<BITTWO,BITONE> ! 42: */ ! 43: /*VARARGS1*/ ! 44: printf(fmt, x1) ! 45: char *fmt; ! 46: unsigned x1; ! 47: { ! 48: ! 49: prf(0, fmt, &x1); ! 50: } ! 51: ! 52: /*VARARGS1*/ ! 53: romprintf(fmt, x1) ! 54: char *fmt; ! 55: unsigned x1; ! 56: { ! 57: ! 58: prf(1, fmt, &x1); ! 59: } ! 60: ! 61: prf(userom, fmt, adx) ! 62: register char *fmt; ! 63: register u_int *adx; ! 64: { ! 65: register int b, c, i; ! 66: char *s; ! 67: int any; ! 68: ! 69: loop: ! 70: while ((c = *fmt++) != '%') { ! 71: if(c == '\0') ! 72: return; ! 73: putchar(userom, c); ! 74: } ! 75: again: ! 76: c = *fmt++; ! 77: /* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */ ! 78: switch (c) { ! 79: ! 80: case 'l': ! 81: goto again; ! 82: case 'x': case 'X': ! 83: b = 16; ! 84: goto number; ! 85: case 'd': case 'D': ! 86: case 'u': /* what a joke */ ! 87: b = 10; ! 88: goto number; ! 89: case 'o': case 'O': ! 90: b = 8; ! 91: number: ! 92: printn(userom, (u_long)*adx, b); ! 93: break; ! 94: case 'c': ! 95: b = *adx; ! 96: for (i = 24; i >= 0; i -= 8) ! 97: if (c = (b >> i) & 0x7f) ! 98: putchar(userom, c); ! 99: break; ! 100: case 'b': ! 101: b = *adx++; ! 102: s = (char *)*adx; ! 103: printn(userom, (u_long)b, *s++); ! 104: any = 0; ! 105: if (b) { ! 106: while (i = *s++) { ! 107: if (b & (1 << (i-1))) { ! 108: putchar(userom, any? ',' : '<'); ! 109: any = 1; ! 110: for (; (c = *s) > 32; s++) ! 111: putchar(userom, c); ! 112: } else ! 113: for (; *s > 32; s++) ! 114: ; ! 115: } ! 116: if (any) ! 117: putchar(userom, '>'); ! 118: } ! 119: break; ! 120: ! 121: case 's': ! 122: s = (char *)*adx; ! 123: while (c = *s++) ! 124: putchar(userom, c); ! 125: break; ! 126: } ! 127: adx++; ! 128: goto loop; ! 129: } ! 130: ! 131: /* ! 132: * Printn prints a number n in base b. ! 133: * We don't use recursion to avoid deep kernel stacks. ! 134: */ ! 135: printn(userom, n, b) ! 136: u_long n; ! 137: { ! 138: char prbuf[11]; ! 139: register char *cp; ! 140: ! 141: if (b == 10 && (int)n < 0) { ! 142: putchar(userom, '-'); ! 143: n = (unsigned)(-(int)n); ! 144: } ! 145: cp = prbuf; ! 146: do { ! 147: *cp++ = "0123456789abcdef"[n%b]; ! 148: n /= b; ! 149: } while (n); ! 150: do ! 151: putchar(userom, *--cp); ! 152: while (cp > prbuf); ! 153: } ! 154: ! 155: /* ! 156: * Print a character on console. ! 157: */ ! 158: putchar(userom, c) ! 159: register c; ! 160: { ! 161: #ifdef ROMPRF ! 162: if (userom) { ! 163: romputchar(c); ! 164: return; ! 165: } ! 166: #endif ! 167: cnputc(c); ! 168: if(c == '\n') ! 169: cnputc('\r'); ! 170: } ! 171: ! 172: peekchar() ! 173: { ! 174: register c; ! 175: ! 176: c = cngetc(); ! 177: if (c == ('c'&037)) { ! 178: printf("^C"); ! 179: _stop(""); ! 180: /* NOTREACHED */ ! 181: } ! 182: return(c); ! 183: } ! 184: ! 185: getchar() ! 186: { ! 187: register c; ! 188: ! 189: while((c = cngetc()) == 0) ! 190: ; ! 191: if (c == '\r') ! 192: c = '\n'; ! 193: else if (c == ('c'&037)) { ! 194: printf("^C"); ! 195: _stop(""); ! 196: /* NOTREACHED */ ! 197: } ! 198: putchar(0, c); ! 199: return(c); ! 200: } ! 201: ! 202: gets(buf) ! 203: char *buf; ! 204: { ! 205: register char *lp; ! 206: register c; ! 207: ! 208: lp = buf; ! 209: for (;;) { ! 210: c = getchar() & 0177; ! 211: switch(c) { ! 212: case '\n': ! 213: case '\r': ! 214: c = '\n'; ! 215: *lp++ = '\0'; ! 216: return; ! 217: case '\b': ! 218: if (lp > buf) { ! 219: lp--; ! 220: putchar(0, ' '); ! 221: putchar(0, '\b'); ! 222: } ! 223: continue; ! 224: case '#': ! 225: case '\177': ! 226: lp--; ! 227: if (lp < buf) ! 228: lp = buf; ! 229: continue; ! 230: case '@': ! 231: case 'u'&037: ! 232: lp = buf; ! 233: putchar(0, '\n'); ! 234: continue; ! 235: default: ! 236: *lp++ = c; ! 237: } ! 238: } ! 239: } ! 240:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.