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