mirror of https://github.com/sheumann/hush.git
Restructure macros in libbb/xatonum.c and its template file to work with the ORCA/C preprocessor.
Also, get rid of a use of long long.
This commit is contained in:
parent
9850090331
commit
af402a28a4
|
@ -10,10 +10,14 @@
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
#define type long
|
#define type long
|
||||||
#define xstrtou(rest) xstrtoul##rest
|
#define xstrtou xstrtoul
|
||||||
#define xstrto(rest) xstrtol##rest
|
#define xstrto xstrtol
|
||||||
#define xatou(rest) xatoul##rest
|
#define xatou xatoul
|
||||||
#define xato(rest) xatol##rest
|
#define xato xatol
|
||||||
|
#define xstrtou_(rest) xstrtoul_##rest
|
||||||
|
#define xstrto_(rest) xstrtol_##rest
|
||||||
|
#define xatou_(rest) xatoul_##rest
|
||||||
|
#define xato_(rest) xatol_##rest
|
||||||
#define XSTR_UTYPE_MAX ULONG_MAX
|
#define XSTR_UTYPE_MAX ULONG_MAX
|
||||||
#define XSTR_TYPE_MAX LONG_MAX
|
#define XSTR_TYPE_MAX LONG_MAX
|
||||||
#define XSTR_TYPE_MIN LONG_MIN
|
#define XSTR_TYPE_MIN LONG_MIN
|
||||||
|
@ -32,10 +36,14 @@ unsigned bb_strtoui(const char *str, char **end, int b)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
#define type int
|
#define type int
|
||||||
#define xstrtou(rest) xstrtou##rest
|
#define xstrtou xstrtou
|
||||||
#define xstrto(rest) xstrtoi##rest
|
#define xstrto xstrtoi
|
||||||
#define xatou(rest) xatou##rest
|
#define xatou xatou
|
||||||
#define xato(rest) xatoi##rest
|
#define xato xatoi
|
||||||
|
#define xstrtou_(rest) xstrtou_##rest
|
||||||
|
#define xstrto_(rest) xstrtoi_##rest
|
||||||
|
#define xatou_(rest) xatou_##rest
|
||||||
|
#define xato_(rest) xatoi_##rest
|
||||||
#define XSTR_UTYPE_MAX UINT_MAX
|
#define XSTR_UTYPE_MAX UINT_MAX
|
||||||
#define XSTR_TYPE_MAX INT_MAX
|
#define XSTR_TYPE_MAX INT_MAX
|
||||||
#define XSTR_TYPE_MIN INT_MIN
|
#define XSTR_TYPE_MIN INT_MIN
|
||||||
|
|
|
@ -6,17 +6,21 @@
|
||||||
You need to define the following (example):
|
You need to define the following (example):
|
||||||
|
|
||||||
#define type long
|
#define type long
|
||||||
#define xstrtou(rest) xstrtoul##rest
|
#define xstrtou xstrtoul
|
||||||
#define xstrto(rest) xstrtol##rest
|
#define xstrto xstrtol
|
||||||
#define xatou(rest) xatoul##rest
|
#define xatou xatoul
|
||||||
#define xato(rest) xatol##rest
|
#define xato xatol
|
||||||
|
#define xstrtou_(rest) xstrtoul_##rest
|
||||||
|
#define xstrto_(rest) xstrtol_##rest
|
||||||
|
#define xatou_(rest) xatoul_##rest
|
||||||
|
#define xato_(rest) xatol_##rest
|
||||||
#define XSTR_UTYPE_MAX ULONG_MAX
|
#define XSTR_UTYPE_MAX ULONG_MAX
|
||||||
#define XSTR_TYPE_MAX LONG_MAX
|
#define XSTR_TYPE_MAX LONG_MAX
|
||||||
#define XSTR_TYPE_MIN LONG_MIN
|
#define XSTR_TYPE_MIN LONG_MIN
|
||||||
#define XSTR_STRTOU strtoul
|
#define XSTR_STRTOU strtoul
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base,
|
unsigned type FAST_FUNC xstrtou_(range_sfx)(const char *numstr, int base,
|
||||||
unsigned type lower,
|
unsigned type lower,
|
||||||
unsigned type upper,
|
unsigned type upper,
|
||||||
const struct suffix_mult *suffixes)
|
const struct suffix_mult *suffixes)
|
||||||
|
@ -74,53 +78,53 @@ unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base,
|
||||||
bb_error_msg_and_die("invalid number '%s'", numstr);
|
bb_error_msg_and_die("invalid number '%s'", numstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xstrtou(_range)(const char *numstr, int base,
|
unsigned type FAST_FUNC xstrtou_(range)(const char *numstr, int base,
|
||||||
unsigned type lower,
|
unsigned type lower,
|
||||||
unsigned type upper)
|
unsigned type upper)
|
||||||
{
|
{
|
||||||
return xstrtou(_range_sfx)(numstr, base, lower, upper, NULL);
|
return xstrtou_(range_sfx)(numstr, base, lower, upper, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xstrtou(_sfx)(const char *numstr, int base,
|
unsigned type FAST_FUNC xstrtou_(sfx)(const char *numstr, int base,
|
||||||
const struct suffix_mult *suffixes)
|
const struct suffix_mult *suffixes)
|
||||||
{
|
{
|
||||||
return xstrtou(_range_sfx)(numstr, base, 0, XSTR_UTYPE_MAX, suffixes);
|
return xstrtou_(range_sfx)(numstr, base, 0, XSTR_UTYPE_MAX, suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xstrtou()(const char *numstr, int base)
|
unsigned type FAST_FUNC xstrtou(const char *numstr, int base)
|
||||||
{
|
{
|
||||||
return xstrtou(_range_sfx)(numstr, base, 0, XSTR_UTYPE_MAX, NULL);
|
return xstrtou_(range_sfx)(numstr, base, 0, XSTR_UTYPE_MAX, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xatou(_range_sfx)(const char *numstr,
|
unsigned type FAST_FUNC xatou_(range_sfx)(const char *numstr,
|
||||||
unsigned type lower,
|
unsigned type lower,
|
||||||
unsigned type upper,
|
unsigned type upper,
|
||||||
const struct suffix_mult *suffixes)
|
const struct suffix_mult *suffixes)
|
||||||
{
|
{
|
||||||
return xstrtou(_range_sfx)(numstr, 10, lower, upper, suffixes);
|
return xstrtou_(range_sfx)(numstr, 10, lower, upper, suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xatou(_range)(const char *numstr,
|
unsigned type FAST_FUNC xatou_(range)(const char *numstr,
|
||||||
unsigned type lower,
|
unsigned type lower,
|
||||||
unsigned type upper)
|
unsigned type upper)
|
||||||
{
|
{
|
||||||
return xstrtou(_range_sfx)(numstr, 10, lower, upper, NULL);
|
return xstrtou_(range_sfx)(numstr, 10, lower, upper, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xatou(_sfx)(const char *numstr,
|
unsigned type FAST_FUNC xatou_(sfx)(const char *numstr,
|
||||||
const struct suffix_mult *suffixes)
|
const struct suffix_mult *suffixes)
|
||||||
{
|
{
|
||||||
return xstrtou(_range_sfx)(numstr, 10, 0, XSTR_UTYPE_MAX, suffixes);
|
return xstrtou_(range_sfx)(numstr, 10, 0, XSTR_UTYPE_MAX, suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned type FAST_FUNC xatou()(const char *numstr)
|
unsigned type FAST_FUNC xatou(const char *numstr)
|
||||||
{
|
{
|
||||||
return xatou(_sfx)(numstr, NULL);
|
return xatou_(sfx)(numstr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Signed ones */
|
/* Signed ones */
|
||||||
|
|
||||||
type FAST_FUNC xstrto(_range_sfx)(const char *numstr, int base,
|
type FAST_FUNC xstrto_(range_sfx)(const char *numstr, int base,
|
||||||
type lower,
|
type lower,
|
||||||
type upper,
|
type upper,
|
||||||
const struct suffix_mult *suffixes)
|
const struct suffix_mult *suffixes)
|
||||||
|
@ -137,51 +141,51 @@ type FAST_FUNC xstrto(_range_sfx)(const char *numstr, int base,
|
||||||
++u; /* = <type>_MIN (01111... + 1 == 10000...) */
|
++u; /* = <type>_MIN (01111... + 1 == 10000...) */
|
||||||
}
|
}
|
||||||
|
|
||||||
r = xstrtou(_range_sfx)(p, base, 0, u, suffixes);
|
r = xstrtou_(range_sfx)(p, base, 0, u, suffixes);
|
||||||
|
|
||||||
if (*numstr == '-') {
|
if (*numstr == '-') {
|
||||||
r = -r;
|
r = -r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r < lower || r > upper) {
|
if (r < lower || r > upper) {
|
||||||
bb_error_msg_and_die("number %s is not in %lld..%lld range",
|
bb_error_msg_and_die("number %s is not in %" PRIdMAX "..%" PRIdMAX " range",
|
||||||
numstr, (long long)lower, (long long)upper);
|
numstr, (uintmax_t)lower, (uintmax_t)upper);
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
type FAST_FUNC xstrto(_range)(const char *numstr, int base, type lower, type upper)
|
type FAST_FUNC xstrto_(range)(const char *numstr, int base, type lower, type upper)
|
||||||
{
|
{
|
||||||
return xstrto(_range_sfx)(numstr, base, lower, upper, NULL);
|
return xstrto_(range_sfx)(numstr, base, lower, upper, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
type FAST_FUNC xstrto()(const char *numstr, int base)
|
type FAST_FUNC xstrto(const char *numstr, int base)
|
||||||
{
|
{
|
||||||
return xstrto(_range_sfx)(numstr, base, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL);
|
return xstrto_(range_sfx)(numstr, base, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
type FAST_FUNC xato(_range_sfx)(const char *numstr,
|
type FAST_FUNC xato_(range_sfx)(const char *numstr,
|
||||||
type lower,
|
type lower,
|
||||||
type upper,
|
type upper,
|
||||||
const struct suffix_mult *suffixes)
|
const struct suffix_mult *suffixes)
|
||||||
{
|
{
|
||||||
return xstrto(_range_sfx)(numstr, 10, lower, upper, suffixes);
|
return xstrto_(range_sfx)(numstr, 10, lower, upper, suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
type FAST_FUNC xato(_range)(const char *numstr, type lower, type upper)
|
type FAST_FUNC xato_(range)(const char *numstr, type lower, type upper)
|
||||||
{
|
{
|
||||||
return xstrto(_range_sfx)(numstr, 10, lower, upper, NULL);
|
return xstrto_(range_sfx)(numstr, 10, lower, upper, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
type FAST_FUNC xato(_sfx)(const char *numstr, const struct suffix_mult *suffixes)
|
type FAST_FUNC xato_(sfx)(const char *numstr, const struct suffix_mult *suffixes)
|
||||||
{
|
{
|
||||||
return xstrto(_range_sfx)(numstr, 10, XSTR_TYPE_MIN, XSTR_TYPE_MAX, suffixes);
|
return xstrto_(range_sfx)(numstr, 10, XSTR_TYPE_MIN, XSTR_TYPE_MAX, suffixes);
|
||||||
}
|
}
|
||||||
|
|
||||||
type FAST_FUNC xato()(const char *numstr)
|
type FAST_FUNC xato(const char *numstr)
|
||||||
{
|
{
|
||||||
return xstrto(_range_sfx)(numstr, 10, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL);
|
return xstrto_(range_sfx)(numstr, 10, XSTR_TYPE_MIN, XSTR_TYPE_MAX, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef type
|
#undef type
|
||||||
|
@ -189,6 +193,10 @@ type FAST_FUNC xato()(const char *numstr)
|
||||||
#undef xstrto
|
#undef xstrto
|
||||||
#undef xatou
|
#undef xatou
|
||||||
#undef xato
|
#undef xato
|
||||||
|
#undef xstrtou_
|
||||||
|
#undef xstrto_
|
||||||
|
#undef xatou_
|
||||||
|
#undef xato_
|
||||||
#undef XSTR_UTYPE_MAX
|
#undef XSTR_UTYPE_MAX
|
||||||
#undef XSTR_TYPE_MAX
|
#undef XSTR_TYPE_MAX
|
||||||
#undef XSTR_TYPE_MIN
|
#undef XSTR_TYPE_MIN
|
||||||
|
|
Loading…
Reference in New Issue