|
|
1.1 root 1: /* $Header: /src386/kernel/coh.386/RCS/printf.c,v 1.6 93/04/16 06:49:16 bin Exp Locker: bin $ */
2: /* (lgl-
3: * The information contained herein is a trade secret of Mark Williams
4: * Company, and is confidential information. It is provided under a
5: * license agreement, and may be copied or disclosed only under the
6: * terms of that agreement. Any reproduction or disclosure of this
7: * material without the express written authorization of Mark Williams
8: * Company or persuant to the license agreement is unlawful.
9: *
10: * COHERENT Version 2.3.37
11: * Copyright (c) 1982, 1983, 1984.
12: * An unpublished work by Mark Williams Company, Chicago.
13: * All rights reserved.
14: -lgl) */
15: /*
16: * Coherent.
17: * Print formatted.
18: *
19: * $Log: printf.c,v $
20: * Revision 1.6 93/04/16 06:49:16 bin
21: * Hal: kernel 76 update
22: *
23: * Revision 1.2 92/01/06 12:00:01 hal
24: * Compile with cc.mwc.
25: *
26: * Revision 1.1 88/03/24 16:14:13 src
27: * Initial revision
28: *
29: * 87/09/20 Allan Cornish /usr/src/sys/coh/printf.c
30: * %U now correctly displays in base 10 rather than base 16.
31: *
32: * 86/12/16 Allan Cornish /usr/src/sys/coh/printf.c
33: * Added '%D' and '%X options to printf().
34: */
35: #include <sys/coherent.h>
36:
37: /*
38: * For indirecting and incrementing argument pointer.
39: */
40: #define ind(p, t) (*((t *) p))
41: #define inc(t1, t2) ((sizeof(t2 *)+sizeof(t1)-1) / sizeof(t1))
42:
43: /*
44: * Table for printing out digits.
45: */
46: char digtab[] ={
47: '0', '1', '2', '3', '4', '5', '6', '7',
48: '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
49: };
50:
51: /*
52: * A simple printf.
53: */
54: printf(fp, a1)
55: register char *fp;
56: {
57: char * cp;
58: register int c;
59: register unsigned *ap;
60: int lflag;
61:
62: ap = (char *)&a1;
63: for (;;) {
64: while ((c=*fp++) != '%') {
65: if (c == '\0')
66: return;
67: putchar(c);
68: }
69:
70: lflag = 0;
71: if ( *fp == 'l' ) {
72: lflag = 1;
73: fp++;
74: }
75:
76: switch ( c = *fp++ ) {
77:
78: case 'c':
79: putchar(*ap++);
80: continue;
81:
82: case 'd':
83: if ( lflag == 0 ) {
84: if ( ((int)(*ap)) < 0 ) {
85: putchar('-');
86: printn( -((long) ((int)(*ap))), 10 );
87: }
88: else
89: printn( ((long)(*ap)), 10 );
90: ap++;
91: continue;
92: }
93: /* fall through */
94: case 'D':
95: if ( *((long *)(ap)) < 0 ) {
96: putchar('-');
97: printn( - *((long *)(ap)), 10 );
98: }
99: else
100: printn( *((long *)(ap)), 10 );
101:
102: ((long *)(ap))++;
103: continue;
104:
105: case 'o':
106: if ( lflag == 0 ) {
107: printn( ((long)(*ap)), 8);
108: ap++;
109: continue;
110: }
111: /* fall through */
112: case 'O':
113: printf( *((long *)(ap)), 8 );
114: ((long *)(ap))++;
115: continue;
116:
117: case 'r':
118: ap = *((int **) ap);
119: fp = ind(ap, char *);
120: ap += inc(int, char *);
121: continue;
122:
123: case 's':
124: cp = ind(ap, char *);
125: ap += inc(int, char *);
126: while ((c=*cp++) != '\0')
127: putchar(c);
128: continue;
129:
130: case 'x':
131: if ( lflag == 0 ) {
132: printn( ((long)(*ap)), 16 );
133: ap++;
134: continue;
135: }
136: /* fall through */
137: case 'X':
138: printn( *((long *)(ap)), 16 );
139: ((long *)(ap))++;
140: continue;
141:
142: case 'u':
143: if ( lflag == 0 ) {
144: printn( ((long)(*ap)), 10);
145: ap++;
146: continue;
147: }
148: /* fall through */
149: case 'U':
150: printn( *((long *)(ap)), 10 );
151: ((long *)(ap))++;
152: continue;
153:
154: case 'p':
155: if (sizeof(char *) > sizeof(int)) {
156: printn( ((long)(*ap)), 16);
157: putchar(':');
158: ap++;
159: }
160: printn( ((long)(*ap)), 16);
161: ap++;
162: continue;
163:
164: default:
165: putchar(c);
166: continue;
167: }
168: }
169: }
170:
171: /*
172: * Print out the unsigned long `v' in the base `b'.
173: */
174: printn( v, b )
175: unsigned long v;
176: {
177: unsigned long n;
178:
179: if ((n=v/b) != 0)
180: printn(n, b);
181:
182: putchar(digtab[v%b]);
183: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.