mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-13 11:04:27 -05:00
Remove unnecessary conditional compilation
This commit is contained in:
parent
3e99b65cf1
commit
d996f9cdf8
1 changed files with 1 additions and 37 deletions
38
src/printf.c
38
src/printf.c
|
@ -28,22 +28,12 @@
|
|||
// float number including padded zeros (dynamically created on stack)
|
||||
#define PRINTF_FTOA_BUFFER_SIZE 32u
|
||||
|
||||
// support for exponential floating point notation (%e/%g)
|
||||
#define PRINTF_SUPPORT_EXPONENTIAL
|
||||
|
||||
// define the default floating point precision
|
||||
#define PRINTF_DEFAULT_FLOAT_PRECISION 6u
|
||||
|
||||
// define the largest float suitable to print with %f
|
||||
#define PRINTF_MAX_FLOAT 1e9
|
||||
|
||||
// support for the long long types (%llu or %p)
|
||||
#define PRINTF_SUPPORT_LONG_LONG
|
||||
|
||||
// support for the ptrdiff_t type (%t)
|
||||
// ptrdiff_t is normally defined in <stddef.h> as long or long long type
|
||||
#define PRINTF_SUPPORT_PTRDIFF_T
|
||||
|
||||
// internal flag definitions
|
||||
#define FLAGS_ZEROPAD (1u << 0u)
|
||||
#define FLAGS_LEFT (1u << 1u)
|
||||
|
@ -78,18 +68,12 @@ static unsigned int _atoi(const char** str);
|
|||
static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen, const char* buf, size_t len, unsigned int width, unsigned int flags);
|
||||
static size_t _ntoa_format(out_fct_type out, char* buffer, size_t idx, size_t maxlen, char* buf, size_t len, bool negative, unsigned int base, unsigned int prec, unsigned int width, unsigned int flags);
|
||||
static size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long value, bool negative, unsigned long base, unsigned int prec, unsigned int width, unsigned int flags);
|
||||
static char _custom(unsigned int flags, size_t *index);
|
||||
|
||||
#ifdef PRINTF_SUPPORT_LONG_LONG
|
||||
static size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags);
|
||||
#endif // PRINTF_SUPPORT_LONG_LONG
|
||||
static char _custom(unsigned int flags, size_t *index);
|
||||
|
||||
#ifdef ENABLE_FLOAT
|
||||
static size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags);
|
||||
|
||||
#ifdef PRINTF_SUPPORT_EXPONENTIAL
|
||||
static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags);
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // ENABLE_FLOAT
|
||||
|
||||
/*******************************
|
||||
|
@ -222,12 +206,10 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
|
|||
format++;
|
||||
}
|
||||
break;
|
||||
#ifdef PRINTF_SUPPORT_PTRDIFF_T
|
||||
case 't':
|
||||
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
break;
|
||||
#endif
|
||||
case 'j':
|
||||
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||
format++;
|
||||
|
@ -289,10 +271,8 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
|
|||
if ((*format == 'i') || (*format == 'd')) {
|
||||
// signed
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#ifdef PRINTF_SUPPORT_LONG_LONG
|
||||
const long long value = va_arg(va, long long);
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
const long value = va_arg(va, long);
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||
|
@ -303,9 +283,7 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
|
|||
} else {
|
||||
// unsigned
|
||||
if (flags & FLAGS_LONG_LONG) {
|
||||
#ifdef PRINTF_SUPPORT_LONG_LONG
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
|
||||
#endif
|
||||
} else if (flags & FLAGS_LONG) {
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags);
|
||||
} else {
|
||||
|
@ -323,7 +301,6 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
|
|||
idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format++;
|
||||
break;
|
||||
#ifdef PRINTF_SUPPORT_EXPONENTIAL
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
|
@ -333,7 +310,6 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
|
|||
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||
format++;
|
||||
break;
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // ENABLE_FLOAT
|
||||
case 'c':
|
||||
{
|
||||
|
@ -398,16 +374,12 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
|
|||
{
|
||||
width = sizeof(void*) * 2u;
|
||||
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
||||
#ifdef PRINTF_SUPPORT_LONG_LONG
|
||||
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
||||
if (is_ll) {
|
||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16u, precision, width, flags);
|
||||
} else {
|
||||
#endif
|
||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16u, precision, width, flags);
|
||||
#ifdef PRINTF_SUPPORT_LONG_LONG
|
||||
}
|
||||
#endif
|
||||
format++;
|
||||
break;
|
||||
}
|
||||
|
@ -576,7 +548,6 @@ size_t _ntoa_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, uns
|
|||
}
|
||||
|
||||
// internal itoa for 'long long' type
|
||||
#ifdef PRINTF_SUPPORT_LONG_LONG
|
||||
size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen, unsigned long long value, bool negative, unsigned long long base, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||
|
@ -598,7 +569,6 @@ size_t _ntoa_long_long(out_fct_type out, char* buffer, size_t idx, size_t maxlen
|
|||
|
||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_LONG_LONG
|
||||
|
||||
/**
|
||||
* Idea: superleaf1995
|
||||
|
@ -673,11 +643,7 @@ size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double v
|
|||
// test for very large values
|
||||
// standard printf behavior is to print EVERY whole number digit -- which could be 100s of characters overflowing your buffers == bad
|
||||
if ((value > PRINTF_MAX_FLOAT) || (value < -PRINTF_MAX_FLOAT)) {
|
||||
#ifdef PRINTF_SUPPORT_EXPONENTIAL
|
||||
return _etoa(out, buffer, idx, maxlen, value, prec, width, flags);
|
||||
#else
|
||||
return 0u;
|
||||
#endif
|
||||
}
|
||||
|
||||
// test for negative
|
||||
|
@ -774,7 +740,6 @@ size_t _ftoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double v
|
|||
return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
|
||||
}
|
||||
|
||||
#ifdef PRINTF_SUPPORT_EXPONENTIAL
|
||||
// internal ftoa variant for exponential floating-point type, contributed by Martijn Jasperse <m.jasperse@gmail.com>
|
||||
size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double value, unsigned int prec, unsigned int width, unsigned int flags)
|
||||
{
|
||||
|
@ -879,5 +844,4 @@ size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, double v
|
|||
}
|
||||
return idx;
|
||||
}
|
||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||
#endif // ENABLE_FLOAT
|
||||
|
|
Loading…
Reference in a new issue