Subversion Repositories NaviCtrl

Rev

Rev 41 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 41 Rev 203
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
{
-
 
98
   DisplayBuff[DispPtr++] = zeichen;
-
 
99
   return(1);
-
 
100
}
-
 
101
 
-
 
102
 
-
 
103
void PRINT(const char * ptr, unsigned int len) {
95
{
104
        for(;len;len--)
96
        for(;len;len--)
105
                Putchar(*ptr++);
97
                (*pPutchar)(*ptr++);
Line 106... Line 98...
106
}
98
}
-
 
99
 
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--)
Line 138... Line 131...
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 */
141
#define HEXPREFIX       0x40            /* add 0x or 0X prefix */
134
#define HEXPREFIX       0x40            /* add 0x or 0X prefix */
Line 142... Line 135...
142
 
135
 
143
void _printf_P (char const *fmt0, ...)      /* Works with string from FLASH */
136
void _printf_P (pVoidFnctChar pPutchar, char const *fmt0, ...)
144
{
137
{
145
        va_list ap;
138
        va_list ap;
146
        register const char *fmt; /* format string */
139
        register const char *fmt; /* format string */
147
        register char ch;       /* character from fmt */
140
        register char ch;       /* character from fmt */
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
 
Line 170... Line 165...
170
        va_start(ap, fmt0);
165
        va_start(ap, fmt0);
Line 171... Line 166...
171
       
166
 
Line 176... Line 171...
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')
184
                        goto done;
179
                        goto done;
185
                fmt++;          /* skip over '%' */
180
                fmt++;          /* skip over '%' */
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) */