environ #15

Merged
cromer merged 27 commits from environ into master 2021-07-17 22:15:24 -04:00
2 changed files with 23 additions and 0 deletions
Showing only changes of commit f580c03ebc - Show all commits

View File

@ -30,6 +30,10 @@ bool is_builtin(char *command) {
return true; return true;
} }
if (strcmp(command, "environ") == 0) {
return true;
}
return false; return false;
} }
@ -40,6 +44,9 @@ void run_builtin(StringArray *args) {
else if (strcmp(args->array[0], "cd") == 0) { else if (strcmp(args->array[0], "cd") == 0) {
change_directory(args); change_directory(args);
} }
else if (strcmp(args->array[0], "environ") == 0) {
print_environ(args);
}
else { else {
fprintf(stderr, "Builtin %s does not exist!\n", args->array[0]); fprintf(stderr, "Builtin %s does not exist!\n", args->array[0]);
} }
@ -72,3 +79,13 @@ void change_directory(StringArray *args) {
} }
} }
} }
void print_environ(StringArray *args) {
if (args->size > 1) {
fprintf(stderr, "Too many arguments!\n");
return;
}
for (size_t i = 0; i < variables->size; i++) {
fprintf(stdout, "%s=%s\n", variables->keys->array[i], variables->values->array[i]);
}
}

View File

@ -44,4 +44,10 @@ void exit_shell(StringArray *args);
*/ */
void change_directory(StringArray *args); void change_directory(StringArray *args);
/**
* Print all of the environment variables.
* @param args The arguments the user input.
*/
void print_environ(StringArray * args);
#endif #endif