aboutsummaryrefslogtreecommitdiff
path: root/src/cli/main.c
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2022-06-06 22:03:57 +0200
committerJan200101 <sentrycraft123@gmail.com>2022-06-08 20:06:12 +0200
commitd5d61d18c89af3f6743b7c56774eebdfdcc87b2c (patch)
treeb4299c1af7e194e9083d4de1bce382102ea46e95 /src/cli/main.c
downloadOFQT-d5d61d18c89af3f6743b7c56774eebdfdcc87b2c.tar.gz
OFQT-d5d61d18c89af3f6743b7c56774eebdfdcc87b2c.zip
Release 0.1.00.1.0
Diffstat (limited to 'src/cli/main.c')
-rw-r--r--src/cli/main.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cli/main.c b/src/cli/main.c
new file mode 100644
index 0000000..7971c7d
--- /dev/null
+++ b/src/cli/main.c
@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "net.h"
+#include "commands.h"
+
+static void help()
+{
+ fprintf(stderr, "OFCL <command>\n"); \
+
+ size_t longestStr;
+ size_t length;
+
+ if (commands_size)
+ {
+ longestStr = 0;
+
+ for (size_t i = 0; i < commands_size; ++i)
+ {
+ length = strlen(commands[i].name);
+
+ if (length > longestStr) longestStr = length;
+ }
+
+ fprintf(stderr, "\nList of commands:\n");
+ for (size_t i = 0; i < commands_size; ++i)
+ {
+ fprintf(stderr, "\t%-*s\t %s\n", (int)longestStr, commands[i].name, commands[i].description);
+ }
+ }
+}
+
+int main(int argc, char** argv)
+{
+ net_init();
+ atexit(net_deinit);
+
+ for (int i = 1; i < argc; ++i)
+ {
+ for (size_t j = 0; j < commands_size; ++j)
+ {
+ if (!strcmp(commands[j].name, argv[i]))
+ return commands[j].func(argc-i, argv+i);
+ }
+ }
+
+ help();
+ return EXIT_SUCCESS;
+} \ No newline at end of file