II. Modify the function free_memory(prog_t *exe) to free the memory
of the whole command line. A recursive solution is advised but not
required.
void free_memory(prog_t *exe) {
// free each non-NULL argument in the array exe->args.args
for(int i = 0; i < exe-="">args.size; i++ ) {
if (exe->args.args[i] != NULL) {
free(exe->args.args[i]);
}
}
// Free the array itself
free(exe->args.args);
// Free each non-NULL exe->redirection
if (exe->redirection.in != NULL) {
free(exe->redirection.in);
}
if (exe->redirection.out1 != NULL) {
free(exe->redirection.out1);
}
if (exe->redirection.out2 != NULL) {
free(exe->redirection.out2);
}
// Free exe itself
free(exe);
}
III. Your default OS shell initializes the $SHELL environmental
variable with its name. For example, echo $SHELL on my computer
displays /bin/bash. Add code at the beginning of the main function
that initializes $SHELL with the value of argv[0].
/* Main function */
int main() {
char *config;
char *fileName = "/sushi.conf";
// read the commands from the file sushi.conf, located in the $HOME directory.
config = super_malloc(strlen(getenv("HOME")) + strlen(fileName) + 1);
strcat(strcpy(config, getenv("HOME")), fileName);
sushi_read_config(config);
prevent_interruption();
while (sushi_exit == 0) {
// display the prompt SUSHI_DEFAULT_PROMPT
printf("%s", SUSHI_DEFAULT_PROMPT);
char *commandLine = sushi_read_line(stdin);
if (commandLine != NULL){
// Call sushi_parse_command() if sushi_read_line() is successfully called
if (sushi_parse_command(commandLine) == 0) {
// store the returnValue to history if no syntax error found.
sushi_store(commandLine);
};
free(commandLine);
}
}
free(config);
return EXIT_SUCCESS;
}