#ifndef __CLI_INTER_PRETER_H
#define __CLI_INTER_PRETER_H

#include "stddef.h"
#include <ctype.h>
#include <string.h>

extern void cli_printf(char *msg, ...);

#define CLI_PRINTF(info, args...) cli_printf(info, ##args);

#define CLI_IPT_ARG_NUM       12  // 支持解析后的参数个数
#define CLI_IPT_ARG_LEN       50  // 每个参数解析后的最大长度
#define CLI_IPT_ARG_STR_LEN   100 // 每个参数解析前字符串形式的最大长度
#define CLI_IPT_ENTRY_NUM_MAX 100 // 菜单中子菜单最大个数（不用内存

typedef void (*command_action)();

#define command_entry_action_with_detail(name, action, arg_type, desp, arg_desp) \
    {                                                                            \
        (name), (command_action)(action), (arg_type), (desp), (arg_desp)}

#define command_entry_sub_menu(name, sub_menu, desp) \
    {                                                \
        (name), (command_action)NULL, (const char *)(sub_menu), (desp), (const char *const *)NULL}

#define command_entry_terminator() \
    {                              \
        (const char *)NULL, (command_action)NULL, (const char *)NULL, (const char *)NULL, (const char *const *)NULL}

typedef const struct
{
    const char        *name;
    command_action     action; // action==NULL means argumentTypes is a subentry
    const char        *arg_type;
    const char        *desp;
    const char *const *arg_desp;
} command_entry;

extern unsigned int cli_ipt_arg_list[CLI_IPT_ARG_NUM][CLI_IPT_ARG_LEN];

extern void array_map_input_to_byte(unsigned char *b, unsigned int *i, unsigned int len);
extern int  command_entry_match(command_entry *main_table, const char *cmd); // return 0: fail, 1: success
extern int  command_entry_hint(command_entry *main_table, const char *cmd, char *out);
extern void print_entry(command_entry *entry);

#endif // __CLI_INTER_PRETER_H