From 0e28997989ffbb65ad765dd1f0c72c251dd86609 Mon Sep 17 00:00:00 2001 From: zwelch Date: Wed, 17 Jun 2009 00:30:36 +0000 Subject: Move definition of parse_type helpers to command.c: - Add declarations in header file. - Improve wrapper implementations to check for underflow. git-svn-id: svn://svn.berlios.de/openocd/trunk@2257 b42882b7-edfa-0310-969c-e2dbd0fdcd60 --- src/helper/command.h | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'src/helper/command.h') diff --git a/src/helper/command.h b/src/helper/command.h index 4e7180fa..e4908dd0 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -113,28 +113,18 @@ int parse_ullong(const char *str, unsigned long long *ul); int parse_long(const char *str, long *ul); int parse_llong(const char *str, long long *ul); -#define DEFINE_PARSE_NUM_WRAP(name, type, max, functype, funcname) \ - static inline int parse_##name(const char *str, type *ul) \ - { \ - functype n; \ - int retval = parse##funcname(str, &n); \ - *ul = n; \ - return n > (max) ? ERROR_COMMAND_SYNTAX_ERROR : retval; \ - } - -#define DEFINE_PARSE_ULONG(name, type, max) \ - DEFINE_PARSE_NUM_WRAP(name, type, max, unsigned long, _ulong) -DEFINE_PARSE_ULONG(uint, unsigned, UINT_MAX) -DEFINE_PARSE_ULONG(u32, uint32_t, UINT32_MAX) -DEFINE_PARSE_ULONG(u16, uint16_t, UINT16_MAX) -DEFINE_PARSE_ULONG(u8, uint8_t, UINT8_MAX) - -#define DEFINE_PARSE_LONG(name, type, max) \ - DEFINE_PARSE_NUM_WRAP(name, type, max, long, _long) -DEFINE_PARSE_LONG(int, int, INT_MAX) -DEFINE_PARSE_LONG(s32, int32_t, INT32_MAX) -DEFINE_PARSE_LONG(s16, int16_t, INT16_MAX) -DEFINE_PARSE_LONG(s8, int8_t, INT8_MAX) +#define DECLARE_PARSE_WRAPPER(name, type) \ + int parse_##name(const char *str, type *ul) + +DECLARE_PARSE_WRAPPER(uint, unsigned); +DECLARE_PARSE_WRAPPER(u32, uint32_t); +DECLARE_PARSE_WRAPPER(u16, uint16_t); +DECLARE_PARSE_WRAPPER(u8, uint8_t); + +DECLARE_PARSE_WRAPPER(int, int); +DECLARE_PARSE_WRAPPER(s32, int32_t); +DECLARE_PARSE_WRAPPER(s16, int16_t); +DECLARE_PARSE_WRAPPER(s8, int8_t); void script_debug(Jim_Interp *interp, const char *cmd, int argc, Jim_Obj *const *argv); -- cgit v1.2.3