This commit is contained in:
@@ -11,7 +11,4 @@ then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Custom compilation..."
|
echo "Custom compilation..."
|
||||||
docker run --rm -v "${PWD}/compiled-firmware/:/app/compiled-firmware" $IMAGE_NAME /bin/bash -c "mkdir -p compiled-firmware; rm ./compiled-firmware/*; cd /app && make -s \
|
docker run --rm -v "${PWD}/compiled-firmware/:/app/compiled-firmware" $IMAGE_NAME /bin/bash -c "mkdir -p ./compiled-firmware; rm ./compiled-firmware/*; cd /app && make -j && cp f4hwn* compiled-firmware/"
|
||||||
EDITION_STRING=Custom \
|
|
||||||
TARGET=f4hwn \
|
|
||||||
&& cp f4hwn* compiled-firmware/"
|
|
827
external/printf/printf.c
vendored
827
external/printf/printf.c
vendored
@@ -40,7 +40,10 @@
|
|||||||
// printf_config.h header file
|
// printf_config.h header file
|
||||||
// default: undefined
|
// default: undefined
|
||||||
#ifdef PRINTF_INCLUDE_CONFIG_H
|
#ifdef PRINTF_INCLUDE_CONFIG_H
|
||||||
#include "printf_config.h"
|
#define PRINTF_DISABLE_SUPPORT_LONG_LONG
|
||||||
|
#define PRINTF_DISABLE_SUPPORT_EXPONENTIAL
|
||||||
|
#define PRINTF_DISABLE_SUPPORT_PTRDIFF_T
|
||||||
|
#define PRINTF_DISABLE_SUPPORT_FLOAT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -119,185 +122,183 @@
|
|||||||
|
|
||||||
|
|
||||||
// output function type
|
// output function type
|
||||||
typedef void (*out_fct_type)(char character, void* buffer, size_t idx, size_t maxlen);
|
typedef void (*out_fct_type)(char character, void *buffer, size_t idx, size_t maxlen);
|
||||||
|
|
||||||
|
|
||||||
// wrapper (used as buffer) for output function type
|
// wrapper (used as buffer) for output function type
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*fct)(char character, void* arg);
|
void (*fct)(char character, void *arg);
|
||||||
void* arg;
|
|
||||||
|
void *arg;
|
||||||
} out_fct_wrap_type;
|
} out_fct_wrap_type;
|
||||||
|
|
||||||
|
|
||||||
// internal buffer output
|
// internal buffer output
|
||||||
static inline void _out_buffer(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_buffer(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
if (idx < maxlen) {
|
||||||
if (idx < maxlen) {
|
((char *) buffer)[idx] = character;
|
||||||
((char*)buffer)[idx] = character;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal null output
|
// internal null output
|
||||||
static inline void _out_null(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_null(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
(void) character;
|
||||||
(void)character; (void)buffer; (void)idx; (void)maxlen;
|
(void) buffer;
|
||||||
|
(void) idx;
|
||||||
|
(void) maxlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal _putchar wrapper
|
// internal _putchar wrapper
|
||||||
static inline void _out_char(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_char(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
(void) buffer;
|
||||||
(void)buffer; (void)idx; (void)maxlen;
|
(void) idx;
|
||||||
if (character) {
|
(void) maxlen;
|
||||||
_putchar(character);
|
if (character) {
|
||||||
}
|
_putchar(character);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal output function wrapper
|
// internal output function wrapper
|
||||||
static inline void _out_fct(char character, void* buffer, size_t idx, size_t maxlen)
|
static inline void _out_fct(char character, void *buffer, size_t idx, size_t maxlen) {
|
||||||
{
|
(void) idx;
|
||||||
(void)idx; (void)maxlen;
|
(void) maxlen;
|
||||||
if (character) {
|
if (character) {
|
||||||
// buffer is the output fct pointer
|
// buffer is the output fct pointer
|
||||||
((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->arg);
|
((out_fct_wrap_type *) buffer)->fct(character, ((out_fct_wrap_type *) buffer)->arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal secure strlen
|
// internal secure strlen
|
||||||
// \return The length of the string (excluding the terminating 0) limited by 'maxsize'
|
// \return The length of the string (excluding the terminating 0) limited by 'maxsize'
|
||||||
static inline unsigned int _strnlen_s(const char* str, size_t maxsize)
|
static inline unsigned int _strnlen_s(const char *str, size_t maxsize) {
|
||||||
{
|
const char *s;
|
||||||
const char* s;
|
for (s = str; *s && maxsize--; ++s);
|
||||||
for (s = str; *s && maxsize--; ++s);
|
return (unsigned int) (s - str);
|
||||||
return (unsigned int)(s - str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal test if char is a digit (0-9)
|
// internal test if char is a digit (0-9)
|
||||||
// \return true if char is a digit
|
// \return true if char is a digit
|
||||||
static inline bool _is_digit(char ch)
|
static inline bool _is_digit(char ch) {
|
||||||
{
|
return (ch >= '0') && (ch <= '9');
|
||||||
return (ch >= '0') && (ch <= '9');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal ASCII string to unsigned int conversion
|
// internal ASCII string to unsigned int conversion
|
||||||
static unsigned int _atoi(const char** str)
|
static unsigned int _atoi(const char **str) {
|
||||||
{
|
unsigned int i = 0U;
|
||||||
unsigned int i = 0U;
|
while (_is_digit(**str)) {
|
||||||
while (_is_digit(**str)) {
|
i = i * 10U + (unsigned int) (*((*str)++) - '0');
|
||||||
i = i * 10U + (unsigned int)(*((*str)++) - '0');
|
}
|
||||||
}
|
return i;
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// output the specified string in reverse, taking care of any zero-padding
|
// output the specified string in reverse, taking care of any zero-padding
|
||||||
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
|
||||||
{
|
_out_rev(out_fct_type out, char *buffer, size_t idx, size_t maxlen, const char *buf, size_t len, unsigned int width,
|
||||||
const size_t start_idx = idx;
|
unsigned int flags) {
|
||||||
|
const size_t start_idx = idx;
|
||||||
|
|
||||||
// pad spaces up to given width
|
// pad spaces up to given width
|
||||||
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
|
if (!(flags & FLAGS_LEFT) && !(flags & FLAGS_ZEROPAD)) {
|
||||||
for (size_t i = len; i < width; i++) {
|
for (size_t i = len; i < width; i++) {
|
||||||
out(' ', buffer, idx++, maxlen);
|
out(' ', buffer, idx++, maxlen);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// reverse string
|
// reverse string
|
||||||
while (len) {
|
while (len) {
|
||||||
out(buf[--len], buffer, idx++, maxlen);
|
out(buf[--len], buffer, idx++, maxlen);
|
||||||
}
|
|
||||||
|
|
||||||
// append pad spaces up to given width
|
|
||||||
if (flags & FLAGS_LEFT) {
|
|
||||||
while (idx - start_idx < width) {
|
|
||||||
out(' ', buffer, idx++, maxlen);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return idx;
|
// append pad spaces up to given width
|
||||||
|
if (flags & FLAGS_LEFT) {
|
||||||
|
while (idx - start_idx < width) {
|
||||||
|
out(' ', buffer, idx++, maxlen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal itoa format
|
// internal itoa format
|
||||||
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_format(out_fct_type out, char *buffer, size_t idx, size_t maxlen, char *buf, size_t len, bool negative,
|
||||||
// pad leading zeros
|
unsigned int base, unsigned int prec, unsigned int width, unsigned int flags) {
|
||||||
if (!(flags & FLAGS_LEFT)) {
|
// pad leading zeros
|
||||||
if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
if (!(flags & FLAGS_LEFT)) {
|
||||||
width--;
|
if (width && (flags & FLAGS_ZEROPAD) && (negative || (flags & (FLAGS_PLUS | FLAGS_SPACE)))) {
|
||||||
|
width--;
|
||||||
|
}
|
||||||
|
while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
|
buf[len++] = '0';
|
||||||
|
}
|
||||||
|
while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
|
buf[len++] = '0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
while ((len < prec) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
|
||||||
buf[len++] = '0';
|
|
||||||
}
|
|
||||||
while ((flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
|
||||||
buf[len++] = '0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle hash
|
// handle hash
|
||||||
if (flags & FLAGS_HASH) {
|
if (flags & FLAGS_HASH) {
|
||||||
if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) {
|
if (!(flags & FLAGS_PRECISION) && len && ((len == prec) || (len == width))) {
|
||||||
len--;
|
len--;
|
||||||
if (len && (base == 16U)) {
|
if (len && (base == 16U)) {
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
if ((base == 16U) && !(flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
buf[len++] = 'x';
|
buf[len++] = 'x';
|
||||||
}
|
} else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
else if ((base == 16U) && (flags & FLAGS_UPPERCASE) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
buf[len++] = 'X';
|
||||||
buf[len++] = 'X';
|
} else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
||||||
}
|
buf[len++] = 'b';
|
||||||
else if ((base == 2U) && (len < PRINTF_NTOA_BUFFER_SIZE)) {
|
}
|
||||||
buf[len++] = 'b';
|
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
||||||
|
buf[len++] = '0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
||||||
buf[len++] = '0';
|
if (negative) {
|
||||||
|
buf[len++] = '-';
|
||||||
|
} else if (flags & FLAGS_PLUS) {
|
||||||
|
buf[len++] = '+'; // ignore the space if the '+' exists
|
||||||
|
} else if (flags & FLAGS_SPACE) {
|
||||||
|
buf[len++] = ' ';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (len < PRINTF_NTOA_BUFFER_SIZE) {
|
return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
|
||||||
if (negative) {
|
|
||||||
buf[len++] = '-';
|
|
||||||
}
|
|
||||||
else if (flags & FLAGS_PLUS) {
|
|
||||||
buf[len++] = '+'; // ignore the space if the '+' exists
|
|
||||||
}
|
|
||||||
else if (flags & FLAGS_SPACE) {
|
|
||||||
buf[len++] = ' ';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return _out_rev(out, buffer, idx, maxlen, buf, len, width, flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// internal itoa for 'long' type
|
// internal itoa for 'long' type
|
||||||
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 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) {
|
||||||
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
char buf[PRINTF_NTOA_BUFFER_SIZE];
|
||||||
size_t len = 0U;
|
size_t len = 0U;
|
||||||
|
|
||||||
// no hash for 0 values
|
// no hash for 0 values
|
||||||
if (!value) {
|
if (!value) {
|
||||||
flags &= ~FLAGS_HASH;
|
flags &= ~FLAGS_HASH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write if precision != 0 and value is != 0
|
// write if precision != 0 and value is != 0
|
||||||
if (!(flags & FLAGS_PRECISION) || value) {
|
if (!(flags & FLAGS_PRECISION) || value) {
|
||||||
do {
|
do {
|
||||||
const char digit = (char)(value % base);
|
const char digit = (char) (value % base);
|
||||||
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
buf[len++] = digit < 10 ? '0' + digit : (flags & FLAGS_UPPERCASE ? 'A' : 'a') + digit - 10;
|
||||||
value /= base;
|
value /= base;
|
||||||
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
|
} while (value && (len < PRINTF_NTOA_BUFFER_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int)base, prec, width, flags);
|
return _ntoa_format(out, buffer, idx, maxlen, buf, len, negative, (unsigned int) base, prec, width, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -574,341 +575,353 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d
|
|||||||
|
|
||||||
|
|
||||||
// internal vsnprintf
|
// internal vsnprintf
|
||||||
static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va)
|
static int _vsnprintf(out_fct_type out, char *buffer, const size_t maxlen, const char *format, va_list va) {
|
||||||
{
|
unsigned int flags, width, precision, n;
|
||||||
unsigned int flags, width, precision, n;
|
size_t idx = 0U;
|
||||||
size_t idx = 0U;
|
|
||||||
|
|
||||||
if (!buffer) {
|
if (!buffer) {
|
||||||
// use null output function
|
// use null output function
|
||||||
out = _out_null;
|
out = _out_null;
|
||||||
}
|
|
||||||
|
|
||||||
while (*format)
|
|
||||||
{
|
|
||||||
// format specifier? %[flags][width][.precision][length]
|
|
||||||
if (*format != '%') {
|
|
||||||
// no
|
|
||||||
out(*format, buffer, idx++, maxlen);
|
|
||||||
format++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// yes, evaluate it
|
|
||||||
format++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// evaluate flags
|
while (*format) {
|
||||||
flags = 0U;
|
// format specifier? %[flags][width][.precision][length]
|
||||||
do {
|
if (*format != '%') {
|
||||||
switch (*format) {
|
// no
|
||||||
case '0': flags |= FLAGS_ZEROPAD; format++; n = 1U; break;
|
out(*format, buffer, idx++, maxlen);
|
||||||
case '-': flags |= FLAGS_LEFT; format++; n = 1U; break;
|
format++;
|
||||||
case '+': flags |= FLAGS_PLUS; format++; n = 1U; break;
|
continue;
|
||||||
case ' ': flags |= FLAGS_SPACE; format++; n = 1U; break;
|
} else {
|
||||||
case '#': flags |= FLAGS_HASH; format++; n = 1U; break;
|
// yes, evaluate it
|
||||||
default : n = 0U; break;
|
format++;
|
||||||
}
|
|
||||||
} while (n);
|
|
||||||
|
|
||||||
// evaluate width field
|
|
||||||
width = 0U;
|
|
||||||
if (_is_digit(*format)) {
|
|
||||||
width = _atoi(&format);
|
|
||||||
}
|
|
||||||
else if (*format == '*') {
|
|
||||||
const int w = va_arg(va, int);
|
|
||||||
if (w < 0) {
|
|
||||||
flags |= FLAGS_LEFT; // reverse padding
|
|
||||||
width = (unsigned int)-w;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
width = (unsigned int)w;
|
|
||||||
}
|
|
||||||
format++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// evaluate precision field
|
|
||||||
precision = 0U;
|
|
||||||
if (*format == '.') {
|
|
||||||
flags |= FLAGS_PRECISION;
|
|
||||||
format++;
|
|
||||||
if (_is_digit(*format)) {
|
|
||||||
precision = _atoi(&format);
|
|
||||||
}
|
|
||||||
else if (*format == '*') {
|
|
||||||
const int prec = (int)va_arg(va, int);
|
|
||||||
precision = prec > 0 ? (unsigned int)prec : 0U;
|
|
||||||
format++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// evaluate length field
|
|
||||||
switch (*format) {
|
|
||||||
case 'l' :
|
|
||||||
flags |= FLAGS_LONG;
|
|
||||||
format++;
|
|
||||||
if (*format == 'l') {
|
|
||||||
flags |= FLAGS_LONG_LONG;
|
|
||||||
format++;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 'h' :
|
// evaluate flags
|
||||||
flags |= FLAGS_SHORT;
|
flags = 0U;
|
||||||
format++;
|
do {
|
||||||
if (*format == 'h') {
|
switch (*format) {
|
||||||
flags |= FLAGS_CHAR;
|
case '0':
|
||||||
format++;
|
flags |= FLAGS_ZEROPAD;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
flags |= FLAGS_LEFT;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case '+':
|
||||||
|
flags |= FLAGS_PLUS;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
flags |= FLAGS_SPACE;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
case '#':
|
||||||
|
flags |= FLAGS_HASH;
|
||||||
|
format++;
|
||||||
|
n = 1U;
|
||||||
|
break;
|
||||||
|
default :
|
||||||
|
n = 0U;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (n);
|
||||||
|
|
||||||
|
// evaluate width field
|
||||||
|
width = 0U;
|
||||||
|
if (_is_digit(*format)) {
|
||||||
|
width = _atoi(&format);
|
||||||
|
} else if (*format == '*') {
|
||||||
|
const int w = va_arg(va, int);
|
||||||
|
if (w < 0) {
|
||||||
|
flags |= FLAGS_LEFT; // reverse padding
|
||||||
|
width = (unsigned int) -w;
|
||||||
|
} else {
|
||||||
|
width = (unsigned int) w;
|
||||||
|
}
|
||||||
|
format++;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
// evaluate precision field
|
||||||
|
precision = 0U;
|
||||||
|
if (*format == '.') {
|
||||||
|
flags |= FLAGS_PRECISION;
|
||||||
|
format++;
|
||||||
|
if (_is_digit(*format)) {
|
||||||
|
precision = _atoi(&format);
|
||||||
|
} else if (*format == '*') {
|
||||||
|
const int prec = (int) va_arg(va, int);
|
||||||
|
precision = prec > 0 ? (unsigned int) prec : 0U;
|
||||||
|
format++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// evaluate length field
|
||||||
|
switch (*format) {
|
||||||
|
case 'l' :
|
||||||
|
flags |= FLAGS_LONG;
|
||||||
|
format++;
|
||||||
|
if (*format == 'l') {
|
||||||
|
flags |= FLAGS_LONG_LONG;
|
||||||
|
format++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'h' :
|
||||||
|
flags |= FLAGS_SHORT;
|
||||||
|
format++;
|
||||||
|
if (*format == 'h') {
|
||||||
|
flags |= FLAGS_CHAR;
|
||||||
|
format++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
|
#if defined(PRINTF_SUPPORT_PTRDIFF_T)
|
||||||
case 't' :
|
case 't' :
|
||||||
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'j' :
|
case 'j' :
|
||||||
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
flags |= (sizeof(intmax_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
case 'z' :
|
case 'z' :
|
||||||
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
default :
|
default :
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
// evaluate specifier
|
|
||||||
switch (*format) {
|
|
||||||
case 'd' :
|
|
||||||
case 'i' :
|
|
||||||
case 'u' :
|
|
||||||
case 'x' :
|
|
||||||
case 'X' :
|
|
||||||
case 'o' :
|
|
||||||
case 'b' : {
|
|
||||||
// set the base
|
|
||||||
unsigned int base;
|
|
||||||
if (*format == 'x' || *format == 'X') {
|
|
||||||
base = 16U;
|
|
||||||
}
|
|
||||||
else if (*format == 'o') {
|
|
||||||
base = 8U;
|
|
||||||
}
|
|
||||||
else if (*format == 'b') {
|
|
||||||
base = 2U;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
base = 10U;
|
|
||||||
flags &= ~FLAGS_HASH; // no hash for dec format
|
|
||||||
}
|
|
||||||
// uppercase
|
|
||||||
if (*format == 'X') {
|
|
||||||
flags |= FLAGS_UPPERCASE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// no plus or space flag for u, x, X, o, b
|
// evaluate specifier
|
||||||
if ((*format != 'i') && (*format != 'd')) {
|
switch (*format) {
|
||||||
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
|
case 'd' :
|
||||||
}
|
case 'i' :
|
||||||
|
case 'u' :
|
||||||
|
case 'x' :
|
||||||
|
case 'X' :
|
||||||
|
case 'o' :
|
||||||
|
case 'b' : {
|
||||||
|
// set the base
|
||||||
|
unsigned int base;
|
||||||
|
if (*format == 'x' || *format == 'X') {
|
||||||
|
base = 16U;
|
||||||
|
} else if (*format == 'o') {
|
||||||
|
base = 8U;
|
||||||
|
} else if (*format == 'b') {
|
||||||
|
base = 2U;
|
||||||
|
} else {
|
||||||
|
base = 10U;
|
||||||
|
flags &= ~FLAGS_HASH; // no hash for dec format
|
||||||
|
}
|
||||||
|
// uppercase
|
||||||
|
if (*format == 'X') {
|
||||||
|
flags |= FLAGS_UPPERCASE;
|
||||||
|
}
|
||||||
|
|
||||||
// ignore '0' flag when precision is given
|
// no plus or space flag for u, x, X, o, b
|
||||||
if (flags & FLAGS_PRECISION) {
|
if ((*format != 'i') && (*format != 'd')) {
|
||||||
flags &= ~FLAGS_ZEROPAD;
|
flags &= ~(FLAGS_PLUS | FLAGS_SPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert the integer
|
// ignore '0' flag when precision is given
|
||||||
if ((*format == 'i') || (*format == 'd')) {
|
if (flags & FLAGS_PRECISION) {
|
||||||
// signed
|
flags &= ~FLAGS_ZEROPAD;
|
||||||
if (flags & FLAGS_LONG_LONG) {
|
}
|
||||||
|
|
||||||
|
// convert the integer
|
||||||
|
if ((*format == 'i') || (*format == 'd')) {
|
||||||
|
// signed
|
||||||
|
if (flags & FLAGS_LONG_LONG) {
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
const long long value = va_arg(va, 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);
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, (unsigned long long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (flags & FLAGS_LONG) {
|
||||||
else if (flags & FLAGS_LONG) {
|
const long value = va_arg(va, long);
|
||||||
const long value = va_arg(va, long);
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long) (value > 0 ? value : 0 - value),
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
value < 0, base, precision, width, flags);
|
||||||
}
|
} else {
|
||||||
else {
|
const int value = (flags & FLAGS_CHAR) ? (char) va_arg(va, int) : (flags & FLAGS_SHORT)
|
||||||
const int value = (flags & FLAGS_CHAR) ? (char)va_arg(va, int) : (flags & FLAGS_SHORT) ? (short int)va_arg(va, int) : va_arg(va, int);
|
? (short int) va_arg(va, int)
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int)(value > 0 ? value : 0 - value), value < 0, base, precision, width, flags);
|
: va_arg(va, int);
|
||||||
}
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned int) (value > 0 ? value : 0 - value),
|
||||||
}
|
value < 0, base, precision, width, flags);
|
||||||
else {
|
}
|
||||||
// unsigned
|
} else {
|
||||||
if (flags & FLAGS_LONG_LONG) {
|
// unsigned
|
||||||
|
if (flags & FLAGS_LONG_LONG) {
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, va_arg(va, unsigned long long), false, base, precision, width, flags);
|
||||||
#endif
|
#endif
|
||||||
}
|
} else if (flags & FLAGS_LONG) {
|
||||||
else if (flags & FLAGS_LONG) {
|
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision,
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, va_arg(va, unsigned long), false, base, precision, width, flags);
|
width, flags);
|
||||||
}
|
} else {
|
||||||
else {
|
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char) va_arg(va, unsigned int)
|
||||||
const unsigned int value = (flags & FLAGS_CHAR) ? (unsigned char)va_arg(va, unsigned int) : (flags & FLAGS_SHORT) ? (unsigned short int)va_arg(va, unsigned int) : va_arg(va, unsigned int);
|
: (flags & FLAGS_SHORT)
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
? (unsigned short int) va_arg(va,
|
||||||
}
|
unsigned int)
|
||||||
}
|
: va_arg(va, unsigned int);
|
||||||
format++;
|
idx = _ntoa_long(out, buffer, idx, maxlen, value, false, base, precision, width, flags);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
format++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
#if defined(PRINTF_SUPPORT_FLOAT)
|
#if defined(PRINTF_SUPPORT_FLOAT)
|
||||||
case 'f' :
|
case 'f' :
|
||||||
case 'F' :
|
case 'F' :
|
||||||
if (*format == 'F') flags |= FLAGS_UPPERCASE;
|
if (*format == 'F') flags |= FLAGS_UPPERCASE;
|
||||||
idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
idx = _ftoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
#if defined(PRINTF_SUPPORT_EXPONENTIAL)
|
||||||
case 'e':
|
case 'e':
|
||||||
case 'E':
|
case 'E':
|
||||||
case 'g':
|
case 'g':
|
||||||
case 'G':
|
case 'G':
|
||||||
if ((*format == 'g')||(*format == 'G')) flags |= FLAGS_ADAPT_EXP;
|
if ((*format == 'g')||(*format == 'G')) flags |= FLAGS_ADAPT_EXP;
|
||||||
if ((*format == 'E')||(*format == 'G')) flags |= FLAGS_UPPERCASE;
|
if ((*format == 'E')||(*format == 'G')) flags |= FLAGS_UPPERCASE;
|
||||||
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
idx = _etoa(out, buffer, idx, maxlen, va_arg(va, double), precision, width, flags);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
#endif // PRINTF_SUPPORT_EXPONENTIAL
|
||||||
#endif // PRINTF_SUPPORT_FLOAT
|
#endif // PRINTF_SUPPORT_FLOAT
|
||||||
case 'c' : {
|
case 'c' : {
|
||||||
unsigned int l = 1U;
|
unsigned int l = 1U;
|
||||||
// pre padding
|
// pre padding
|
||||||
if (!(flags & FLAGS_LEFT)) {
|
if (!(flags & FLAGS_LEFT)) {
|
||||||
while (l++ < width) {
|
while (l++ < width) {
|
||||||
out(' ', buffer, idx++, maxlen);
|
out(' ', buffer, idx++, maxlen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// char output
|
// char output
|
||||||
out((char)va_arg(va, int), buffer, idx++, maxlen);
|
out((char) va_arg(va, int), buffer, idx++, maxlen);
|
||||||
// post padding
|
// post padding
|
||||||
if (flags & FLAGS_LEFT) {
|
if (flags & FLAGS_LEFT) {
|
||||||
while (l++ < width) {
|
while (l++ < width) {
|
||||||
out(' ', buffer, idx++, maxlen);
|
out(' ', buffer, idx++, maxlen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 's' : {
|
case 's' : {
|
||||||
const char* p = va_arg(va, char*);
|
const char *p = va_arg(va, char*);
|
||||||
unsigned int l = _strnlen_s(p, precision ? precision : (size_t)-1);
|
unsigned int l = _strnlen_s(p, precision ? precision : (size_t) -1);
|
||||||
// pre padding
|
// pre padding
|
||||||
if (flags & FLAGS_PRECISION) {
|
if (flags & FLAGS_PRECISION) {
|
||||||
l = (l < precision ? l : precision);
|
l = (l < precision ? l : precision);
|
||||||
}
|
}
|
||||||
if (!(flags & FLAGS_LEFT)) {
|
if (!(flags & FLAGS_LEFT)) {
|
||||||
while (l++ < width) {
|
while (l++ < width) {
|
||||||
out(' ', buffer, idx++, maxlen);
|
out(' ', buffer, idx++, maxlen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// string output
|
// string output
|
||||||
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
while ((*p != 0) && (!(flags & FLAGS_PRECISION) || precision--)) {
|
||||||
out(*(p++), buffer, idx++, maxlen);
|
out(*(p++), buffer, idx++, maxlen);
|
||||||
}
|
}
|
||||||
// post padding
|
// post padding
|
||||||
if (flags & FLAGS_LEFT) {
|
if (flags & FLAGS_LEFT) {
|
||||||
while (l++ < width) {
|
while (l++ < width) {
|
||||||
out(' ', buffer, idx++, maxlen);
|
out(' ', buffer, idx++, maxlen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'p' : {
|
case 'p' : {
|
||||||
width = sizeof(void*) * 2U;
|
width = sizeof(void *) * 2U;
|
||||||
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
const bool is_ll = sizeof(uintptr_t) == sizeof(long long);
|
||||||
if (is_ll) {
|
if (is_ll) {
|
||||||
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags);
|
idx = _ntoa_long_long(out, buffer, idx, maxlen, (uintptr_t)va_arg(va, void*), false, 16U, precision, width, flags);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#endif
|
#endif
|
||||||
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long)((uintptr_t)va_arg(va, void*)), false, 16U, precision, width, flags);
|
idx = _ntoa_long(out, buffer, idx, maxlen, (unsigned long) ((uintptr_t) va_arg(va, void*)), false, 16U,
|
||||||
|
precision, width, flags);
|
||||||
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
#if defined(PRINTF_SUPPORT_LONG_LONG)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case '%' :
|
case '%' :
|
||||||
out('%', buffer, idx++, maxlen);
|
out('%', buffer, idx++, maxlen);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default :
|
||||||
out(*format, buffer, idx++, maxlen);
|
out(*format, buffer, idx++, maxlen);
|
||||||
format++;
|
format++;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// termination
|
// termination
|
||||||
out((char)0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
|
out((char) 0, buffer, idx < maxlen ? idx : maxlen - 1U, maxlen);
|
||||||
|
|
||||||
// return written chars without terminating \0
|
// return written chars without terminating \0
|
||||||
return (int)idx;
|
return (int) idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
int printf_(const char* format, ...)
|
int printf_(const char *format, ...) {
|
||||||
{
|
va_list va;
|
||||||
va_list va;
|
va_start(va, format);
|
||||||
va_start(va, format);
|
char buffer[1];
|
||||||
char buffer[1];
|
const int ret = _vsnprintf(_out_char, buffer, (size_t) -1, format, va);
|
||||||
const int ret = _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
va_end(va);
|
||||||
va_end(va);
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int sprintf_(char* buffer, const char* format, ...)
|
int sprintf_(char *buffer, const char *format, ...) {
|
||||||
{
|
va_list va;
|
||||||
va_list va;
|
va_start(va, format);
|
||||||
va_start(va, format);
|
const int ret = _vsnprintf(_out_buffer, buffer, (size_t) -1, format, va);
|
||||||
const int ret = _vsnprintf(_out_buffer, buffer, (size_t)-1, format, va);
|
va_end(va);
|
||||||
va_end(va);
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int snprintf_(char* buffer, size_t count, const char* format, ...)
|
int snprintf_(char *buffer, size_t count, const char *format, ...) {
|
||||||
{
|
va_list va;
|
||||||
va_list va;
|
va_start(va, format);
|
||||||
va_start(va, format);
|
const int ret = _vsnprintf(_out_buffer, buffer, count, format, va);
|
||||||
const int ret = _vsnprintf(_out_buffer, buffer, count, format, va);
|
va_end(va);
|
||||||
va_end(va);
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vprintf_(const char* format, va_list va)
|
int vprintf_(const char *format, va_list va) {
|
||||||
{
|
char buffer[1];
|
||||||
char buffer[1];
|
return _vsnprintf(_out_char, buffer, (size_t) -1, format, va);
|
||||||
return _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
|
int vsnprintf_(char *buffer, size_t count, const char *format, va_list va) {
|
||||||
{
|
return _vsnprintf(_out_buffer, buffer, count, format, va);
|
||||||
return _vsnprintf(_out_buffer, buffer, count, format, va);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
|
int fctprintf(void (*out)(char character, void *arg), void *arg, const char *format, ...) {
|
||||||
{
|
va_list va;
|
||||||
va_list va;
|
va_start(va, format);
|
||||||
va_start(va, format);
|
const out_fct_wrap_type out_fct_wrap = {out, arg};
|
||||||
const out_fct_wrap_type out_fct_wrap = { out, arg };
|
const int ret = _vsnprintf(_out_fct, (char *) (uintptr_t) &out_fct_wrap, (size_t) -1, format, va);
|
||||||
const int ret = _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va);
|
va_end(va);
|
||||||
va_end(va);
|
return ret;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
#define PRINTF_DISABLE_SUPPORT_LONG_LONG
|
|
||||||
#define PRINTF_DISABLE_SUPPORT_EXPONENTIAL
|
|
||||||
#define PRINTF_DISABLE_SUPPORT_PTRDIFF_T
|
|
||||||
#define PRINTF_DISABLE_SUPPORT_FLOAT
|
|
Reference in New Issue
Block a user