Annotation of researchv9/libc/gen/debug.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Scaled down version of C Library printf.
                      3:  * Only %s %u %d (==%u) %o %x %D are recognized.
                      4:  * Used to print diagnostic information
                      5:  * directly on console tty.
                      6:  * Since it is not interrupt driven,
                      7:  * all system activities are pretty much
                      8:  * suspended.
                      9:  * Printf should not be used for chit-chat.
                     10:  */
                     11: /* VARARGS1 */
                     12: _printf(fmt, x1)
                     13: register char *fmt;
                     14: unsigned x1;
                     15: {
                     16:        register c;
                     17:        register unsigned *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:                adx++;
                     35:        } else if (c=='D' || c=='O' || c =='X') {
                     36:                _printn(*(long *)adx, c=='O'? 8: (c=='X'? 16:10));
                     37:                adx += (sizeof(long) / sizeof(int)) - 1;
                     38:        }
                     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: _putchar(c)
                     61: char c;
                     62: {
                     63:        write(1,&c,1);
                     64: }

unix.superglobalmegacorp.com

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