cli_inter_preter.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef __CLI_INTER_PRETER_H
  2. #define __CLI_INTER_PRETER_H
  3. #include "stddef.h"
  4. #include <ctype.h>
  5. #include <string.h>
  6. extern void cli_printf(char *msg, ...);
  7. #define CLI_PRINTF(info, args...) cli_printf(info, ##args);
  8. #define CLI_IPT_ARG_NUM 12 // 支持解析后的参数个数
  9. #define CLI_IPT_ARG_LEN 50 // 每个参数解析后的最大长度
  10. #define CLI_IPT_ARG_STR_LEN 100 // 每个参数解析前字符串形式的最大长度
  11. #define CLI_IPT_ENTRY_NUM_MAX 100 // 菜单中子菜单最大个数(不用内存
  12. typedef void (*command_action)();
  13. #define command_entry_action_with_detail(name, action, arg_type, desp, arg_desp) \
  14. { \
  15. (name), (command_action)(action), (arg_type), (desp), (arg_desp) \
  16. }
  17. #define command_entry_sub_menu(name, sub_menu, desp) \
  18. { \
  19. (name), (command_action)NULL, (const char *)(sub_menu), (desp), (const char *const *)NULL \
  20. }
  21. #define command_entry_terminator() \
  22. { \
  23. (const char *)NULL, (command_action)NULL, (const char *)NULL, (const char *)NULL, (const char *const *)NULL \
  24. }
  25. typedef const struct
  26. {
  27. const char *name;
  28. command_action action; // action==NULL means argumentTypes is a subentry
  29. const char *arg_type;
  30. const char *desp;
  31. const char *const *arg_desp;
  32. } command_entry;
  33. extern unsigned int cli_ipt_arg_list[CLI_IPT_ARG_NUM][CLI_IPT_ARG_LEN];
  34. extern void array_map_input_to_byte(unsigned char *b, unsigned int *i, unsigned int len);
  35. extern int command_entry_match(command_entry *main_table, const char *cmd); // return 0: fail, 1: success
  36. extern int command_entry_hint(command_entry *main_table, const char *cmd, char *out);
  37. extern void print_entry(command_entry *entry);
  38. #endif // __CLI_INTER_PRETER_H