diff options
author | makefunstuff <[email protected]> | 2024-07-13 22:04:48 +0200 |
---|---|---|
committer | makefunstuff <[email protected]> | 2024-07-13 22:04:48 +0200 |
commit | 714036825c38be947eb88a82c02425d7932d2919 (patch) | |
tree | c6723bd239fa5cc93b78ef9e9b7ba5576f708db1 /csrc/main.c | |
parent | 9b9e63476616a123eb4d00f87f677ef2d9478897 (diff) | |
download | tinkerbunk-714036825c38be947eb88a82c02425d7932d2919.tar.gz |
upd
Diffstat (limited to '')
-rw-r--r-- | csrc/main.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/csrc/main.c b/csrc/main.c new file mode 100644 index 0000000..f8393e5 --- /dev/null +++ b/csrc/main.c @@ -0,0 +1,45 @@ +#include "cp.h" +#include "http.h" +#include "sh.h" +#include "stat.h" +#include "wc.h" +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int main(int argc, char *argv[]) { + if (argc < 3) { + return 1; + } + + char *command = argv[1]; + + if (command == NULL) { + return 1; + } + + if (strcmp(command, "cp") == 0) { + char *src = argv[2]; + char *dst = argv[3]; + FileStatus status = copy_file(src, dst); + if (status == READ_ERROR) { + fprintf(stderr, "Error reading file: %s\n", src); + } else if (status == WRITE_ERROR) { + fprintf(stderr, "Error writing file: %s\n", dst); + } + } else if (strncmp(command, "wc", 2) == 0) { + char *src = argv[2]; + int lines = count_lines(src); + printf("%d\n", lines); + } else if (strncmp(command, "sh", 2) == 0) { + shell(); + } else if (strncmp(command, "stat", 4) == 0) { + char *filename = argv[2]; + if (mstat(filename) == STAT_ERR) { + return 1; + } + } else if (strncmp(command, "http", 4) == 0) { + int port = atoi(argv[2]); + start_server(port); + } +} |