(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 validrets;
*c = '\0';
validrets += !skip;
break;
}
// return the number of char read so far (cannot be skipped %*n is not valid) // return the number of char read so far (cannot be skipped %*n is not valid)
case 'n': case 'n':
*va_arg(*args, int *) = in->bytes_read; *va_arg(*args, int *) = in->bytes_read;
break; break;
// we are expecting the char '%' to be in the input stream, if not err and return // we are expecting the char '%' to be in the input stream, if not err and return
case '%': { case '%': {
if (__scanf_peek(in) != '%') return validrets; if (__scanf_peek(in) != '%') return validrets;
else __scanf_in( in ); else __scanf_in( in );
break; break;
} }
// the next read, even if valid, will not be stored // the next read, even if valid, will not be stored
case '*': case '*':
skip = true; skip = true;
goto loopagain; goto loopagain;
case 'h': case 'h':
MOD = (size_letter == 'h') ? sizeof(char) : sizeof(short); MOD = (size_letter == 'h') ? sizeof(char) : sizeof(short);
size_letter = 'h'; size_letter = 'h';
goto loopagain; goto loopagain;
case 'l': case 'l':
MOD = (size_letter == 'l') ? sizeof(long long) : sizeof(long); MOD = (size_letter == 'l') ? sizeof(long long) : sizeof(long);
/* FP conversions will adjust to sizeof(double) later */ /* FP conversions will adjust to sizeof(double) later */
size_letter = 'l'; size_letter = 'l';
goto loopagain; goto loopagain;
case 'L': case 'L':
MOD = sizeof(long double); MOD = sizeof(long double);
size_letter = 'L'; size_letter = 'L';
goto loopagain; goto loopagain;
case 'j': case 'j':
MOD = sizeof(intmax_t); MOD = sizeof(intmax_t);
goto loopagain; goto loopagain;
case 'z': case 'z':
MOD = sizeof(size_t); MOD = sizeof(size_t);
goto loopagain; goto loopagain;
case 't': case 't':
MOD = sizeof(ptrdiff_t); MOD = sizeof(ptrdiff_t);
goto loopagain; goto loopagain;
case '0' ... '9': { case '0' ... '9': {
user_length = user_length * 10 + (int) ( format[pos] - '0' ); user_length = user_length * 10 + (int) ( format[pos] - '0' );
readmaxlength = user_length; readmaxlength = user_length;
goto loopagain; goto loopagain;
break; break;
} }
case 'd': case 'd':
case 'i': case 'i':
case 'o': case 'o':
case 'u': case 'u':
case 'x': case 'x':
case 'X': { case 'X': {
int f = format[pos]; int f = format[pos];
int base = (f == 'd' || f == 'u') ? 10 : int base = (f == 'd' || f == 'u') ? 10 :
(f == 'o') ? 8: (f == 'o') ? 8:
(f == 'x' || f == 'X') ? 16 : 0; (f == 'x' || f == 'X') ? 16 : 0;
bool use_unsigned = (f == 'o' || f == 'x' || f == 'X'); bool use_unsigned = (f == 'o' || f == 'x' || f == 'X');
long long int temp; long long int temp;
err = __strto_int(in, base, NULL, &temp, use_unsigned, 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;
} }
validrets += !skip;
break;
}
case 'p': { case 's': {
long int temp; char temp;
if (!skip) { int curstrlength = 0;
void *p = (void *) va_arg( *args, void** ); // get the adress of the target pointer (void**) __purge_space(in);
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;
}
case 'c': { char *c = skip ? NULL : va_arg(*args, char *);
if(readmaxlength == INT_MAX) for(int u = 0; u < readmaxlength; u++) {
readmaxlength = 1; temp = __scanf_peek(in);
char *c = skip ? NULL : va_arg(*args, char *); if(temp==EOF && curstrlength==0) return validrets;
if(isspace(temp) || ((temp==EOF && curstrlength!=0))) {
for(int u = 0; u < readmaxlength; u++) { if(c) {
int temp = __scanf_in(in); *c = 0;
if(temp==EOF) return EOF; validrets++;
else if(c) *c++ = temp;
}
validrets += !skip;
break;
}
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