Commit 0e62ceb149de528a6d278ea5c9e85a0cbd4ad8ac

Authored by grouille
1 parent 8c1065af

Code propre

Showing 5 changed files with 87 additions and 23 deletions   Show diff stats
@@ -3,5 +3,5 @@ Doucement, Etrange. Odorat; odorant; @@ -3,5 +3,5 @@ Doucement, Etrange. Odorat; odorant;
3 L'ile, L'ocean; aaee''ee 3 L'ile, L'ocean; aaee''ee
4 chiens 4 chiens
5 chienne 5 chienne
6 -chia 6 +chie
7 Doucement. 7 Doucement.
1 -banane  
2 -banc  
3 -bilan  
4 -chien  
5 -chienne  
6 - 1 +bien
  2 +bon
  3 +bio
  4 +blanc
  5 +banc
  6 +banane
  7 +aspirateur
  8 +chaussette
  9 +chien
  10 +chienne
  11 +chiens
  12 +Doucement
  13 +Etrange
  14 +Odorat
  15 +odorant
  16 +L'ile
  17 +L'ocean
  18 +aaee''ee
7 \ No newline at end of file 19 \ No newline at end of file
@@ -8,24 +8,39 @@ @@ -8,24 +8,39 @@
8 8
9 int main(int argc, char *argv[]) 9 int main(int argc, char *argv[])
10 { 10 {
  11 + init_pgrm();
11 Node tree = NULL; 12 Node tree = NULL;
12 int error = 0; 13 int error = 0;
13 FILE* fp_lib; 14 FILE* fp_lib;
14 FILE* fp_txt; 15 FILE* fp_txt;
  16 +
  17 + if(argc < 3)
  18 + {
  19 + printf("Le nombre d'arguments est incorrect. Veuillez réessayer.\n");
  20 + return EXIT_FAILURE;
  21 + }
  22 +
15 fp_lib = fopen(argv[argc-2], "r"); 23 fp_lib = fopen(argv[argc-2], "r");
16 fp_txt = fopen(argv[argc-1], "r"); 24 fp_txt = fopen(argv[argc-1], "r");
17 25
  26 + if(fp_lib==NULL || fp_txt==NULL)
  27 + {
  28 + printf("Erreur de lecture d'un des fichiers passés en paramètres.\n");
  29 + return EXIT_FAILURE;
  30 + }
  31 +
18 init_tree(&tree); 32 init_tree(&tree);
19 read_lib(fp_lib, &tree); 33 read_lib(fp_lib, &tree);
20 - read_txt(fp_txt, &tree, &error); 34 + read_txt(fp_txt, &tree, &error, fp_txt);
21 35
22 // printf("%p\n", tree); 36 // printf("%p\n", tree);
23 37
24 //print_first(tree); 38 //print_first(tree);
25 //printf("\n"); 39 //printf("\n");
26 //print_tree(tree, 0); 40 //print_tree(tree, 0);
27 -  
28 - printf("erreurs : %d\n", error); 41 +
  42 + if(error<2) printf("Dans le texte %s, %d mot n'est pas dans le dictionnaire %s.\n", argv[argc-1], error, argv[argc-2]);
  43 + else printf("Dans le texte %s, %d mots ne sont pas dans le dictionnaire %s.\n", argv[argc-1], error, argv[argc-2]);
29 44
30 free_tree(&tree); 45 free_tree(&tree);
31 fclose(fp_lib); 46 fclose(fp_lib);
@@ -102,7 +102,7 @@ char max_index(char word[]) @@ -102,7 +102,7 @@ char max_index(char word[])
102 return index; 102 return index;
103 } 103 }
104 104
105 -void scan_word(Node Tree, char word[], int* error) // si un mot démarre juste après un caractère de fin, la fonction ne lit pas les mots séparément 105 +void scan_word(Node Tree, char word[], int* error, FILE* fp_txt) // si un mot démarre juste après un caractère de fin, la fonction ne lit pas les mots séparément
106 { 106 {
107 bool endWord = false; 107 bool endWord = false;
108 bool stop = false; 108 bool stop = false;
@@ -124,8 +124,7 @@ void scan_word(Node Tree, char word[], int* error) // si un mot démarre juste a @@ -124,8 +124,7 @@ void scan_word(Node Tree, char word[], int* error) // si un mot démarre juste a
124 } 124 }
125 else 125 else
126 { 126 {
127 - printf("mot : %s erreur :%c %d \n", word, word[ind], word[ind]);  
128 - (*error)++; 127 + add_error(error, word, ind, Tree, fp_txt);
129 //printf("%d\n", ind); 128 //printf("%d\n", ind);
130 ind = max_index(word); 129 ind = max_index(word);
131 //printf("%d\n", ind); 130 //printf("%d\n", ind);
@@ -135,11 +134,38 @@ void scan_word(Node Tree, char word[], int* error) // si un mot démarre juste a @@ -135,11 +134,38 @@ void scan_word(Node Tree, char word[], int* error) // si un mot démarre juste a
135 } 134 }
136 if(!endWord && !stop) 135 if(!endWord && !stop)
137 { 136 {
138 - (*error)++;  
139 - printf("---%s---\n", word); 137 + add_error(error, word, ind, Tree, fp_txt);
140 } 138 }
141 } 139 }
142 140
  141 +void add_error(int* error, char word[], int index, Node Tree, FILE* fp_txt)
  142 +{
  143 + (*error)++;
  144 + if(index==0)
  145 + {
  146 + printf("Le mot %s ne correspond à aucun mot du dictionnaire.\n\n", word);
  147 + return;
  148 + }
  149 + else if(index<strlen(word))
  150 + printf("Il y a une erreur dans le mot '%s', au caractère %c d'incide %d.\n\n", word, word[index], index);
  151 + else
  152 + printf("Il manque au moins une lettre au mot '%s'.\n\n", word);
  153 + make_correction(word, index, Tree, fp_txt);
  154 +}
  155 +
  156 +void make_correction(char word[], int index, Node Tree, FILE* fp_txt)
  157 +{
  158 + return;
  159 +}
  160 +
  161 +void init_pgrm(void)
  162 +{
  163 + printf("\n------------------------------------------\n");
  164 + printf("Correcteur ortographique.\n");
  165 + printf("Normand Quentin & Rouillé Guillaume.\n");
  166 + printf("------------------------------------------\n\n");
  167 +}
  168 +
