add loop and builtins

This commit is contained in:
2021-06-27 15:20:53 -04:00
parent 3eb6bae306
commit eefb71ccd5
6 changed files with 22 additions and 9 deletions

9
doc/code/builtins.txt Normal file
View File

@@ -0,0 +1,9 @@
void run_builtin(StringArray *args) {
if (strcmp(args->array[0], "exit") == 0) {
exit_shell(args);
}
}
void exit_shell(StringArray *args) {
exit(EXIT_SUCCESS);
}

View File

@@ -13,10 +13,6 @@ void loop() {
insert_string_array(&args, token);
token = strtok_r(NULL, " ", &saveptr);
}
if (line != NULL) {
free(line);
line = NULL;
}
if (args.size == 0) {
continue;
@@ -25,7 +21,5 @@ void loop() {
if (is_builtin(args.array[0])) {
run_builtin(&args);
}
free_string_array(&args);
}
}