2009-11-11 03:20:49 -06:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
2016-05-16 15:41:00 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
2009-11-11 03:20:49 -06:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
2009-12-03 06:14:28 -06:00
|
|
|
#include <helper/log.h>
|
2009-11-11 03:20:49 -06:00
|
|
|
|
2009-11-18 17:20:58 -06:00
|
|
|
COMMAND_HANDLER(handle_foo_command)
|
|
|
|
{
|
|
|
|
if (CMD_ARGC < 1 || CMD_ARGC > 2)
|
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
|
|
|
|
|
|
|
uint32_t address;
|
|
|
|
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
|
|
|
|
|
|
|
|
const char *msg = "<unchanged>";
|
2012-01-27 10:44:06 -06:00
|
|
|
if (CMD_ARGC == 2) {
|
2009-11-18 17:20:58 -06:00
|
|
|
bool enable;
|
|
|
|
COMMAND_PARSE_ENABLE(CMD_ARGV[1], enable);
|
|
|
|
msg = enable ? "enable" : "disable";
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_INFO("%s: address=0x%8.8" PRIx32 " enabled=%s", CMD_NAME, address, msg);
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool foo_flag;
|
|
|
|
|
|
|
|
COMMAND_HANDLER(handle_flag_command)
|
|
|
|
{
|
|
|
|
return CALL_COMMAND_HANDLER(handle_command_parse_bool,
|
2012-01-27 10:44:06 -06:00
|
|
|
&foo_flag, "foo flag");
|
2009-11-18 17:20:58 -06:00
|
|
|
}
|
|
|
|
|
2009-11-21 15:49:00 -06:00
|
|
|
static const struct command_registration foo_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "bar",
|
|
|
|
.handler = &handle_foo_command,
|
|
|
|
.mode = COMMAND_ANY,
|
2010-01-09 01:13:39 -06:00
|
|
|
.usage = "address ['enable'|'disable']",
|
2009-11-29 18:48:40 -06:00
|
|
|
.help = "an example command",
|
2009-11-21 15:49:00 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "baz",
|
|
|
|
.handler = &handle_foo_command,
|
|
|
|
.mode = COMMAND_ANY,
|
2010-01-09 01:13:39 -06:00
|
|
|
.usage = "address ['enable'|'disable']",
|
2009-11-29 18:48:40 -06:00
|
|
|
.help = "a sample command",
|
2009-11-21 15:49:00 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "flag",
|
|
|
|
.handler = &handle_flag_command,
|
|
|
|
.mode = COMMAND_ANY,
|
2009-11-29 18:48:40 -06:00
|
|
|
.usage = "[on|off]",
|
|
|
|
.help = "set a flag",
|
2009-11-21 15:49:00 -06:00
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
2009-11-11 03:20:49 -06:00
|
|
|
static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
|
|
|
|
{
|
2009-11-15 06:57:12 -06:00
|
|
|
if (CMD_ARGC > 1)
|
2009-11-11 03:20:49 -06:00
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
2012-01-27 10:44:06 -06:00
|
|
|
if (1 == CMD_ARGC) {
|
2009-11-11 03:20:49 -06:00
|
|
|
*sep = " ";
|
2009-11-15 10:15:59 -06:00
|
|
|
*name = CMD_ARGV[0];
|
2012-01-27 10:44:06 -06:00
|
|
|
} else
|
2009-11-11 03:20:49 -06:00
|
|
|
*sep = *name = "";
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
COMMAND_HANDLER(handle_hello_command)
|
|
|
|
{
|
|
|
|
const char *sep, *name;
|
|
|
|
int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
|
2021-07-03 09:47:35 -05:00
|
|
|
if (retval == ERROR_OK)
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "Greetings%s%s!", sep, name);
|
2009-11-11 03:20:49 -06:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-11-21 21:27:20 -06:00
|
|
|
const struct command_registration hello_command_handlers[] = {
|
2009-11-21 15:49:00 -06:00
|
|
|
{
|
|
|
|
.name = "hello",
|
2010-01-09 01:13:39 -06:00
|
|
|
.handler = handle_hello_command,
|
2009-11-21 15:49:00 -06:00
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.help = "prints a warm welcome",
|
2010-01-09 01:13:39 -06:00
|
|
|
.usage = "[name]",
|
2009-11-21 15:49:00 -06:00
|
|
|
},
|
2009-11-21 17:52:12 -06:00
|
|
|
{
|
|
|
|
.name = "foo",
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.help = "example command handler skeleton",
|
|
|
|
.chain = foo_command_handlers,
|
2019-01-04 08:13:53 -06:00
|
|
|
.usage = "",
|
2009-11-21 17:52:12 -06:00
|
|
|
},
|
2009-11-21 15:49:00 -06:00
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|