From 9db82493c339b61cc587cad9e3dbbd5157a4f1d4 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 18 Jun 2010 22:48:14 +0200 Subject: [PATCH] UCW: Cosmetic cleanups of strtonum --- ucw/strtonum-gen.h | 8 ++++++-- ucw/strtonum.c | 2 +- ucw/strtonum.h | 18 +++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ucw/strtonum-gen.h b/ucw/strtonum-gen.h index c21a9880..079548ff 100644 --- a/ucw/strtonum-gen.h +++ b/ucw/strtonum-gen.h @@ -7,8 +7,10 @@ * of the GNU Lesser General Public License. */ -/* This is not a normall header file, it is generator of a function for converting strings to integers - * of a certain type. This file should be used only by ucw/stronum.c . +/* + * This is not a normal header file, it is a generator of a function for + * converting strings to integers of a certain type. This file should be used + * by ucw/stronum.c only. */ #define STN_DECLARE(type, suffix) STN_DECLARE_CONVERTOR(type, suffix) @@ -27,6 +29,7 @@ STN_DECLARE(STN_TYPE, STN_SUFFIX) uns sign, base; err = str_to_num_init(&p, flags, &sign, &base); + const char *parse_string(void) { const STN_TYPE max = STN_MAX; @@ -98,6 +101,7 @@ STN_DECLARE(STN_TYPE, STN_SUFFIX) return NULL; } + if (!err) err = parse_string(); diff --git a/ucw/strtonum.c b/ucw/strtonum.c index 5a494165..43656fca 100644 --- a/ucw/strtonum.c +++ b/ucw/strtonum.c @@ -56,7 +56,7 @@ static const char *str_to_num_init(const char **pp, const uns flags, uns *sign, const char *err = NULL; const char *p = *pp; - // Parse sign + // Parse sign *sign = 0; if (flags & (STN_SIGNS)) { diff --git a/ucw/strtonum.h b/ucw/strtonum.h index 28580415..597790bc 100644 --- a/ucw/strtonum.h +++ b/ucw/strtonum.h @@ -14,7 +14,7 @@ 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_TRUNC = 0x100, // Allow range overflow -> truncate to the allowed range STN_DEC = 0x200, // Support decimal numbers STN_HEX = 0x400, // Support hexadecimal numbers (0x...) STN_BIN = 0x800, // Support binary numbers (0b...) @@ -26,18 +26,18 @@ enum str_to_num_flags { #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_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) \ +#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(type, suffix, usuffix) \ +#define STN_SIGNED_CONVERTOR(type, suffix, usuffix) \ static inline const char *str_to_##suffix(type *num, const char *str, const char **next, const uns flags) \ -{ \ - return str_to_##usuffix((void *) num, str, next, flags | STN_SIGNED); \ +{ \ + return str_to_##usuffix((void *) num, str, next, flags | STN_SIGNED); \ } STN_DECLARE_CONVERTOR(uns, uns); -- 2.39.2