shell: implement optional "BASE#nnnn" numeric literals

function                                             old     new   delta
evaluate_string                                      729     851    +122

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2019-05-19 17:23:31 +02:00
parent 30a4c32a4d
commit 9edd268bad
3 changed files with 51 additions and 6 deletions

View File

@ -65,15 +65,19 @@ PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
#if ENABLE_FEATURE_SH_MATH_64
typedef long long arith_t;
#define ARITH_FMT "%lld"
#define strto_arith_t strtoull
# define ARITH_FMT "%lld"
#else
typedef long arith_t;
#define ARITH_FMT "%ld"
#define strto_arith_t strtoul
# define ARITH_FMT "%ld"
#endif
#if !ENABLE_FEATURE_SH_MATH_BASE
# if ENABLE_FEATURE_SH_MATH_64
# define strto_arith_t strtoull
# else
# define strto_arith_t strtoul
# endif
#endif
//TODO: bash supports "BASE#nnnnn" numeric literals, e.g. 2#1111 = 15.
//Make strto_arith_t() support that?
typedef const char* FAST_FUNC (*arith_var_lookup_t)(const char *name);
typedef void FAST_FUNC (*arith_var_set_t)(const char *name, const char *val);