From acd09bd426807475cfe622eb18f0d51ce2ca6be9 Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Tue, 19 Oct 2021 14:22:25 +0200 Subject: [PATCH] TP17 Organisation du code --- APL1.1/TP17/exo1/Makefile | 45 ++++++++++++++++++++++++ APL1.1/TP17/exo1/exo1 | Bin 0 -> 23144 bytes APL1.1/TP17/exo1/lire.h | 8 +++++ APL1.1/TP17/exo1/lire.s | 30 ++++++++++++++++ APL1.1/TP17/exo1/main.c | 25 ++++++++++++++ APL1.1/TP17/exo1/options.c | 19 +++++++++++ APL1.1/TP17/exo1/options.h | 8 +++++ APL1.1/TP17/exo1/personne.c | 33 ++++++++++++++++++ APL1.1/TP17/exo1/personne.h | 16 +++++++++ APL1.1/TP17/exo1/repertoire.c | 37 ++++++++++++++++++++ APL1.1/TP17/exo1/repertoire.h | 20 +++++++++++ APL1.1/TP17/exo2/Makefile | 18 ++++++++++ APL1.1/TP17/exo2/attente.c | 62 ++++++++++++++++++++++++++++++++++ APL1.1/TP17/exo2/file.c | 44 ++++++++++++++++++++++++ APL1.1/TP17/exo2/file.h | 25 ++++++++++++++ 15 files changed, 390 insertions(+) create mode 100644 APL1.1/TP17/exo1/Makefile create mode 100755 APL1.1/TP17/exo1/exo1 create mode 100644 APL1.1/TP17/exo1/lire.h create mode 100644 APL1.1/TP17/exo1/lire.s create mode 100644 APL1.1/TP17/exo1/main.c create mode 100644 APL1.1/TP17/exo1/options.c create mode 100644 APL1.1/TP17/exo1/options.h create mode 100644 APL1.1/TP17/exo1/personne.c create mode 100644 APL1.1/TP17/exo1/personne.h create mode 100644 APL1.1/TP17/exo1/repertoire.c create mode 100644 APL1.1/TP17/exo1/repertoire.h create mode 100644 APL1.1/TP17/exo2/Makefile create mode 100755 APL1.1/TP17/exo2/attente.c create mode 100644 APL1.1/TP17/exo2/file.c create mode 100644 APL1.1/TP17/exo2/file.h diff --git a/APL1.1/TP17/exo1/Makefile b/APL1.1/TP17/exo1/Makefile new file mode 100644 index 0000000..e974eb3 --- /dev/null +++ b/APL1.1/TP17/exo1/Makefile @@ -0,0 +1,45 @@ +# TP 19 Exercice 1 : fichier Makefile + +# CHAPITRE 1 : BUT FINAL + +but : exo1 + +# CHAPITRE 2 : VARIABLES + +OFILES = lire.o \ + personne.o \ + repertoire.o \ + options.o \ + main.o + +CC = gcc + +CFLAGS = -Wall -ansi -pedantic -g + +# CHAPITRE 3 : DEPENDANCES (REGLES IMPLICITES) + +options.o : options.h + +personne.o : personne.h lire.h + +repertoire.o : repertoire.h personne.h + +main.o : personne.h repertoire.h options.h + + +#CHAPITRE 4 : DEPENDANCES AVEC COMMANDES + +lire.o : lire.s lire.h + as -o lire.o lire.s + +exo1 : $(OFILES) + $(CC) $(CFLAGS) -o exo1 $(OFILES) + +#CHAPITRE 5 : NETTOYAGE DES FICHIERS GENERES + +clean : + -rm -f $(OFILES) exo1 + +#CHAPITRE 6 : BUTS FACTICES + +.PHONY : but clean diff --git a/APL1.1/TP17/exo1/exo1 b/APL1.1/TP17/exo1/exo1 new file mode 100755 index 0000000000000000000000000000000000000000..538856f555277bd70c53eb192a8e1da00e06706d GIT binary patch literal 23144 zcmeHPdvsLCd7pcC?>@BBYK3?SFf15|Y)3DQF;BBAB)r1nVFL~%kjrX!rQKNCmG?n_ z;2K-RMI|_pw29N=#!h=0w@KQhbs8t62{x`@C+V@B2ROkAN$pe=$04!9kzXI%I~(NHFgrXb$V@@i z-mTDcOWyAT)G*&B+Z%5jrc3`TDBa7NdQ)9X7B}_A8+ude!k&gbOP4e(S=^Y*G%n)J zlU>cYC~R)tu$Act*h!)(eT`{lxNgHqb}}v+F4F(2ir&tssnL5BXy(di6N;CqWP5vZoFZ=GlqBSKz8)bu1YY zOf{cacXw|gmt?toHrBtFnPw`Ni7i`Z=3>!wH|sCtbD-t&(byekEP0379ZmJJ{%k6p z?}kb|Q^>QvXm4*O2C3MdsM(!LM|)HI5>k~W#+4mKe1!iH2=fBMHCkUr4 z&H0Bo{td!uD|7xR$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-|p?O~~ODi1;|o6qG7c=I)eO_%!cjG6BiJfF$t%xGZ`wxE6ey@`Axjvo`pl%TKYq|9hG8{Lb2Vm`YUo5N@y zHZq02KKe9|1vAN#GEx2?FvI^5nk}XOk!An&O8@I(>VKVSuDvb1zTIr!&}QOGI_33Z z3*EMTLwJ41nsN^Rst-um*qQASSwo}^87c2t65`iZyz@4fcdO|Nmarld{mT#&ylkR3N(!>n-F$gwN4vVRiQNjr7vd7C4DYETkr4n{>nivMmudaRzZmRkM4FCu zmXdM-)mr8vFLsnsw@nE_vEdgfL-y`)EoL?qQd(iUKVbfRpdIf{! z;-mE62mU3TnNjwub3_WN_Fb|byZuqn`9l)PSLcirOiG7QAE~JH>G30_6fWwrYG0jO zQc#^!B3Vjy|KAB3oe5I<>Ku@Q^o;~c%6=uM;2(iUXN(lC&KW5fB4s4I{esH)_tj`j zl)gIWq~IATsM@#p|I^@;eyfz@U*tep!IP3s`q+(+^54Utkxx|pv=!q?LbX4U)KTMq z91N>|Q0ggoR4GbmtDb${rmyy03NBDL0yceB?U!u&YTvA2l@gTD9{==Emh4ylXF(|_ z;Y$)#K>1(cCs45JpA8C*f(MnLg!cBI1>LH@YpxJfkoNc1WN-g_VB+^UJ_krn-M^~u zYTD%$uHa9hQ*F^#_sbU>sJ2qP2&{xF{R?1F?8s%Oc;BeLlX{LiheYvDN$IILcoQ@d zQTpopfM?{!yPlLRN$D&27I;>D7Lvlv0&bJ20!mLox<9b$tNWR4QeW9=*DvBwrn;2< zYCoR*J@x5C616YIRkcj%+wbj2mXd-~rM{q+@_n+xlO+-_DLqAAFpmE679nwyS4j$J z*QX;_b{a|USuW&#w)tz9T|JKez-poYpe_FG`nO1ZyZ?f%LVunb7=adTRrS#QHkIxA zt?g1@367&rY@3N(GPzbN$c1$tP+Ch>+^PRx +#include +#include "personne.h" +#include "repertoire.h" +#include "options.h" + +int main(void) { + options opt; + repertoire r = construire_repertoire(); + while ((opt=saisir_option())!=SORTIR) + switch(opt) { + case AJOUTER : + ajouter_personne(r, saisir_personne()); + break; + case AFFICHER : + afficher_repertoire(r); + break; + default : + ; /* rien a faire */ + } + detruire_repertoire(r); + return EXIT_SUCCESS; +} diff --git a/APL1.1/TP17/exo1/options.c b/APL1.1/TP17/exo1/options.c new file mode 100644 index 0000000..cf3938c --- /dev/null +++ b/APL1.1/TP17/exo1/options.c @@ -0,0 +1,19 @@ +#include +#include +#include "options.h" + +options saisir_option() { + short o; + printf("\nChoisissez une option :\n"); + printf("1] Ajouter une personne.\n"); + printf("2] Afficher le repertoire.\n"); + printf("3] Sortir\n"); + printf("? "); + scanf("%hd", &o); + switch(o) { + case 1 : return AJOUTER; + case 2 : return AFFICHER; + case 3 : return SORTIR; + default : return AFFICHER; + } +} \ No newline at end of file diff --git a/APL1.1/TP17/exo1/options.h b/APL1.1/TP17/exo1/options.h new file mode 100644 index 0000000..557d45c --- /dev/null +++ b/APL1.1/TP17/exo1/options.h @@ -0,0 +1,8 @@ +#ifndef OPTIONS_H +#define OPTIONS_H + +typedef enum {AJOUTER, AFFICHER, SORTIR} options; + +options saisir_option(); + +#endif /* OPTIONS_H */ \ No newline at end of file diff --git a/APL1.1/TP17/exo1/personne.c b/APL1.1/TP17/exo1/personne.c new file mode 100644 index 0000000..38195d8 --- /dev/null +++ b/APL1.1/TP17/exo1/personne.c @@ -0,0 +1,33 @@ +/* TP 19 Exercice 1 : fichier personne.c */ + +#include +#include +#include +#include "personne.h" +#include "lire.h" + +personne construire_personne(const char *nom, const char *tel) { + personne p = (personne) malloc(sizeof(struct s_personne)); + strcpy(p->nom, nom); + strcpy(p->tel, tel); + return p; +} + +personne saisir_personne() { + personne p = (personne) malloc(sizeof(struct s_personne)); + printf("\nEntrez le nom de la personne : "); + fflush(stdout); + lire(p->nom, 30); + printf("Entrez son numero de telephone : "); + fflush(stdout); + lire(p->tel, 20); + return p; +} + +void afficher_personne(personne p) { + printf("%-30s %-20s\n", p->nom, p->tel); +} + +void detruire_personne(personne p) { + free(p); +} diff --git a/APL1.1/TP17/exo1/personne.h b/APL1.1/TP17/exo1/personne.h new file mode 100644 index 0000000..079ef3e --- /dev/null +++ b/APL1.1/TP17/exo1/personne.h @@ -0,0 +1,16 @@ +/* TP 19 Exercice 1 : fichier personne.h */ + +#ifndef PERSONNE_H +#define PERSONNE_H + +typedef struct s_personne { + char nom[30]; + char tel[20]; +} * personne; + +personne construire_personne(const char*, const char*); +personne saisir_personne(); +void afficher_personne(personne); +void detruire_personne(personne); + +#endif /* PERSONNE_H */ diff --git a/APL1.1/TP17/exo1/repertoire.c b/APL1.1/TP17/exo1/repertoire.c new file mode 100644 index 0000000..e31e22a --- /dev/null +++ b/APL1.1/TP17/exo1/repertoire.c @@ -0,0 +1,37 @@ +/* TP 19 Exercice 1 : fichier repertoire.c */ + +#include +#include +#include "repertoire.h" +#include "lire.h" + +repertoire construire_repertoire() { + repertoire r = (repertoire) malloc(sizeof(struct s_repertoire)); + r->taille = 0; + return r; +} + +void afficher_repertoire(repertoire r) { + int i = 0; + printf("\n%-30s %-20s\n", "Nom", "Telephone"); + for(; itaille; i++) + afficher_personne((r->personnes)[i]); +} + +int ajouter_personne(repertoire r, personne p) { + if (r->taillepersonnes)[r->taille] = p; + (r->taille)++; + return 0; + } else + return 1; +} + +void detruire_repertoire(repertoire r) { + int i = r->taille; + while(i-->0) { + free((r->personnes)[i]); + } + free(r); +} + diff --git a/APL1.1/TP17/exo1/repertoire.h b/APL1.1/TP17/exo1/repertoire.h new file mode 100644 index 0000000..f6db222 --- /dev/null +++ b/APL1.1/TP17/exo1/repertoire.h @@ -0,0 +1,20 @@ +/* TP 19 Exercice 1 : fichier repertoire.h */ + +#ifndef REPERTOIRE_H +#define REPERTOIRE_H + +#include "personne.h" + +#define CAPACITE 100 + +typedef struct s_repertoire { + int taille; + personne personnes[CAPACITE]; +} * repertoire; + +repertoire construire_repertoire(); +void afficher_repertoire(repertoire); +int ajouter_personne(repertoire, personne); +void detruire_repertoire(repertoire); + +#endif /* REPERTOIRE_H */ diff --git a/APL1.1/TP17/exo2/Makefile b/APL1.1/TP17/exo2/Makefile new file mode 100644 index 0000000..a91b234 --- /dev/null +++ b/APL1.1/TP17/exo2/Makefile @@ -0,0 +1,18 @@ +but : exo2 + +OFILES = file.o \ + attente.o + +CC = gcc +CFLAGS = -Wall -ansi -pedantic -g + +file.o : file.h +attente.o : file.h + +exo2 : $(OFILES) + $(CC) $(CFLAGS) -o attente.out $(OFILES) + +clean : + -rm -f $(OFILES) exo2 + +.PHONY : but clean diff --git a/APL1.1/TP17/exo2/attente.c b/APL1.1/TP17/exo2/attente.c new file mode 100755 index 0000000..f9836b7 --- /dev/null +++ b/APL1.1/TP17/exo2/attente.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include "file.h" + +#define TAILLE_MIN 30 +#define TAILLE_INC 10 + +char *saisie(const char* invite) { + char *temp = (char *) malloc(TAILLE_MIN); + int c, i=0, taille = TAILLE_MIN; + + printf("\n%s", invite); + while(((c=getchar())!=EOF)&&(c!='\n')) { + if (i>=taille) { + taille += TAILLE_INC; + temp = (char *) realloc(temp, taille); + } + temp[i++] = c; + } + temp = (char *) realloc(temp, i+1); + temp[i] = '\0'; + return temp; +} + +int main(void) { + int choix = 0; + char *s; + file f = {NULL, NULL}; + + while (choix != '3') { + printf("\nFaites votre choix :\n"); + printf("\t1. nouveau client\n"); + printf("\t2. client suivant\n"); + printf("\t3. fermer boutique\n"); + printf("? "); + choix = getchar(); + while(getchar() != '\n'); + switch (choix) { + case '1': + s = saisie("Nom du client : "); + file_push(f, s); + break; + case '2': + if (file_empty(f)) { + printf("\nAucun Client a l'horizon...\n"); + } else { + s = file_pop(f); + printf("\nClient suivant : %s\n", s); + free(s); + } + break; + case '3': + printf("\nOn ferme !\n\n"); + break; + default: + printf("Ne tapez pas n'importe quoi !\n"); + } + } + file_clear(f); + return EXIT_SUCCESS; +} diff --git a/APL1.1/TP17/exo2/file.c b/APL1.1/TP17/exo2/file.c new file mode 100644 index 0000000..4e69565 --- /dev/null +++ b/APL1.1/TP17/exo2/file.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include "file.h" + +int file_empty(file f) { + return (f[DEBUT] == NULL); +} + +void file_push(file f, char *s) { + liste l = (liste) malloc(sizeof(struct maillon)); + l->nom = s; + l->suivant = NULL; + if (f[FIN] == NULL) + f[DEBUT] = l; + else + f[FIN]->suivant = l; + f[FIN] = l; +} + +char *file_top(file f) { + return f[DEBUT]->nom; +} + +char *file_pop(file f) { + struct maillon m = *(f[DEBUT]); + free(f[DEBUT]); + f[DEBUT]=m.suivant; + if (f[DEBUT] == NULL) + f[FIN] = NULL; + return m.nom; +} + +void file_clear(file f) { + liste tmp,l = f[DEBUT]; + + while(l != NULL) { + tmp = l->suivant; + free(l->nom); + free(l); + l = tmp; + } + f[DEBUT] = f[FIN] = NULL; +} \ No newline at end of file diff --git a/APL1.1/TP17/exo2/file.h b/APL1.1/TP17/exo2/file.h new file mode 100644 index 0000000..095a1b7 --- /dev/null +++ b/APL1.1/TP17/exo2/file.h @@ -0,0 +1,25 @@ +#ifndef FILE_H +#define FILE_H + +struct maillon { + char *nom; + struct maillon *suivant; +}; + +typedef struct maillon *liste; + +enum indice {DEBUT, FIN, TAILLE_FILE}; + +typedef liste file[TAILLE_FILE]; + +int file_empty(file f); + +void file_push(file f, char *s); + +char *file_top(file f); + +char *file_pop(file f); + +void file_clear(file f); + +#endif /* FILE_H */ \ No newline at end of file