From 8b16068941819b951136b07b2e8e70adbe66fd65 Mon Sep 17 00:00:00 2001 From: zwelch Date: Wed, 17 Jun 2009 00:29:56 +0000 Subject: [PATCH] Improve definitions of parse_ulong and parse_ullong: - Use macro to eliminate duplicate body definitions. - Rename okay as is_okay; add parenthesis to help "clarify" logic. git-svn-id: svn://svn.berlios.de/openocd/trunk@2253 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/helper/command.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/helper/command.c b/src/helper/command.c index ca8a1c1b..7196cbe1 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -863,17 +863,14 @@ long jim_global_long(const char *variable) return 0; } -int parse_ullong(const char *str, unsigned long long *ul) -{ - char *end; - *ul = strtoull(str, &end, 0); - bool okay = *str && !*end && ULLONG_MAX != *ul; - return okay ? ERROR_OK : ERROR_COMMAND_SYNTAX_ERROR; -} -int parse_ulong(const char *str, unsigned long *ul) -{ - char *end; - *ul = strtoul(str, &end, 0); - bool okay = *str && !*end && ULONG_MAX != *ul; - return okay ? ERROR_OK : ERROR_COMMAND_SYNTAX_ERROR; -} +#define DEFINE_PARSE_NUM_TYPE(name, type, func, max) \ + int parse##name(const char *str, type *ul) \ + { \ + char *end; \ + *ul = func(str, &end, 0); \ + bool is_okay = *str && !*end && (max != *ul); \ + return is_okay ? ERROR_OK : ERROR_COMMAND_SYNTAX_ERROR; \ + } +DEFINE_PARSE_NUM_TYPE(_ulong, unsigned long , strtoul, ULONG_MAX) +DEFINE_PARSE_NUM_TYPE(_ullong, unsigned long long, strtoull, ULLONG_MAX) + -- 2.39.5