cli_inter_preter.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #define command_entry_sub_menu(name, sub_menu, desp) \
  17. { \
  18. (name), (command_action)NULL, (const char *)(sub_menu), (desp), (const char *const *)NULL}
  19. #define command_entry_terminator() \
  20. { \
  21. (const char *)NULL, (command_action)NULL, (const char *)NULL, (const char *)NULL, (const char *const *)NULL}
  22. typedef const struct
  23. {
  24. const char *name;
  25. command_action action; // action==NULL means argumentTypes is a subentry
  26. const char *arg_type;
  27. const char *desp;
  28. const char *const *arg_desp;
  29. } command_entry;
  30. extern unsigned int cli_ipt_arg_list[CLI_IPT_ARG_NUM][CLI_IPT_ARG_LEN];
  31. extern void array_map_input_to_byte(unsigned char *b, unsigned int *i, unsigned int len);
  32. extern int command_entry_match(command_entry *main_table, const char *cmd); // return 0: fail, 1: success
  33. extern int command_entry_hint(command_entry *main_table, const char *cmd, char *out);
  34. extern void print_entry(command_entry *entry);
  35. #endif // __CLI_INTER_PRETER_H