Rev 41 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 41 | Rev 203 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | Copyright (C) 1993 Free Software Foundation |
2 | Copyright (C) 1993 Free Software Foundation |
Line 3... | Line 3... | ||
3 | 3 | ||
4 | This file is part of the GNU IO Library. This library is free |
4 | This file is part of the GNU IO Library. This library is free |
5 | software; you can redistribute it and/or modify it under the |
5 | software; you can redistribute it and/or modify it under the |
Line 69... | Line 69... | ||
69 | 69 | ||
70 | Alexander Popov |
70 | Alexander Popov |
71 | sasho@vip.orbitel.bg |
71 | sasho@vip.orbitel.bg |
72 | ****************************************************************************** |
72 | ****************************************************************************** |
73 | Changed file to work with LPC - ARM. |
73 | Changed file to work with LPC - ARM. |
74 | Ingo Busker |
74 | Ingo Busker |
75 | busker@mikrocontroller.com 02.2005 |
75 | busker@mikrocontroller.com 02.2005 |
76 | ******************************************************************************/ |
76 | ******************************************************************************/ |
Line 77... | Line 77... | ||
77 | 77 | ||
78 | 78 | ||
79 | /* |
79 | /* |
80 | * Actual printf innards. |
80 | * Actual printf innards. |
Line 87... | Line 87... | ||
87 | #include <stdarg.h> |
87 | #include <stdarg.h> |
88 | #else |
88 | #else |
89 | #include <varargs.h> |
89 | #include <varargs.h> |
90 | #endif |
90 | #endif |
91 | #include "91x_lib.h" |
91 | #include "91x_lib.h" |
92 | #include "menu.h" |
92 | #include "printf_P.h" |
Line 93... | Line -... | ||
93 | - | ||
94 | - | ||
95 | //#define LIGHTPRINTF |
93 | |
96 | char Putchar(char zeichen) |
94 | void PRINT(pVoidFnctChar pPutchar, const char * ptr, unsigned int len) |
97 | { |
95 | { |
98 | DisplayBuff[DispPtr++] = zeichen; |
96 | for(;len;len--) |
99 | return(1); |
97 | (*pPutchar)(*ptr++); |
Line 100... | Line -... | ||
100 | } |
- | |
101 | 98 | } |
|
102 | - | ||
103 | void PRINT(const char * ptr, unsigned int len) { |
- | |
104 | for(;len;len--) |
99 | |
105 | Putchar(*ptr++); |
- | |
106 | } |
- | |
107 | 100 | void PRINTP(pVoidFnctChar pPutchar, const char * ptr, unsigned int len) |
|
108 | void PRINTP(const char * ptr, unsigned int len) { |
101 | { |
109 | for(;len;len--) |
102 | for(;len;len--) |
Line 110... | Line 103... | ||
110 | Putchar(*ptr++); |
103 | (*pPutchar)(*ptr++); |
111 | } |
104 | } |
112 | 105 | ||
113 | void PAD_SP(signed char howmany) { |
106 | void PAD_SP(pVoidFnctChar pPutchar, signed char howmany) { |
Line 114... | Line 107... | ||
114 | for(;howmany>0;howmany--) |
107 | for(;howmany>0;howmany--) |
115 | Putchar(' '); |
108 | (*pPutchar)(' '); |
116 | } |
109 | } |
117 | 110 | ||
Line 118... | Line 111... | ||
118 | void PAD_0(signed char howmany) { |
111 | void PAD_0(pVoidFnctChar pPutchar, signed char howmany) { |
Line 119... | Line 112... | ||
119 | for(;howmany>0;howmany--) |
112 | for(;howmany>0;howmany--) |
120 | Putchar('0'); |
113 | (*pPutchar)('0'); |
121 | } |
114 | } |
122 | 115 | ||
123 | #define BUF 40 |
116 | #define BUF 40 |
124 | 117 | ||
Line 125... | Line 118... | ||
125 | /* |
118 | /* |
126 | * Macros for converting digits to letters and vice versa |
119 | * Macros for converting digits to letters and vice versa |
127 | */ |
120 | */ |
128 | #define to_digit(c) ((c) - '0') |
121 | #define to_digit(c) ((c) - '0') |
129 | #define is_digit(c) ((c)<='9' && (c)>='0') |
122 | #define is_digit(c) ((c)<='9' && (c)>='0') |
130 | #define to_char(n) ((n) + '0') |
123 | #define to_char(n) ((n) + '0') |
131 | 124 | ||
132 | /* |
125 | /* |
133 | * Flags used during conversion. |
126 | * Flags used during conversion. |
134 | */ |
127 | */ |
Line 135... | Line 128... | ||
135 | #define LONGINT 0x01 /* long integer */ |
128 | #define LONGINT 0x01 /* long integer */ |
136 | #define LONGDBL 0x02 /* long double; unimplemented */ |
129 | #define LONGDBL 0x02 /* long double; unimplemented */ |
137 | #define SHORTINT 0x04 /* short integer */ |
130 | #define SHORTINT 0x04 /* short integer */ |
138 | #define ALT 0x08 /* alternate form */ |
131 | #define ALT 0x08 /* alternate form */ |
139 | #define LADJUST 0x10 /* left adjustment */ |
132 | #define LADJUST 0x10 /* left adjustment */ |
140 | #define ZEROPAD 0x20 /* zero (as opposed to blank) pad */ |
133 | #define ZEROPAD 0x20 /* zero (as opposed to blank) pad */ |
Line 165... | Line 158... | ||
165 | quite grok this spaghetti code ... */ |
158 | quite grok this spaghetti code ... */ |
166 | signed char size = 0; /* size of converted field or string */ |
159 | signed char size = 0; /* size of converted field or string */ |
167 | char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ |
160 | char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */ |
168 | char ox[2]; /* space for 0x hex-prefix */ |
161 | char ox[2]; /* space for 0x hex-prefix */ |
Line -... | Line 162... | ||
- | 162 | ||
- | 163 | if(pPutchar == NULL) return; |
|
169 | 164 | ||
170 | va_start(ap, fmt0); |
165 | va_start(ap, fmt0); |
171 | 166 | ||
Line 172... | Line 167... | ||
172 | fmt = fmt0; |
167 | fmt = fmt0; |
173 | 168 | ||
174 | /* |
169 | /* |
175 | * Scan the format for conversions (`%' character). |
170 | * Scan the format for conversions (`%' character). |
176 | */ |
171 | */ |
177 | for (;;) { |
172 | for (;;) { |
178 | for (fmark = fmt; (ch = (*fmt)) != '\0' && ch != '%'; fmt++) |
173 | for (fmark = fmt; (ch = (*fmt)) != '\0' && ch != '%'; fmt++) |
179 | /* void */; |
174 | /* void */; |
180 | if ((n = fmt - fmark) != 0) { |
175 | if ((n = fmt - fmark) != 0) { |
181 | PRINTP(fmark, n); |
176 | PRINTP(pPutchar, fmark, n); |
182 | } |
177 | } |
183 | if (ch == '\0') |
178 | if (ch == '\0') |
Line 203... | Line 198... | ||
203 | register unsigned int _d; |
198 | register unsigned int _d; |
204 | _d=va_arg(ap, unsigned int); |
199 | _d=va_arg(ap, unsigned int); |
205 | _ulong = flags&SHORTINT ? (unsigned long)(unsigned short)_d : (unsigned long)_d; |
200 | _ulong = flags&SHORTINT ? (unsigned long)(unsigned short)_d : (unsigned long)_d; |
206 | } |
201 | } |
207 | } |
202 | } |
208 | 203 | ||
209 | #ifndef LIGHTPRINTF |
204 | #ifndef LIGHTPRINTF |
210 | if(ch==' ') { |
205 | if(ch==' ') { |
211 | /* |
206 | /* |
212 | * ``If the space and + flags both appear, the space |
207 | * ``If the space and + flags both appear, the space |
213 | * flag will be ignored.'' |
208 | * flag will be ignored.'' |
Line 287... | Line 282... | ||
287 | } else { |
282 | } else { |
288 | register int _d; |
283 | register int _d; |
289 | _d=va_arg(ap, int); |
284 | _d=va_arg(ap, int); |
290 | _ulong = flags&SHORTINT ? (long)(short)_d : (long)_d; |
285 | _ulong = flags&SHORTINT ? (long)(short)_d : (long)_d; |
291 | } |
286 | } |
292 | 287 | ||
293 | if ((long)_ulong < 0) { |
288 | if ((long)_ulong < 0) { |
294 | _ulong = -_ulong; |
289 | _ulong = -_ulong; |
295 | sign = '-'; |
290 | sign = '-'; |
296 | } |
291 | } |
297 | base = DEC; |
292 | base = DEC; |
298 | goto number; |
293 | goto number; |
299 | } else |
294 | } else |
300 | /* |
295 | /* |
301 | if (ch=='n') { |
296 | if (ch=='n') { |
302 | if (flags & LONGINT) |
297 | if (flags & LONGINT) |
303 | *va_arg(ap, long *) = ret; |
298 | *va_arg(ap, long *) = ret; |
304 | else if (flags & SHORTINT) |
299 | else if (flags & SHORTINT) |
305 | *va_arg(ap, short *) = ret; |
300 | *va_arg(ap, short *) = ret; |
306 | else |
301 | else |
307 | *va_arg(ap, int *) = ret; |
302 | *va_arg(ap, int *) = ret; |
308 | continue; // no output |
303 | continue; // no output |
309 | } else |
304 | } else |
310 | */ |
305 | */ |
311 | #ifndef LIGHTPRINTF |
306 | #ifndef LIGHTPRINTF |
312 | if (ch=='O'||ch=='o') { |
307 | if (ch=='O'||ch=='o') { |
313 | if (ch=='O') |
308 | if (ch=='O') |
314 | flags |= LONGINT; |
309 | flags |= LONGINT; |
315 | base = OCT; |
310 | base = OCT; |
316 | goto nosign; |
311 | goto nosign; |
Line 354... | Line 349... | ||
354 | size = prec; |
349 | size = prec; |
355 | } else |
350 | } else |
356 | size = strlen(cp); |
351 | size = strlen(cp); |
357 | sign = '\0'; |
352 | sign = '\0'; |
358 | } else |
353 | } else |
359 | #endif /* LIGHTPRINTF */ |
354 | #endif /* LIGHTPRINTF */ |
360 | if(ch=='U'||ch=='u') { |
355 | if(ch=='U'||ch=='u') { |
361 | if (ch=='U') |
356 | if (ch=='U') |
362 | flags |= LONGINT; |
357 | flags |= LONGINT; |
363 | base = DEC; |
358 | base = DEC; |
364 | goto nosign; |
359 | goto nosign; |
Line 398... | Line 393... | ||
398 | } |
393 | } |
399 | *--cp=_d; |
394 | *--cp=_d; |
400 | _ulong /= base; |
395 | _ulong /= base; |
401 | } while (notlastdigit); |
396 | } while (notlastdigit); |
402 | #ifndef LIGHTPRINTF |
397 | #ifndef LIGHTPRINTF |
403 | // handle octal leading 0 |
398 | // handle octal leading 0 |
404 | if (base==OCT && flags & ALT && *cp != '0') |
399 | if (base==OCT && flags & ALT && *cp != '0') |
405 | *--cp = '0'; |
400 | *--cp = '0'; |
406 | #endif |
401 | #endif |
407 | } |
402 | } |
Line 447... | Line 442... | ||
447 | fieldsz += 2; |
442 | fieldsz += 2; |
448 | fieldsz += dpad; |
443 | fieldsz += dpad; |
Line 449... | Line 444... | ||
449 | 444 | ||
450 | /* right-adjusting blank padding */ |
445 | /* right-adjusting blank padding */ |
451 | if ((flags & (LADJUST|ZEROPAD)) == 0) |
446 | if ((flags & (LADJUST|ZEROPAD)) == 0) |
Line 452... | Line 447... | ||
452 | PAD_SP(width - fieldsz); |
447 | PAD_SP(pPutchar, width - fieldsz); |
453 | 448 | ||
454 | /* prefix */ |
449 | /* prefix */ |
455 | if (sign) { |
450 | if (sign) { |
456 | PRINT(&sign, 1); |
451 | PRINT(pPutchar, &sign, 1); |
457 | } else if (flags & HEXPREFIX) { |
452 | } else if (flags & HEXPREFIX) { |
458 | ox[0] = '0'; |
453 | ox[0] = '0'; |
459 | ox[1] = ch; |
454 | ox[1] = ch; |
Line 460... | Line 455... | ||
460 | PRINT(ox, 2); |
455 | PRINT(pPutchar, ox, 2); |
461 | } |
456 | } |
462 | 457 | ||
Line 463... | Line 458... | ||
463 | /* right-adjusting zero padding */ |
458 | /* right-adjusting zero padding */ |
464 | if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) |
459 | if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD) |
Line 465... | Line 460... | ||
465 | PAD_0(width - fieldsz); |
460 | PAD_0(pPutchar, width - fieldsz); |
466 | 461 | ||
Line 467... | Line 462... | ||
467 | /* leading zeroes from decimal precision */ |
462 | /* leading zeroes from decimal precision */ |
468 | PAD_0(dpad); |
463 | PAD_0(pPutchar, dpad); |
469 | 464 | ||
470 | /* the string or number proper */ |
465 | /* the string or number proper */ |
471 | PRINT(cp, size); |
466 | PRINT(pPutchar, cp, size); |
472 | 467 | ||
473 | /* left-adjusting padding (always blank) */ |
468 | /* left-adjusting padding (always blank) */ |