|
|
1.1 root 1: /* $Header: /src386/STREAMS/coh.386/RCS/printf.c,v 2.3 93/08/09 13:35:58 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 2.3 93/08/09 13:35:58 bin
21: * Kernel 82 changes
22: *
23: * Revision 2.2 93/07/26 14:29:00 nigel
24: * Nigel's R80
25: *
26: * Revision 1.2 92/01/06 12:00:01 hal
27: * Compile with cc.mwc.
28: *
29: * Revision 1.1 88/03/24 16:14:13 src
30: * Initial revision
31: *
32: * 87/09/20 Allan Cornish /usr/src/sys/coh/printf.c
33: * %U now correctly displays in base 10 rather than base 16.
34: *
35: * 86/12/16 Allan Cornish /usr/src/sys/coh/printf.c
36: * Added '%D' and '%X options to printf().
37: */
38: #include <sys/coherent.h>
39:
40: /*
41: * For indirecting and incrementing argument pointer.
42: */
43: #define ind(p, t) (*((t *) p))
44: #define inc(t1, t2) ((sizeof(t2 *)+sizeof(t1)-1) / sizeof(t1))
45:
46: /*
47: * Table for printing out digits.
48: */
49: char digtab[] ={
50: '0', '1', '2', '3', '4', '5', '6', '7',
51: '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
52: };
53:
54: /*
55: * A simple printf.
56: */
57: printf(fp, a1)
58: register char *fp;
59: {
60: char * cp;
61: register int c;
62: register unsigned *ap;
63: int lflag;
64:
65: ap = (char *)&a1;
66: for (;;) {
67: while ((c=*fp++) != '%') {
68: if (c == '\0')
69: return;
70: putchar(c);
71: }
72:
73: lflag = 0;
74: if ( *fp == 'l' ) {
75: lflag = 1;
76: fp++;
77: }
78:
79: switch ( c = *fp++ ) {
80:
81: case 'c':
82: putchar(*ap++);
83: continue;
84:
85: case 'd':
86: if ( lflag == 0 ) {
87: if ( ((int)(*ap)) < 0 ) {
88: putchar('-');
89: printn( -((long) ((int)(*ap))), 10 );
90: }
91: else
92: printn( ((long)(*ap)), 10 );
93: ap++;
94: continue;
95: }
96: /* fall through */
97: case 'D':
98: if ( *((long *)(ap)) < 0 ) {
99: putchar('-');
100: printn( - *((long *)(ap)), 10 );
101: }
102: else
103: printn( *((long *)(ap)), 10 );
104:
105: ((long *)(ap))++;
106: continue;
107:
108: case 'o':
109: if ( lflag == 0 ) {
110: printn( ((long)(*ap)), 8);
111: ap++;
112: continue;
113: }
114: /* fall through */
115: case 'O':
116: printf( *((long *)(ap)), 8 );
117: ((long *)(ap))++;
118: continue;
119:
120: case 'r':
121: ap = *((int **) ap);
122: fp = ind(ap, char *);
123: ap += inc(int, char *);
124: continue;
125:
126: case 's':
127: cp = ind (ap, char *);
128: ap += inc (int, char *);
129: if (cp == NULL)
130: cp = "{NULL}";
131:
132: while ((c = * cp++) != '\0')
133: putchar (c);
134: continue;
135:
136: case 'x':
137: if ( lflag == 0 ) {
138: printn( ((long)(*ap)), 16 );
139: ap++;
140: continue;
141: }
142: /* fall through */
143: case 'X':
144: printn( *((long *)(ap)), 16 );
145: ((long *)(ap))++;
146: continue;
147:
148: case 'u':
149: if ( lflag == 0 ) {
150: printn( ((long)(*ap)), 10);
151: ap++;
152: continue;
153: }
154: /* fall through */
155: case 'U':
156: printn( *((long *)(ap)), 10 );
157: ((long *)(ap))++;
158: continue;
159:
160: case 'p':
161: if (sizeof(char *) > sizeof(int)) {
162: printn( ((long)(*ap)), 16);
163: putchar(':');
164: ap++;
165: }
166: printn( ((long)(*ap)), 16);
167: ap++;
168: continue;
169:
170: default:
171: putchar(c);
172: continue;
173: }
174: }
175: }
176:
177: /*
178: * Print out the unsigned long `v' in the base `b'.
179: */
180: printn( v, b )
181: unsigned long v;
182: {
183: unsigned long n;
184:
185: if ((n=v/b) != 0)
186: printn(n, b);
187:
188: putchar(digtab[v%b]);
189: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.