diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..e87876dd7ec55e7577ff9e5ac33e2be1385163ad --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +CC=gcc -Wall -Wextra -ansi + +TARGET=prog2d + +OBJ=interpreteur.o list.o + +all: $(TARGET) + +$(TARGET): $(OBJ) + $(CC) main.c $^ -o $(TARGET) + +%.o: %.c %.h + $(CC) -c $< + +interpreteur.o: interpreteur.c interpreteur.h list.h + $(CC) -c $< + +clean: + rm $(OBJ) $(TARGET) + +re: clean all \ No newline at end of file diff --git a/a.out b/a.out deleted file mode 100755 index 3f19027cc3c8c4ae8005f632132486827d782a92..0000000000000000000000000000000000000000 Binary files a/a.out and /dev/null differ diff --git a/interpreteur.c b/interpreteur.c index 99a76c9823fc4ee3fd312766fd10d45ce15bd923..e5bc6e97380343ffab7f133fa56129f7753ee308 100644 --- a/interpreteur.c +++ b/interpreteur.c @@ -1,5 +1,10 @@ #include "interpreteur.h" +#include <stdio.h> +#include <stdlib.h> +/** + * \brief tronque un entier entre 0 et 255 + */ int troncate(int n) { if (n<0) return 0; @@ -9,6 +14,9 @@ int troncate(int n) { return n; } +/** + * \brief interprete le fichier d'entrée en déplaçant le curseur + */ void interpreteur(char **matrix, int height, int width) { curseur cur; int i, j, a, b; @@ -20,25 +28,25 @@ void interpreteur(char **matrix, int height, int width) { char buf[256]; char *endptr; - /* initialise le module random */ + /* initialisation du module random */ srand((unsigned) time(&t)); cur.x = 0; cur.y = 0; + /* on commence en haut à gauche, direction à droite */ cur.current_char = matrix[0][0]; cur.current_dir = E; while (cur.current_char != '@') { - printf("=-=-=-=-=-=-=\n"); - printf("current char: %i = %c\n", cur.current_char, cur.current_char); + /*printf("=-=-=-=-=-=-=\n"); + printf("current char: %i = %c\n", cur.current_char, cur.current_char);*/ /* Action en fonction du caractère lu */ /* Si on est sur un pont, on ne lit pas l'instruction et on avance sur le pont */ if (bridge) { bridge--; - } /* Si on est en mode chaine de caractere on empile ce qu'on lit */ @@ -47,13 +55,11 @@ void interpreteur(char **matrix, int height, int width) { string_mode = 1 - string_mode; else push(cur.current_char, &pile); - } else { + /* switch pour les actions en fonction du caractère lu */ switch (cur.current_char) { - - case '+': a = pop(&pile); b = pop(&pile); @@ -240,7 +246,7 @@ void interpreteur(char **matrix, int height, int width) { case '~': printf("Veuillez entrer un caratere\n"); - tmp = fgetchar(); + tmp = getchar(); push(tmp, &pile); break; @@ -309,16 +315,11 @@ void interpreteur(char **matrix, int height, int width) { cur.current_char = matrix[cur.y][cur.x]; - print_list(pile); - //printf("string_mode: %i\n", string_mode); - //printf("bridge: %i\n", bridge); + /*print_list(pile); + printf("string_mode: %i\n", string_mode); + printf("bridge: %i\n", bridge);*/ } - printf("Contenu de la pile :\n"); - while (!is_empty(pile)) - { - printf("%i, ", pop(&pile)); - } printf("Fin de l'interpreteur\n"); } \ No newline at end of file