summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-04-27 14:38:16 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-04-27 14:38:16 -0400
commit88d3515ae85924b8aea8c0546d33451ee369b7dd (patch)
treea5b825af7959d79bbd00f0dcfa5987671cb84c1a /src/main.c
downloadlazysphere-88d3515ae85924b8aea8c0546d33451ee369b7dd.tar.gz
lazysphere-88d3515ae85924b8aea8c0546d33451ee369b7dd.tar.bz2
lazysphere-88d3515ae85924b8aea8c0546d33451ee369b7dd.zip
initial
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..a2582c2
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,49 @@
+#include "shared.h"
+#include "command.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+int main (ARGUMENTS) {
+ if (argc < 1) {
+ error("error: argument 0 missing");
+ }
+
+ struct stat buf;
+ lstat(argv[0], &buf);
+
+ if (!S_ISLNK(buf.st_mode)) {
+ if (argc < 2) {
+ printf("usage: lazysphere [function [arguments]...]\n\n");
+ printf("currently defined functions:\n");
+ printf("\tdd, cat, yes\n");
+ return EXIT_SUCCESS;
+ }
+ argc--;
+ argv = &argv[1];
+ }
+
+ const char* cmd;
+ if (strncmp("./", argv[0], 2) == 0) {
+ cmd = argv[0] + 2;
+ } else {
+ cmd = argv[0];
+ }
+
+ if (streql(cmd, "dd")) {
+ return dd(NEXT_ARGS);
+ } else if (streql(cmd, "cat")) {
+ return cat(NEXT_ARGS);
+ } else if (streql(cmd, "yes")) {
+ return yes(NEXT_ARGS);
+ } else {
+ error("error: invalid command %s", cmd);
+ }
+
+ return EXIT_SUCCESS;
+}
+