1: /*
   2:  * Copyright (c) 1986 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  *	@(#)prf.c	1.4 (2.11BSD) 1996/06/04
   7:  */
   8: 
   9: #include "../machine/cons.h"
  10: 
  11: #define KLADDR  ((struct dldevice *)0177560)
  12: 
  13: #define CTRL(x) ('x' & 037)
  14: 
  15: /*
  16:  * Scaled down version of C Library printf.  Only %s %u %d (==%u) %o %x %D
  17:  * are recognized.  Used to print diagnostic information directly on
  18:  * console tty.  Since it is not interrupt driven, all system activities
  19:  * are pretty much suspended.  Printf should not be used for chit-chat.
  20:  */
  21: printf(fmt, x1)
  22:     register char *fmt;
  23:     unsigned x1;
  24: {
  25:     register c;
  26:     register unsigned int *adx;
  27:     unsigned char *s;
  28: 
  29:     adx = &x1;
  30: loop:
  31:     while ((c = *fmt++) != '%') {
  32:         if (c == '\0')
  33:             return;
  34:         putchar(c);
  35:     }
  36:     c = *fmt++;
  37:     if (c == 'd' || c == 'u' || c == 'o' || c == 'x')
  38:         printn((long)*adx, c=='o'? 8: (c=='x'? 16:10));
  39:     else if (c == 's') {
  40:         s = (unsigned char *)*adx;
  41:         while (c = *s++)
  42:             putchar(c);
  43:     } else if (c == 'D' || c == 'O') {
  44:         printn(*(long *)adx, c == 'D' ?  10 : 8);
  45:         adx += (sizeof(long) / sizeof(int)) - 1;
  46:     } else if (c == 'c')
  47:         putchar((char *)*adx);
  48:     adx++;
  49:     goto loop;
  50: }
  51: 
  52: /*
  53:  * Print an unsigned integer in base b.
  54:  */
  55: printn(n, b)
  56:     long n;
  57:     register int b;
  58: {
  59:     long a;
  60: 
  61:     if (n < 0) {    /* shouldn't happen */
  62:         putchar('-');
  63:         n = -n;
  64:     }
  65:     if (a = n/b)
  66:         printn(a, b);
  67:     putchar("0123456789ABCDEF"[(int)(n%b)]);
  68: }
  69: 
  70: putchar(c)
  71:     register c;
  72: {
  73:     register s;
  74:     register unsigned timo;
  75: 
  76: #ifdef notdef
  77:     /*
  78: 	 *  If last char was a break or null, don't print
  79: 	 */
  80:     if ((KLADDR->dlrbuf & 0177) == 0)
  81:         return;
  82: #endif
  83:     /*
  84:          *  If we got a XOFF, wait for a XON
  85:          */
  86:     if ((KLADDR->dlrcsr & DL_RDONE) != 0)
  87:         if ((KLADDR->dlrbuf & 0177) == 19)
  88:             while ((KLADDR->dlrbuf & 0177) != 17)
  89:                 continue;
  90:     /*
  91: 	 * Try waiting for the console tty to come ready,
  92: 	 * otherwise give up after a reasonable time.
  93: 	 */
  94:     timo=60000;
  95:     while ((KLADDR->dlxcsr & DLXCSR_TRDY) == 0)
  96:         if (--timo == 0)
  97:             break;
  98:     if (c == 0)
  99:         return(c);
 100:     s = KLADDR->dlxcsr;
 101:     KLADDR->dlxcsr = 0;
 102:     KLADDR->dlxbuf = c;
 103:     if (c == '\n') {
 104:         putchar('\r');
 105:         putchar(0177);
 106:     }
 107:     putchar(0);
 108:     KLADDR->dlxcsr = s;
 109:     return(c);
 110: }
 111: 
 112: getchar()
 113: {
 114:     register c;
 115: 
 116:     KLADDR->dlrcsr = DL_RE;
 117:     while ((KLADDR->dlrcsr & DL_RDONE) == 0)
 118:         continue;
 119:     c = KLADDR->dlrbuf & 0177;
 120:     if (c=='\r')
 121:         c = '\n';
 122:     return(c);
 123: }
 124: 
 125: gets(buf)
 126:     char *buf;
 127: {
 128:     register char *lp, *cp;
 129:     register int c;
 130: 
 131:     lp = buf;
 132:     for (;;) {
 133:         c = getchar() & 0177;
 134:         switch (c) {
 135:             default:
 136:                 if (c < ' ' || c >= 127)
 137:                     putchar(CTRL(G));
 138:                 else {
 139:                     *lp++ = c;
 140:                     putchar(c);
 141:                 }
 142:                 break;
 143: 
 144:             case '\n':
 145:             case '\r':
 146:                 putchar('\n');
 147:                 c = '\n';
 148:                 *lp++ = '\0';
 149:                 return;
 150: 
 151:             case '\177':
 152:             case '\b':
 153:             case '#':
 154:                 if (lp <= buf)
 155:                     putchar(CTRL(G));
 156:                 else {
 157:                     lp--;
 158:                     putchar('\b');
 159:                     putchar(' ');
 160:                     putchar('\b');
 161:                 }
 162:                 break;
 163: 
 164:             case CTRL(U):
 165:             case '@':
 166:                 while (lp > buf) {
 167:                     lp--;
 168:                     putchar('\b');
 169:                     putchar(' ');
 170:                     putchar('\b');
 171:                 }
 172:                 break;
 173: 
 174:             case CTRL(R):
 175:                 putchar('^');
 176:                 putchar('R');
 177:                 putchar('\n');
 178:                 for (cp = buf; cp < lp; cp++)
 179:                     putchar(*cp);
 180:                 break;
 181:         }
 182:     }
 183: }

Defined functions

getchar defined in line 112; used 4 times
printf defined in line 21; used 173 times
printn defined in line 55; used 3 times
putchar defined in line 70; used 33 times

Defined macros

CTRL defined in line 13; used 4 times
KLADDR defined in line 11; used 12 times
Last modified: 1996-06-05
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 980
Valid CSS Valid XHTML 1.0 Strict