143 bool no_accent(char word[]) 169 bool no_accent(char word[])
144 { 170 {
145 int index_max = max_index(word); 171 int index_max = max_index(word);
@@ -148,17 +174,18 @@ bool no_accent(char word[]) @@ -148,17 +174,18 @@ bool no_accent(char word[])
148 return true; 174 return true;
149 } 175 }
150 176
151 -void read_txt(FILE* fp, Node* Tree, int* error) 177 +void read_txt(FILE* fp, Node* Tree, int* error, FILE* fp_txt)
152 { 178 {
153 char word[MAX]; 179 char word[MAX];
154 while(1) 180 while(1)
155 { 181 {
156 if(fscanf(fp, "%s", word)!=1) 182 if(fscanf(fp, "%s", word)!=1)
157 break; 183 break;
158 - scan_word(*Tree, word, error); 184 + if(no_accent(word)) // !!! MOTS AVEC ACCENTS NON PRIS EN COMPTE
  185 + scan_word(*Tree, word, error, fp_txt);
159 } 186 }
160 - if(feof(fp)) printf("Fin normale de lecture fichier.\n");  
161 - if(ferror(fp)) printf("Erreur de lecture fichier.\n"); 187 + if(feof(fp)) printf("Fin de la lecture du fichier à scanner.\n\n");
  188 + if(ferror(fp)) printf("Erreur lors de la lecture du fichier à scanner.\n\n");
162 } 189 }
163 190
164 void read_lib(FILE* fp, Node* Tree) 191 void read_lib(FILE* fp, Node* Tree)
@@ -173,10 +200,11 @@ void read_lib(FILE* fp, Node* Tree) @@ -173,10 +200,11 @@ void read_lib(FILE* fp, Node* Tree)
173 if(no_accent(word)) 200 if(no_accent(word))
174 add_in_tree(*Tree, word); 201 add_in_tree(*Tree, word);
175 } 202 }
176 - if(feof(fp)) printf("Fin normale de lecture bibliothèque.\n");  
177 - if(ferror(fp)) printf("Erreur de lecture bibliothèque.\n"); 203 + if(feof(fp)) printf("Fin de la lecture de la bibliothèque.\n\n");
  204 + if(ferror(fp)) printf("Erreur lors de la lecture de la bibliothèque.\n\n");
178 } 205 }
179 206
  207 +
180 void print_tree(Node Tree, int index) 208 void print_tree(Node Tree, int index)
181 { 209 {
182 if(is_empty_tree(Tree)) 210 if(is_empty_tree(Tree))
@@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
8 #include <stdio.h> 8 #include <stdio.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <stdbool.h> 10 #include <stdbool.h>
  11 +#include <string.h>
11 #define MAX 30 // taille maximale d'une chaîne lue dans un fichier 12 #define MAX 30 // taille maximale d'une chaîne lue dans un fichier
12 #define NB_CARAC 27 // nombre de caractères différents pouvant être identifiés -> 89 avec accentués 13 #define NB_CARAC 27 // nombre de caractères différents pouvant être identifiés -> 89 avec accentués
13 14
@@ -43,13 +44,13 @@ bool is_end_caract(char letter); @@ -43,13 +44,13 @@ bool is_end_caract(char letter);
43 char max_index(char word[]); 44 char max_index(char word[]);
44 45
45 // Détermine si le mot 'word' est présent dans l'arbre indexé 46 // Détermine si le mot 'word' est présent dans l'arbre indexé
46 -void scan_word(Node Tree, char word[], int* error); 47 +void scan_word(Node Tree, char word[], int* error, FILE*);
47 48
48 // Retourne 'true' si le mot 'word' est non accentué, 'false' sinon 49 // Retourne 'true' si le mot 'word' est non accentué, 'false' sinon
49 bool no_accent(char word[]); 50 bool no_accent(char word[]);
50 51
51 // Transmet les mots du texte à analyser à 'scan_word' 52 // Transmet les mots du texte à analyser à 'scan_word'
52 -void read_txt(FILE* fp, Node* Tree, int* error); 53 +void read_txt(FILE* fp, Node* Tree, int* error, FILE*);
53 54
54 // Transmet les mots de la biliothèque à 'add_in_tree' 55 // Transmet les mots de la biliothèque à 'add_in_tree'
55 void read_lib(FILE* fp, Node* Tree); 56 void read_lib(FILE* fp, Node* Tree);
@@ -66,3 +67,11 @@ void print_first(Node Tree); @@ -66,3 +67,11 @@ void print_first(Node Tree);
66 // Libère l'espace mémoire associé à l'arbre indexé 67 // Libère l'espace mémoire associé à l'arbre indexé
67 void free_tree(Node* Tree); 68 void free_tree(Node* Tree);
68 69
  70 +// Ajoute une erreur
  71 +void add_error(int*, char*, int, Node, FILE*);
  72 +
  73 +// Corrige les erreurs
  74 +void make_correction(char *, int, Node, FILE*);
  75 +
  76 +// Initialise le programme
  77 +void init_pgrm(void);