1/*****************************************************************************
2
3 Copyright � 1993, 1994 Digital Equipment Corporation,
4 Maynard, Massachusetts.
5
6 All Rights Reserved
7
8Permission to use, copy, modify, and distribute this software and its

--- 65 unchanged lines hidden (view full) ---

74#include "lib.h"
75#include <stdarg.h>
76
77
78
79
80
81/* The string s is terminated by a '\0' */
82void PutString(char *s)
82void
83PutString(const char *s)
84{
85 while (*s) PutChar(*s++);
86}
87
88/* print c count times */
88void PutRepChar(char c, int count)
89void
90PutRepChar(char c, int count)
91{
92 while (count--) PutChar(c);
93}
94
95/* put string reverse */
94void PutStringReverse(char *s, int index)
96void
97PutStringReverse(const char *s, int index)
98{
99 while ((index--) > 0) PutChar(s[index]);
100}
101
102/* prints value in radix, in a field width width, with fill
103 character fill
104 if radix is negative, print as signed quantity
105 if width is negative, left justify
106 if width is 0, use whatever is needed
107 if fill is 0, use ' '
108 */
106void PutNumber(sl value, int radix, int width, char fill)
109void
110PutNumber(sl value, int radix, int width, char fill)
111{
112 char buffer[40];
113 ui bufferindex = 0;
114 ul uvalue;
115 uw digit;
116 uw left = FALSE;
117 uw negative = FALSE;
118

--- 75 unchanged lines hidden (view full) ---

194/*
195 * Output the n digits after the decimal place.
196 */
197 for (i = 1; i < 6; i++) {
198 b = (ul)(power(10, i) * (double)(a - (ul) a));
199 PutChar((char)(b % 10) + '0');
200 }
201}
198char *FormatItem(char *f, va_list *ap)
202const char *
203FormatItem(const char *f, va_list *ap)
204{
205 char c;
206 int fieldwidth = 0;
207 int leftjust = FALSE;
208 int radix = 0;
209 char fill = ' ';
210 if (*f == '0') fill = '0';
211 while (c = *f++) {

--- 10 unchanged lines hidden (view full) ---

222 char a = va_arg(*ap, char);
223
224 if (leftjust) PutChar(a & 0x7f);
225 if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1);
226 if (!leftjust) PutChar(a & 0x7f);
227 return(f);
228 }
229 case 's': {
225 char *a = va_arg(*ap, char *);
230 const char *a = va_arg(*ap, const char *);
231
227 if (leftjust) PutString((char *) a);
228 if (fieldwidth > strlen((char *) a))
229 PutRepChar(fill, fieldwidth - strlen((char *)a));
230 if (!leftjust) PutString((char *) a);
232 if (leftjust) PutString((const char *) a);
233 if (fieldwidth > strlen((const char *) a))
234 PutRepChar(fill, fieldwidth - strlen((const char *)a));
235 if (!leftjust) PutString((const char *) a);
236 return(f);
237 }
238 case 'd': radix = -10;
239 break;
240 case 'u': radix = 10;
241 break;
242 case 'x': radix = 16;
243 break;

--- 16 unchanged lines hidden (view full) ---

260 if (leftjust) fieldwidth = -fieldwidth;
261 {
262 sl a = va_arg(*ap, sl);
263 PutNumber(a, radix, fieldwidth, fill);
264 }
265 return(f);
266}
267
263void printf(char *f, ...)
268int
269printf(const char *f, ...)
270{
271 va_list ap;
272
273 va_start(ap, f);
274
275 while (*f) {
276 if (*f == '%') f = FormatItem(f + 1, &ap);
277 else PutChar(*f++);
278 }
279
280 if (*(f-1)=='\n') {
281 /* add a line-feed (SimOS console output goes to shell */
282 PutChar('\r');
283 }
284
285 va_end(ap); /* clean up */
286 return 0;
287}
288
282void panic(char *f, ...)
289void
290panic(const char *f, ...)
291{
292 va_list ap;
293
294 va_start(ap, f);
295
296 printf("CONSOLE PANIC (looping): ");
297 while (*f) {
298 if (*f == '%') f = FormatItem(f + 1, &ap);
299 else PutChar(*f++);
300 }
301
302 va_end(ap); /* clean up */
303 while(1);
304}
305
306