target/riscv: Update debug_defines.h.
[openocd.git] / src / hello.c
blobdb6774eaa350f74a14331194a1e5f54e9ed68ff9
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
5 ***************************************************************************/
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 #include <helper/log.h>
12 COMMAND_HANDLER(handle_foo_command)
14 if (CMD_ARGC < 1 || CMD_ARGC > 2)
15 return ERROR_COMMAND_SYNTAX_ERROR;
17 uint32_t address;
18 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
20 const char *msg = "<unchanged>";
21 if (CMD_ARGC == 2) {
22 bool enable;
23 COMMAND_PARSE_ENABLE(CMD_ARGV[1], enable);
24 msg = enable ? "enable" : "disable";
27 LOG_INFO("%s: address=0x%8.8" PRIx32 " enabled=%s", CMD_NAME, address, msg);
28 return ERROR_OK;
31 static bool foo_flag;
33 COMMAND_HANDLER(handle_flag_command)
35 return CALL_COMMAND_HANDLER(handle_command_parse_bool,
36 &foo_flag, "foo flag");
39 static const struct command_registration foo_command_handlers[] = {
41 .name = "bar",
42 .handler = &handle_foo_command,
43 .mode = COMMAND_ANY,
44 .usage = "address ['enable'|'disable']",
45 .help = "an example command",
48 .name = "baz",
49 .handler = &handle_foo_command,
50 .mode = COMMAND_ANY,
51 .usage = "address ['enable'|'disable']",
52 .help = "a sample command",
55 .name = "flag",
56 .handler = &handle_flag_command,
57 .mode = COMMAND_ANY,
58 .usage = "[on|off]",
59 .help = "set a flag",
61 COMMAND_REGISTRATION_DONE
64 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
66 if (CMD_ARGC > 1)
67 return ERROR_COMMAND_SYNTAX_ERROR;
68 if (1 == CMD_ARGC) {
69 *sep = " ";
70 *name = CMD_ARGV[0];
71 } else
72 *sep = *name = "";
74 return ERROR_OK;
76 COMMAND_HANDLER(handle_hello_command)
78 const char *sep, *name;
79 int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
80 if (retval == ERROR_OK)
81 command_print(CMD, "Greetings%s%s!", sep, name);
82 return retval;
85 const struct command_registration hello_command_handlers[] = {
87 .name = "hello",
88 .handler = handle_hello_command,
89 .mode = COMMAND_ANY,
90 .help = "prints a warm welcome",
91 .usage = "[name]",
94 .name = "foo",
95 .mode = COMMAND_ANY,
96 .help = "example command handler skeleton",
97 .chain = foo_command_handlers,
98 .usage = "",
100 COMMAND_REGISTRATION_DONE