target: use unsigned int for timeout_ms
[openocd.git] / src / hello.c
blob4e27d4d68d2104aac43b2a5c382be29b8884d942
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>
11 #include "hello.h"
13 COMMAND_HANDLER(handle_foo_command)
15 if (CMD_ARGC < 1 || CMD_ARGC > 2)
16 return ERROR_COMMAND_SYNTAX_ERROR;
18 uint32_t address;
19 COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
21 const char *msg = "<unchanged>";
22 if (CMD_ARGC == 2) {
23 bool enable;
24 COMMAND_PARSE_ENABLE(CMD_ARGV[1], enable);
25 msg = enable ? "enable" : "disable";
28 LOG_INFO("%s: address=0x%8.8" PRIx32 " enabled=%s", CMD_NAME, address, msg);
29 return ERROR_OK;
32 static bool foo_flag;
34 COMMAND_HANDLER(handle_flag_command)
36 return CALL_COMMAND_HANDLER(handle_command_parse_bool,
37 &foo_flag, "foo flag");
40 static const struct command_registration foo_command_handlers[] = {
42 .name = "bar",
43 .handler = &handle_foo_command,
44 .mode = COMMAND_ANY,
45 .usage = "address ['enable'|'disable']",
46 .help = "an example command",
49 .name = "baz",
50 .handler = &handle_foo_command,
51 .mode = COMMAND_ANY,
52 .usage = "address ['enable'|'disable']",
53 .help = "a sample command",
56 .name = "flag",
57 .handler = &handle_flag_command,
58 .mode = COMMAND_ANY,
59 .usage = "[on|off]",
60 .help = "set a flag",
62 COMMAND_REGISTRATION_DONE
65 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
67 if (CMD_ARGC > 1)
68 return ERROR_COMMAND_SYNTAX_ERROR;
69 if (1 == CMD_ARGC) {
70 *sep = " ";
71 *name = CMD_ARGV[0];
72 } else
73 *sep = *name = "";
75 return ERROR_OK;
77 COMMAND_HANDLER(handle_hello_command)
79 const char *sep, *name;
80 int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
81 if (retval == ERROR_OK)
82 command_print(CMD, "Greetings%s%s!", sep, name);
83 return retval;
86 const struct command_registration hello_command_handlers[] = {
88 .name = "hello",
89 .handler = handle_hello_command,
90 .mode = COMMAND_ANY,
91 .help = "prints a warm welcome",
92 .usage = "[name]",
95 .name = "foo",
96 .mode = COMMAND_ANY,
97 .help = "example command handler skeleton",
98 .chain = foo_command_handlers,
99 .usage = "",
101 COMMAND_REGISTRATION_DONE