diff options
author | Jakob Kaivo <jkk@ung.org> | 2024-06-06 17:02:32 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2024-06-06 17:02:32 -0400 |
commit | d8353afab7c754968ebbaa8fa1cd3f6f4b83d86e (patch) | |
tree | 077bfbff86d29acbd06693bc19def74b7743749d /src/stdio/__scanf.c | |
parent | 5da931dfa4b3846b1ca459290a6724eb67d1685c (diff) |
rework formatted I/O to do most validation in __conv(), use __conv() from __printf(), implement more and more robust __printf() functionality
Diffstat (limited to 'src/stdio/__scanf.c')
-rw-r--r-- | src/stdio/__scanf.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/stdio/__scanf.c b/src/stdio/__scanf.c index 9869fa37..5e43303e 100644 --- a/src/stdio/__scanf.c +++ b/src/stdio/__scanf.c @@ -126,7 +126,10 @@ int __scanf(struct io_options *opt, const char * format, va_list arg) } while (*format) { - struct io_conversion conv = { .dir = IO_IN }; + struct io_conversion conv = { + .func = opt->fnname, + .dir = IO_IN, + }; if (isspace(*format)) { int c = 0; @@ -156,7 +159,7 @@ int __scanf(struct io_options *opt, const char * format, va_list arg) break; } - format += __conv(format, &conv); + format += __conv(format, &conv, arg); switch (conv.spec) { case 'd': /* base 10 int */ @@ -171,8 +174,6 @@ int __scanf(struct io_options *opt, const char * format, va_list arg) //case L_z: ASSIGN(signed size_t, arg, i, 0, 0); break; /* TODO!!! */ //case L_t: ASSIGN(signed ptrdiff_t, arg, i, 0, 0); break; /* TODO!!! */ default: ASSIGN(int, arg, i, INT_MIN, INT_MAX); break; - - /* case L_L: UNDEFINED(""); break; */ } break; @@ -190,8 +191,6 @@ int __scanf(struct io_options *opt, const char * format, va_list arg) case L_z: ASSIGN(size_t, arg, u, 0, SIZE_MAX); break; case L_t: ASSIGN(ptrdiff_t, arg, u, 0, PTRDIFF_MAX); break; default: ASSIGN(unsigned int, arg, u, 0, UINT_MAX); break; - - /* case L_L: UNDEFINED(""); break; */ } break; @@ -218,16 +217,12 @@ int __scanf(struct io_options *opt, const char * format, va_list arg) case 'c': /* width (default 1) characters */ - if (conv.has_width == 0) { + if ((conv.flags & F_WIDTH) == 0) { conv.width = 1; } break; case 's': - if (conv.length != L_default && conv.length != L_l) { - //__bad_length(length, 's'); - } - char *str = va_arg(arg, char *); /* TODO: only use width if conv.has_width == 1 */ @@ -269,14 +264,13 @@ int __scanf(struct io_options *opt, const char * format, va_list arg) break; default: - UNDEFINED("Unknown conversion specifier '%c'", *format); + /* ub already handled by __conv() */ break; } format++; } - (void)arg; return ret; } |