From 11b05638c7109933924f2a2774860dae4afee60b Mon Sep 17 00:00:00 2001 From: amelie-certin Date: Wed, 14 Dec 2016 23:43:58 +0100 Subject: [PATCH] menu --- src/gestorth.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gestorth.h | 4 +++ src/main3.c | 6 ++--- 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/gestorth.c b/src/gestorth.c index 7544e79..8f91fe6 100644 --- a/src/gestorth.c +++ b/src/gestorth.c @@ -1,5 +1,76 @@ #include "gestorth.h" +/** + * \brief Function for guide user into the third main menu + */ +void main3Menu(void) { + int choice; + do { + printf("\n\n*** Dictionaries management ***\n\n" + "\t1. Open an existing dictionary\n" + "\t0. Quit\n\n"); + do { + printf("Your choice: "); + } while(!getIntRange(&choice, 0, 1)); + switch (choice) { + case 1: + menu3OpenDictionary(); + break; + case 0: + printf("Good bye!\n"); + break; + } + } while(choice != 0); +} + +/** + * \brief Function for guide user into the third menu + */ +void menu3(Dictionary *dico) { + int choice; + do { + printf("\n\n--- Dictionary %s ---\n\n" + "\t1. Find unknown words\n" + "\t2. Suggest a correction for unknown words\n" + "\t3. Auto correct a text file\n" + "\t0. Return to Dictionaries management\n\n", dico->filename); + do { + printf("Your choice: "); + } while(!getIntRange(&choice, 0, 3)); + char *filename = malloc(sizeof(char) * 255); + printf("Please tape the path to your txt file: "); + getString(255, filename); + switch (choice) { + case 1: + listMissingWords(dico, filename); + break; + case 2: + suggestSimilarWords(dico, filename); + break; + case 3: + autoCorrectFile(dico, filename); + break; + case 0: + freeDictionary(dico); + clear(); + break; + } + free(filename); + } while(choice != 0); +} + +/** + * \brief Help the user to open a Dictionary + */ +void menu3OpenDictionary(void) { + char *dico = menuSelectDictionary(); + if(dico != NULL) { + menu3(selectDictionary(dico)); + free(dico); + dico = NULL; + } +} + /** * \param dico The dictionary who contains words * \param filename The name of the file who contain the text diff --git a/src/gestorth.h b/src/gestorth.h index a745fc0..33640d7 100644 --- a/src/gestorth.h +++ b/src/gestorth.h @@ -5,6 +5,10 @@ #include "linked_words.h" #include +void main3Menu(void); +void menu3(Dictionary *dico); +void menu3OpenDictionary(void); + void searchMissingWords(Dictionary *dico, const char *filename, int code); void listMissingWords(Dictionary *dico, const char *filename); void suggestSimilarWords(Dictionary *dico, const char *filename); diff --git a/src/main3.c b/src/main3.c index 202630d..853fee6 100644 --- a/src/main3.c +++ b/src/main3.c @@ -1,9 +1,7 @@ #include "gestorth.h" int main(void) { - // Should use the menu3 method - Dictionary *dico = selectDictionary("demo"); - listMissingWords(dico, "yolo.txt"); - freeDictionary(dico); + clear(); + main3Menu(); return 0; }