Deleted Added
sdiff udiff text old ( 7977:60051d2262c2 ) new ( 7978:9700266d52f4 )
full compact
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)
83{
84 while (*s) PutChar(*s++);
85}
86
87/* print c count times */
88void PutRepChar(char c, int count)
89{
90 while (count--) PutChar(c);
91}
92
93/* put string reverse */
94void PutStringReverse(char *s, int index)
95{
96 while ((index--) > 0) PutChar(s[index]);
97}
98
99/* prints value in radix, in a field width width, with fill
100 character fill
101 if radix is negative, print as signed quantity
102 if width is negative, left justify
103 if width is 0, use whatever is needed
104 if fill is 0, use ' '
105 */
106void PutNumber(sl value, int radix, int width, char fill)
107{
108 char buffer[40];
109 ui bufferindex = 0;
110 ul uvalue;
111 uw digit;
112 uw left = FALSE;
113 uw negative = FALSE;
114

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

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

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

217 char a = va_arg(*ap, char);
218
219 if (leftjust) PutChar(a & 0x7f);
220 if (fieldwidth > 0) PutRepChar(fill, fieldwidth - 1);
221 if (!leftjust) PutChar(a & 0x7f);
222 return(f);
223 }
224 case 's': {
225 char *a = va_arg(*ap, char *);
226
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);
231 return(f);
232 }
233 case 'd': radix = -10;
234 break;
235 case 'u': radix = 10;
236 break;
237 case 'x': radix = 16;
238 break;

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

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