SRC = main.c
SRC += cli.c cli_readline.c command.c command_tbl.c
-SRC += cmd_help.c cmd_date.c cmd_mem.c cmd_boot.c cmd_gpio.c cmd_misc.c
+SRC += cmd_help.c cmd_run.c cmd_boot.c cmd_misc.c
+SRC += cmd_date.c cmd_mem.c cmd_gpio.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 getopt-min.c
SRC += timer.c serial.c i2c.c bcd.c pcf8583.c mmc.c
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
}
}
}
-
-
-command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
-{
- int i;
- (void) cmdtp;
-
- if (argc < 2)
- return CMD_RET_USAGE;
-
- for (i = 1; i < argc; ++i) {
- char *arg;
-
- arg = getenv_char(argv[i]);
- if (arg == NULL) {
- printf_P(PSTR("## Error: \"%s\" is not set\n"), argv[i]);
- return CMD_RET_FAILURE;
- }
-
- if (run_command(arg, flag) != 0)
- return CMD_RET_FAILURE;
- }
- return CMD_RET_SUCCESS;
-}
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2000
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2000-2003
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
#include <util/atomic.h>
#include "command.h"
-#include "cli_readline.h"
-#include "cli.h"
+#include "cli_readline.h" /* console_buffer[] */
+#include "cli.h" /* run_command() */
#include "env.h"
#include "con-utils.h"
#include "z80-if.h"
--- /dev/null
+/*
+ * (C) Copyright 2016 Leo C. <erbl259-lmu@yahoo.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0
+ */
+
+#include "common.h"
+#include <string.h>
+#include <stdio.h>
+
+#include "ff.h"
+#include "config.h"
+#include "command.h"
+#include "cli_readline.h" /* console_buffer[] */
+#include "cli.h" /* run_command() */
+#include "env.h"
+
+
+command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ int i;
+ (void) cmdtp;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ for (i = 1; i < argc; ++i) {
+ char *arg;
+
+ arg = getenv_char(argv[i]);
+ if (arg == NULL) {
+ printf_P(PSTR("## Error: \"%s\" is not set\n"), argv[i]);
+ return CMD_RET_FAILURE;
+ }
+
+ if (run_command(arg, flag) != 0)
+ return CMD_RET_FAILURE;
+ }
+ return CMD_RET_SUCCESS;
+}
+
+static int source(FIL *fp, int flag, int argc, char * const argv[])
+{
+ int lineno = 0;
+ int res = 0;
+
+ (void)argc; (void)argv;
+
+ while (!f_eof(fp) && !f_error(fp) && !res) {
+ lineno++;
+ if (f_gets(console_buffer, CONFIG_SYS_CBSIZE, fp)) {
+ int i = strlen(console_buffer) - 1;
+ if (i != 0) {
+ if (i > 0) {
+ if (console_buffer[i] != '\n') {
+ printf_P(PSTR("Error: line %d to long\n"), lineno);
+ res = -1;
+ break;
+ }
+ }
+ console_buffer[i] = 0;
+ res = run_command(console_buffer, flag);
+ }
+ }
+ }
+ return !f_eof(fp) || res;
+}
+
+command_ret_t do_source(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ FIL File;
+ int res;
+
+ (void) cmdtp;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ res = f_open(&File, argv[1], FA_READ );
+ if (res) {
+ printf_P(PSTR("Error: failed to open script '%s'\n"), argv[1]);
+ return CMD_RET_FAILURE;
+ }
+
+ printf_P(PSTR("Executing script: '%s'...\n"), argv[1]);
+ res = source(&File, flag, --argc, ++argv);
+ f_close(&File);
+ if (res != 0) {
+ return CMD_RET_FAILURE;
+ }
+ return CMD_RET_SUCCESS;
+}
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* SPDX-License-Identifier: GPL-2.0
*/
extern command_ret_t do_sd(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_fat_stat(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_fat_ls(cmd_tbl_t *, int, int, char * const []);
-//extern command_ret_t do_fat_read(cmd_tbl_t *, int, int, char * const []);
-//extern command_ret_t do_fat_write(cmd_tbl_t *, int, int, char * const []);
extern command_ret_t do_fat_rw(cmd_tbl_t *, int, int, char * const []);
+extern command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+extern command_ret_t do_source(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
#ifdef CONFIG_SYS_LONGHELP
const FLASH char sd_help_text[] =
" - run the commands in the environment variable(s) 'var'",
var_complete
),
+CMD_TBL_ITEM_COMPLETE(
+ source, CONFIG_SYS_MAXARGS, 1, do_source,
+ "run commands from a file",
+ "filename\n"
+ " - 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",
/ 3: f_lseek() function is removed in addition to 2. */
-#define _USE_STRFUNC 0
+#define _USE_STRFUNC 2
/* This option switches string functions, f_gets(), f_putc(), f_puts() and
/ f_printf().
/
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2014 Google, Inc
* Simon Glass <sjg@chromium.org>
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2014 Google, Inc
* Simon Glass <sjg@chromium.org>
/*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
*
* (C) Copyright 2000-2009
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
- * SPDX-License-Identifier: GPL-2.0+
+ * SPDX-License-Identifier: GPL-2.0
*/
/*
typedef const FLASH struct cmd_tbl_s cmd_tbl_t;
-extern command_ret_t do_run(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
-
/**
* Process a command with arguments. We look up the command and execute it
* if valid. Otherwise we print a usage message.