@@ -37,6 +37,24 @@ uint32_t *parse_number32(const char *argv)
return n;
}
+uint16_t *parse_number16(const char *argv)
+{
+ unsigned long long tmp;
+ uint16_t *n = malloc(sizeof(*n));
+ char *endptr;
+
+ if (!argv)
+ return NULL;
+
+ errno = 0;
+ tmp = strtoul(argv, &endptr, 0);
+ if (errno || *endptr != '\0' || tmp > UINT16_MAX)
+ return NULL;
+
+ *n = tmp;
+ return n;
+}
+
/* Parse a GPR number, returning an error if it's greater than 32 */
int *parse_gpr(const char *argv)
{
@@ -8,12 +8,14 @@
#define ADDRESS32 (parse_number32, NULL)
#define DATA (parse_number64, NULL)
#define DATA32 (parse_number32, NULL)
+#define DATA16 (parse_number16, NULL)
#define DEFAULT_DATA(default) (parse_number64, default)
#define GPR (parse_gpr, NULL)
#define SPR (parse_spr, NULL)
uint64_t *parse_number64(const char *argv);
uint32_t *parse_number32(const char *argv);
+uint16_t *parse_number16(const char *argv);
int *parse_gpr(const char *argv);
int *parse_spr(const char *argv);
bool *parse_flag_noarg(const char *argv);
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com> --- src/parsers.c | 18 ++++++++++++++++++ src/parsers.h | 2 ++ 2 files changed, 20 insertions(+)