X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=functions%2F_PDCLIB%2Fscan.c;h=ccd3cdb9a01cb6003531780406a75e85e80b508d;hb=d865c4403fc91d1f1ac95ba76febcee9f429bb97;hp=6910aef66f3b60586f16a164d395128a8615960e;hpb=6a0967a533b77ae2113da317450ca48e8569a12b;p=pdclib diff --git a/functions/_PDCLIB/scan.c b/functions/_PDCLIB/scan.c index 6910aef..ccd3cdb 100644 --- a/functions/_PDCLIB/scan.c +++ b/functions/_PDCLIB/scan.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /* _PDCLIB_scan( const char *, struct _PDCLIB_status_t * ) This file is part of the Public Domain C Library (PDCLib). @@ -16,6 +14,8 @@ #include #include +#ifndef REGTEST + /* Using an integer's bits as flags for both the conversion flags and length modifiers. */ @@ -27,7 +27,7 @@ #define E_intmax 1<<10 #define E_size 1<<11 #define E_ptrdiff 1<<12 -#define E_intptr 1<<13 +#define E_pointer 1<<13 #define E_ldouble 1<<14 #define E_unsigned 1<<16 @@ -285,7 +285,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) case 's': { char * c = va_arg( status->arg, char * ); - while ( ( status->current < status->width ) && + while ( ( status->current < status->width ) && ( ( rc = GET( status ) ) != EOF ) ) { if ( isspace( rc ) ) @@ -345,7 +345,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) } while ( *endspec != ']' ); // read according to scanlist, equiv. to %s above char * c = va_arg( status->arg, char * ); - while ( ( status->current < status->width ) && + while ( ( status->current < status->width ) && ( ( rc = GET( status ) ) != EOF ) ) { if ( negative_scanlist ) @@ -384,7 +384,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) } case 'p': status->base = 16; - status->flags |= E_unsigned; + status->flags |= E_pointer; break; case 'n': { @@ -522,7 +522,7 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) if ( ! ( status->flags & E_suppressed ) ) { switch ( status->flags & ( E_char | E_short | E_long | E_llong | - E_intmax | E_size | E_ptrdiff | + E_intmax | E_size | E_ptrdiff | E_pointer | E_unsigned ) ) { case E_char: @@ -577,6 +577,11 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) *( va_arg( status->arg, ptrdiff_t * ) ) = (ptrdiff_t)( value * sign ); break; + case E_pointer: + /* E_pointer always implies unsigned */ + *( uintptr_t* )( va_arg( status->arg, void * ) ) = (uintptr_t)( value * sign ); + break; + default: puts( "UNSUPPORTED SCANF FLAG COMBINATION" ); return NULL; /* behaviour unspecified */ @@ -589,12 +594,15 @@ const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) return NULL; } +#endif #ifdef TEST #define _PDCLIB_FILEID "_PDCLIB/scan.c" #define _PDCLIB_STRINGIO -#include <_PDCLIB_test.h> +#include "_PDCLIB_test.h" + +#ifndef REGTEST static int testscanf( char const * s, char const * format, ... ) { @@ -613,12 +621,16 @@ static int testscanf( char const * s, char const * format, ... ) return status.n; } +#endif + #define TEST_CONVERSION_ONLY int main( void ) { +#ifndef REGTEST char source[100]; #include "scanf_testcases.h" +#endif return TEST_RESULTS; }