diff --git a/Main.c b/Main.c index 4a358beef874c48984800911e88c432293bb47fb..62c7ea3e4666480ab6c4766d1570310f823db5d2 100644 --- a/Main.c +++ b/Main.c @@ -71,11 +71,37 @@ int main(int argc, char* argv[]) { char* current_directory; // parse_line(""); + // free_memory(); + // parse_line("ls"); + // parse_command(); + // execute_command(); + // free_memory(); + // parse_line("ls -l"); + // parse_command(); + // execute_command(); + // free_memory(); + // parse_line("ls -l | grep a"); + // parse_command(); + // execute_command(); + // free_memory(); + // parse_line("ls -l | grep a | grep b"); + // parse_command(); + // execute_command(); + // free_memory(); + // parse_line("ls -l | grep a | grep b | grep c"); + // parse_command(); + // execute_command(); + // free_memory(); + + // parse_line("ls -l | grep a | grep b | grep c | grep v"); + // parse_command(); + // execute_command(); + // free_memory(); // Run until user willingly quits. while (run_program == 1) { @@ -195,7 +221,7 @@ void parse_command() { } // Print same value as above, but in command_argv to prove it exists. - printf("%d | command_argv arg: %s\n", index, (*(*command_argv->argv + index))); + printf("%d | command_argv arg: %s\n", index, (*(*command_argv->argv + 1))); ++command_argv; printf("\n"); @@ -395,9 +421,9 @@ void set_umask(char* string_val) { void free_memory() { int index; makeargv_struct* temp_pointer; + makeargv_struct* orig_pointer = command_argv; index = 0; - // Free all of command_argv values. while (line_argv->argc > 0) { temp_pointer = command_argv; @@ -405,10 +431,10 @@ void free_memory() { free(*(*command_argv->argv)); free(*(command_argv->argv)); free(command_argv->argv); - free(command_argv); command_argv = temp_pointer; line_argv->argc--; } + free(orig_pointer); // Free line_argv values. free(*(*(line_argv->argv + index)));