You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

58 lines
2.1 KiB

  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. ***************************************************************************/
  19. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include "log.h"
  23. static COMMAND_HELPER(handle_hello_args, const char **sep, const char **name)
  24. {
  25. if (argc > 1)
  26. {
  27. LOG_ERROR("%s: too many arguments", CMD_NAME);
  28. return ERROR_COMMAND_SYNTAX_ERROR;
  29. }
  30. if (1 == argc)
  31. {
  32. *sep = " ";
  33. *name = args[0];
  34. }
  35. else
  36. *sep = *name = "";
  37. return ERROR_OK;
  38. }
  39. COMMAND_HANDLER(handle_hello_command)
  40. {
  41. const char *sep, *name;
  42. int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name);
  43. if (ERROR_OK == retval)
  44. command_print(cmd_ctx, "Greetings%s%s!", sep, name);
  45. return retval;
  46. }
  47. int hello_register_commands(struct command_context_s *cmd_ctx)
  48. {
  49. struct command_s *cmd = register_command(cmd_ctx, NULL, "hello",
  50. &handle_hello_command, COMMAND_ANY,
  51. "option");
  52. return cmd ? ERROR_OK : -ENOMEM;
  53. }