From 77e038d66576e5a2f9e4b777d7d33c5e106e20b6 Mon Sep 17 00:00:00 2001
From: Anteunis Charles <charles.anteunis@gmail.com>
Date: Sun, 15 Dec 2019 18:52:01 +0100
Subject: [PATCH] tests OK sur fichiers du prof

---
 fact.txt       |  6 ++++++
 hellodiag.txt  | 13 +++++++++++++
 helloworld.txt |  2 ++
 interpreteur.c | 53 +++++++++++++++++++++++++++++++++++---------------
 lessmore.txt   | 25 ++++++++++++++++++++++++
 main.c         |  3 +++
 sieve.txt      |  5 +++++
 7 files changed, 91 insertions(+), 16 deletions(-)
 create mode 100644 fact.txt
 create mode 100644 hellodiag.txt
 create mode 100644 helloworld.txt
 create mode 100644 lessmore.txt
 create mode 100644 sieve.txt

diff --git a/fact.txt b/fact.txt
new file mode 100644
index 0000000..e7d3a2a
--- /dev/null
+++ b/fact.txt
@@ -0,0 +1,6 @@
+15 5
+&>=1-=v v *_;.v
+ ^    _;>$=^  [
+      @,*<   5 
+          2 =  
+           \   
\ No newline at end of file
diff --git a/hellodiag.txt b/hellodiag.txt
new file mode 100644
index 0000000..f20a2c0
--- /dev/null
+++ b/hellodiag.txt
@@ -0,0 +1,13 @@
+26 12
+64+[                      
+    "         @_,4#2!=;6' 
+     !                 6  
+      d               "   
+       l             H    
+        r           e     
+         o         l      
+          W       l       
+                 o        
+            "   ,         
+             0 "          
+              /           
\ No newline at end of file
diff --git a/helloworld.txt b/helloworld.txt
new file mode 100644
index 0000000..46d9a19
--- /dev/null
+++ b/helloworld.txt
@@ -0,0 +1,2 @@
+26 1
+64+"!dlroW ,olleH">=2#2,_@
\ No newline at end of file
diff --git a/interpreteur.c b/interpreteur.c
index 061f6c6..99a76c9 100644
--- a/interpreteur.c
+++ b/interpreteur.c
@@ -17,6 +17,7 @@ void interpreteur(char **matrix, int height, int width) {
     time_t t;
     int string_mode = 0;
     int bridge = 0;
+    char buf[256];
     char *endptr;
 
     /* initialise le module random */
@@ -25,24 +26,33 @@ void interpreteur(char **matrix, int height, int width) {
     cur.x = 0;
     cur.y = 0;
     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);
         /* Action en fonction du caractère lu */
-        switch (cur.current_char)
+
+        /* Si on est sur un pont, on ne lit pas l'instruction et on avance sur le pont */
+        if (bridge)
         {
-            /* Si on est sur un pont, on ne lit pas l'instruction et on avance sur le pont */
-            if (bridge)
-            {
-                bridge--;
-                break;
-            }
+            bridge--;
+            
+        }
 
-            /* Si on est en mode chaine de caractere on empile ce qu'on lit */
-            if (string_mode) {
+        /* Si on est en mode chaine de caractere on empile ce qu'on lit */
+        else if (string_mode == 1) {
+            if (cur.current_char == '"')
+                string_mode = 1 - string_mode;
+            else
                 push(cur.current_char, &pile);
-                break;
-            }   
+            
+        }
+        else {
+        switch (cur.current_char)
+        {
+               
 
             case '+':
                 a = pop(&pile);
@@ -167,8 +177,14 @@ void interpreteur(char **matrix, int height, int width) {
                 break;
 
             case '$':
-                a = pop(&pile);
-                b = pop(&pile);
+                if (is_empty(pile))
+                    a = 0;
+                else
+                    a = pop(&pile);
+                if (is_empty(pile))
+                    b = 0;
+                else
+                    b = pop(&pile);
                 push(a, &pile);
                 push(b, &pile);
                 break;
@@ -210,16 +226,16 @@ void interpreteur(char **matrix, int height, int width) {
                 break;
 
             case '&':
-                char buf[256];
                 printf("Veuillez entrer un entier\n");
                 fgets(buf, 256, stdin);
-                a = strtol(buf, NULL, 10);
+                a = strtol(buf, &endptr, 10);
                 while (buf == endptr)
                 {
                     printf("Erreur, veuillez saisir un nombre\n");
                     fgets(buf, 256, stdin);
-                    a = strtol(buf, endptr, 10);
+                    a = strtol(buf, &endptr, 10);
                 }
+                push(a, &pile);
                 break;
             
             case '~':
@@ -244,6 +260,7 @@ void interpreteur(char **matrix, int height, int width) {
             default:
                 break;
         }
+        }
 
         /* Déplacement du curseur et lecture du prochain caractère */
         switch (cur.current_dir)
@@ -291,6 +308,10 @@ 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);
     }
 
     printf("Contenu de la pile :\n");
diff --git a/lessmore.txt b/lessmore.txt
new file mode 100644
index 0000000..1f6b991
--- /dev/null
+++ b/lessmore.txt
@@ -0,0 +1,25 @@
+77 24
+vv  <      <                                                                 
+    2                                                                        
+   >^v v<                                                                    
+ v1<?>3v4                                                                    
+   >^<  ^<                                                                   
+>  >?>  ?>5^                                                                 
+   >v<  v<                                                                   
+ v9<?>7v6                                                                    
+   >v< v<                                                                    
+    8                                                                        
+    >  >   ^                                                                 
+ vv  <      <                                                                
+     2                                                                       
+    >^v v<                                                                   
+  v1<?>3v4                                                                   
+    >^<  ^<                                                                  
+ >  >?>  ?>5^                                                                
+    >v<  v<     v          ,*25           <<                                 
+  v9<?>7v6                                ,,                                 
+    >v< v<                                ""                                 
+     8                                    ><                                 
+     >  >   ^                             ""v                                
+  >*=.>0"!rebmun tupnI">=2#2,_;25*,=&=99p`|^<       _0"!niw uoY">=2#2,_;25*,@
+      ^         <                         >=99g01-*+^                        
\ No newline at end of file
diff --git a/main.c b/main.c
index e0cc210..aa40014 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
 #include "list.h"
 #include "affichage.h"
+#include "interpreteur.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -63,6 +64,8 @@ int main(int argc, char const *argv[])
         matrix[i][j] = c;
         j++;
     }
+    
+    interpreteur(matrix, height, width);
 
     return 0;
 }
diff --git a/sieve.txt b/sieve.txt
new file mode 100644
index 0000000..88ee4cf
--- /dev/null
+++ b/sieve.txt
@@ -0,0 +1,5 @@
+80 4
+2>=3g" "-!v$  g30          <                                                    
+ |!`"O"=+1_=.=03p>03g+="O"`|                                                    
+ @               ^  p3$" "=<                                                    
+2 234567890123456789012345678901234567890123456789012345678901234567890123456789
\ No newline at end of file
-- 
GitLab