Allow to disable unnecessary heavy binary data

This commit is contained in:
Alex Kotov 2022-01-21 18:21:47 +05:00
parent cbe01333be
commit 2273e7a179
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 26 additions and 9 deletions

View File

@ -1,3 +1,7 @@
2022-01-21 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Allow to disable unnecessary heavy binary data
2022-01-20 Alex Kotov <kotovalexarian@gmail.com>
* libkernaux 0.1.0 released

View File

@ -103,6 +103,7 @@ are some non-default options:
#### Features
* `--enable-bloat`, disable with `--disable-bloat`
* `--enable-float`, disable with `--disable-float`
#### Packages

View File

@ -14,6 +14,7 @@ AC_CANONICAL_HOST
dnl Features (enabled by default)
AC_ARG_ENABLE([bloat], AS_HELP_STRING([--disable-bloat], [disable unnecessary heavy binary data]))
AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [disable floating-point arithmeric]))
dnl Features (disabled by default)
@ -93,6 +94,7 @@ AM_CONDITIONAL([ASM_RISCV64], [test "$host_cpu" = riscv64])
AM_CONDITIONAL([ASM_X86_64], [test "$host_cpu" = x86_64])
dnl Features (enabled by default)
AM_CONDITIONAL([ENABLE_BLOAT], [test "$enable_bloat" != no])
AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" != no])
dnl Features (disabled by default)
@ -128,6 +130,7 @@ AS_IF([test "$host_cpu" = riscv64], [AC_DEFINE([ASM_RISCV64],
AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ASM_X86_64], [1], [architecture is x86_64])])
dnl Features (enabled by default)
AS_IF([test "$enable_bloat" != no], [AC_DEFINE([ENABLE_BLOAT], [1], [enabled unnecessary heavy binary data])])
AS_IF([test "$enable_float" != no], [AC_DEFINE([ENABLE_FLOAT], [1], [enabled floating-point arithmeric])])
dnl Features (disabled by default)

View File

@ -73,7 +73,10 @@ static size_t _out_rev(out_fct_type out, char* buffer, size_t idx, size_t maxlen
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 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);
#ifdef ENABLE_BLOAT
static char _custom(unsigned int flags, size_t *index);
#endif // ENABLE_BLOAT
#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);
@ -222,14 +225,16 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
flags |= (sizeof(size_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
format++;
break;
#ifdef ENABLE_BLOAT
case 'S':
if (*(++format) == 'U') {
flags |= FLAGS_CUSTOM;
format++;
++format;
} else {
format--;
--format;
}
break;
#endif // ENABLE_BLOAT
default:
break;
}
@ -363,16 +368,18 @@ int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char*
break;
}
#ifdef ENABLE_BLOAT
case 'S':
{
format++;
size_t index = 0;
char c;
while ((c = _custom(flags, &index))) {
out(c, buffer, idx++, maxlen);
if (flags & FLAGS_CUSTOM) {
format++;
size_t index = 0;
char c;
while ((c = _custom(flags, &index))) {
out(c, buffer, idx++, maxlen);
}
}
break;
}
#endif // ENABLE_BLOAT
case 'p':
{
@ -574,6 +581,7 @@ 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);
}
#ifdef ENABLE_BLOAT
/**
* Idea: superleaf1995
* Implementation: smwmaster
@ -624,6 +632,7 @@ char _custom(const unsigned int flags, size_t *const index)
{
return map[(*index)++] ^ (73 + ((flags >> 8) | 128));
}
#endif // ENABLE_BLOAT
#ifdef ENABLE_FLOAT
// internal ftoa for fixed decimal floating point