mirror of
https://github.com/tailix/libkernaux.git
synced 2025-02-17 15:45:32 -05:00
Main: include/kernaux/print.h: Functions "[v]printf" renamed to "[v]fprintf"
This commit is contained in:
parent
982b36c6b7
commit
aa6077b88c
10 changed files with 42 additions and 41 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -99,13 +99,13 @@
|
||||||
/examples/assert_guards
|
/examples/assert_guards
|
||||||
/examples/assert_simple
|
/examples/assert_simple
|
||||||
/examples/cmdline
|
/examples/cmdline
|
||||||
|
/examples/fprintf
|
||||||
|
/examples/fprintf_va
|
||||||
/examples/ntoa
|
/examples/ntoa
|
||||||
/examples/panic_guards
|
/examples/panic_guards
|
||||||
/examples/panic_simple
|
/examples/panic_simple
|
||||||
/examples/pfa
|
/examples/pfa
|
||||||
/examples/printf
|
|
||||||
/examples/printf_fmt
|
/examples/printf_fmt
|
||||||
/examples/printf_va
|
|
||||||
/examples/snprintf
|
/examples/snprintf
|
||||||
/examples/snprintf_va
|
/examples/snprintf_va
|
||||||
/examples/units_human
|
/examples/units_human
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
2022-06-07 Alex Kotov <kotovalexarian@gmail.com>
|
2022-06-07 Alex Kotov <kotovalexarian@gmail.com>
|
||||||
|
|
||||||
* include/kernaux/libc.h: Has been split into separate headers
|
* 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 <kotovalexarian@gmail.com>
|
2022-06-06 Alex Kotov <kotovalexarian@gmail.com>
|
||||||
|
|
||||||
|
|
48
Makefile.am
48
Makefile.am
|
@ -130,6 +130,30 @@ examples_cmdline_SOURCES = examples/cmdline.c
|
||||||
endif
|
endif
|
||||||
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 #
|
# examples/ntoa #
|
||||||
#################
|
#################
|
||||||
|
@ -174,18 +198,6 @@ examples_pfa_SOURCES = examples/pfa.c
|
||||||
endif
|
endif
|
||||||
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 #
|
# examples/printf_fmt #
|
||||||
#######################
|
#######################
|
||||||
|
@ -198,18 +210,6 @@ examples_printf_fmt_SOURCES = examples/printf_fmt.c
|
||||||
endif
|
endif
|
||||||
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 #
|
# examples/snprintf #
|
||||||
#####################
|
#####################
|
||||||
|
|
|
@ -69,8 +69,8 @@ zero). Work-in-progress APIs can change at any time.
|
||||||
* [Example](/examples/ntoa.c)
|
* [Example](/examples/ntoa.c)
|
||||||
* [printf replacement](/include/kernaux/printf.h) (*stable since* **0.1.0**)
|
* [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!
|
* Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you!
|
||||||
* [printf](/examples/printf.c)
|
* [fprintf](/examples/fprintf.c)
|
||||||
* [vprintf](/examples/printf_va.c)
|
* [vfprintf](/examples/fprintf_va.c)
|
||||||
* [snprintf](/examples/snprintf.c)
|
* [snprintf](/examples/snprintf.c)
|
||||||
* [vsnprintf](/examples/snprintf_va.c)
|
* [vsnprintf](/examples/snprintf_va.c)
|
||||||
* libc replacement
|
* libc replacement
|
||||||
|
|
|
@ -21,7 +21,7 @@ static void my_putchar(const char chr, void *arg)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
const int result = kernaux_printf(
|
const int result = kernaux_fprintf(
|
||||||
my_putchar,
|
my_putchar,
|
||||||
(char*)data,
|
(char*)data,
|
||||||
"Hello, %s! Session ID: %u.",
|
"Hello, %s! Session ID: %u.",
|
|
@ -23,7 +23,7 @@ static int my_printf(const char *const format, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
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);
|
va_end(va);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
|
@ -9,18 +9,18 @@ extern "C" {
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tiny printf/vprintf implementation
|
* Tiny [v]fprintf implementation
|
||||||
* \param out An output function which takes one character and an argument pointer
|
* \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 arg An argument pointer for user data passed to output function
|
||||||
* \param format A string that specifies the format of the output
|
* \param format A string that specifies the format of the output
|
||||||
* \param va A value identifying a variable arguments list
|
* \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
|
* \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_fprintf(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_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 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 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
|
* \param format A string that specifies the format of the output
|
||||||
|
|
|
@ -54,7 +54,7 @@ void kernaux_console_printf(const char *format, ...)
|
||||||
|
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, format);
|
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);
|
va_end(va);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2014-2019 Marco Paland <info@paland.com>
|
* Copyright (c) 2014-2019 Marco Paland <info@paland.com>
|
||||||
*
|
*
|
||||||
* Tiny printf, sprintf and (v)snprintf implementation, optimized for speed on
|
* Tiny [v]fprintf, sfprintf and [v]snprintf implementation, optimized for speed
|
||||||
* embedded systems with a very limited resources. These routines are thread
|
* on embedded systems with a very limited resources. These routines are thread
|
||||||
* safe and reentrant!
|
* 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 *
|
* 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(out, 0);
|
||||||
KERNAUX_NOTNULL_RETVAL(format, 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;
|
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(out, 0);
|
||||||
KERNAUX_NOTNULL_RETVAL(format, 0);
|
KERNAUX_NOTNULL_RETVAL(format, 0);
|
||||||
|
|
|
@ -36,7 +36,7 @@ static void test(const char *const expected, const char *const format, ...)
|
||||||
memset(buffer, '\0', sizeof(buffer));
|
memset(buffer, '\0', sizeof(buffer));
|
||||||
buffer_index = 0;
|
buffer_index = 0;
|
||||||
va_start(va, format);
|
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);
|
va_end(va);
|
||||||
assert((size_t)result == strlen(expected));
|
assert((size_t)result == strlen(expected));
|
||||||
assert(strcmp(expected, buffer) == 0);
|
assert(strcmp(expected, buffer) == 0);
|
||||||
|
@ -54,7 +54,7 @@ int main()
|
||||||
{
|
{
|
||||||
memset(buffer, '\0', sizeof(buffer));
|
memset(buffer, '\0', sizeof(buffer));
|
||||||
buffer_index = 0;
|
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);
|
assert(strcmp("Hello, World!", buffer) == 0);
|
||||||
|
|
||||||
{% for case in cases %}
|
{% for case in cases %}
|
||||||
|
|
Loading…
Add table
Reference in a new issue