void execute_command (command_t c, int time_travel) { /* FIXME: Replace this with your implementation. You may need to add auxiliary functions and otherwise modify the source code. You can also use external functions defined in the GNU C Library. */ if(c == NULL) return; if(time_travel ==1) execute_time_travel(c); else { switch(c->type) { case SIMPLE_COMMAND: execute_simple_command(c); break; case PIPE_COMMAND: printf("pipe;"); execute_pipe_command(c); break; default: break; } } }
void execute_command (command_t c, int time_travel) { /* FIXME: Replace this with your implementation. You may need to add auxiliary functions and otherwise modify the source code. You can also use external functions defined in the GNU C Library. */ if(c == NULL) return; if(time_travel ==1) execute_time_travel(c); else { switch(c->type) { case SIMPLE_COMMAND: execute_simple_command(c); break; case AND_COMMAND: execute_and_command(c); break; case OR_COMMAND: execute_or_command(c); break; case PIPE_COMMAND: execute_pipe_command(c); break; case SUBSHELL_COMMAND: execute_subshell_command(c); break; case SEQUENCE_COMMAND: execute_sequence_command(c); break; case WHILE_COMMAND: execute_while_command(c); break; case FOR_COMMAND: execute_for_command(c); break; case UNTIL_COMMAND: execute_until_command(c); break; case IF_COMMAND: execute_if_command(c); break; case NOT_COMMAND: execute_not_command(c); break; default: error(1,0, "Error: Unknown command!"); break; } //error (1, 0, "command execution not yet implemented"); } }
int main (int argc, char **argv) { int opt; int command_number = 1; int print_tree = 0; int time_travel = 0; program_name = argv[0]; for (;;) switch (getopt (argc, argv, "pt")) { case 'p': print_tree = 1; break; case 't': time_travel = 1; break; default: usage (); break; case -1: goto options_exhausted; } options_exhausted:; // There must be exactly one file argument. if (optind != argc - 1) usage (); script_name = argv[optind]; FILE *script_stream = fopen (script_name, "r"); if (! script_stream) error (1, errno, "%s: cannot open", script_name); command_stream_t command_stream = make_command_stream (get_next_byte, script_stream); command_t last_command = NULL; command_t command; if (time_travel == 1 && !print_tree) { last_command = execute_time_travel(command_stream); } else { while ((command = read_command_stream (command_stream))) { if (print_tree) { printf ("# %d\n", command_number++); print_command (command); } else { last_command = command; execute_command (command, time_travel); } } } return print_tree || !last_command ? 0 : command_status (last_command); }
int main (int argc, char **argv) { int command_number = 1; bool print_tree = false; bool time_travel = false; char* measure_file_name = NULL; program_name = argv[0]; for (;;) switch (getopt (argc, argv, "pm:t")) { case 'p': print_tree = true; break; case 'm': measure_file_name = optarg; break; case 't': time_travel = true; break; default: usage (); break; case -1: goto options_exhausted; } options_exhausted:; // There must be exactly one file argument. if (optind != argc - 1) usage (); script_name = argv[optind]; FILE *script_stream = fopen (script_name, "r"); if (! script_stream) error (1, errno, "%s: cannot open", script_name); command_stream_t command_stream = make_command_stream (get_next_byte, script_stream); int ret = 0; command_t command; if (print_tree) { while ((command = read_command_stream (command_stream))) { printf ("# %d\n", command_number++); print_command (command, false, 0, 0); } } else if (time_travel) { ret = execute_time_travel (command_stream); } else { ret = execute_sequential (command_stream, measure_file_name); } return ret; }