]> pd.if.org Git - pdclib/blob - functions/stdio/vfprintf.c
Comment cleanups.
[pdclib] / functions / stdio / vfprintf.c
1 /* vfprintf( FILE *, const char *, va_list )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <stdint.h>
10
11 #ifndef REGTEST
12
13 int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg )
14 {
15     /* TODO: This function should interpret format as multibyte characters.  */
16     struct _PDCLIB_status_t status;
17     status.base = 0;
18     status.flags = 0;
19     status.n = SIZE_MAX;
20     status.i = 0;
21     status.current = 0;
22     status.s = NULL;
23     status.width = 0;
24     status.prec = 0;
25     status.stream = stream;
26     va_copy( status.arg, arg );
27
28     while ( *format != '\0' )
29     {
30         const char * rc;
31         if ( ( *format != '%' ) || ( ( rc = _PDCLIB_print( format, &status ) ) == format ) )
32         {
33             /* No conversion specifier, print verbatim */
34             putc( *(format++), stream );
35             status.i++;
36         }
37         else
38         {
39             /* Continue parsing after conversion specifier */
40             format = rc;
41         }
42     }
43     va_end( status.arg );
44     return status.i;
45 }
46
47 #endif
48
49 #ifdef TEST
50 #define _PDCLIB_FILEID "stdio/vfprintf.c"
51 #define _PDCLIB_FILEIO
52
53 #include <_PDCLIB_test.h>
54
55 static int testprintf( FILE * stream, const char * format, ... )
56 {
57     int i;
58     va_list arg;
59     va_start( arg, format );
60     i = vfprintf( stream, format, arg );
61     va_end( arg );
62     return i;
63 }
64
65 int main( void )
66 {
67     FILE * target;
68     TESTCASE( ( target = tmpfile() ) != NULL );
69 #include "printf_testcases.h"
70     TESTCASE( fclose( target ) == 0 );
71     return TEST_RESULTS;
72 }
73
74 #endif