(formatting: case indent)

This commit is contained in:
Lephenixnoir 2024-01-14 20:23:55 +01:00
parent 55ae7df318
commit 5b85d53826
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495

View file

@ -248,183 +248,183 @@ int __scanf(
pos++; pos++;
switch( format[pos] ) { switch(format[pos]) {
// we need to decrypt the corresponding scanf set of character // we need to decrypt the corresponding scanf set of character
case '[': { case '[': {
err = __scanset( format, &pos ); err = __scanset( format, &pos );
if (err!=0) return validrets; if (err!=0) return validrets;
int currentlength = 0; int currentlength = 0;
// we need to assign the read char to the corresponding pointer // we need to assign the read char to the corresponding pointer
char *c = skip ? NULL : va_arg(*args, char *); char *c = skip ? NULL : va_arg(*args, char *);
for(int u=0; u<readmaxlength; u++) { for(int u=0; u<readmaxlength; u++) {
int temp = __scanf_peek(in); int temp = __scanf_peek(in);
if(__is_allowed(temp)) { if(__is_allowed(temp)) {
__scanf_in(in); __scanf_in(in);
if(c) *c++ = temp; if(c) *c++ = temp;
currentlength++; currentlength++;
}
else if(temp==EOF && !currentlength && !validrets)
return EOF;
else break;
} }
if(!currentlength) else if(temp==EOF && !currentlength && !validrets)
return validrets; return EOF;
*c = '\0'; else break;
validrets += !skip;
break;
} }
if(!currentlength)
// return the number of char read so far (cannot be skipped %*n is not valid) return validrets;
case 'n': *c = '\0';
*va_arg(*args, int *) = in->bytes_read; validrets += !skip;
break; break;
}
// we are expecting the char '%' to be in the input stream, if not err and return // return the number of char read so far (cannot be skipped %*n is not valid)
case '%': { case 'n':
if (__scanf_peek(in) != '%') return validrets; *va_arg(*args, int *) = in->bytes_read;
else __scanf_in( in ); break;
break;
}
// the next read, even if valid, will not be stored // we are expecting the char '%' to be in the input stream, if not err and return
case '*': case '%': {
skip = true; if (__scanf_peek(in) != '%') return validrets;
goto loopagain; else __scanf_in( in );
break;
}
case 'h': // the next read, even if valid, will not be stored
MOD = (size_letter == 'h') ? sizeof(char) : sizeof(short); case '*':
size_letter = 'h'; skip = true;
goto loopagain; goto loopagain;
case 'l':
MOD = (size_letter == 'l') ? sizeof(long long) : sizeof(long);
/* FP conversions will adjust to sizeof(double) later */
size_letter = 'l';
goto loopagain;
case 'L':
MOD = sizeof(long double);
size_letter = 'L';
goto loopagain;
case 'j':
MOD = sizeof(intmax_t);
goto loopagain;
case 'z':
MOD = sizeof(size_t);
goto loopagain;
case 't':
MOD = sizeof(ptrdiff_t);
goto loopagain;
case '0' ... '9': { case 'h':
user_length = user_length * 10 + (int) ( format[pos] - '0' ); MOD = (size_letter == 'h') ? sizeof(char) : sizeof(short);
readmaxlength = user_length; size_letter = 'h';
goto loopagain; goto loopagain;
break; case 'l':
} MOD = (size_letter == 'l') ? sizeof(long long) : sizeof(long);
/* FP conversions will adjust to sizeof(double) later */
size_letter = 'l';
goto loopagain;
case 'L':
MOD = sizeof(long double);
size_letter = 'L';
goto loopagain;
case 'j':
MOD = sizeof(intmax_t);
goto loopagain;
case 'z':
MOD = sizeof(size_t);
goto loopagain;
case 't':
MOD = sizeof(ptrdiff_t);
goto loopagain;
case 'd': case '0' ... '9': {
case 'i': user_length = user_length * 10 + (int) ( format[pos] - '0' );
case 'o': readmaxlength = user_length;
case 'u': goto loopagain;
case 'x': break;
case 'X': { }
int f = format[pos];
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; case 'd':
err = __strto_int(in, base, NULL, &temp, use_unsigned, case 'i':
case 'o':
case 'u':
case 'x':
case 'X': {
int f = format[pos];
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;
err = __strto_int(in, base, NULL, &temp, use_unsigned,
readmaxlength);
if (err == EOF && validrets == 0) return EOF;
if (err != 0) return validrets;
if (skip) __scanf_store_i( temp, 0, args );
else __scanf_store_i( temp, MOD, args );
validrets++;
break;
}
case 'a':
case 'A':
case 'e':
case 'E':
case 'f':
case 'F':
case 'g':
case 'G': {
/* Adjust interpretation of no size / 'l' size */
if(size_letter == 0)
MOD = sizeof(float);
if(size_letter == 'l')
MOD = sizeof(double);
// read a double from the current input stream
// and store in the corresponding arg as a char by reference
long double temp;
err = __strto_fp( in, NULL, NULL, &temp,
readmaxlength);
if (err == EOF && validrets == 0) return EOF;
if (err != 0) return validrets;
if (skip) __scanf_store_d( temp, 0, args );
else __scanf_store_d( temp, MOD, args );
validrets++;
break;
}
case 'p': {
long int temp;
if (!skip) {
void *p = (void *) va_arg( *args, void** ); // get the adress of the target pointer (void**)
err = __strto_int( in, 0, p, NULL, true,
readmaxlength); readmaxlength);
if (err == EOF && validrets == 0) return EOF;
if (err != 0) return validrets;
if (skip) __scanf_store_i( temp, 0, args );
else __scanf_store_i( temp, MOD, args );
validrets++;
break;
} }
else err = __strto_int( in, 0, &temp, NULL, true,
readmaxlength);
if (err == 0) validrets++;
else return validrets;
skip = false;
break;
}
case 'a': case 'c': {
case 'A': if(readmaxlength == INT_MAX)
case 'e': readmaxlength = 1;
case 'E': char *c = skip ? NULL : va_arg(*args, char *);
case 'f':
case 'F':
case 'g':
case 'G': {
/* Adjust interpretation of no size / 'l' size */
if(size_letter == 0)
MOD = sizeof(float);
if(size_letter == 'l')
MOD = sizeof(double);
// read a double from the current input stream for(int u = 0; u < readmaxlength; u++) {
// and store in the corresponding arg as a char by reference int temp = __scanf_in(in);
long double temp; if(temp==EOF) return EOF;
err = __strto_fp( in, NULL, NULL, &temp, else if(c) *c++ = temp;
readmaxlength);
if (err == EOF && validrets == 0) return EOF;
if (err != 0) return validrets;
if (skip) __scanf_store_d( temp, 0, args );
else __scanf_store_d( temp, MOD, args );
validrets++;
break;
}
case 'p': {
long int temp;
if (!skip) {
void *p = (void *) va_arg( *args, void** ); // get the adress of the target pointer (void**)
err = __strto_int( in, 0, p, NULL, true,
readmaxlength);
}
else err = __strto_int( in, 0, &temp, NULL, true,
readmaxlength);
if (err == 0) validrets++;
else return validrets;
skip = false;
break;
} }
validrets += !skip;
break;
}
case 'c': { case 's': {
if(readmaxlength == INT_MAX) char temp;
readmaxlength = 1; int curstrlength = 0;
char *c = skip ? NULL : va_arg(*args, char *); __purge_space(in);
for(int u = 0; u < readmaxlength; u++) { char *c = skip ? NULL : va_arg(*args, char *);
int temp = __scanf_in(in); for(int u = 0; u < readmaxlength; u++) {
if(temp==EOF) return EOF; temp = __scanf_peek(in);
else if(c) *c++ = temp; if(temp==EOF && curstrlength==0) return validrets;
} if(isspace(temp) || ((temp==EOF && curstrlength!=0))) {
validrets += !skip; if(c) {
break; *c = 0;
} validrets++;
case 's': {
char temp;
int curstrlength = 0;
__purge_space(in);
char *c = skip ? NULL : va_arg(*args, char *);
for(int u = 0; u < readmaxlength; u++) {
temp = __scanf_peek(in);
if(temp==EOF && curstrlength==0) return validrets;
if(isspace(temp) || ((temp==EOF && curstrlength!=0))) {
if(c) {
*c = 0;
validrets++;
}
break;
}
else {
int temp = __scanf_in( in );
if(c)
*c++ = temp;
curstrlength++;
} }
break;
}
else {
int temp = __scanf_in( in );
if(c)
*c++ = temp;
curstrlength++;
} }
break;
} }
break;
}
} }
} }
// we are looking for a specific character in the input stream // we are looking for a specific character in the input stream