add loop and builtins

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

View File

@ -9,7 +9,7 @@
\usepackage{array}
\usepackage{adjustbox}
\usepackage{titling}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,letterpaper]{geometry}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{xcolor}

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);
}
}

View File

@ -1,2 +1,3 @@
\section{Código}
\input{sections/codigo/ciclo}
\input{sections/codigo/ciclo}
\input{sections/codigo/builtins}

View File

@ -0,0 +1,5 @@
\subsection{Builtins}
Los builtins son comandos que son parte del shell, por lo tanto el sistema operativo no los proporciona. Un ejemplo es el comando\
''exit''. Este comando no existe en el sistema operativo, por lo tanto el shell debe actuar cuando el usuario lo escribe en vez\
de lanzar un proceso nuevo.
\lstinputlisting{code/builtins.txt}

View File

@ -1 +1,5 @@
\section{Conclusiones}
\section{Conclusiones}
Lo cosa mas importante que se puede aprender del proyecto es que el shell es un puente entre el usuario y el sistema operativo.\
El shell es responsable para lanzar programas, interpretar comandos y un shells mas avanzados interpretar un lenguaje de\
scripting para poder facilitar tareas o automatizarlas. Por lo tanto el shell es una parte integral para el sistema operativo\
especialmente en sistemas como GNU/Linux o BSD.