summaryrefslogtreecommitdiff
path: root/avr
diff options
context:
space:
mode:
authorLeo C2018-04-08 12:48:28 +0200
committerLeo C2018-07-21 13:15:41 +0200
commit5caa8c2b8906f17ca97aad2be3d746c3b5fef8f3 (patch)
tree26855a716ec1b1ee87f6ee7f98cd6748618f8f00 /avr
parent8da60ec50c642816ed55a2004e99afea1cc25147 (diff)
downloadz180-stamp-5caa8c2b8906f17ca97aad2be3d746c3b5fef8f3.zip
Global help
Diffstat (limited to 'avr')
-rw-r--r--avr/Tupfile2
-rw-r--r--avr/cmd_fat.c25
-rw-r--r--avr/cmd_help.c16
-rw-r--r--avr/cmd_sd.c26
-rw-r--r--avr/command.c91
-rw-r--r--avr/command_tbl.c3
6 files changed, 56 insertions, 107 deletions
diff --git a/avr/Tupfile b/avr/Tupfile
index c5a265d..d650514 100644
--- a/avr/Tupfile
+++ b/avr/Tupfile
@@ -7,7 +7,7 @@ FATFS = $(FATFSD)/ff.c $(FATFSD)/ffunicode.c
SRC = main.c
SRC += cli.c cli_readline.c command.c command_tbl.c
-SRC += cmd_help.c cmd_run.c cmd_boot.c cmd_misc.c
+SRC += cmd_run.c cmd_boot.c cmd_misc.c
SRC += cmd_date.c cmd_mem.c cmd_gpio.c cmd_attach.c
SRC += cmd_loadihex.c cmd_loadcpm3.c cmd_sd.c cmd_fat.c
SRC += env.c xmalloc.c con-utils.c print-utils.c
diff --git a/avr/cmd_fat.c b/avr/cmd_fat.c
index 0fc6f83..bb0eca1 100644
--- a/avr/cmd_fat.c
+++ b/avr/cmd_fat.c
@@ -536,9 +536,6 @@ command_ret_t do_rw(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const
}
-static
-command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
-
cmd_tbl_t cmd_tbl_fat[] = {
CMD_TBL_ITEM(
stat, 2, CTBL_REPEAT, do_stat,
@@ -600,31 +597,13 @@ CMD_TBL_ITEM(
#endif
},
/* Mark end of table */
-{ 0 },
+CMD_TBL_END(cmd_tbl_fat)
};
-static
-command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
-{
- return _do_help(cmd_tbl_fat, cmdtp, flag, argc, argv);
-}
-
command_ret_t do_fat(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
{
- cmd_tbl_t *cp;
-
- if (argc < 2)
- return CMD_RET_USAGE;
-
- /* drop initial "fat" arg */
- argc--;
- argv++;
-
- cp = find_cmd(argv[0], cmd_tbl_fat);
-
- if (cp)
- return cp->cmd(cmdtp, flag, argc, argv);
+ puts_P(PSTR("Huch?"));
return CMD_RET_USAGE;
}
diff --git a/avr/cmd_help.c b/avr/cmd_help.c
deleted file mode 100644
index 4a52f5e..0000000
--- a/avr/cmd_help.c
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
- *
- * Copyright 2000-2009
- * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier: GPL-2.0
- */
-
-#include "common.h"
-#include "command.h"
-
-command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
-{
- return _do_help(cmd_tbl, cmdtp, flag, argc, argv);
-}
diff --git a/avr/cmd_sd.c b/avr/cmd_sd.c
index 98955bd..9cd664b 100644
--- a/avr/cmd_sd.c
+++ b/avr/cmd_sd.c
@@ -316,9 +316,6 @@ command_ret_t do_ioctl_sync(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char
}
-static
-command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[]);
-
cmd_tbl_t cmd_tbl_sd[] = {
CMD_TBL_ITEM(
status, 2, CTBL_REPEAT, do_status,
@@ -377,31 +374,12 @@ CMD_TBL_ITEM(
#endif
},
/* Mark end of table */
-{ 0 },
+CMD_TBL_END(cmd_tbl_sd)
};
-static
-command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
-{
- return _do_help(cmd_tbl_sd, cmdtp, flag, argc, argv);
-}
-
command_ret_t do_sd(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
{
- cmd_tbl_t *cp;
-
- if (argc < 2)
- return CMD_RET_USAGE;
-
- /* drop initial "sd" arg */
- argc--;
- argv++;
-
- cp = find_cmd(argv[0], cmd_tbl_sd);
-
- if (cp)
- return cp->cmd(cmdtp, flag, argc, argv);
-
+ puts_P("Huch?");
return CMD_RET_USAGE;
}
diff --git a/avr/command.c b/avr/command.c
index 07fff78..938edc3 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -69,17 +69,64 @@ int cmd_tbl_item_count(cmd_tbl_t *p)
return count;
}
+/***************************************************************************
+ * find command table entry for a command
+ */
+cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table)
+{
+ cmd_tbl_t *cmdtp;
+ cmd_tbl_t *cmdtp_temp = table; /*Init value */
+ int table_len = cmd_tbl_item_count(table);
+ size_t len;
+ uint_fast8_t n_found = 0;
+
+ char *optenv = getenv_str(PSTR("cmd"));
+ bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
+
+ if (!cmd)
+ return NULL;
+
+ len = strlen(cmd);
+
+ for (cmdtp = table;
+ cmdtp != table + table_len;
+ cmdtp++) {
+ if (strncmp_P(cmd, cmdtp->name, len) == 0 &&
+ (opt_debug || cmdtp->name[0] != '!')) {
+ if (len == strlen_P(cmdtp->name))
+ return cmdtp; /* full match */
+
+ cmdtp_temp = cmdtp; /* abbreviated command ? */
+ n_found++;
+ }
+ }
+ if (n_found == 1) /* exactly one match */
+ return cmdtp_temp;
+
+ return NULL; /* not found or ambiguous command */
+}
+
+cmd_tbl_t *get_cmd_tbl_start(cmd_tbl_t *cmdtp)
+{
+ cmd_tbl_t *p = cmdtp;
+
+ while (p->name != NULL)
+ ++p;
+
+ return p->subcmd;
+}
+
/*
* Use puts() instead of printf() to avoid printf buffer overflow
* for long help messages
*/
-command_ret_t _do_help(cmd_tbl_t *tbl_start, cmd_tbl_t * cmdtp,
- uint_fast8_t flag, int argc, char * const argv[])
+command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
{
-
(void) flag;
+ cmd_tbl_t *tbl_start = get_cmd_tbl_start(cmdtp);
+
char *optenv = getenv_str(PSTR("cmd"));
bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
@@ -139,44 +186,6 @@ command_ret_t _do_help(cmd_tbl_t *tbl_start, cmd_tbl_t * cmdtp,
return CMD_RET_SUCCESS;
}
-/***************************************************************************
- * find command table entry for a command
- */
-cmd_tbl_t *find_cmd (const char *cmd, cmd_tbl_t *table)
-{
- cmd_tbl_t *cmdtp;
- cmd_tbl_t *cmdtp_temp = table; /*Init value */
- int table_len = cmd_tbl_item_count(table);
- size_t len;
- uint_fast8_t n_found = 0;
-
- char *optenv = getenv_str(PSTR("cmd"));
- bool opt_debug = optenv && strstr_P(optenv, PSTR("debug")) != NULL;
-
- if (!cmd)
- return NULL;
-
- len = strlen(cmd);
-
- for (cmdtp = table;
- cmdtp != table + table_len;
- cmdtp++) {
- if (strncmp_P(cmd, cmdtp->name, len) == 0 &&
- (opt_debug || cmdtp->name[0] != '!')) {
- if (len == strlen_P(cmdtp->name))
- return cmdtp; /* full match */
-
- cmdtp_temp = cmdtp; /* abbreviated command ? */
- n_found++;
- }
- }
- if (n_found == 1) /* exactly one match */
- return cmdtp_temp;
-
- return NULL; /* not found or ambiguous command */
-}
-
-
command_ret_t cmd_usage(const FLASH cmd_tbl_t *cmdtp)
{
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index 3f74be8..1b34ec1 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -8,7 +8,6 @@
#include "command.h"
#include "cmd_mem.h"
-extern command_ret_t do_help(cmd_tbl_t *, uint_fast8_t, int, char * const []);
extern command_ret_t do_echo(cmd_tbl_t *, uint_fast8_t, int, char * const []);
extern command_ret_t do_sleep(cmd_tbl_t *, uint_fast8_t, int, char * const []);
extern command_ret_t do_env_print(cmd_tbl_t *, uint_fast8_t, int, char * const []);
@@ -407,5 +406,5 @@ CMD_TBL_ITEM(
#endif
},
/* Mark end of table */
-{ 0 },
+CMD_TBL_END(cmd_tbl)
};