X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc.so_src%2Fscanf.c;h=6fff1764be0e3e1962e314e2cde477ce1a59111c;hb=98bd9c0c8985c50c42231c116a4e18fedd47761e;hp=3a561c4bc21e23e12f6679ef470ea1ba61639caf;hpb=f194730e75d6d3681e5f99a4efed1616fd1ea738;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc.so_src/scanf.c b/Usermode/Libraries/libc.so_src/scanf.c index 3a561c4b..6fff1764 100644 --- a/Usermode/Libraries/libc.so_src/scanf.c +++ b/Usermode/Libraries/libc.so_src/scanf.c @@ -148,9 +148,12 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char } ptr; long long ival; //long double rval; - int maxlen = 0, offset = -1; + int maxlen = 0; + // int offset = -1; enum e_vcscanf_sizes size = _VCSCANF_UNDEF; enum e_vcscanf_types valtype; + int fail = 0; + int nnewch; const char *set_start; int set_len; @@ -160,6 +163,7 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char { while( (ich = __getc(h)) && isspace(ich) ) nch ++; + if(ich) __rewind(h); continue ; } @@ -185,12 +189,14 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char } // %n$ - Direct offset selection, shouldn't be mixed with just % + #if 0 for( ; isdigit(fch); fch = *format++ ) maxlen = maxlen * 10 + (fch - '0'); if( fch == '$' ) { offset = maxlen; maxlen = 0; } + #endif // Supress assignemnt? if( fch == '*' ) @@ -259,22 +265,30 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char { // Decimal integer case 'd': - nch += _vcscanf_int(__getc, __rewind, h, 10, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 10, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // variable-base integer case 'i': - nch += _vcscanf_int(__getc, __rewind, h, 0, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 0, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // Octal integer case 'o': - nch += _vcscanf_int(__getc, __rewind, h, 8, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 8, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // Hexadecimal integer case 'x': case 'X': - nch += _vcscanf_int(__getc, __rewind, h, 16, maxlen, &ival); + nnewch = _vcscanf_int(__getc, __rewind, h, 16, maxlen, &ival); + if(nnewch==0) fail=1; + nch += nnewch; valtype = _VCSCANF_INT; break; // strtod format float @@ -301,21 +315,22 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char maxlen = -1; ich = 0; - while( maxlen -- && (ich = __getc(h)) && !isblank(ich) ) + while( maxlen -- && (ich = __getc(h)) && !isspace(ich) ) { if(ptr._char) *ptr._char++ = ich; nch ++; } if( maxlen >= 0 && ich ) __rewind(h); + if(ptr._char) *ptr._char++ = 0; valtype = _VCSCANF_NOTYPE; break; // match a set of characters - case '[': - fch = *format++; - if( fch == '^' ) { + case '[': { + int invert = 0; + if( *format++ == '^' ) { // Invert - fch = *format; + invert = 1; } set_start = format; set_len = 0; @@ -326,16 +341,20 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char fch = *format++; } while( fch && fch != ']' ); + if( maxlen == 0 ) + maxlen = -1; ich = 0; - while( maxlen -- && (ich = __getc(h)) && memchr(set_start, set_len, ich) ) + while( maxlen -- && (ich = __getc(h)) && invert == !memchr(set_start, set_len, ich) ) { if(ptr._char) *ptr._char++ = ich; nch ++; } if( maxlen >= 0 && ich ) __rewind(h); + if(ptr._char) *ptr._char++ = 0; valtype = _VCSCANF_NOTYPE; break; + } case 'p': // read back printf("%p") valtype = _VCSCANF_NOTYPE; break; @@ -351,7 +370,10 @@ int _vcscanf(int (*__getc)(void*), void (*__rewind)(void*), void *h, const char valtype = _VCSCANF_NOTYPE; break; } - + + if(fail) + break; + switch(valtype) { case _VCSCANF_NOTYPE: @@ -403,7 +425,8 @@ int vsscanf(const char *str, const char *format, va_list ap) int _vfscanf_getc(void *h) { - return fgetc(h); // TODO: Handle -1 -> 0 + int ch = fgetc(h); + return ch == -1 ? 0 : ch; } void _vfscanf_rewind(void *h) {