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

Defined functions

getchar defined in line 103; used 3 times
printf defined in line 12; used 413 times
printn defined in line 46; used 3 times
putchar defined in line 67; used 26 times

Defined variables

KLADDR defined in line 66; used 8 times

Defined struct's

device defined in line 62; used 2 times
  • in line 66(2)
Last modified: 1982-08-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 928
Valid CSS Valid XHTML 1.0 Strict