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