From fbc736463f2ca2f5dbf1b7c412f408245e61df97 Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 12 Mar 2023 18:39:39 +0200 Subject: Revert VGA C driver --- lib/libk/stdio.h | 35 +++++++++++------------------ lib/libk/stdio/vfprintf.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ lib/libk/stdio/vfprintf.cpp | 54 --------------------------------------------- 3 files changed, 67 insertions(+), 76 deletions(-) create mode 100644 lib/libk/stdio/vfprintf.c delete mode 100644 lib/libk/stdio/vfprintf.cpp (limited to 'lib/libk') diff --git a/lib/libk/stdio.h b/lib/libk/stdio.h index 5ef68f1..b28eb5e 100644 --- a/lib/libk/stdio.h +++ b/lib/libk/stdio.h @@ -7,22 +7,19 @@ ///@defgroup stdio stdio ///@{ -#ifdef __cplusplus -/** - * An object type used for streams - */ -struct kIoDevice { - /** Function that prints a character to the stream */ - virtual void putc(char) = 0; - /** Function that prints a string to the stream */ - virtual int puts(const char *, int) = 0; - /** Flush write buffers */ - virtual void flush() = 0; -}; -typedef kIoDevice FILE; -#else -typedef void FILE; -#endif +/// An object type used for streams +typedef struct FILE { + int id; + + /// Function that prints a character to the stream + void (*putc)(const struct FILE *, char); + + /// Function that prints a string to the stream + int (*puts)(const struct FILE *, const char *, int); + + /// Flush write buffers + void (*flush)(const struct FILE *); +} FILE; /** A FILE value corresponding to stdin, the keyboard buffer */ extern FILE *stdin; @@ -31,9 +28,6 @@ extern FILE *stdout; /** A FILE value corresponding to stderr, the uart */ extern FILE *stderr; -#ifdef __cplusplus -extern "C" { -#endif /** * Write the formatted string to stdout * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal) @@ -50,9 +44,6 @@ int fprintf(FILE *restrict stream, const char *restrict format, ...); * Write the formatted string to stream; see printf */ int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap); -#ifdef __cplusplus -} -#endif ///@} ///@} diff --git a/lib/libk/stdio/vfprintf.c b/lib/libk/stdio/vfprintf.c new file mode 100644 index 0000000..d24e43e --- /dev/null +++ b/lib/libk/stdio/vfprintf.c @@ -0,0 +1,54 @@ +#include +#include + +static char buffer[3 * sizeof(int) + 2]; + +int +vfprintf(FILE *restrict stream, const char *restrict format, va_list params) +{ + int written = 0; + + int s = 0; + int l = 0; + for (int i = 0; format[i] != '\0'; ++i) { + if (format[i] == '%') { + written += stream->puts(stream, &format[s], l); + s = i + 2; + ++i; + + switch (format[i]) { + case 's': { + const char *arg = va_arg(params, const char *); + written += stream->puts(stream, arg, -1); + } break; + case 'c': { + const int arg = va_arg(params, int); + stream->putc(stream, arg); + ++written; + } break; + case 'd': { + const char *arg = itoa(buffer, va_arg(params, int), 10); + written += stream->puts(stream, arg, -1); + } break; + case 'u': { + const char *arg = utoa(buffer, va_arg(params, unsigned int), 10); + written += stream->puts(stream, arg, -1); + } break; + case 'x': { + const char *arg = utoa(buffer, va_arg(params, unsigned int), 16); + written += stream->puts(stream, arg, -1); + } break; + } + + l = 0; + } + + else + ++l; + } + + if (l > 0) { written += stream->puts(stream, &format[s], l); } + + stream->flush(stream); + return written; +} diff --git a/lib/libk/stdio/vfprintf.cpp b/lib/libk/stdio/vfprintf.cpp deleted file mode 100644 index aa9256d..0000000 --- a/lib/libk/stdio/vfprintf.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include - -static char buffer[3 * sizeof(int) + 2]; - -extern "C" int -vfprintf(FILE *restrict stream, const char *restrict format, va_list params) -{ - int written = 0; - - int s = 0; - int l = 0; - for (int i = 0; format[i] != '\0'; ++i) { - if (format[i] == '%') { - written += stream->puts(&format[s], l); - s = i + 2; - ++i; - - switch (format[i]) { - case 's': { - const char *arg = va_arg(params, const char *); - written += stream->puts(arg, -1); - } break; - case 'c': { - const int arg = va_arg(params, int); - stream->putc(arg); - ++written; - } break; - case 'd': { - const char *arg = itoa(buffer, va_arg(params, int), 10); - written += stream->puts(arg, -1); - } break; - case 'u': { - const char *arg = utoa(buffer, va_arg(params, unsigned int), 10); - written += stream->puts(arg, -1); - } break; - case 'x': { - const char *arg = utoa(buffer, va_arg(params, unsigned int), 16); - written += stream->puts(arg, -1); - } break; - } - - l = 0; - } - - else - ++l; - } - - if (l > 0) { written += stream->puts(&format[s], l); } - - stream->flush(); - return written; -} -- cgit v1.2.1