X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Fstrtonum.h;h=fc99e23749e39147784d1cd252b2c7e6a27102ad;hb=bc2bbfcbe76e78db9cde27455ddbcfe1ddcc61d6;hp=f4ff4f7a06d73d349a9d31e42b3ceea37b092f00;hpb=863b8193b9cff85ac027c78fbcc2f3d9441e126e;p=libucw.git diff --git a/ucw/strtonum.h b/ucw/strtonum.h index f4ff4f7a..fc99e237 100644 --- a/ucw/strtonum.h +++ b/ucw/strtonum.h @@ -10,40 +10,54 @@ #ifndef _STRTONUM_H #define _STRTONUM_H +#ifdef CONFIG_UCW_CLEAN_ABI +#define str_to_uintmax ucw_str_to_uintmax +#define str_to_uint ucw_str_to_uint + +// FIXME: For backwards compatibility, will be removed soon +#define str_to_uns ucw_str_to_uns +#endif + +// Set (flags & 0x1f) in the range 1 to 31 to denote the default base of the number enum str_to_num_flags { STN_SIGNED = 0x20, // The resulting range is signed STN_MINUS = 0x40, // Allow optional '-' sign STN_PLUS = 0x80, // Allow optional '+' sign - STN_TRUNC = 0x100, // Allow range overflow -> truncate to the resulting range - STN_DEC = 0x200, // Support decimal numbers + STN_TRUNC = 0x100, // Allow range overflow -> truncate to the allowed range + STN_DEC = 0x200, // Support decimal numbers (currently no prefix) STN_HEX = 0x400, // Support hexadecimal numbers (0x...) STN_BIN = 0x800, // Support binary numbers (0b...) STN_OCT = 0x1000, // Support octal numbers (0o...) - STN_UNDERSCORE = 0x2000, // Number can contain underscore characters to increase readability (eg. 1_000_000) - STN_ZCHAR = 0x4000, // Number can be terminated only by \0 character + STN_OCT0 = 0x2000, // Support octal numbers (0[0-7]...) + STN_UNDERSCORE = 0x4000, // Number can contain underscore characters to increase readability (eg. 1_000_000) + STN_WHOLE = 0x8000, // Number can be terminated only by \0 character }; #define STN_DBASES_MASK 0x1F #define STN_SIGNS (STN_MINUS | STN_PLUS) #define STN_BASES (STN_DEC | STN_HEX | STN_BIN | STN_OCT) -#define STN_FLAGS (STN_MINUS | STN_PLUS | STN_BASES) -#define STN_UFLAGS (STN_FLAGS | STN_UNDERSCORE) -#define STN_SFLAGS (STN_FLAGS | STN_SIGNED) -#define STN_USFLAGS (STN_SFLAGS | STN_UNDERSCORE) - -#define STN_DECLARE_CONVERTOR(type, suffix) \ -const char *str_to_##suffix(type *num, const char *str, const char **next, const uns flags) - -#define STN_SIGNED_CONVERTOR(utype, itype, suffix) \ -static inline const char *str_to_##suffix(itype *num, const char *str, const char **next, const uns flags) \ -{ \ - return str_to##suffix((utype*) num, str, next, flags | STN_SIGNED); \ +#define STN_BASES0 (STN_BASES | STN_OCT0) +#define STN_FLAGS (STN_MINUS | STN_PLUS | STN_BASES) +#define STN_UFLAGS (STN_FLAGS | STN_UNDERSCORE) +#define STN_SFLAGS (STN_FLAGS | STN_SIGNED) +#define STN_USFLAGS (STN_SFLAGS | STN_UNDERSCORE) + +#define STN_DECLARE_CONVERTOR(type, suffix) \ +const char *str_to_##suffix(type *num, const char *str, const char **next, const uint flags) + +#define STN_SIGNED_CONVERTOR(type, suffix, usuffix) \ +static inline const char *str_to_##suffix(type *num, const char *str, const char **next, const uint flags) \ +{ \ + return str_to_##usuffix((void *) num, str, next, flags | STN_SIGNED | STN_PLUS | STN_MINUS); \ } -STN_DECLARE_CONVERTOR(uns, uns); -STN_SIGNED_CONVERTOR(uns, int, int) +STN_DECLARE_CONVERTOR(uint, uint); +STN_SIGNED_CONVERTOR(int, int, uint) STN_DECLARE_CONVERTOR(uintmax_t, uintmax); -STN_SIGNED_CONVERTOR(uintmax_t, intmax_t, intmax) +STN_SIGNED_CONVERTOR(intmax_t, intmax, uintmax) + +// FIXME: For backwards compatibility, will be removed soon +STN_DECLARE_CONVERTOR(uns, uns); #endif