target: don't implicitly include "algorithm.h"
[openocd/ztw.git] / src / hello.c
blob275150a4ba0bd1fa243edde3ec50d0810ecbf8d8
1 /***************************************************************************
2 * Copyright (C) 2009 Zachary T Welch <zw@superlucidity.net> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 #include "log.h"
25 static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
27 if (argc > 1)
29 LOG_ERROR("%s: too many arguments", CMD_NAME);
30 return ERROR_COMMAND_SYNTAX_ERROR;
32 if (1 == argc)
34 *sep = " ";
35 *name = args[0];
37 else
38 *sep = *name = "";
40 return ERROR_OK;
42 COMMAND_HANDLER(handle_hello_command)
44 const char *sep, *name;
45 int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
46 if (ERROR_OK == retval)
47 command_print(cmd_ctx, "Greetings%s%s!", sep, name);
48 return retval;
51 int hello_register_commands(struct command_context *cmd_ctx)
53 struct command *cmd = register_command(cmd_ctx, NULL, "hello",
54 &handle_hello_command, COMMAND_ANY,
55 "option");
56 return cmd ? ERROR_OK : -ENOMEM;