diff options
author | Alistair Popple <alistair@popple.id.au> | 2018-06-20 15:34:09 +1000 |
---|---|---|
committer | Alistair Popple <alistair@popple.id.au> | 2018-06-25 16:05:38 +1000 |
commit | 92006e53c927472d62ee1637e6ad6cad35b53d5e (patch) | |
tree | d6f3034152c706cf65b69b2a41da4f26febb9f2a /src/ring.c | |
parent | 7e98b3be26424f41876aea9af30085030e80fef3 (diff) | |
download | pdbg-92006e53c927472d62ee1637e6ad6cad35b53d5e.tar.gz pdbg-92006e53c927472d62ee1637e6ad6cad35b53d5e.zip |
pdbg: Use new command parsing
This switches all commands except the htm command to use the new command/option
parsing code. For the moment we leave the usage help and generic targeting flag
processing alone, but future changes should allow this to also use the common
parsing code.
Signed-off-by: Alistair Popple <alistair@popple.id.au>
Diffstat (limited to 'src/ring.c')
-rw-r--r-- | src/ring.c | 32 |
1 files changed, 5 insertions, 27 deletions
@@ -18,11 +18,12 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <assert.h> -#include <target.h> -#include <operations.h> +#include <libpdbg.h> #include "main.h" +#include "optcmd.h" static int pdbg_getring(struct pdbg_target *target, uint32_t index, uint64_t *addr, uint64_t *len) { @@ -51,31 +52,8 @@ static int pdbg_getring(struct pdbg_target *target, uint32_t index, uint64_t *ad return 1; } -int handle_getring(int optind, int argc, char *argv[]) +static int _getring(uint64_t ring_addr, uint64_t ring_len) { - uint64_t ring_addr, ring_len; - char *endptr; - - if (optind + 2 >= argc) { - printf("%s: command '%s' requires two arguments (address and length)\n", - argv[0], argv[optind]); - return -1; - } - - errno = 0; - ring_addr = strtoull(argv[optind + 1], &endptr, 0); - if (errno || *endptr != '\0') { - printf("%s: command '%s' couldn't parse ring address '%s'\n", - argv[0], argv[optind], argv[optind + 1]); - return -1; - } - - ring_len = strtoull(argv[optind + 2], &endptr, 0); - if (errno || *endptr != '\0') { - printf("%s: command '%s' couldn't parse ring length '%s'\n", - argv[0], argv[optind], argv[optind + 2]); - return -1; - } - return for_each_target("chiplet", pdbg_getring, &ring_addr, &ring_len); } +OPTCMD_DEFINE_CMD_WITH_ARGS(getring, _getring, (ADDRESS, DATA)); |