1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* (C) Copyright 2016, 2018 Leo C. <erbl259-lmu@yahoo.de>
*
* SPDX-License-Identifier: GPL-2.0
*/
#include "cmd_run.h"
#include "ff.h"
#include "cli_readline.h" /* console_buffer[] */
#include "cli.h" /* run_command() */
#include "env.h"
command_ret_t do_run(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag, int argc, char * const argv[])
{
if (argc < 2)
return CMD_RET_USAGE;
for (int i = 1; i < argc; ++i) {
char *arg;
arg = getenv_str(argv[i]);
if (arg == NULL) {
printf_P(PSTR("run: \"%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;
}
command_ret_t do_bootd(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag, int argc UNUSED, char * const argv[] UNUSED)
{
return run_command(getenv_str("bootcmd"), flag);
}
static int source(FIL *fp, uint_fast8_t flag, int argc UNUSED, char * const argv[] UNUSED)
{
int lineno = 0;
int res = 0;
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 UNUSED, uint_fast8_t flag, int argc, char * const argv[])
{
FIL File;
int res;
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;
}
|