mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 04:23:38 +01:00
stdio: make all scanf tests pass
The tests are still far from exhaustive but that's a good start.
This commit is contained in:
parent
b61cc096d9
commit
2215b3c267
9 changed files with 26 additions and 61 deletions
|
@ -449,65 +449,26 @@ int __scanf(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'd': {
|
case 'd':
|
||||||
// read a long int (in base 10 - decimal) from the current input stream
|
case 'i':
|
||||||
// and store in the corresponding arg as a char by reference
|
case 'o':
|
||||||
long long int temp;
|
case 'u':
|
||||||
err = __strto_int( in, 10, NULL, &temp, false ); // base is 10 as for strtol
|
|
||||||
if (err != 0) return validrets;
|
|
||||||
if (skip) __scanf_store_i( temp, MODSKIP, args );
|
|
||||||
else __scanf_store_i( temp, MOD, args );
|
|
||||||
validrets++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'i': {
|
|
||||||
// read a signed int (base to be defined at read) from the current input stream
|
|
||||||
// and store in the corresponding arg as a char by reference
|
|
||||||
long long int temp;
|
|
||||||
err = __strto_int( in, 0, NULL, &temp, false ); // base is 0 as for strtol
|
|
||||||
if (err != 0) return validrets;
|
|
||||||
if (skip) __scanf_store_i( temp, MODSKIP, args );
|
|
||||||
else __scanf_store_i( temp, MOD, args );
|
|
||||||
validrets++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'u': {
|
|
||||||
// read a unsigned int (in base 10 - decimal) from the current input stream
|
|
||||||
// and store in the corresponding arg as a char by reference
|
|
||||||
long long int temp;
|
|
||||||
err = __strto_int( in, 10, NULL, &temp, false ); // base is 10 as for strtol - use_unsigned must be false (validated with glibc6.2 behaviour)
|
|
||||||
if (err != 0) return validrets;
|
|
||||||
if (skip) __scanf_store_i( temp, MODSKIP, args );
|
|
||||||
else __scanf_store_i( temp, MOD, args );
|
|
||||||
validrets++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'o': {
|
|
||||||
// read a unsigned int (in base 8 - octal) from the current input stream
|
|
||||||
// and store in the corresponding arg as a char by reference
|
|
||||||
long long int temp;
|
|
||||||
err = __strto_int( in, 8, NULL, &temp, true ); // base is 8 as for strtol
|
|
||||||
if (err != 0) return validrets;
|
|
||||||
if (skip) __scanf_store_i( temp, MODSKIP, args );
|
|
||||||
else __scanf_store_i( temp, MOD, args );
|
|
||||||
validrets++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
case 'X': {
|
case 'X': {
|
||||||
// read a unsigned int (in base 16 - hexadecimal) from the current input stream
|
int f = format[pos];
|
||||||
// and store in the corresponding arg as a char by reference
|
int base = (f == 'd' || f == 'u') ? 10 :
|
||||||
|
(f == 'o') ? 8:
|
||||||
|
(f == 'x' || f == 'X') ? 16 : 0;
|
||||||
|
bool use_unsigned = (f == 'o' || f == 'x' || f == 'X');
|
||||||
|
|
||||||
long long int temp;
|
long long int temp;
|
||||||
err = __strto_int( in, 16, NULL, &temp, true ); // base is 16 as for strtol
|
err = __strto_int(in, base, NULL, &temp, use_unsigned);
|
||||||
if (err != 0) return validrets;
|
if (err == EOF && validrets == 0) return EOF;
|
||||||
|
if (err != 0) return validrets;
|
||||||
if (skip) __scanf_store_i( temp, MODSKIP, args );
|
if (skip) __scanf_store_i( temp, MODSKIP, args );
|
||||||
else __scanf_store_i( temp, MOD, args );
|
else __scanf_store_i( temp, MOD, args );
|
||||||
validrets++;
|
validrets++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
|
@ -522,7 +483,8 @@ int __scanf(
|
||||||
// and store in the corresponding arg as a char by reference
|
// and store in the corresponding arg as a char by reference
|
||||||
long double temp;
|
long double temp;
|
||||||
err = __strto_fp( in, NULL, NULL, &temp );
|
err = __strto_fp( in, NULL, NULL, &temp );
|
||||||
if (err != 0) return validrets;
|
if (err == EOF && validrets == 0) return EOF;
|
||||||
|
if (err != 0) return validrets;
|
||||||
if (skip) __scanf_store_d( temp, MODSKIP, args );
|
if (skip) __scanf_store_d( temp, MODSKIP, args );
|
||||||
else __scanf_store_d( temp, MOD, args );
|
else __scanf_store_d( temp, MOD, args );
|
||||||
validrets++;
|
validrets++;
|
||||||
|
|
|
@ -16,6 +16,7 @@ int __strto_int(struct __scanf_input *input, int base, long *outl,
|
||||||
/* Accept a sign character */
|
/* Accept a sign character */
|
||||||
bool negative = false;
|
bool negative = false;
|
||||||
int sign = __scanf_peek(input);
|
int sign = __scanf_peek(input);
|
||||||
|
if(sign == EOF) return EOF;
|
||||||
if(sign == '-') negative = true;
|
if(sign == '-') negative = true;
|
||||||
if(sign == '-' || sign == '+') __scanf_in(input);
|
if(sign == '-' || sign == '+') __scanf_in(input);
|
||||||
|
|
||||||
|
@ -39,6 +40,8 @@ int __strto_int(struct __scanf_input *input, int base, long *outl,
|
||||||
if(base == 0)
|
if(base == 0)
|
||||||
base = 8;
|
base = 8;
|
||||||
}
|
}
|
||||||
|
else if(__scanf_peek(input) == EOF)
|
||||||
|
return EOF;
|
||||||
if(base == 0)
|
if(base == 0)
|
||||||
base = 10;
|
base = 10;
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ double strtod(char const * restrict ptr, char ** restrict endptr)
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return d;
|
return d;
|
||||||
|
|
|
@ -13,7 +13,7 @@ float strtof(char const * restrict ptr, char ** restrict endptr)
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return f;
|
return f;
|
||||||
|
|
|
@ -19,7 +19,7 @@ long int strtol(char const * restrict ptr, char ** restrict endptr, int base)
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
@ -13,7 +13,7 @@ long double strtold(char const * restrict ptr, char ** restrict endptr)
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return ld;
|
return ld;
|
||||||
|
|
|
@ -14,7 +14,7 @@ long long int strtoll(char const * restrict ptr, char ** restrict endptr,
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
@ -14,7 +14,7 @@ unsigned long int strtoul(char const * restrict ptr, char ** restrict endptr,
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return n;
|
return n;
|
||||||
|
|
|
@ -14,7 +14,7 @@ unsigned long long int strtoull(char const * restrict ptr,
|
||||||
__scanf_end(&in);
|
__scanf_end(&in);
|
||||||
|
|
||||||
if(err != 0)
|
if(err != 0)
|
||||||
errno = err;
|
errno = (err == EOF) ? EINVAL : err;
|
||||||
if(err != EINVAL && endptr)
|
if(err != EINVAL && endptr)
|
||||||
*endptr = (char *)in.str;
|
*endptr = (char *)in.str;
|
||||||
return n;
|
return n;
|
||||||
|
|
Loading…
Reference in a new issue