From 61b363279fca92f20e4b48bc214427a1e51f8402 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 27 Jun 2021 14:07:00 -0400 Subject: [PATCH 1/5] change report structure --- doc/Informe.tex | 35 ++++++++++++++++++++++++----------- doc/code/loop.txt | 0 doc/sections/conclusiones.tex | 1 + doc/sections/introduccion.tex | 1 + 4 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 doc/code/loop.txt create mode 100644 doc/sections/conclusiones.tex create mode 100644 doc/sections/introduccion.tex diff --git a/doc/Informe.tex b/doc/Informe.tex index b1b0cc0..6a000b9 100644 --- a/doc/Informe.tex +++ b/doc/Informe.tex @@ -11,15 +11,30 @@ \usepackage{titling} \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry} \usepackage{amsmath} - \usepackage{listings} + +\lstdefinestyle{freefempp}{ + language=C, + basicstyle=\scriptsize\ttfamily, + commentstyle=\itshape\color{gray}, + keywordstyle=\color{blue}, + numberstyle=\color{red}, + stringstyle=\color{red}, + identifierstyle=\color{violet}, + showstringspaces=false, + %float, + %frame=single, + %numbers=left +} + \lstset{ - basicstyle=\small\ttfamily, - columns=flexible, - breaklines=true, - inputencoding=utf8, - extendedchars=true, - literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1 + basicstyle=\footnotesize\ttfamily, + columns=flexible, + breaklines=true, + inputencoding=utf8, + extendedchars=true, + literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1, + style=freefempp } \usepackage{hyperref} @@ -62,11 +77,9 @@ Carlos Faúndez \hypersetup{pageanchor=true} \pagenumbering{arabic} -\newpage -\section{Introducción} +\include{sections/introduccion} -\newpage -\section{Conclusiones} +\include{sections/conclusiones} \end{document} diff --git a/doc/code/loop.txt b/doc/code/loop.txt new file mode 100644 index 0000000..e69de29 diff --git a/doc/sections/conclusiones.tex b/doc/sections/conclusiones.tex new file mode 100644 index 0000000..ab71532 --- /dev/null +++ b/doc/sections/conclusiones.tex @@ -0,0 +1 @@ +\section{Conclusiones} \ No newline at end of file diff --git a/doc/sections/introduccion.tex b/doc/sections/introduccion.tex new file mode 100644 index 0000000..bdefbcc --- /dev/null +++ b/doc/sections/introduccion.tex @@ -0,0 +1 @@ +\section{Introducción} \ No newline at end of file -- 2.30.2 From 3eb6bae3064701b3b74f11eaf806ab9390b3b023 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 27 Jun 2021 14:34:03 -0400 Subject: [PATCH 2/5] add introduction and first code example --- doc/Informe.tex | 3 +++ doc/code/loop.txt | 31 +++++++++++++++++++++++++++++++ doc/sections/codigo.tex | 2 ++ doc/sections/codigo/ciclo.tex | 6 ++++++ doc/sections/introduccion.tex | 4 +++- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 doc/sections/codigo.tex create mode 100644 doc/sections/codigo/ciclo.tex diff --git a/doc/Informe.tex b/doc/Informe.tex index 6a000b9..883df2d 100644 --- a/doc/Informe.tex +++ b/doc/Informe.tex @@ -12,6 +12,7 @@ \usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,a4paper]{geometry} \usepackage{amsmath} \usepackage{listings} +\usepackage{xcolor} \lstdefinestyle{freefempp}{ language=C, @@ -79,6 +80,8 @@ Carlos Faúndez \include{sections/introduccion} +\include{sections/codigo} + \include{sections/conclusiones} \end{document} diff --git a/doc/code/loop.txt b/doc/code/loop.txt index e69de29..0d606ff 100644 --- a/doc/code/loop.txt +++ b/doc/code/loop.txt @@ -0,0 +1,31 @@ +void loop() { + while (1) { + print_input_line(); + + char *line = get_console_input(); + + StringArray args; + create_string_array(&args); + + char *saveptr = NULL; + char *token = strtok_r(line, " ", &saveptr); + while (token) { + insert_string_array(&args, token); + token = strtok_r(NULL, " ", &saveptr); + } + if (line != NULL) { + free(line); + line = NULL; + } + + if (args.size == 0) { + continue; + } + + if (is_builtin(args.array[0])) { + run_builtin(&args); + } + + free_string_array(&args); + } +} diff --git a/doc/sections/codigo.tex b/doc/sections/codigo.tex new file mode 100644 index 0000000..b42ba62 --- /dev/null +++ b/doc/sections/codigo.tex @@ -0,0 +1,2 @@ +\section{Código} +\input{sections/codigo/ciclo} \ No newline at end of file diff --git a/doc/sections/codigo/ciclo.tex b/doc/sections/codigo/ciclo.tex new file mode 100644 index 0000000..809bb07 --- /dev/null +++ b/doc/sections/codigo/ciclo.tex @@ -0,0 +1,6 @@ +\subsection{Ciclo principal} +El ciclo principal controla todo la funcionamiento del shell. El ciclo debe correr infinitamente hasta que recibe un señal o un\ +comando de salir(exit). La primera cosa que tiene que hacer en el ciclo es mostrar un mensaje de entrada y esperar que el\ +usuario ingresa un comando. Luego separar la entrada en varios argumentos. Finalmente interpretar los argumentos y decidir que\ +hacer con ellos. +\lstinputlisting{code/loop.txt} \ No newline at end of file diff --git a/doc/sections/introduccion.tex b/doc/sections/introduccion.tex index bdefbcc..5631dbd 100644 --- a/doc/sections/introduccion.tex +++ b/doc/sections/introduccion.tex @@ -1 +1,3 @@ -\section{Introducción} \ No newline at end of file +\section{Introducción} +El propósito del proyecto semestral es crear un shell básico para aprender los básicos de que hace un shell en un sistema\ +operativo. Hay varios partes que son importante como la creación de procesos, redireccionamiento y el entorno. \ No newline at end of file -- 2.30.2 From eefb71ccd54aa3fc51ff50162aa56c682e771daa Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 27 Jun 2021 15:20:53 -0400 Subject: [PATCH 3/5] add loop and builtins --- doc/Informe.tex | 2 +- doc/code/builtins.txt | 9 +++++++++ doc/code/loop.txt | 6 ------ doc/sections/codigo.tex | 3 ++- doc/sections/codigo/builtins.tex | 5 +++++ doc/sections/conclusiones.tex | 6 +++++- 6 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 doc/code/builtins.txt create mode 100644 doc/sections/codigo/builtins.tex diff --git a/doc/Informe.tex b/doc/Informe.tex index 883df2d..84b42a0 100644 --- a/doc/Informe.tex +++ b/doc/Informe.tex @@ -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} diff --git a/doc/code/builtins.txt b/doc/code/builtins.txt new file mode 100644 index 0000000..3c382cf --- /dev/null +++ b/doc/code/builtins.txt @@ -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); +} diff --git a/doc/code/loop.txt b/doc/code/loop.txt index 0d606ff..c480d5b 100644 --- a/doc/code/loop.txt +++ b/doc/code/loop.txt @@ -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); } } diff --git a/doc/sections/codigo.tex b/doc/sections/codigo.tex index b42ba62..1b2b97c 100644 --- a/doc/sections/codigo.tex +++ b/doc/sections/codigo.tex @@ -1,2 +1,3 @@ \section{Código} -\input{sections/codigo/ciclo} \ No newline at end of file +\input{sections/codigo/ciclo} +\input{sections/codigo/builtins} \ No newline at end of file diff --git a/doc/sections/codigo/builtins.tex b/doc/sections/codigo/builtins.tex new file mode 100644 index 0000000..d8c4115 --- /dev/null +++ b/doc/sections/codigo/builtins.tex @@ -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} \ No newline at end of file diff --git a/doc/sections/conclusiones.tex b/doc/sections/conclusiones.tex index ab71532..0ee2ed5 100644 --- a/doc/sections/conclusiones.tex +++ b/doc/sections/conclusiones.tex @@ -1 +1,5 @@ -\section{Conclusiones} \ No newline at end of file +\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. \ No newline at end of file -- 2.30.2 From 8ad820c9fc96d34deaab2ccc894476ee532b354d Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 27 Jun 2021 15:25:11 -0400 Subject: [PATCH 4/5] remove aux files in sections when cleaning --- doc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Makefile b/doc/Makefile index a0a7aae..9e2646d 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -4,6 +4,6 @@ informe: pdflatex -synctex=1 -interaction=nonstopmode "Informe.tex" clean: - rm -f *.log *.toc *.gz *.aux *.out Informe.pdf + rm -f *.log *.toc *.gz *.aux sections/*.aux *.out Informe.pdf .PHONY: informe clean -- 2.30.2 From e951ccb7ee909be92141fe3aa98a349cb915fc68 Mon Sep 17 00:00:00 2001 From: Chris Cromer Date: Sun, 27 Jun 2021 15:28:36 -0400 Subject: [PATCH 5/5] add missing param to main documentation --- src/myshellin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/myshellin.c b/src/myshellin.c index 479acae..35bb9fc 100644 --- a/src/myshellin.c +++ b/src/myshellin.c @@ -19,6 +19,7 @@ /** * The main entry point to the program. * @param argc The number of arguments passed. + * @param argv An array with the arguments passed. * @return Returns 0 on success or an error code on failure. */ int main(int argc, char **argv) { -- 2.30.2