From 7522f3a6028ef771db2f4993dc979112648c7e79 Mon Sep 17 00:00:00 2001 From: Hedy Li Date: Tue, 28 Sep 2021 09:22:52 +0800 Subject: [PATCH] Remove trailing whitespaces --- src/main.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/main.c b/src/main.c index 3ad05e9..9992ac0 100644 --- a/src/main.c +++ b/src/main.c @@ -18,7 +18,7 @@ char *homedir; // HOME directory of current user pid_t shell_pid; // pid of current shell (gets only on start) pid_t pid; // FIXME: this shouldn't be global i think -char **split_line(char *line, char *delim) { +char **split_line(char *line, char *delim) { int bufsize = 64; position = 0; char **tokens = malloc(bufsize * sizeof(char*)); @@ -61,13 +61,13 @@ int execute(char **command, int status) { wpid = waitpid(pid, &status, WUNTRACED); // FIXME: warning unused variable } while (!WIFEXITED(status) && !WIFSIGNALED(status)); } - - if (status >= 256) + + if (status >= 256) status = 1; return status; } -int parse_command(char **command, int status) { +int parse_command(char **command, int status) { int variable = 0; int where_var[position - 1]; for (int i = 0; i <= position - 1; i++) { // Loop for checking if line has variable @@ -88,7 +88,7 @@ int parse_command(char **command, int status) { command[i] = status_string; } else { command[i] = getenv(command[i]); - if (command[i] == NULL) + if (command[i] == NULL) command[i] = ""; } } @@ -98,10 +98,10 @@ int parse_command(char **command, int status) { if (command[0][strlen(command[0]) - 1] == ';'){ // FIXME: parse all word not only first command[0][strlen(command[0])-1] = '\0'; } else if (command[0][0] == ';'){ // Check if command is ; or first char of command is ; - command[0][0] = '\0'; + command[0][0] = '\0'; } - - if (status >= 256) + + if (status >= 256) status = 1; if (!strcmp(command[0], "exit")) { // FIXME: add switch statement (if possible) @@ -120,17 +120,17 @@ int parse_command(char **command, int status) { printf("orsh: cd: too many arguments\n"); } else { chdir(command[1]); - getcwd(pwd, sizeof(pwd)); + getcwd(pwd, sizeof(pwd)); } } else if (!strcmp(command[0], "pwd")) { - printf("%s\n", pwd); + printf("%s\n", pwd); } else if (!strcmp(command[0], "!")) { if (status != 0) status = 0; else if (status == 0) status = 1; } else { - status = execute(command, status); + status = execute(command, status); } return status; } @@ -163,9 +163,9 @@ void signal_handler(int sig) { printf("\n"); print_ps(); } else if (shell_pid == getpid()) { // Do nothing because readline prints the prompt - } else + } else raise(sig); - + } int main(int argc, char *argv[]) { @@ -176,7 +176,7 @@ int main(int argc, char *argv[]) { char** args; int status = 0; // FIXME int command_status = 0; // FIXME - signal(SIGINT, signal_handler); + signal(SIGINT, signal_handler); if (argc >= 2) { FILE *script = fopen(argv[1], "r"); if (script == NULL) { @@ -184,10 +184,10 @@ int main(int argc, char *argv[]) { return 1; } while (fgets(script_line, 100, script) != NULL) { - args = split_line(script_line, " "); + args = split_line(script_line, " "); command_status = parse_command(args, command_status); } - + } else { while(1) { line = readline("orsh> "); // FIXME: add prompt @@ -195,11 +195,11 @@ int main(int argc, char *argv[]) { printf("exit\n"); break; } - commands = split_line(line, ";"); + commands = split_line(line, ";"); int after_parse_position = position; // To know where we in ; list FIXME for (int i = 0; i <= after_parse_position - 1; i++) { args = split_line(commands[i], " "); - + command_status = parse_command(args, command_status); } }