15 #include <sys/queue.h>
36 #define CLI_ROOT_NAME "/"
37 #define CLI_BIN_NAME "bin"
52 #define CLI_RECURSE_FLAG (1 << 0)
53 #define CLI_LONG_LIST_FLAG (1 << 1)
66 #define CLI_NODE_TYPES \
68 "Unknown", "Directory", "Command", "File", "Alias", "String", NULL \
82 typedef int (*
cli_ffunc_t)(
struct cli_node *node,
char *buff,
int len, uint32_t opt);
91 TAILQ_ENTRY(cli_node) next;
92 struct cli_node *parent;
104 const char *short_desc;
105 const char *alias_str;
112 #define MAX_CMD_FILES 16
115 char *filename[MAX_CMD_FILES];
126 CIRCLEQ_HEAD(, cli_hist) hd_hist;
135 struct cli_hist *curr_hist;
138 struct cli_node *exe_node;
142 struct cli_vt100 *vt;
149 struct cli_node *node_mem;
150 struct cli_hist *hist_mem;
154 CIRCLEQ_HEAD(, cli_hist) free_hist;
158 extern struct cli *this_cli;
162 #define CLEAR_TO_EOL (1 << 0)
163 #define DISPLAY_PROMPT (1 << 1)
164 #define PROMPT_CONTINUE (1 << 2)
165 #define DELETE_CHAR (1 << 3)
166 #define CLEAR_LINE (1 << 4)
168 #define CLI_USE_TIMERS (1 << 8)
169 #define CLI_NODES_UNLIMITED (1 << 9)
170 #define CLI_YIELD_IO (1 << 10)
171 #define CLI_DEFAULT_TREE (1 << 11)
174 cli_set_flag(uint32_t x)
176 this_cli->flags |= x;
180 cli_clr_flag(uint32_t x)
182 this_cli->flags &= ~x;
186 cli_tst_flag(uint32_t x)
188 return this_cli->flags & x;
239 #define c_dir(n) { CLI_DIR_NODE, .dir = {.name = (n), .bin = 0} }
240 #define c_bin(n) { CLI_DIR_NODE, .dir = {.name = (n), .bin = 1} }
241 #define c_cmd(n, f, h) { CLI_CMD_NODE, .cmd = {.name = (n), .cfunc = (f), .short_desc = (h)} }
242 #define c_file(n, rw, h) { CLI_FILE_NODE, .file = {.name = (n), .ffunc = (rw), .short_desc = (h)} }
243 #define c_alias(n, l, h) { CLI_ALIAS_NODE, .alias = {.name = (n), .alias_atr = (l), .short_desc = (h)} }
244 #define c_str(n, f, s) { CLI_STR_NODE, .str = {.name = (n), .sfunc = (f), .string = (s)} }
245 #define c_end() { CLI_UNK_NODE, .dir = { NULL } }
249 cli_set_user_state(
void *val)
251 this_cli->user_state = val;
260 static inline struct cli_node *
263 CNE_ASSERT(this_cli != NULL);
264 return this_cli->root.tqh_first;
273 static inline struct cli_node *
276 CNE_ASSERT(this_cli != NULL);
277 return this_cli->bins[0];
289 CNE_ASSERT(this_cli != NULL);
290 this_cli->bins[0] = node;
302 return (this_cli) ? 1 : 0;
321 while ((*s1 !=
'\0') && (*s2 !=
'\0')) {
342 is_node(
struct cli_node *node, uint32_t types)
344 return node->type & types;
426 if (this_cli && this_cli->exe_node) {
427 const char *p = this_cli->exe_node->short_desc;
429 cne_printf(
" Usage: %s\n", (p) ? p :
"No description found");
442 static inline const char *
445 const char *node_str[] = CLI_NODE_TYPES;
446 switch (node->type) {
477 path = this_cli->scratch;
484 strcat(path, node->name);
537 static inline uint32_t
540 return this_cli->nb_hist;
559 static inline struct cli_node *
562 return this_cli->root.tqh_first;
716 CNDP_API
struct cli_node *
cli_add_dir(
const char *dirname,
struct cli_node *parent);
733 const char *short_desc);
749 CNDP_API
struct cli_node *
cli_add_alias(
const char *name,
struct cli_node *dir,
const char *line,
750 const char *short_desc);
767 const char *short_desc);
793 CNDP_API
int cli_add_tree(
struct cli_node *dir,
struct cli_tree *tree);
CNDP_API struct cli_node * cli_create_root(const char *dirname)
CNDP_API int cli_setup_with_defaults(void)
static int cli_add_cmdfile(const char *filename)
static int cli_usage(void)
static struct cli_node * cli_root_node(void)
int(* cli_cfunc_t)(int argc, char **argv)
CNDP_API struct cli_node * cli_add_alias(const char *name, struct cli_node *dir, const char *line, const char *short_desc)
static void set_cwd(struct cli_node *node)
CNDP_API struct cli_node * cli_add_file(const char *name, struct cli_node *dir, cli_ffunc_t func, const char *short_desc)
static char * cli_path_string(struct cli_node *node, char *path)
static int is_node(struct cli_node *node, uint32_t types)
CNDP_API int cli_default_tree_init(void)
CNDP_API void cli_start(const char *msg)
CNDP_API int cli_add_bin(struct cli_node *node)
CNDP_API void cli_set_quit_flag(void)
static int is_command(struct cli_node *node)
static int is_executable(struct cli_node *node)
static int is_file(struct cli_node *node)
CNDP_API int cli_del_bin(struct cli_node *node)
CNDP_API void cli_use_timers(void)
static int is_cli_valid(void)
CNDP_API int cli_setup_with_tree(cli_tree_t tree)
static int is_match(const char *s1, const char *s2)
CNDP_API int cli_remove_node(struct cli_node *node)
CNDP_API void cli_destroy(void)
int(* cli_prompt_t)(int continuation)
int(* cli_ffunc_t)(struct cli_node *node, char *buff, int len, uint32_t opt)
CNDP_API int cli_create(struct cli_cfg *cfg)
static char * cli_cwd_path(void)
static int cli_set_history_size(uint32_t nb_hist)
CNDP_API int cli_execute_cmdfile(const char *path)
CNDP_API int cli_add_tree(struct cli_node *dir, struct cli_tree *tree)
CNDP_API int cli_add_bin_path(const char *path)
CNDP_API int cli_setup(cli_prompt_t prompt, cli_tree_t default_func)
CNDP_API int cli_execute_cmdfiles(void)
static struct cli_node * get_cwd(void)
CNDP_API int cli_get_quit_flag(void)
CNDP_API struct cli_node * cli_add_cmd(const char *name, struct cli_node *dir, cli_cfunc_t func, const char *short_desc)
static int is_directory(struct cli_node *node)
CNDP_API int cli_execute_cmd(int argc, char **argv)
static void cli_history_list(void)
CNDP_API void cli_start_with_timers(const char *msg)
static const char * cli_node_type(struct cli_node *node)
struct cli_node __cne_cache_aligned
CNDP_API int cli_add_str(const char *name, cli_sfunc_t func, const char *str)
cli_files_t cli_cmd_files
static int is_alias(struct cli_node *node)
static struct cli_node * get_root(void)
CNDP_API cli_prompt_t cli_set_prompt(cli_prompt_t prompt)
CNDP_API int cli_execute(void)
static uint32_t cli_get_history_size(void)
static void cli_pwd(struct cli_node *node)
CNDP_API int cli_create_with_defaults(struct cli_cfg *cfg)
CNDP_API struct cli_node * cli_add_dir(const char *dirname, struct cli_node *parent)
CNDP_API int cli_nodes_unlimited(void)
char *(* cli_sfunc_t)(const char *str)
CNDP_API int cli_set_history(uint32_t nb_hist)
CNDP_API void cli_history_dump(void)
CNDP_API int cne_printf(const char *fmt,...)
TAILQ_HEAD(pktdev_driver_list, pktdev_driver)