]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/cmd_run.c
2 * (C) Copyright 2016, 2018 Leo C. <erbl259-lmu@yahoo.de>
4 * SPDX-License-Identifier: GPL-2.0
10 #include "cli_readline.h" /* console_buffer[] */
11 #include "cli.h" /* run_command() */
15 command_ret_t
do_run(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag
, int argc
, char * const argv
[])
20 for (int i
= 1; i
< argc
; ++i
) {
23 arg
= getenv_str(argv
[i
]);
25 printf_P(PSTR("run: \"%s\" is not set\n"), argv
[i
]);
26 return CMD_RET_FAILURE
;
29 if (run_command(arg
, flag
) != 0)
30 return CMD_RET_FAILURE
;
32 return CMD_RET_SUCCESS
;
35 command_ret_t
do_bootd(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag
, int argc UNUSED
, char * const argv
[] UNUSED
)
37 return run_command(getenv_str("bootcmd"), flag
);
40 static int source(FIL
*fp
, uint_fast8_t flag
, int argc UNUSED
, char * const argv
[] UNUSED
)
45 while (!f_eof(fp
) && !f_error(fp
) && !res
) {
47 if (f_gets(console_buffer
, CONFIG_SYS_CBSIZE
, fp
)) {
48 int i
= strlen(console_buffer
) - 1;
51 if (console_buffer
[i
] != '\n') {
52 printf_P(PSTR("Error: line %d to long\n"), lineno
);
57 console_buffer
[i
] = 0;
58 res
= run_command(console_buffer
, flag
);
62 return !f_eof(fp
) || res
;
65 command_ret_t
do_source(cmd_tbl_t
*cmdtp UNUSED
, uint_fast8_t flag
, int argc
, char * const argv
[])
73 res
= f_open(&File
, argv
[1], FA_READ
);
75 printf_P(PSTR("Error: failed to open script '%s'\n"), argv
[1]);
76 return CMD_RET_FAILURE
;
79 printf_P(PSTR("Executing script: '%s'...\n"), argv
[1]);
80 res
= source(&File
, flag
, --argc
, ++argv
);
83 return CMD_RET_FAILURE
;
85 return CMD_RET_SUCCESS
;