3 /* _PDCLIB_scan( const char *, struct _PDCLIB_status_t * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
14 /* Using an integer's bits as flags for both the conversion flags and length
17 #define E_suppressed 1<<0
22 #define E_intmax 1<<10
24 #define E_ptrdiff 1<<12
25 #define E_intptr 1<<13
26 #define E_ldouble 1<<14
27 #define E_unsigned 1<<16
30 static bool MATCH( const char x, struct _PDCLIB_status_t * status )
32 if ( status->stream != NULL )
34 /* Matching against stream */
35 if ( status->stream->buffer[ status->stream->bufidx ] == x )
37 getc( status->stream );
48 /* Matching against string */
49 if ( *(status->s) == x )
63 const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status )
65 const char * orig_spec = spec;
66 if ( *(++spec) == '%' )
68 /* %% -> match single '%' */
69 MATCH( *spec, status );
72 /* Initializing status structure */
79 /* '*' suppresses assigning parsed value to variable */
82 status->flags |= E_suppressed;
86 /* If a width is given, strtol() will return its value. If not given,
87 strtol() will return zero. In both cases, endptr will point to the
88 rest of the conversion specifier - just what we need.
90 status->width = (int)strtol( spec, (char**)&spec, 10 );
92 /* Optional length modifier
93 We step one character ahead in any case, and step back only if we find
94 there has been no length modifier (or step ahead another character if it
95 has been "hh" or "ll").
103 status->flags |= E_char;
109 status->flags |= E_short;
115 /* ll -> long long */
116 status->flags |= E_llong;
122 status->flags |= E_long;
126 /* j -> intmax_t, which might or might not be long long */
127 status->flags |= E_intmax;
130 /* z -> size_t, which might or might not be unsigned int */
131 status->flags |= E_size;
134 /* t -> ptrdiff_t, which might or might not be long */
135 status->flags |= E_ptrdiff;
138 /* L -> long double */
139 status->flags |= E_ldouble;
146 /* Conversion specifier */
153 /* status->base = 0; */
157 status->flags |= E_unsigned;
161 status->flags |= E_unsigned;
165 status->flags |= E_unsigned;
185 status->flags |= E_unsigned;
189 int * val = va_arg( status->arg, int * );
194 /* No conversion specifier. Bad conversion. */
197 /* TODO: Actual conversions */
202 #include <_PDCLIB_test.h>
206 TESTCASE( NO_TESTDRIVER );