From ed3c2fc0de85a9f32971cd6d1acc40acf334353e Mon Sep 17 00:00:00 2001 From: Anteunis Charles <charles.anteunis@gmail.com> Date: Sun, 15 Dec 2019 02:17:05 +0100 Subject: [PATCH] add files --- a.out | Bin 0 -> 8920 bytes affichage.h | 6 +++++ interpreteur.c | 56 +++++++++++++++++++++++++++++++++++++++ interpreteur.h | 19 ++++++++++++++ list.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ list.h | 40 ++++++++++++++++++++++++++++ main.c | 61 ++++++++++++++++++++++++++++++++++++++++++ test.txt | 5 ++++ 8 files changed, 257 insertions(+) create mode 100755 a.out create mode 100644 affichage.h create mode 100644 interpreteur.c create mode 100644 interpreteur.h create mode 100644 list.c create mode 100644 list.h create mode 100644 main.c create mode 100644 test.txt diff --git a/a.out b/a.out new file mode 100755 index 0000000000000000000000000000000000000000..3f19027cc3c8c4ae8005f632132486827d782a92 GIT binary patch literal 8920 zcmX^A>+L^w1_nlE28ISE1_lOx1_p)$EDQ{-3<?Y&Aj!bM;K9Ja5Fa1l=<XWj8srZW zMa7J$T&z5hIX4(V=7hLLgrF(`>lZ*3V}SD685kH?p%|nhKE5Qiq6EZ(;P`k{^9;Bc z7(nK2V}Zzn_)sQ9fQ6v}!hn$R@x>*jNyQKj*q^B8J>!Fzrv+63<3qU&98mMvpaKx{ z;xkfn3Q~)(m?yvwF)s|N9>fQQJCw`705uQBkB?6-E-A{)ONR=e`!@}0o*Psi#D_A$ z6pGnk_mt+9XXd5EXXd5lgZZfbT>~`_6z3oVKzwvFK;keAiq{ulb6gxl9ATmi450V} z#RG^2i$dcQ#s|eKGXnzy%<TC1yqx&r%G{*<ocMy0B8K>Q?B>CY0ht5R4>p^DfdLf$ zATwe7`1qVeeC7!VK;ppyssY4DHV<SLCsYnZf&2*yllXWaPd{&07f)CkR)ClTat}xy zG}|!TfO-sM4mcdZk_-$=3=9nhAhrSn0|x^G1BU_wg9L~V#R>`x3<(Sj3=Ikl3>DDu z0m*YHf`gR7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%Pe$Wsqwzs29FX-_qsfEjjzRO?pwVK`+%jmei<g0c0W_2ZS`)&+ zz~F#SjRHeFmN<mQSv)-U;z3at502URg8TvoNYa2rRD1y__8^H3n#|(UzzGaQr82-0 R6+}-O11uq7BwSDc0syP#Gr0f& literal 0 HcmV?d00001 diff --git a/affichage.h b/affichage.h new file mode 100644 index 0000000..55d8de4 --- /dev/null +++ b/affichage.h @@ -0,0 +1,6 @@ +#ifndef AFFICHAGE_H +#define AFFICHAGE_H + +void print_grid(char **tab); + +#endif \ No newline at end of file diff --git a/interpreteur.c b/interpreteur.c new file mode 100644 index 0000000..2b3dc4c --- /dev/null +++ b/interpreteur.c @@ -0,0 +1,56 @@ +#include "interpreteur.h" + +void interpreteur(char **matrix, int height, int width) { + curseur cur; + int i, j; + list pile = empty(); + char tmp; + + cur.x = 0; + cur.y = 0; + cur.current_char = matrix[0][0]; + + while (cur.current_char != '@') { + + /* Action en fonction du caractère lu */ + switch (cur.current_char) + { + case 48 ... 57: + /* si on lit un entier */ + push(cur.current_char - 48, &pile); + break; + + case '>': + cur.current_dir = W; + break; + + case ',': + if (is_empty(pile)) + tmp = '0'; + else + tmp = pop(&pile) + 48; + break; + + default: + break; + } + + /* Déplacement du curseur et lecture du prochain caractère */ + switch (cur.current_dir) + { + case N: + cur.x = cur.x - 1; + /* Gérer les cas si on est au bord de la matrice */ + cur.current_char = matrix[cur.y][cur.x]; + break; + + case NW: + cur.x = cur.x - 1; + cur.y = cur.y + 1; + break; + + default: + break; + } + } +} \ No newline at end of file diff --git a/interpreteur.h b/interpreteur.h new file mode 100644 index 0000000..57ee305 --- /dev/null +++ b/interpreteur.h @@ -0,0 +1,19 @@ +#ifndef INTERPRETEUR_H +#define INTERPRETEUR_H + +#include "list.h" + +typedef enum direction { + N, S, E, W, NE, NW, SE, SW +} direction; + +typedef struct curseur { + int x; + int y; + char current_char; + direction current_dir; +} curseur; + +void interpreteur(char **matrix, int height, int width); + +#endif \ No newline at end of file diff --git a/list.c b/list.c new file mode 100644 index 0000000..cf6802c --- /dev/null +++ b/list.c @@ -0,0 +1,70 @@ +#include "list.h" + +/** + * Return the empty list + */ +list empty() { + return NULL; +} + +/** + * Return true if l is empty, else false + * \param l the list to test + */ +int is_empty(list l) { + return l==NULL; +} + +/** + * Add an element to the head of a list + * \param e the element to add + * \param l a pointer to the list + * \attention modify the list, l must be allocated + */ +void push(int e, list *l) { + list tmp = (elem *)malloc(sizeof(elem)); + + tmp->val = e; + tmp->next = *l; + *l = tmp; +} + +/** + * Return the head of the list and pop it from the list + * \param l a pointer to the list + * \attention modify the list, return 0 if l is empty + */ +int pop(list *l) { + if (l==NULL) + return 0; + int res = (*l)->val; + list tmp = *l; + + *l = (*l)->next; + free(tmp); + return res; +} + +/** + * Return the length of a list + * \param l the list we want the length + * \attention recursive function + */ +int len(list l) { + if (is_empty(l)) + return 0; + else + return 1 + len(l->next); +} + +/** + * Print a list like this : head->...->...->NULL + * \param l the list we want to print + */ +void print_list(list l) { + while (l != NULL) { + printf("%i->",l->val); + l = l->next; + } + printf("NULL\n"); +} \ No newline at end of file diff --git a/list.h b/list.h new file mode 100644 index 0000000..5830bd4 --- /dev/null +++ b/list.h @@ -0,0 +1,40 @@ +#ifndef LIST_H +#define LIST_H + +#include<stdio.h> +#include<stdlib.h> + +/** + * \file list.h + * \author Charles Anteunis + * + * Definiton of the int list structure in C + */ + +/** + * Definition of list type + * + */ +typedef struct elem * list; + +/** + * Definition of a list element + */ +typedef struct elem { + int val; + list next; +} elem; + +list empty(); + +int is_empty(list l); + +void push(int e, list *l); + +int pop(list *l); + +int len(list l); + +void print_list(list l); + +#endif \ No newline at end of file diff --git a/main.c b/main.c new file mode 100644 index 0000000..3ed035e --- /dev/null +++ b/main.c @@ -0,0 +1,61 @@ +#include "list.h" +#include "affichage.h" +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char const *argv[]) +{ + FILE *f; + char c = '\0'; + int height = 0, width = 0; + int i, j; + char **matrix; + + if (argc == 1) { + printf("Usage: ./prog2d file\n"); + return 0; + } + else { + /* ouverture du fichier à lire */ + if ((f = fopen(argv[1], "r")) == NULL) { + printf("Error while reading file\n"); + exit(1); + } + } + + /* on récupère le nombre de colonnes du fichier */ + fread(&c, sizeof(char), 1, f); + while ( c != ' ') { + width = 10*width + strtol(&c, NULL, 10); + fread(&c, sizeof(char), 1, f); + } + width = width/10; + + /* on récupère le nombre de lignes du fichier */ + fread(&c, sizeof(char), 1, f); + while (c != '\n') { + height = 10*height + strtol(&c, NULL, 10); + fread(&c, sizeof(char), 1, f); + } + height = height/10; + + matrix = (char **) malloc(height*sizeof(char *)); + for (i=0 ; i<height ; i++) { + matrix[i] = (char *) malloc(width*sizeof(char)); + } + + i = 0; + j = 0; + /* On remplit la matrice avec les données du fichier */ + while (fread(&c, sizeof(char), 1, f)) { + if (c == '\n') { + i++; + j = 0; + continue; + } + matrix[i][j] = c; + j++; + } + + return 0; +} diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..64aa092 --- /dev/null +++ b/test.txt @@ -0,0 +1,5 @@ +26 12 +a +bsf +czef qsf +d qsf qsf \ No newline at end of file -- GitLab