From df8f2e4bd06bf153a4f604fd8759b2212fe72a7a Mon Sep 17 00:00:00 2001 From: lvlhead Date: Tue, 23 Jul 2024 10:31:45 -0700 Subject: [PATCH] Add include guards to printf library to reduce compiled code to what we use --- external/printf/printf.c | 19 +++++++++++++------ external/printf/printf.h | 8 ++++---- printf_config.h | 1 + 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/external/printf/printf.c b/external/printf/printf.c index 93029741c..da9bc2545 100644 --- a/external/printf/printf.c +++ b/external/printf/printf.c @@ -643,6 +643,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const } } +#ifndef PRINTF_VOXLESS // evaluate length field switch (*format) { case 'l' : @@ -653,6 +654,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const format++; } break; + case 'h' : flags |= FLAGS_SHORT; format++; @@ -661,6 +663,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const format++; } break; + #if defined(PRINTF_SUPPORT_PTRDIFF_T) case 't' : flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG); @@ -678,6 +681,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const default : break; } +#endif // PRINTF_VOXLESS // evaluate specifier switch (*format) { @@ -754,6 +758,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const format++; break; } + #if defined(PRINTF_SUPPORT_FLOAT) case 'f' : case 'F' : @@ -818,7 +823,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const format++; break; } - +#ifndef PRINTF_VOXLESS case 'p' : { width = sizeof(void*) * 2U; flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE; @@ -836,7 +841,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const format++; break; } - +#endif // PRINTF_VOXLESS case '%' : out('%', buffer, idx++, maxlen); format++; @@ -858,7 +863,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const /////////////////////////////////////////////////////////////////////////////// - +#ifndef PRINTF_VOXLESS int printf_(const char* format, ...) { va_list va; @@ -868,7 +873,7 @@ int printf_(const char* format, ...) va_end(va); return ret; } - +#endif int sprintf_(char* buffer, const char* format, ...) { @@ -889,12 +894,13 @@ int snprintf_(char* buffer, size_t count, const char* format, ...) return ret; } - +#ifndef PRINTF_VOXLESS int vprintf_(const char* format, va_list va) { char buffer[1]; return _vsnprintf(_out_char, buffer, (size_t)-1, format, va); } +#endif int vsnprintf_(char* buffer, size_t count, const char* format, va_list va) @@ -902,7 +908,7 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va) return _vsnprintf(_out_buffer, buffer, count, format, va); } - +#ifndef PRINTF_VOXLESS int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...) { va_list va; @@ -912,3 +918,4 @@ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* for va_end(va); return ret; } +#endif diff --git a/external/printf/printf.h b/external/printf/printf.h index 8f7a4c8fe..472337179 100644 --- a/external/printf/printf.h +++ b/external/printf/printf.h @@ -48,7 +48,7 @@ extern "C" { */ void _putchar(char character); - +#ifndef PRINTF_VOXLESS /** * Tiny printf implementation * You have to implement _putchar if you use printf() @@ -59,7 +59,7 @@ void _putchar(char character); */ #define printf printf_ int printf_(const char* format, ...); - +#endif /** * Tiny sprintf implementation @@ -88,6 +88,7 @@ int snprintf_(char* buffer, size_t count, const char* format, ...); int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); +#ifndef PRINTF_VOXLESS /** * Tiny vprintf implementation * \param format A string that specifies the format of the output @@ -97,7 +98,6 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va); #define vprintf vprintf_ int vprintf_(const char* format, va_list va); - /** * printf with output function * You may use this as dynamic alternative to printf() with its fixed _putchar() output @@ -107,7 +107,7 @@ int vprintf_(const char* format, va_list va); * \return The number of characters that are sent to the output function, not counting the terminating null character */ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...); - +#endif #ifdef __cplusplus } diff --git a/printf_config.h b/printf_config.h index 3e4070f41..ce68046b4 100644 --- a/printf_config.h +++ b/printf_config.h @@ -2,3 +2,4 @@ #define PRINTF_DISABLE_SUPPORT_EXPONENTIAL #define PRINTF_DISABLE_SUPPORT_PTRDIFF_T #define PRINTF_DISABLE_SUPPORT_FLOAT +#define PRINTF_VOXLESS