printf.c (7977:60051d2262c2) | printf.c (7978:9700266d52f4) |
---|---|
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' */ | 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) |
83{ 84 while (*s) PutChar(*s++); 85} 86 87/* print c count times */ | 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) |
89{ 90 while (count--) PutChar(c); 91} 92 93/* put string reverse */ | 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) |
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 */ | 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) |
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} | 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) |
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': { | 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 *); |
226 | 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); |
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 | 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, ...) |
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 */ | 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; |
|
280} 281 | 287} 288 |
282void panic(char *f, ...) | 289void 290panic(const 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 | 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 |