]> pd.if.org Git - pdclib/blob - functions/stdio/vfscanf.c
Started debugging scanf() functions.
[pdclib] / functions / stdio / vfscanf.c
1 /* $Id$ */
2
3 /* vfscanf( 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 <ctype.h>
12
13 #ifndef REGTEST
14
15 int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg )
16 {
17     struct _PDCLIB_status_t status;
18     status.base = 0;
19     status.flags = 0;
20     status.n = 0; 
21     status.i = 0;
22     status.this = 0;
23     status.s = NULL;
24     status.width = 0;
25     status.prec = 0;
26     status.stream = stream;
27     va_copy( status.arg, arg );
28     while ( *format != '\0' )
29     {
30         const char * rc;
31         if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) )
32         {
33             /* No conversion specifier, match verbatim */
34             if ( isspace( *format ) )
35             {
36                 /* Whitespace char in format string: Skip all whitespaces */
37                 /* No whitespaces in input do not result in matching error */
38                 while ( isspace( *status.s ) )
39                 {
40                     ++status.s;
41                     ++status.i;
42                 }
43             }
44             else
45             {
46                 /* Non-whitespace char in format string: Match verbatim */
47                 if ( *status.s != *format )
48                 {
49                     /* Matching error */
50                     return status.n;
51                 }
52                 else
53                 {
54                     ++status.s;
55                     ++status.i;
56                 }
57             }
58             ++format;
59         }
60         else
61         {
62             /* Continue parsing after conversion specifier */
63             format = rc;
64         }
65     }
66     va_end( status.arg );
67     return status.n;
68 }
69
70 #endif
71
72 #ifdef TEST
73 #include <_PDCLIB_test.h>
74
75 int main( void )
76 {
77     TESTCASE( NO_TESTDRIVER );
78     return TEST_RESULTS;
79 }
80
81 #endif