summaryrefslogtreecommitdiff
path: root/command.c
diff options
context:
space:
mode:
authorWilliam Casarin <jb55@jb55.com>2018-07-09 15:48:55 -0700
committerWilliam Casarin <jb55@jb55.com>2018-07-09 15:49:33 -0700
commit0206052b5660cb77cdd0a0ac3c83dd4c3d996007 (patch)
treef0b0f1cd48f0f8f67d85e981be114e84d36ac8b3 /command.c
parentc999204365695799c9b7d79f4973d307421afecb (diff)
started on positioning + command structure
Diffstat (limited to 'command.c')
-rw-r--r--command.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/command.c b/command.c
new file mode 100644
index 0000000..a4b4e55
--- /dev/null
+++ b/command.c
@@ -0,0 +1,40 @@
+
+#include "command.h"
+
+#include "ccan/tal/tal.h"
+#include "ccan/tal/str/str.h"
+
+void
+command_init(struct command *cmd) {
+ cmd->children = NULL;
+}
+
+int
+command_is_prefix(struct command *cmd) {
+ size_t count = tal_count(cmd->children);
+ return count > 0;
+}
+
+
+struct command *
+test_root_commands(tal_t *ctx) {
+ unsigned long i, j;
+ struct command *cmds = NULL;
+ struct command *child = NULL;
+
+ cmds = tal_arr(ctx, struct command, 5);
+
+ const unsigned long c = 'a';
+ for (i = 0; i < tal_count(cmds); i++) {
+ cmds[i].name = tal_fmt(cmds, "hello-%d", (int)i);
+ cmds[i].bind = tal_fmt(cmds, "%c", (int)(c+i));
+ child = cmds[i].children = tal_arr(cmds, struct command, i % 2);
+ for (j = 0; j < tal_count(child); j++) {
+ child[j].name = tal_fmt(child, "child-%d-%d", (int)i, (int)j);
+ child[j].bind = tal_fmt(child, "%c", (int)(c+j));
+ child[j].children = NULL;
+ }
+ }
+
+ return cmds;
+}