diff --git a/ChangeLog b/ChangeLog index 52b84d4..7b8e563 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,7 +17,7 @@ * include/kernaux/libc.h: Has been split into separate headers * include/kernaux/print.h: Functions "[v]printf" renamed to "[v]fprintf" - * include/kernaux/file.h: Added + * include/kernaux/io.h: Added 2022-06-06 Alex Kotov diff --git a/Makefile.am b/Makefile.am index fd26376..c41c273 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,12 +41,12 @@ endif if WITH_ELF libkernaux_la_SOURCES += src/elf.c endif -if WITH_FILE -libkernaux_la_SOURCES += src/file.c -endif if WITH_FRAMEBUFFER libkernaux_la_SOURCES += src/framebuffer.c endif +if WITH_IO +libkernaux_la_SOURCES += src/io.c +endif if WITH_LIBC libkernaux_la_LIBADD += libc/libc.la endif diff --git a/README.md b/README.md index 7608a30..b1281e6 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ zero). Work-in-progress APIs can change at any time. * [Assert](/examples/assert.c) * [Panic](/examples/panic.c) * Stack trace *(planned)* - * [File simulator](/include/kernaux/file.h) (*work in progress*) + * [Input/output](/include/kernaux/io.h) (*work in progress*) * Architecture-specific code (*work in progress*) * [Declarations](/include/kernaux/arch/) * [Functions](/include/kernaux/asm/) diff --git a/bindings/ruby/ext/default/file.c b/bindings/ruby/ext/default/io.c similarity index 86% rename from bindings/ruby/ext/default/file.c rename to bindings/ruby/ext/default/io.c index 4fe5cbe..f27c6d8 100644 --- a/bindings/ruby/ext/default/file.c +++ b/bindings/ruby/ext/default/io.c @@ -1,6 +1,6 @@ #include "main.h" -#ifdef KERNAUX_VERSION_WITH_FILE +#ifdef KERNAUX_VERSION_WITH_IO static VALUE rb_KernAux_File_initialize(VALUE self, VALUE out); @@ -8,7 +8,7 @@ static ID rb_intern_ATout = Qnil; static VALUE rb_KernAux_File = Qnil; -void init_file() { +void init_io() { rb_gc_register_mark_object(ID2SYM(rb_intern_ATout = rb_intern("@out"))); rb_gc_register_mark_object(rb_KernAux_File = @@ -24,4 +24,4 @@ VALUE rb_KernAux_File_initialize(VALUE self, VALUE out) return Qnil; } -#endif // KERNAUX_VERSION_WITH_FILE +#endif // KERNAUX_VERSION_WITH_IO diff --git a/bindings/ruby/ext/default/main.c b/bindings/ruby/ext/default/main.c index d01eeac..12f97f8 100644 --- a/bindings/ruby/ext/default/main.c +++ b/bindings/ruby/ext/default/main.c @@ -22,12 +22,13 @@ void Init_default() init_version(); init_assert(); +#ifdef KERNAUX_VERSION_WITH_IO + init_io(); +#endif // KERNAUX_VERSION_WITH_IO + #ifdef KERNAUX_VERSION_WITH_CMDLINE init_cmdline(); #endif // KERNAUX_VERSION_WITH_CMDLINE -#ifdef KERNAUX_VERSION_WITH_FILE - init_file(); -#endif // KERNAUX_VERSION_WITH_FILE #ifdef KERNAUX_VERSION_WITH_NTOA init_ntoa(); #endif // KERNAUX_VERSION_WITH_NTOA diff --git a/bindings/ruby/ext/default/main.h b/bindings/ruby/ext/default/main.h index 43fdee0..9e56965 100644 --- a/bindings/ruby/ext/default/main.h +++ b/bindings/ruby/ext/default/main.h @@ -15,12 +15,13 @@ extern VALUE rb_KernAux_Error; void init_version(); void init_assert(); +#ifdef KERNAUX_VERSION_WITH_IO +void init_io(); +#endif // KERNAUX_VERSION_WITH_IO + #ifdef KERNAUX_VERSION_WITH_CMDLINE void init_cmdline(); #endif // KERNAUX_VERSION_WITH_CMDLINE -#ifdef KERNAUX_VERSION_WITH_FILE -void init_file(); -#endif // KERNAUX_VERSION_WITH_FILE #ifdef KERNAUX_VERSION_WITH_NTOA void init_ntoa(); #endif // KERNAUX_VERSION_WITH_NTOA diff --git a/bindings/ruby/ext/default/version.c b/bindings/ruby/ext/default/version.c index 8be0703..f7ed813 100644 --- a/bindings/ruby/ext/default/version.c +++ b/bindings/ruby/ext/default/version.c @@ -1,7 +1,7 @@ #include "main.h" static VALUE rb_KernAux_Version_with_cmdlineQN(VALUE self); -static VALUE rb_KernAux_Version_with_fileQN(VALUE self); +static VALUE rb_KernAux_Version_with_ioQN(VALUE self); static VALUE rb_KernAux_Version_with_ntoaQN(VALUE self); static VALUE rb_KernAux_Version_with_printfQN(VALUE self); @@ -14,8 +14,8 @@ void init_version() rb_define_singleton_method(rb_KernAux_Version, "with_cmdline?", rb_KernAux_Version_with_cmdlineQN, 0); - rb_define_singleton_method(rb_KernAux_Version, "with_file?", - rb_KernAux_Version_with_fileQN, 0); + rb_define_singleton_method(rb_KernAux_Version, "with_io?", + rb_KernAux_Version_with_ioQN, 0); rb_define_singleton_method(rb_KernAux_Version, "with_ntoa?", rb_KernAux_Version_with_ntoaQN, 0); rb_define_singleton_method(rb_KernAux_Version, "with_printf?", @@ -31,9 +31,9 @@ VALUE rb_KernAux_Version_with_cmdlineQN(VALUE self) #endif } -VALUE rb_KernAux_Version_with_fileQN(VALUE self) +VALUE rb_KernAux_Version_with_ioQN(VALUE self) { -#ifdef KERNAUX_VERSION_WITH_FILE +#ifdef KERNAUX_VERSION_WITH_IO return Qtrue; #else return Qfalse; diff --git a/bindings/ruby/lib/kernaux.rb b/bindings/ruby/lib/kernaux.rb index 8c8b705..ac0f3cc 100644 --- a/bindings/ruby/lib/kernaux.rb +++ b/bindings/ruby/lib/kernaux.rb @@ -16,7 +16,6 @@ require_relative 'kernaux/default' require_relative 'kernaux/assert' require_relative 'kernaux/cmdline' require_relative 'kernaux/errors' +require_relative 'kernaux/io' require_relative 'kernaux/ntoa' require_relative 'kernaux/printf' - -require_relative 'kernaux/file' diff --git a/bindings/ruby/lib/kernaux/file.rb b/bindings/ruby/lib/kernaux/io.rb similarity index 91% rename from bindings/ruby/lib/kernaux/file.rb rename to bindings/ruby/lib/kernaux/io.rb index cb1e0eb..fa4d3eb 100644 --- a/bindings/ruby/lib/kernaux/file.rb +++ b/bindings/ruby/lib/kernaux/io.rb @@ -2,7 +2,7 @@ # rubocop:disable Lint/EmptyClass -if KernAux::Version.with_file? +if KernAux::Version.with_io? module KernAux ## # File simulator. diff --git a/configure.ac b/configure.ac index ffba5da..1010735 100644 --- a/configure.ac +++ b/configure.ac @@ -59,8 +59,8 @@ AC_ARG_WITH( [all], AS_HELP_STRING([--without-all], [without a AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser])) AC_ARG_WITH( [console], AS_HELP_STRING([--without-console], [without serial console])) AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils])) -AC_ARG_WITH( [file], AS_HELP_STRING([--without-file], [without file simulator])) AC_ARG_WITH( [framebuffer], AS_HELP_STRING([--without-framebuffer], [without framebuffer])) +AC_ARG_WITH( [io], AS_HELP_STRING([--without-io], [without input/output])) AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record])) AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser])) AC_ARG_WITH( [ntoa], AS_HELP_STRING([--without-ntoa], [without itoa/ftoa])) @@ -90,8 +90,8 @@ AC_DEFUN([do_without_all], if test -z "$with_cmdline"; then with_cmdline=no; fi if test -z "$with_console"; then with_console=no; fi if test -z "$with_elf"; then with_elf=no; fi -if test -z "$with_file"; then with_file=no; fi if test -z "$with_framebuffer"; then with_framebuffer=no; fi +if test -z "$with_io"; then with_io=no; fi if test -z "$with_mbr"; then with_mbr=no; fi if test -z "$with_multiboot2"; then with_multiboot2=no; fi if test -z "$with_ntoa"; then with_ntoa=no; fi @@ -125,8 +125,8 @@ AS_IF([test "$with_all" = no ], [with_all=no], [with_all= AS_IF([test "$with_cmdline" = no ], [with_cmdline=no], [with_cmdline=yes]) AS_IF([test "$with_console" = no ], [with_console=no], [with_console=yes]) AS_IF([test "$with_elf" = no ], [with_elf=no], [with_elf=yes]) -AS_IF([test "$with_file" = no ], [with_file=no], [with_file=yes]) AS_IF([test "$with_framebuffer" = no ], [with_framebuffer=no], [with_framebuffer=yes]) +AS_IF([test "$with_io" = no ], [with_io=no], [with_io=yes]) AS_IF([test "$with_mbr" = no ], [with_mbr=no], [with_mbr=yes]) AS_IF([test "$with_multiboot2" = no ], [with_multiboot2=no], [with_multiboot2=yes]) AS_IF([test "$with_ntoa" = no ], [with_ntoa=no], [with_ntoa=yes]) @@ -181,8 +181,8 @@ dnl Packages (enabled by default) AM_CONDITIONAL([WITH_CMDLINE], [test "$with_cmdline" = yes]) AM_CONDITIONAL([WITH_CONSOLE], [test "$with_console" = yes]) AM_CONDITIONAL([WITH_ELF], [test "$with_elf" = yes]) -AM_CONDITIONAL([WITH_FILE], [test "$with_file" = yes]) AM_CONDITIONAL([WITH_FRAMEBUFFER], [test "$with_framebuffer" = yes]) +AM_CONDITIONAL([WITH_IO], [test "$with_io" = yes]) AM_CONDITIONAL([WITH_MBR], [test "$with_mbr" = yes]) AM_CONDITIONAL([WITH_MULTIBOOT2], [test "$with_multiboot2" = yes]) AM_CONDITIONAL([WITH_NTOA], [test "$with_ntoa" = yes]) @@ -220,8 +220,8 @@ dnl Packages (enabled by default) AS_IF([test "$with_cmdline" = yes], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])]) AS_IF([test "$with_console" = yes], [AC_DEFINE([WITH_CONSOLE], [1], [with serial console])]) AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])]) -AS_IF([test "$with_file" = yes], [AC_DEFINE([WITH_FILE], [1], [with file simulator])]) AS_IF([test "$with_framebuffer" = yes], [AC_DEFINE([WITH_FRAMEBUFFER], [1], [with framebuffer])]) +AS_IF([test "$with_io" = yes], [AC_DEFINE([WITH_IO], [1], [with input/output])]) AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])]) AS_IF([test "$with_multiboot2" = yes], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])]) AS_IF([test "$with_ntoa" = yes], [AC_DEFINE([WITH_NTOA], [1], [with ntoa])]) @@ -246,8 +246,8 @@ dnl Packages (enabled by default) AS_IF([test "$with_cmdline" = no], [AC_SUBST([comment_line_cmdline], [//])]) AS_IF([test "$with_console" = no], [AC_SUBST([comment_line_console], [//])]) AS_IF([test "$with_elf" = no], [AC_SUBST([comment_line_elf], [//])]) -AS_IF([test "$with_file" = no], [AC_SUBST([comment_line_file], [//])]) AS_IF([test "$with_framebuffer" = no], [AC_SUBST([comment_line_framebuffer], [//])]) +AS_IF([test "$with_io" = no], [AC_SUBST([comment_line_io], [//])]) AS_IF([test "$with_mbr" = no], [AC_SUBST([comment_line_mbr], [//])]) AS_IF([test "$with_multiboot2" = no], [AC_SUBST([comment_line_multiboot2], [//])]) AS_IF([test "$with_ntoa" = no], [AC_SUBST([comment_line_ntoa], [//])]) diff --git a/examples/Makefile.am b/examples/Makefile.am index 509c5b3..7ff97b2 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -26,7 +26,7 @@ endif ########### if WITH_PRINTF -if WITH_FILE +if WITH_IO TESTS += fprintf fprintf_LDADD = $(top_builddir)/libkernaux.la fprintf_SOURCES = fprintf.c @@ -38,7 +38,7 @@ endif ############## if WITH_PRINTF -if WITH_FILE +if WITH_IO TESTS += fprintf_va fprintf_va_LDADD = $(top_builddir)/libkernaux.la fprintf_va_SOURCES = fprintf_va.c diff --git a/examples/fprintf.c b/examples/fprintf.c index 79acf62..4f00c86 100644 --- a/examples/fprintf.c +++ b/examples/fprintf.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/examples/fprintf_va.c b/examples/fprintf_va.c index bc53772..3e7fc4d 100644 --- a/examples/fprintf_va.c +++ b/examples/fprintf_va.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/include/Makefile.am b/include/Makefile.am index dd404f2..8f7a5bf 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -25,12 +25,12 @@ endif if WITH_ELF nobase_include_HEADERS += kernaux/elf.h endif -if WITH_FILE -nobase_include_HEADERS += kernaux/file.h -endif if WITH_FRAMEBUFFER nobase_include_HEADERS += kernaux/framebuffer.h endif +if WITH_IO +nobase_include_HEADERS += kernaux/io.h +endif if WITH_MBR nobase_include_HEADERS += kernaux/mbr.h endif diff --git a/include/kernaux.h.in b/include/kernaux.h.in index e346c5d..02db77d 100644 --- a/include/kernaux.h.in +++ b/include/kernaux.h.in @@ -10,8 +10,8 @@ @comment_line_cmdline@#include @comment_line_console@#include @comment_line_elf@#include -@comment_line_file@#include @comment_line_framebuffer@#include +@comment_line_io@#include @comment_line_mbr@#include @comment_line_multiboot2@#include @comment_line_ntoa@#include diff --git a/include/kernaux/file.h b/include/kernaux/io.h similarity index 84% rename from include/kernaux/file.h rename to include/kernaux/io.h index 0af4c30..cc163ca 100644 --- a/include/kernaux/file.h +++ b/include/kernaux/io.h @@ -1,5 +1,5 @@ -#ifndef KERNAUX_INCLUDED_FILE -#define KERNAUX_INCLUDED_FILE +#ifndef KERNAUX_INCLUDED_IO +#define KERNAUX_INCLUDED_IO #ifdef __cplusplus extern "C" { diff --git a/include/kernaux/printf.h.in b/include/kernaux/printf.h.in index 8e26dbb..ae06398 100644 --- a/include/kernaux/printf.h.in +++ b/include/kernaux/printf.h.in @@ -8,7 +8,7 @@ extern "C" { #include #include -@comment_line_file@#include +@comment_line_io@#include /** * Tiny [v]fprintf implementation @@ -18,8 +18,8 @@ extern "C" { * \param va A value identifying a variable arguments list * \return The number of characters that are sent to the output function, not counting the terminating null character */ -@comment_line_file@int kernaux_fprintf(KernAux_File file, void* arg, const char* format, ...); -@comment_line_file@int kernaux_vfprintf(KernAux_File file, void* arg, const char* format, va_list va); +@comment_line_io@int kernaux_fprintf(KernAux_File file, void* arg, const char* format, ...); +@comment_line_io@int kernaux_vfprintf(KernAux_File file, void* arg, const char* format, va_list va); /** * Tiny [v]snprintf implementation diff --git a/include/kernaux/version.h.in b/include/kernaux/version.h.in index ce776f5..6c1cfaf 100644 --- a/include/kernaux/version.h.in +++ b/include/kernaux/version.h.in @@ -4,8 +4,8 @@ @comment_line_cmdline@#define KERNAUX_VERSION_WITH_CMDLINE @comment_line_console@#define KERNAUX_VERSION_WITH_CONSOLE @comment_line_elf@#define KERNAUX_VERSION_WITH_ELF -@comment_line_file@#define KERNAUX_VERSION_WITH_FILE @comment_line_framebuffer@#define KERNAUX_VERSION_WITH_FRAMEBUFFER +@comment_line_io@#define KERNAUX_VERSION_WITH_IO @comment_line_mbr@#define KERNAUX_VERSION_WITH_MBR @comment_line_multiboot2@#define KERNAUX_VERSION_WITH_MULTIBOOT2 @comment_line_ntoa@#define KERNAUX_VERSION_WITH_NTOA diff --git a/src/console.c b/src/console.c index df318b1..69ed314 100644 --- a/src/console.c +++ b/src/console.c @@ -14,8 +14,8 @@ #include #endif -#ifdef WITH_FILE -#include +#ifdef WITH_IO +#include #endif #ifdef WITH_PRINTF #include @@ -23,7 +23,7 @@ #include -#if defined(WITH_FILE) && defined(WITH_PRINTF) +#if defined(WITH_IO) && defined(WITH_PRINTF) static void kernaux_console_printf_putc( const char c, void *const arg __attribute__((unused)) @@ -51,7 +51,7 @@ void kernaux_console_print(const char *const s) } } -#if defined(WITH_FILE) && defined(WITH_PRINTF) +#if defined(WITH_IO) && defined(WITH_PRINTF) void kernaux_console_printf(const char *format, ...) { KERNAUX_ASSERT(format); diff --git a/src/file.c b/src/io.c similarity index 93% rename from src/file.c rename to src/io.c index 33a50c5..b7a0391 100644 --- a/src/file.c +++ b/src/io.c @@ -3,7 +3,7 @@ #endif #include -#include +#include #include diff --git a/src/printf.c b/src/printf.c index 6ec9694..685a63d 100644 --- a/src/printf.c +++ b/src/printf.c @@ -66,7 +66,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d * Implementations: main API * *****************************/ -#ifdef WITH_FILE +#ifdef WITH_IO int kernaux_fprintf(const KernAux_File file, void* arg, const char* format, ...) { @@ -90,7 +90,7 @@ int kernaux_vfprintf(const KernAux_File file, void* arg, const char* format, va_ return _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va); } -#endif // WITH_FILE +#endif // WITH_IO int kernaux_snprintf(char* buffer, size_t count, const char* format, ...) { diff --git a/tests/printf_gen.jinja b/tests/printf_gen.jinja index d579de5..5fc98d9 100644 --- a/tests/printf_gen.jinja +++ b/tests/printf_gen.jinja @@ -4,8 +4,8 @@ #include -#ifdef WITH_FILE -#include +#ifdef WITH_IO +#include #endif #include @@ -18,7 +18,7 @@ static char buffer[BUFFER_SIZE]; static size_t buffer_index; -#ifdef WITH_FILE +#ifdef WITH_IO static const char *const data = "foobar"; @@ -34,14 +34,14 @@ static void test_putchar(const char chr, void *const arg) buffer[buffer_index++] = chr; } -#endif // WITH_FILE +#endif // WITH_IO static void test(const char *const expected, const char *const format, ...) { va_list va; int result; -#ifdef WITH_FILE +#ifdef WITH_IO memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; va_start(va, format); @@ -63,7 +63,7 @@ static void test(const char *const expected, const char *const format, ...) int main() { -#ifdef WITH_FILE +#ifdef WITH_IO memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; struct KernAux_File file = KernAux_File_create(test_putchar);