1 // ----------------------------------------------------------------------------
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
8 int vfprintf( FILE * restrict stream, const char * restrict format, va_list ap ) { /* TODO */ };
10 /* PDPC code - unreviewed
14 ret = vvprintf(format, arg, stream, NULL);
33 else if (*format == '%')
40 vint = va_arg(arg, int);
49 *nptr++ = (char)('0' + vint % 10);
61 } while (nptr != numbuf);
63 else if (*format == 's')
65 vcptr = va_arg(arg, char *);
69 memcpy(s, vcptr, len);
76 chcount += strlen(vcptr);
79 else if (*format == 'c')
81 vint = va_arg(arg, int);
85 else if (*format == '%')
94 extraCh = examine(&format, fq, s, &arg, chcount);
112 static int examine(const char **formt, FILE *fq, char *s, va_list *arg,
128 unsigned long ulvalue;
142 /* processing flags */
148 case '-': flagMinus = 1;
150 case '+': flagPlus = 1;
152 case ' ': flagSpace = 1;
154 case '#': flagHash = 1;
156 case '0': flagZero = 1;
167 if (flagSpace && flagPlus)
178 /* processing width */
179 if (isdigit((unsigned char)*format))
181 while (isdigit((unsigned char)*format))
183 width = width * 10 + (*format - '0');
188 /* processing precision */
193 while (isdigit((unsigned char)*format))
195 precision = precision * 10 + (*format - '0');
200 /* processing h/l/L */
205 else if (*format == 'l')
209 else if (*format == 'L')
223 /* processing specifier */
226 if (strchr("dxXuiop", specifier) != NULL)
228 #if defined(__MSDOS__) && !defined(__PDOS__)
229 if (specifier == 'p')
236 lvalue = va_arg(*arg, long);
240 lvalue = va_arg(*arg, short);
244 lvalue = va_arg(*arg, int);
246 ulvalue = (unsigned long)lvalue;
247 if ((lvalue < 0) && ((specifier == 'd') || (specifier == 'i')))
256 if ((specifier == 'X') || (specifier == 'x') || (specifier == 'p'))
260 else if (specifier == 'o')
268 if (specifier == 'p')
270 #if defined(__OS2__) || defined(__PDOS__)
273 #if defined(__MSDOS__) && !defined(__PDOS__)
280 rem = (int)(ulvalue % base);
283 work[x] = (char)('0' + rem);
287 if ((specifier == 'X') || (specifier == 'p'))
289 work[x] = (char)('A' + (rem - 10));
293 work[x] = (char)('a' + (rem - 10));
297 #if defined(__MSDOS__) && !defined(__PDOS__)
298 if ((x == 4) && (specifier == 'p'))
304 ulvalue = ulvalue / base;
306 while (x < precision)
333 if (flagHash && (toupper(specifier) == 'X'))
356 else if (specifier == 's')
358 svalue = va_arg(*arg, char *);
364 p = memchr(svalue, '\0', precision);
367 length = (int)(p - svalue);
376 length = strlen(svalue);
382 extraCh += (width - length);
383 for (x = 0; x < (width - length); x++)
389 for (x = 0; x < length; x++)
398 extraCh += (width - length);
399 for (x = 0; x < (width - length); x++)