Move definition of parse_type helpers to command.c:
authorzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 17 Jun 2009 00:30:36 +0000 (00:30 +0000)
committerzwelch <zwelch@b42882b7-edfa-0310-969c-e2dbd0fdcd60>
Wed, 17 Jun 2009 00:30:36 +0000 (00:30 +0000)
- 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.c
src/helper/command.h

index 9a8907d6ac13374264339f868c19820264bb2105..bb3de2cec1e958990de17efa934535663635ebf0 100644 (file)
@@ -880,3 +880,32 @@ DEFINE_PARSE_NUM_TYPE(_ulong, unsigned long , strtoul, 0, ULONG_MAX)
 DEFINE_PARSE_NUM_TYPE(_ullong, unsigned long long, strtoull, 0, ULLONG_MAX)
 DEFINE_PARSE_NUM_TYPE(_long, long , strtol, LONG_MIN, LONG_MAX)
 DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MIN, LLONG_MAX)
 DEFINE_PARSE_NUM_TYPE(_ullong, unsigned long long, strtoull, 0, ULLONG_MAX)
 DEFINE_PARSE_NUM_TYPE(_long, long , strtol, LONG_MIN, LONG_MAX)
 DEFINE_PARSE_NUM_TYPE(_llong, long long, strtoll, LLONG_MIN, LLONG_MAX)
+
+#define DEFINE_PARSE_WRAPPER(name, type, min, max, functype, funcname) \
+       int parse_##name(const char *str, type *ul) \
+       { \
+               functype n; \
+               int retval = parse##funcname(str, &n); \
+               if (ERROR_OK != retval) \
+                       return retval; \
+               if (n > max) \
+                       return ERROR_COMMAND_SYNTAX_ERROR; \
+               if (min) \
+                       return ERROR_COMMAND_SYNTAX_ERROR; \
+               *ul = n; \
+               return ERROR_OK; \
+       }       
+
+#define DEFINE_PARSE_ULONG(name, type, min, max) \
+       DEFINE_PARSE_WRAPPER(name, type, min, max, unsigned long, _ulong)
+DEFINE_PARSE_ULONG(uint, unsigned, 0, UINT_MAX)
+DEFINE_PARSE_ULONG(u32, uint32_t, 0, UINT32_MAX)
+DEFINE_PARSE_ULONG(u16, uint16_t, 0, UINT16_MAX)
+DEFINE_PARSE_ULONG(u8, uint8_t, 0, UINT8_MAX)
+
+#define DEFINE_PARSE_LONG(name, type, min, max) \
+       DEFINE_PARSE_WRAPPER(name, type, min, max, long, _long)
+DEFINE_PARSE_LONG(int, int, n < INT_MIN, INT_MAX)
+DEFINE_PARSE_LONG(s32, int32_t, n < INT32_MIN, INT32_MAX)
+DEFINE_PARSE_LONG(s16, int16_t, n < INT16_MIN, INT16_MAX)
+DEFINE_PARSE_LONG(s8, int8_t, n < INT8_MIN, INT8_MAX)
index 4e7180faaf457fadd938be8a264930b6596f83cc..e4908dd0e2ca4ff6d875be8cdb251d403238b02b 100644 (file)
@@ -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);
 
 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);
 
 
 void script_debug(Jim_Interp *interp, const char *cmd, int argc, Jim_Obj *const *argv);
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)