Question: / * XXX DO NOT MODIFY THIS FILE XXX * / #define _ POSIX _ C _ SOURCE 2 0 0 8 0 9 #include

/* XXX DO NOT MODIFY THIS FILE XXX */
#define _POSIX_C_SOURCE 200809
#include
#include
#include
#include
#include
#include
#include
#include
#include "exit.h"
#include "params.h"
#include "parser.h"
#include "runner.h"
#include "signal.h"
#include "util/gprintf.h"
#include "wait.h"
/** Main bigshell loop
*/
int
main(int argc, char *argv[])
{
struct command_list *cl =0;
/* Program initialization routines */
if (parser_init()<0) goto err;
/* TODO Enable this line once you've implemented the function */
//if (signal_init()<0) goto err;
/* Main Event Loop: REPL -- Read Evaluate Print Loop */
for (;;){
prompt:
/* Check on backround jobs */
if (wait_on_bg_jobs()<0) goto err;
/* Read input and parse it into a list of commands */
/* TODO Enable this line once you've implemented the function */
//if (signal_enable_interrupt(SIGINT)<0) goto err;
int res = command_list_parse(&cl, stdin);
/* TODO Enable this line once you've implemented the function */
// if (signal_ignore(SIGINT)<0) goto err;
if (res ==-1){/* System library errors */
switch (errno){/* Handle specific errors */
case EINTR:
clearerr(stdin);
errno =0;
fputc('
', stderr);
goto prompt;
default:
goto err; /* Unrecoverable errors */
}
} else if (res <0){/* Parser syntax errors */
fprintf(stderr, "Syntax error: %s
", command_list_strerror(res));
errno =0;
goto prompt;
} else if (res ==0){/* No commands parsed */
if (feof(stdin)) bigshell_exit(); /* Exit on eof */
goto prompt; /* Blank line */
} else {
gprintf("Parsed command list to execute:");
#ifndef NDEBUG
command_list_print(cl, stderr);
fputc('
', stderr);
#endif
gprintf("executing command list with %zu commands", cl->command_count);
/* Execute commands */
run_command_list(cl);
/* Cleanup */
command_list_free(cl);
free(cl);
cl =0;
}
}
err:
if (cl) command_list_free(cl);
free(cl);
params.status =127;
warn(0);
bigshell_exit();
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!