From aa6077b88c582e11d4d6a6077b2a0ab3fe817a0e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Tue, 7 Jun 2022 19:24:11 +0300 Subject: [PATCH] Main: include/kernaux/print.h: Functions "[v]printf" renamed to "[v]fprintf" --- .gitignore | 4 +-- ChangeLog | 1 + Makefile.am | 48 +++++++++++++------------- README.md | 4 +-- examples/{printf.c => fprintf.c} | 2 +- examples/{printf_va.c => fprintf_va.c} | 2 +- include/kernaux/printf.h | 8 ++--- src/console.c | 2 +- src/printf.c | 8 ++--- tests/printf_gen.jinja | 4 +-- 10 files changed, 42 insertions(+), 41 deletions(-) rename examples/{printf.c => fprintf.c} (94%) rename examples/{printf_va.c => fprintf_va.c} (90%) diff --git a/.gitignore b/.gitignore index 69ea55b..262f016 100644 --- a/.gitignore +++ b/.gitignore @@ -99,13 +99,13 @@ /examples/assert_guards /examples/assert_simple /examples/cmdline +/examples/fprintf +/examples/fprintf_va /examples/ntoa /examples/panic_guards /examples/panic_simple /examples/pfa -/examples/printf /examples/printf_fmt -/examples/printf_va /examples/snprintf /examples/snprintf_va /examples/units_human diff --git a/ChangeLog b/ChangeLog index 3f97076..9019ff7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2022-06-07 Alex Kotov * include/kernaux/libc.h: Has been split into separate headers + * include/kernaux/print.h: Functions "[v]printf" renamed to "[v]fprintf" 2022-06-06 Alex Kotov diff --git a/Makefile.am b/Makefile.am index d9200c6..8b1e799 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,6 +130,30 @@ examples_cmdline_SOURCES = examples/cmdline.c endif endif +################### +# examples/fprintf # +################### + +if ENABLE_TESTS +if WITH_PRINTF +TESTS += examples/fprintf +examples_fprintf_LDADD = libkernaux.a +examples_fprintf_SOURCES = examples/fprintf.c +endif +endif + +###################### +# examples/fprintf_va # +###################### + +if ENABLE_TESTS +if WITH_PRINTF +TESTS += examples/fprintf_va +examples_fprintf_va_LDADD = libkernaux.a +examples_fprintf_va_SOURCES = examples/fprintf_va.c +endif +endif + ################# # examples/ntoa # ################# @@ -174,18 +198,6 @@ examples_pfa_SOURCES = examples/pfa.c endif endif -################### -# examples/printf # -################### - -if ENABLE_TESTS -if WITH_PRINTF -TESTS += examples/printf -examples_printf_LDADD = libkernaux.a -examples_printf_SOURCES = examples/printf.c -endif -endif - ####################### # examples/printf_fmt # ####################### @@ -198,18 +210,6 @@ examples_printf_fmt_SOURCES = examples/printf_fmt.c endif endif -###################### -# examples/printf_va # -###################### - -if ENABLE_TESTS -if WITH_PRINTF -TESTS += examples/printf_va -examples_printf_va_LDADD = libkernaux.a -examples_printf_va_SOURCES = examples/printf_va.c -endif -endif - ##################### # examples/snprintf # ##################### diff --git a/README.md b/README.md index d719770..95bf032 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,8 @@ zero). Work-in-progress APIs can change at any time. * [Example](/examples/ntoa.c) * [printf replacement](/include/kernaux/printf.h) (*stable since* **0.1.0**) * Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you! - * [printf](/examples/printf.c) - * [vprintf](/examples/printf_va.c) + * [fprintf](/examples/fprintf.c) + * [vfprintf](/examples/fprintf_va.c) * [snprintf](/examples/snprintf.c) * [vsnprintf](/examples/snprintf_va.c) * libc replacement diff --git a/examples/printf.c b/examples/fprintf.c similarity index 94% rename from examples/printf.c rename to examples/fprintf.c index ae44419..b101a47 100644 --- a/examples/printf.c +++ b/examples/fprintf.c @@ -21,7 +21,7 @@ static void my_putchar(const char chr, void *arg) int main() { - const int result = kernaux_printf( + const int result = kernaux_fprintf( my_putchar, (char*)data, "Hello, %s! Session ID: %u.", diff --git a/examples/printf_va.c b/examples/fprintf_va.c similarity index 90% rename from examples/printf_va.c rename to examples/fprintf_va.c index 12e1841..25adf8a 100644 --- a/examples/printf_va.c +++ b/examples/fprintf_va.c @@ -23,7 +23,7 @@ static int my_printf(const char *const format, ...) { va_list va; va_start(va, format); - const int result = kernaux_vprintf(my_putchar, (char*)data, format, va); + const int result = kernaux_vfprintf(my_putchar, (char*)data, format, va); va_end(va); return result; } diff --git a/include/kernaux/printf.h b/include/kernaux/printf.h index 0028eb3..618282d 100644 --- a/include/kernaux/printf.h +++ b/include/kernaux/printf.h @@ -9,18 +9,18 @@ extern "C" { #include /** - * Tiny printf/vprintf implementation + * Tiny [v]fprintf implementation * \param out An output function which takes one character and an argument pointer * \param arg An argument pointer for user data passed to output function * \param format A string that specifies the format of the output * \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_printf(void (*out)(char character, void* arg), void* arg, const char* format, ...); -int kernaux_vprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va); +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); /** - * Tiny snprintf/vsnprintf implementation + * Tiny [v]snprintf implementation * \param buffer A pointer to the buffer where to store the formatted string * \param count The maximum number of characters to store in the buffer, including a terminating null character * \param format A string that specifies the format of the output diff --git a/src/console.c b/src/console.c index 7e861dd..412d454 100644 --- a/src/console.c +++ b/src/console.c @@ -54,7 +54,7 @@ void kernaux_console_printf(const char *format, ...) va_list va; va_start(va, format); - kernaux_vprintf(kernaux_console_printf_putc, NULL, format, va); + kernaux_vfprintf(kernaux_console_printf_putc, NULL, format, va); va_end(va); } #endif diff --git a/src/printf.c b/src/printf.c index c6b7df6..408af28 100644 --- a/src/printf.c +++ b/src/printf.c @@ -1,8 +1,8 @@ /** * Copyright (c) 2014-2019 Marco Paland * - * Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on - * embedded systems with a very limited resources. These routines are thread + * Tiny [v]fprintf, sfprintf and [v]snprintf implementation, optimized for speed + * on embedded systems with a very limited resources. These routines are thread * safe and reentrant! */ @@ -66,7 +66,7 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d * Implementations: main API * *****************************/ -int kernaux_printf(void (*out)(char character, void* arg), void* arg, const char* format, ...) +int kernaux_fprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...) { KERNAUX_NOTNULL_RETVAL(out, 0); KERNAUX_NOTNULL_RETVAL(format, 0); @@ -79,7 +79,7 @@ int kernaux_printf(void (*out)(char character, void* arg), void* arg, const char return ret; } -int kernaux_vprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va) +int kernaux_vfprintf(void (*out)(char character, void* arg), void* arg, const char* format, va_list va) { KERNAUX_NOTNULL_RETVAL(out, 0); KERNAUX_NOTNULL_RETVAL(format, 0); diff --git a/tests/printf_gen.jinja b/tests/printf_gen.jinja index 7cd6ae9..cd530a0 100644 --- a/tests/printf_gen.jinja +++ b/tests/printf_gen.jinja @@ -36,7 +36,7 @@ static void test(const char *const expected, const char *const format, ...) memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; va_start(va, format); - result = kernaux_vprintf(test_putchar, (char*)data, format, va); + result = kernaux_vfprintf(test_putchar, (char*)data, format, va); va_end(va); assert((size_t)result == strlen(expected)); assert(strcmp(expected, buffer) == 0); @@ -54,7 +54,7 @@ int main() { memset(buffer, '\0', sizeof(buffer)); buffer_index = 0; - kernaux_printf(test_putchar, (char*)data, "Hello, World!"); + kernaux_fprintf(test_putchar, (char*)data, "Hello, World!"); assert(strcmp("Hello, World!", buffer) == 0); {% for case in cases %}