From c07ec996170cb522e4ac8179c332dfbca2d8de5b Mon Sep 17 00:00:00 2001 From: solar Date: Thu, 8 Apr 2010 08:37:21 +0000 Subject: [PATCH] No more errors from _PDCLIB_scan tests. Yay... --- functions/_PDCLIB/scan.c | 52 ++++++++++++++++++++++++++++++++++++---- functions/stdio/sscanf.c | 4 +++- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/functions/_PDCLIB/scan.c b/functions/_PDCLIB/scan.c index 63afff2..8aaabfb 100644 --- a/functions/_PDCLIB/scan.c +++ b/functions/_PDCLIB/scan.c @@ -88,10 +88,40 @@ static void UNGET( int c, struct _PDCLIB_status_t * status ) /* Helper function to check if a character is part of a given scanset */ -static bool NOT_IN_SCANSET( const char * start_scanlist, const char * end_scanlist, bool negate_scanlist, int rc ) +static bool IN_SCANSET( const char * scanlist, const char * end_scanlist, int rc ) { // SOLAR - return true; + int previous = -1; + while ( scanlist != end_scanlist ) + { + if ( ( *scanlist == '-' ) && ( previous != -1 ) ) + { + /* possible scangroup ("a-z") */ + if ( ++scanlist == end_scanlist ) + { + /* '-' at end of scanlist does not describe a scangroup */ + return rc == '-'; + } + while ( ++previous <= (unsigned char)*scanlist ) + { + if ( previous == rc ) + { + return true; + } + } + previous = -1; + } + else + { + /* not a scangroup, check verbatim */ + if ( rc == (unsigned char)*scanlist ) + { + return true; + } + previous = (unsigned char)(*scanlist++); + } + } + return false; } @@ -330,9 +360,21 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) while ( ( status->this < status->width ) && ( ( rc = GET( status ) ) != EOF ) ) { - if ( NOT_IN_SCANSET( spec, endspec, negative_scanlist, rc ) ) + if ( negative_scanlist ) { - break; + if ( IN_SCANSET( spec, endspec, rc ) ) + { + UNGET( rc, status ); + break; + } + } + else + { + if ( ! IN_SCANSET( spec, endspec, rc ) ) + { + UNGET( rc, status ); + break; + } } value_parsed = true; *(c++) = rc; @@ -345,7 +387,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) } else { - if ( status->n == 0 ) + if ( rc == EOF ) { status->n = -1; } diff --git a/functions/stdio/sscanf.c b/functions/stdio/sscanf.c index 343f8ec..477ed67 100644 --- a/functions/stdio/sscanf.c +++ b/functions/stdio/sscanf.c @@ -1544,7 +1544,9 @@ void suite_five() // missing on first character memset( buffer, '\0', BUFSIZE ); int n; - CHECK_EQUAL( sscanf( string + 0, "%[b]%n", buffer, &n ), 0 ); + int rc_ = sscanf( string + 0, "%[b]%n", buffer, &n ); + CHECK_EQUAL( rc_, 0 ); + //CHECK_EQUAL( sscanf( string + 0, "%[b]%n", buffer, &n ), 0 ); CHECK_FALSE( memcmp( buffer, "", 1 ) ); } { -- 2.40.0