diff --git a/cshell b/cshell new file mode 100755 index 0000000..1449a24 Binary files /dev/null and b/cshell differ diff --git a/handleJSON.c b/handleJSON.c new file mode 100644 index 0000000..b0e942c --- /dev/null +++ b/handleJSON.c @@ -0,0 +1,47 @@ +// This file exists because I hate myself too much to use cJSON + +#include +#include +#include + +enum TokenType { + INTEGER, + CHAR, + TRUE, + FALSE, + IDENTIFIER, + VALUE, + COLON, + R_CURLY_BRACE, + L_CURLY_BRACE, + R_BRACKET, + L_BRACKET, + DOUBLE_QUOTES, + COMMA, + END_OF_FILE, +}; + +struct Token { + enum TokenType type; + char value[100]; +}; + +void advancePosition(int *pos, char *currentChar, char *input[]) { + if(pos < sizeof(input)) { + currentChar = input[*pos]; + printf("Advancing to %s at position %s", currentChar, *pos); + } else { + currentChar = "\0"; + printf("End of Input"); + } +} + +void skipWhiteSpace(int *pos, char currentChar) { + if (currentChar != "\0" && is_space(currentChar) == true) { + pos++; + } +} + +void tokenizeJSON() { + +} \ No newline at end of file diff --git a/main b/main deleted file mode 100755 index 9d84fe4..0000000 Binary files a/main and /dev/null differ diff --git a/main.c b/main.c index a369bcd..6813c24 100644 --- a/main.c +++ b/main.c @@ -3,10 +3,10 @@ #include #include #include +#include #define INPUT_SIZE 1024 - -const double VERSION = 0.1; +#define VERSION 0.1f void execute(char **args) { pid_t pid = fork(); @@ -67,31 +67,67 @@ int main() { input[strcspn(input, "\n")] = '\0'; + parse_input(input, args); + // built in command checks + + // TODO: add commands to handle creating and deleting users + // also modify permissions for admin users and regular users + // This will have to come after i finish the JSON parser + + // TODO: add mkdir, rmdir, mkfile, and rmfile commands built in + if (strcmp("exit", input) == 0) { exit(0); + } else if (strcmp("help", input) == 0) { - printf("Welcome to cShell, my simple terminal written in C\nBuilt-in commands:\n\texit\n\thelp\n\tcd\n\tversion\n"); + printf("Welcome to cShell, my simple terminal written in C\nBuilt-in commands:\n\texit\n\thelp\n\tcd [dir name]\n\tversion\n\tmkdir [dir name]\n\trmdir [dir name]\n\tmkfile [file name]\n\trmfile [file name]\n\n"); continue; + } else if (strcmp("version", input) == 0) { printf("cShell version: %f\n", VERSION); continue; - } - parse_input(input, args); - - // handle 'cd' command - if (strcmp("cd", args[0]) == 0) { + } else if (strcmp("cd", args[0]) == 0) { if (args[1] == NULL) { fprintf(stderr, "Missing argument for command \"cd\"\n"); } else { if (chdir(args[1]) != 0) { - perror("chdir failed"); + perror("chdir failed\n"); + } else { + free(cwd); + cwd = getCWD(); } - char *cwd = getCWD(); } continue; + + } else if (strcmp("mkfile", args[0]) == 0) { + FILE *file = fopen(args[1], "w"); + if (file == NULL) { + perror("Error making file"); + } else { printf("success\n"); } + continue; + + } else if (strcmp("mkdir", args[0]) == 0) { + if (mkdir(args[1], 0777) != 0) { + perror("Error making directory"); + } else { printf("success\n"); } + continue; + + } else if (strcmp("rmfile", args[0]) == 0) { + if (remove(args[1]) != 0) { + perror("Error removing file"); + } else { printf("success\n"); } + continue; + + } else if (strcmp("rmdir", args[0]) == 0) { + if (rmdir(args[1]) != 0) { + perror("Error removing directory"); + } else { printf("success\n"); } + continue; } + + // execute the external command execute(args); }