X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2F_PDCLIB%2Fscan.c;h=f41079bd78ee98908e98642e14011ff3ac21718a;hb=8fca29703edff11c81af1e6039bcf115a83b6bbc;hp=c9826109cd56e9fe6af0fa0cd3e5b86564e4a74c;hpb=130aada9561127ae33af4dc4a5057c52e8718d2a;p=pdclib.old diff --git a/functions/_PDCLIB/scan.c b/functions/_PDCLIB/scan.c index c982610..f41079b 100644 --- a/functions/_PDCLIB/scan.c +++ b/functions/_PDCLIB/scan.c @@ -47,7 +47,7 @@ static int GET( struct _PDCLIB_status_t * status ) } else { - return *((status->s)++); + return ( *status->s == '\0' ) ? EOF : *((status->s)++); } } @@ -106,7 +106,12 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) strtol() will return zero. In both cases, endptr will point to the rest of the conversion specifier - just what we need. */ + char const * prev_spec = spec; status->width = (int)strtol( spec, (char**)&spec, 10 ); + if ( spec == prev_spec ) + { + status->width = SIZE_MAX; + } /* Optional length modifier We step one character ahead in any case, and step back only if we find @@ -209,7 +214,16 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) *(c++) = rc; value_parsed = true; } - return value_parsed ? spec : NULL; + if ( value_parsed ) + { + ++status->n; + return ++spec; + } + else + { + /* FIXME: Need two kinds of "no match" here: zero width, and input error */ + return NULL; + } } case 's': { @@ -239,7 +253,8 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) if ( value_parsed ) { *c = '\0'; - return spec; + ++status->n; + return ++spec; } else { @@ -366,8 +381,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) /* ASSIGN( E_size | E_unsigned, unsigned size_t ); */ ASSIGN( E_ptrdiff, ptrdiff_t ); /* ASSIGN( E_ptrdiff | E_unsigned, unsigned ptrdiff_t ); */ + default: + puts( "UNSUPPORTED SCANF FLAG COMBINATION" ); + return NULL; } - return spec; + return ++spec; } /* TODO: Floats. */ return NULL; @@ -376,10 +394,13 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) #ifdef TEST #include <_PDCLIB_test.h> +#include + + int main( void ) { - TESTCASE( NO_TESTDRIVER ); + /* Testing covered by fscanf.c */ return TEST_RESULTS; }