summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyril Bur <cyrilbur@gmail.com>2018-02-09 15:38:40 +1100
committerAlistair Popple <alistair@popple.id.au>2018-02-16 16:22:22 +1100
commitc5067f140bc26727c8a1355119d9b829d9d4ff78 (patch)
tree7dd227fdb7a218a446c065f6da09e78fb7390966
parent96fb461e34868ad3253c2bc6aee1ae0655921c45 (diff)
downloadpdbg-c5067f140bc26727c8a1355119d9b829d9d4ff78.tar.gz
pdbg-c5067f140bc26727c8a1355119d9b829d9d4ff78.zip
main: Prepare to change command handling
Signed-off-by: Cyril Bur <cyrilbur@gmail.com>
-rw-r--r--src/main.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index cdf075d..ca060d6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,6 +26,8 @@
#include <limits.h>
#include <inttypes.h>
+#include <ccan/array_size/array_size.h>
+
#include <config.h>
#include <libpdbg.h>
@@ -76,6 +78,15 @@ static int **processorsel[MAX_PROCESSORS];
static int *chipsel[MAX_PROCESSORS][MAX_CHIPS];
static int threadsel[MAX_PROCESSORS][MAX_CHIPS][MAX_THREADS];
+static struct {
+ const char *name;
+ const char *args;
+ const char *desc;
+ int (*fn)(int, int, char **);
+} actions[] = {
+ { "none yet", "nothing", "placeholder", NULL },
+};
+
static void print_usage(char *pname)
{
printf("Usage: %s [options] command ...\n\n", pname);
@@ -365,8 +376,17 @@ static bool parse_command(int argc, char *argv[])
bool opt_error = true;
char *endptr;
+ /*
+ * In order to make the series changing this code cleaner,
+ * this is going to happen gradually.
+ * Eventually parse_command() will be deleted but so that this
+ * can be done over multiple patches neatly remove the error
+ * check here and print the usage later.
+ * We'll just have a lie a bit for now.
+ */
+ if (i >= argc || !parse_cmd(argv[i]))
+ return false;
- opt_error = i == argc || !parse_cmd(argv[i]);
i++;
while (i < argc && !opt_error) {
if (cmd_arg_idx >= MAX_CMD_ARGS ||
@@ -582,13 +602,19 @@ void print_target(struct pdbg_target *target, int level)
int main(int argc, char *argv[])
{
- int rc = 0;
- uint8_t *buf;
struct pdbg_target *target;
+ bool found = true;
+ int i, rc = 0;
+ uint8_t *buf;
if (parse_options(argc, argv))
return 1;
+ if (optind >= argc) {
+ print_usage(argv[0]);
+ return 1;
+ }
+
/* Disable unselected targets */
if (target_select())
return 1;
@@ -711,10 +737,24 @@ int main(int argc, char *argv[])
rc = run_htm_analyse();
break;
default:
- PR_ERROR("Unsupported command\n");
+ found = false;
break;
}
+ for (i = 0; i < ARRAY_SIZE(actions); i++) {
+ if (strcmp(argv[optind], actions[i].name) == 0) {
+ found = true;
+ rc = actions[i].fn(optind, argc, argv);
+ break;
+ }
+ }
+
+ if (!found) {
+ PR_ERROR("Unsupported command: %s\n", argv[optind]);
+ print_usage(argv[0]);
+ return 1;
+ }
+
if (rc <= 0) {
printf("No valid targets found or specified. Try adding -p/-c/-t options to specify a target.\n");
printf("Alternatively run %s -a probe to get a list of all valid targets\n", argv[0]);
OpenPOWER on IntegriCloud