summaryrefslogtreecommitdiff
path: root/src/helper
diff options
context:
space:
mode:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-17 00:29:56 +0000
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2009-06-17 00:29:56 +0000
commit8b16068941819b951136b07b2e8e70adbe66fd65 (patch)
treed7f1d8509151576e9c360930abe63e11f8c4622d /src/helper
parentc928fe0fa052cc93d7bb6bb02cdc86d805515bb1 (diff)
downloadopenocd_libswd-8b16068941819b951136b07b2e8e70adbe66fd65.tar.gz
openocd_libswd-8b16068941819b951136b07b2e8e70adbe66fd65.tar.bz2
openocd_libswd-8b16068941819b951136b07b2e8e70adbe66fd65.tar.xz
openocd_libswd-8b16068941819b951136b07b2e8e70adbe66fd65.zip
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
Diffstat (limited to 'src/helper')
-rw-r--r--src/helper/command.c25
1 files 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)
+