diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 49 |
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; +} + |