console_line #7
@ -37,19 +37,19 @@ bool is_builtin(char *command) {
|
||||
|
||||
/**
|
||||
* Run the builtin command.
|
||||
* @param string_array An array of strings containing the arguments to run.
|
||||
* @param args An array of strings containing the arguments to run.
|
||||
*/
|
||||
void run_builtin(StringArray *string_array) {
|
||||
if (strcmp(string_array->array[0], "exit") == 0) {
|
||||
exit_shell(string_array);
|
||||
void run_builtin(StringArray *args) {
|
||||
if (strcmp(args->array[0], "exit") == 0) {
|
||||
exit_shell(args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit the shell.
|
||||
* @param string_array The arguments that were used to call exit. This is used to free the memory before exit.
|
||||
* @param args The arguments that were used to call exit. This is used to free the memory before exit.
|
||||
*/
|
||||
void exit_shell(StringArray *string_array) {
|
||||
free_string_array(string_array);
|
||||
void exit_shell(StringArray *args) {
|
||||
free_string_array(args);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
14
src/loop.c
14
src/loop.c
@ -40,13 +40,13 @@ void loop() {
|
||||
|
||||
remove_new_line(line);
|
||||
|
||||
StringArray string_array;
|
||||
create_string_array(&string_array);
|
||||
StringArray args;
|
||||
create_string_array(&args);
|
||||
|
||||
char *saveptr = NULL;
|
||||
char *token = strtok_r(line, " ", &saveptr);
|
||||
while (token) {
|
||||
insert_string_array(&string_array, token);
|
||||
insert_string_array(&args, token);
|
||||
token = strtok_r(NULL, " ", &saveptr);
|
||||
}
|
||||
if (line != NULL) {
|
||||
@ -55,14 +55,14 @@ void loop() {
|
||||
}
|
||||
|
||||
// The user didn't type anything so restart the loop
|
||||
if (string_array.size == 0) {
|
||||
if (args.size == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_builtin(string_array.array[0])) {
|
||||
run_builtin(&string_array);
|
||||
if (is_builtin(args.array[0])) {
|
||||
run_builtin(&args);
|
||||
}
|
||||
|
||||
free_string_array(&string_array);
|
||||
free_string_array(&args);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user