aboutsummaryrefslogtreecommitdiffstats
path: root/src/command.h
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2023-12-24 04:26:00 -0600
committerLibravatar bigfoot547 <[email protected]>2023-12-24 04:26:00 -0600
commit20d9fc5b5356a1054cb104ba6651b77184abf0db (patch)
tree5f115d8051dad73069d3a632a6f2c260cf7efdac /src/command.h
initial commit
Diffstat (limited to 'src/command.h')
-rw-r--r--src/command.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/command.h b/src/command.h
new file mode 100644
index 0000000..469422c
--- /dev/null
+++ b/src/command.h
@@ -0,0 +1,77 @@
+#ifndef L2SU_COMMAND_H_INCLUDED
+#define L2SU_COMMAND_H_INCLUDED
+
+#include <stddef.h>
+
+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 */