rename string array variable to make it clear what it is

This commit is contained in:
Chris Cromer 2021-06-26 22:51:39 -04:00
parent 4ea527064a
commit 60004f08dc
2 changed files with 14 additions and 14 deletions

View File

@ -37,19 +37,19 @@ bool is_builtin(char *command) {
/** /**
* Run the builtin 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) { void run_builtin(StringArray *args) {
if (strcmp(string_array->array[0], "exit") == 0) { if (strcmp(args->array[0], "exit") == 0) {
exit_shell(string_array); exit_shell(args);
} }
} }
/** /**
* Exit the shell. * 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) { void exit_shell(StringArray *args) {
free_string_array(string_array); free_string_array(args);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View File

@ -40,13 +40,13 @@ void loop() {
remove_new_line(line); remove_new_line(line);
StringArray string_array; StringArray args;
create_string_array(&string_array); create_string_array(&args);
char *saveptr = NULL; char *saveptr = NULL;
char *token = strtok_r(line, " ", &saveptr); char *token = strtok_r(line, " ", &saveptr);
while (token) { while (token) {
insert_string_array(&string_array, token); insert_string_array(&args, token);
token = strtok_r(NULL, " ", &saveptr); token = strtok_r(NULL, " ", &saveptr);
} }
if (line != NULL) { if (line != NULL) {
@ -55,14 +55,14 @@ void loop() {
} }
// The user didn't type anything so restart the loop // The user didn't type anything so restart the loop
if (string_array.size == 0) { if (args.size == 0) {
continue; continue;
} }
if (is_builtin(string_array.array[0])) { if (is_builtin(args.array[0])) {
run_builtin(&string_array); run_builtin(&args);
} }
free_string_array(&string_array); free_string_array(&args);
} }
} }