console.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #ifndef __LIB_CONSOLE_H
  24. #define __LIB_CONSOLE_H
  25. #include <sys/types.h>
  26. #include <compiler.h>
  27. /* command args */
  28. typedef struct {
  29. const char *str;
  30. unsigned int u;
  31. int i;
  32. } cmd_args;
  33. typedef int (*console_cmd)(int argc, const cmd_args *argv);
  34. /* a block of commands to register */
  35. typedef struct {
  36. const char *cmd_str;
  37. const char *help_str;
  38. const console_cmd cmd_callback;
  39. } cmd;
  40. typedef struct _cmd_block {
  41. struct _cmd_block *next;
  42. size_t count;
  43. const cmd *list;
  44. } cmd_block;
  45. /* register a static block of commands at init time */
  46. #define STATIC_COMMAND_START static const cmd _cmd_list[] = {
  47. #define STATIC_COMMAND(a,b,c) {a,b,c},
  48. #define STATIC_COMMAND_END(name) }; const cmd_block _cmd_block_##name __SECTION(".commands")= { NULL, sizeof(_cmd_list) / sizeof(_cmd_list[0]), _cmd_list }
  49. /* external api */
  50. int console_init(void);
  51. void console_start(void);
  52. void console_register_commands(cmd_block *block);
  53. int console_run_command(const char *string);
  54. #endif