summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo C2018-07-28 12:47:35 +0200
committerLeo C2018-07-28 12:47:35 +0200
commitdab74a42d544d3f45777eff471f1ee0166b4aaae (patch)
treeed2dbdbf286b72c3db26b4e73b186f433b0d90e3
parent04f849375f8277203eddbeac2bfbfbfc433bbacf (diff)
downloadz180-stamp-dab74a42d544d3f45777eff471f1ee0166b4aaae.zip
Fix help, env subcommands
-rw-r--r--avr/command.c29
-rw-r--r--avr/command_tbl.c35
-rw-r--r--avr/env.c88
-rw-r--r--include/env.h8
4 files changed, 117 insertions, 43 deletions
diff --git a/avr/command.c b/avr/command.c
index c9137ea..b4a972c 100644
--- a/avr/command.c
+++ b/avr/command.c
@@ -22,6 +22,11 @@
#include "env.h"
#include "debug.h"
+#define DEBUG_CMD 1 /* set to 1 to debug */
+
+#define debug_cmd(fmt, args...) \
+ debug_cond(DEBUG_CMD, fmt, ##args)
+
jmp_buf cmd_jbuf;
@@ -64,7 +69,7 @@ int cmd_tbl_item_count(cmd_tbl_t *p)
int count = 0;
while (p->name != NULL) {
- if (p->subcmd && p->flags & CTBL_SUBCMDAUTO) {
+ if (p->subcmd) {
cmd_tbl_t *sub = p->subcmd;
while (sub->name != NULL) {
if (sub->flags & CTBL_SUBCMDAUTO)
@@ -72,7 +77,9 @@ int cmd_tbl_item_count(cmd_tbl_t *p)
sub++;
}
}
- p++; count++;
+ if ((p->flags & CTBL_SUBCMDAUTO) == 0)
+ count++;
+ p++;
}
return count;
}
@@ -110,7 +117,7 @@ cmd_tbl_t *_find_cmd (const char *cmd, cmd_tbl_t *table, find_cmd_para_t *para)
cmdtp_ret = cmdtp; /* abbreviated command ? */
n_found++;
- } else if (cmdtp->subcmd && cmdtp->flags & CTBL_SUBCMDAUTO) {
+ } else if (cmdtp->subcmd) {
cmd_tbl_t *sub = _find_cmd(cmd, cmdtp->subcmd, para);
if (sub && sub->flags & CTBL_SUBCMDAUTO) {
cmdtp_ret = sub;
@@ -179,12 +186,11 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
cmd_tbl_t *tp = tbl_start;
int i = 0;
while (tp->name != NULL) {
- uint_fast8_t len;
- if (tp->subcmd && tp->flags & CTBL_SUBCMDAUTO) {
+ if (tp->subcmd) {
cmd_tbl_t *sub = tp->subcmd;
while (sub->name != NULL) {
if (sub->flags & CTBL_SUBCMDAUTO) {
- len = strlen_P(sub->name);
+ uint_fast8_t len = strlen_P(sub->name);
if (len > maxlen_cmd)
maxlen_cmd = len;
cmd_list[i++] = sub;
@@ -192,10 +198,13 @@ command_ret_t do_help(cmd_tbl_t *cmdtp, uint_fast8_t flag UNUSED, int argc, char
sub++;
}
}
- len = strlen_P(tp->name);
- if (len > maxlen_cmd)
- maxlen_cmd = len;
- cmd_list[i++] = tp++;
+ if ((tp->flags & CTBL_SUBCMDAUTO) == 0) {
+ uint_fast8_t len = strlen_P(tp->name);
+ if (len > maxlen_cmd)
+ maxlen_cmd = len;
+ cmd_list[i++] = tp;
+ }
+ tp++;
}
/* Sort command list */
qsort(cmd_list, cmd_items, sizeof (cmd_tbl_t *), cmpstring_PP);
diff --git a/avr/command_tbl.c b/avr/command_tbl.c
index 7a6b776..ea41fc7 100644
--- a/avr/command_tbl.c
+++ b/avr/command_tbl.c
@@ -107,33 +107,12 @@ CMD_TBL_ITEM_COMPLETE(
" - run the commands in the script file 'filename'",
var_complete
),
-CMD_TBL_ITEM_COMPLETE(
- printenv, CONFIG_SYS_MAXARGS, 1, do_env_print,
- "print environment variables",
- "[-s] [name ...]\n"
- " Print value of environment variable(s) 'name'\n"
- " If no names are given, print values of all environment variables\n"
- " -s Print in setenv form",
- var_complete
-),
-CMD_TBL_ITEM_COMPLETE(
- setenv, CONFIG_SYS_MAXARGS, 0, do_env_set,
- "set environment variables",
- "name value ...\n"
- " - set environment variable 'name' to 'value ...'\n"
- "setenv name\n"
- " - delete environment variable 'name'",
- var_complete
-),
-CMD_TBL_ITEM(
- saveenv, 1, 0, do_env_save,
- "save environment variables to persistent storage",
- ""
-),
-CMD_TBL_ITEM(
- defaultenv, 1, 0, do_env_default,
- "set all environment variables to their default values",
- ""
+
+CMD_TBL_ITEM_TOP(
+ env, CONFIG_SYS_MAXARGS, 0, do_env,
+ "environment handling commands",
+ "",
+ cmd_tbl_env
),
CMD_TBL_ITEM(
@@ -332,7 +311,7 @@ CMD_TBL_ITEM_TOP(
cmd_tbl_sd
),
CMD_TBL_ITEM_TOP(
- fat, CONFIG_SYS_MAXARGS, CTBL_SUBCMDAUTO, do_fat,
+ fat, CONFIG_SYS_MAXARGS, 0, do_fat,
"fat filesystem commands",
"<subcommand> args ...\n"
"fat help\n"
diff --git a/avr/env.c b/avr/env.c
index 44c5742..add281c 100644
--- a/avr/env.c
+++ b/avr/env.c
@@ -795,3 +795,91 @@ int env_complete(char *var, int maxv, char *cmdv[], int bufsz, char *buf)
return found;
}
#endif
+
+cmd_tbl_t cmd_tbl_env[] = {
+CMD_TBL_ITEM_COMPLETE(
+ printenv, CONFIG_SYS_MAXARGS, 1|CTBL_SUBCMDAUTO, do_env_print,
+ "print environment variables",
+ "[-s] [name ...]\n"
+ " Print value of environment variable(s) 'name'\n"
+ " If no names are given, print values of all environment variables\n"
+ " -s Print in setenv form",
+ var_complete
+),
+CMD_TBL_ITEM_COMPLETE(
+ setenv, CONFIG_SYS_MAXARGS, CTBL_SUBCMDAUTO, do_env_set,
+ "set environment variables",
+ "name value ...\n"
+ " - set environment variable 'name' to 'value ...'\n"
+ "setenv name\n"
+ " - delete environment variable 'name'",
+ var_complete
+),
+CMD_TBL_ITEM(
+ saveenv, 1, CTBL_SUBCMDAUTO, do_env_save,
+ "save environment variables to persistent storage",
+ ""
+),
+CMD_TBL_ITEM(
+ defaultenv, 1, CTBL_SUBCMDAUTO, do_env_default,
+ "set all environment variables to their default values",
+ ""
+),
+
+CMD_TBL_ITEM_COMPLETE(
+ print, CONFIG_SYS_MAXARGS, 1, do_env_print,
+ "print environment variables",
+ "[-s] [name ...]\n"
+ " Print value of environment variable(s) 'name'\n"
+ " If no names are given, print values of all environment variables\n"
+ " -s Print in setenv form",
+ var_complete
+),
+CMD_TBL_ITEM_COMPLETE(
+ set, CONFIG_SYS_MAXARGS, 0, do_env_set,
+ "set environment variables",
+ "name value ...\n"
+ " - set environment variable 'name' to 'value ...'\n"
+ "setenv name\n"
+ " - delete environment variable 'name'",
+ var_complete
+),
+CMD_TBL_ITEM(
+ save, 1, 0, do_env_save,
+ "save environment variables to persistent storage",
+ ""
+),
+CMD_TBL_ITEM(
+ default, 1, 0, do_env_default,
+ "set all environment variables to their default values",
+ ""
+),
+
+CMD_TBL_ITEM(
+ help, CONFIG_SYS_MAXARGS, CTBL_RPT, do_help,
+ "Print sub command description/usage",
+ "\n"
+ " - print brief description of all sub commands\n"
+ "env help command ...\n"
+ " - print detailed usage of sub cmd 'command'"
+),
+
+/* This does not use the CMD_TBL_ITEM macro as ? can't be used in symbol names */
+ {FSTR("?"), CONFIG_SYS_MAXARGS, 1, do_help,
+ NULL,
+#ifdef CONFIG_SYS_LONGHELP
+ FSTR(""),
+#endif /* CONFIG_SYS_LONGHELP */
+ NULL,
+#ifdef CONFIG_AUTO_COMPLETE
+ NULL,
+#endif
+},
+/* Mark end of table */
+CMD_TBL_END(cmd_tbl_env)
+};
+
+command_ret_t do_env(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+ return CMD_RET_USAGE;
+}
diff --git a/include/env.h b/include/env.h
index 1dbe30f..4666688 100644
--- a/include/env.h
+++ b/include/env.h
@@ -1,5 +1,5 @@
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014, 2018 Leo C. <erbl259-lmu@yahoo.de>
*
* SPDX-License-Identifier: GPL-2.0
*/
@@ -9,11 +9,9 @@
#include "command.h"
-command_ret_t do_env_print(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-command_ret_t do_env_default(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-command_ret_t do_env_set(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-command_ret_t do_env_save(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+extern cmd_tbl_t cmd_tbl_env[];
+command_ret_t do_env(cmd_tbl_t *, uint_fast8_t, int, char * const []);
int env_init(void);
char *getenv_str(const MEMX char *name);
unsigned long getenv_ulong(const MEMX char *name, int base, unsigned long default_val);