diff --git a/.gitignore b/.gitignore index 262f016..10690cf 100644 --- a/.gitignore +++ b/.gitignore @@ -95,6 +95,7 @@ /include/kernaux.h /include/kernaux/console.h +/include/kernaux/printf.h /examples/assert_guards /examples/assert_simple diff --git a/ChangeLog b/ChangeLog index 9019ff7..e1d7ae7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,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 2022-06-06 Alex Kotov diff --git a/README.md b/README.md index 95bf032..ed8c424 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ zero). Work-in-progress APIs can change at any time. * [Panic: simple](/examples/panic_simple.c) * [Panic: guards](/examples/panic_guards.c) * Stack trace *(planned)* + * [File simulator](/include/kernaux/file.h) (*work in progress*) * Device drivers (for debugging only) * [Serial console](/include/kernaux/console.h) (*work in progress*) * [Framebuffer](/include/kernaux/framebuffer.h) (*planned*) @@ -67,7 +68,7 @@ zero). Work-in-progress APIs can change at any time. * Usual functions * [itoa/ftoa replacement](/include/kernaux/ntoa.h) (*stable since* **0.1.0**, *non-breaking since* **?.?.?**) * [Example](/examples/ntoa.c) - * [printf replacement](/include/kernaux/printf.h) (*stable since* **0.1.0**) + * [printf replacement](/include/kernaux/printf.h.in) (*stable since* **0.1.0**, *non-breaking since* **?.?.?**) * Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you! * [fprintf](/examples/fprintf.c) * [vfprintf](/examples/fprintf_va.c) @@ -117,6 +118,7 @@ All packages are included by default. To exclude all packages except those explicitly included, use `--without-all`. * `--with[out]-cmdline` - command line parser +* `--with[out]-file` - file simulator * `--with[out]-ntoa` - itoa/ftoa * `--with[out]-printf` - printf diff --git a/configure.ac b/configure.ac index 6947d0b..a54d16c 100644 --- a/configure.ac +++ b/configure.ac @@ -32,6 +32,7 @@ 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( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record])) AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser])) @@ -62,6 +63,7 @@ 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_mbr"; then with_mbr=no; fi if test -z "$with_multiboot2"; then with_multiboot2=no; fi @@ -94,6 +96,7 @@ 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_mbr" = no ], [with_mbr=no], [with_mbr=yes]) AS_IF([test "$with_multiboot2" = no ], [with_multiboot2=no], [with_multiboot2=yes]) @@ -147,6 +150,7 @@ 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_MBR], [test "$with_mbr" = yes]) AM_CONDITIONAL([WITH_MULTIBOOT2], [test "$with_multiboot2" = yes]) @@ -183,6 +187,7 @@ 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_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])]) @@ -205,6 +210,7 @@ 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_mbr" = no], [AC_SUBST([comment_line_mbr], [//])]) AS_IF([test "$with_multiboot2" = no], [AC_SUBST([comment_line_multiboot2], [//])]) @@ -230,6 +236,7 @@ AC_CONFIG_FILES([ libc/Makefile include/kernaux.h include/kernaux/console.h + include/kernaux/printf.h ]) AC_LANG([C]) diff --git a/include/Makefile.am b/include/Makefile.am index d47fc5e..fa33ef5 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -24,6 +24,9 @@ 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 diff --git a/include/kernaux.h.in b/include/kernaux.h.in index bdbd28c..97135e8 100644 --- a/include/kernaux.h.in +++ b/include/kernaux.h.in @@ -8,6 +8,7 @@ @comment_line_cmdline@#include @comment_line_console@#include @comment_line_elf@#include +@comment_line_file@#include @comment_line_framebuffer@#include @comment_line_mbr@#include @comment_line_multiboot2@#include diff --git a/include/kernaux/file.h b/include/kernaux/file.h new file mode 100644 index 0000000..dbcc5d9 --- /dev/null +++ b/include/kernaux/file.h @@ -0,0 +1,14 @@ +#ifndef KERNAUX_INCLUDED_FILE +#define KERNAUX_INCLUDED_FILE + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*KernAux_File_Out)(char c, void *arg); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/kernaux/printf.h b/include/kernaux/printf.h.in similarity index 88% rename from include/kernaux/printf.h rename to include/kernaux/printf.h.in index 618282d..425e908 100644 --- a/include/kernaux/printf.h +++ b/include/kernaux/printf.h.in @@ -8,6 +8,8 @@ extern "C" { #include #include +@comment_line_file@#include + /** * Tiny [v]fprintf implementation * \param out An output function which takes one character and an argument pointer @@ -16,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 */ -int kernaux_fprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); -int kernaux_vfprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va); +@comment_line_file@int kernaux_fprintf(KernAux_File_Out out, void* arg, const char* format, ...); +@comment_line_file@int kernaux_vfprintf(KernAux_File_Out out, void* arg, const char* format, va_list va); /** * Tiny [v]snprintf implementation