#ifndef L2SU_COMMAND_H_INCLUDED #define L2SU_COMMAND_H_INCLUDED #include enum { CMD_NODE_TYPE_NULL, CMD_NODE_TYPE_LITERAL, CMD_NODE_TYPE_ARGUMENT, CMD_NODE_FLAG_EXEC = 0x100 }; enum { CMD_INIT_SUCCESS, CMD_INIT_ERROR }; enum { CMD_RESULT_SUCCESS, CMD_RESULT_FAIL }; enum { CMD_VALIDATE_PASS, /* yep this argument is correct */ CMD_VALIDATE_FAIL_SKIP, /* this argument is NOT correct */ CMD_VALIDATE_FAIL_ERROR /* this argument IS the correct argument, but it is invalid (stop searching siblings) */ }; enum { CMD_PARSE_SUCCESS, /* parse successful */ CMD_PARSE_ESYNTAX, /* invalid command syntax */ CMD_PARSE_EUSAGE /* function was called with NULL arguments */ }; struct l2_command_node; struct l2_context_node { struct l2_context_node *next; struct l2_command_node *node; char *value; /* for argument command nodes */ }; typedef unsigned (l2_cmd_proc_t)(struct l2_context_node * /* ctx */, char ** /* args */); typedef unsigned (l2_cmd_validate_proc_t)(const char * /* arg */); struct l2_command_node { unsigned type; const char *name; union { /* for literal nodes */ const char **aliases; /* for argument nodes */ l2_cmd_validate_proc_t *validate_proc; /* a validate_proc of NULL is assumed to always return CMD_VALIDATE_PASS */ } extra; l2_cmd_proc_t *cmd_proc; struct l2_command_node *children; }; extern struct l2_command_node l2_cmd_root; /* unsigned l2_cmd_init(void); */ struct l2_parseinfo { char **argv; l2_cmd_proc_t *proc; struct l2_context_node *ctx; }; unsigned l2_cmd_parse_command(char **argv, struct l2_parseinfo *parseinfo); void l2_cmd_free_ctx(struct l2_context_node *ctx); #endif /* include guard */