From 6142fac0d400d4d7e0f44b9f1154eb5fa6e78300 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Fri, 19 Jul 2024 12:00:46 +0200 Subject: [PATCH] Cleaning static debug_printing() in fsm.c using static char *tab[] = { STATE, RULES, DATA } --- src/fsm.c | 43 +++++++++++++------------------------------ src/main.c | 6 +++--- 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/src/fsm.c b/src/fsm.c index e03964c..11530cf 100644 --- a/src/fsm.c +++ b/src/fsm.c @@ -80,50 +80,33 @@ void fsm_set_SITUATIONS_box_RESET_VALUE (int value) } } - -/******************************************************************************/ -/* G E T T E R S & D E B U G G E R S */ -/******************************************************************************/ - int fsm_get_EXEC_EDIT () {return choice_EXEC_EDIT;} int fsm_get_STATE_RULES_DATA () {return choice_STATE_RULES_DATA;} int fsm_get_OBJECTS_box_RESET_VALUE () {return choice_OBJECTS_box_RESET_VALUE;} int fsm_get_SITUATIONS_box_RESET_VALUE () {return choice_SITUATIONS_box_RESET_VALUE;} -static char *fsm_get_str_EXEC_EDIT (int value) -{ - switch (value) { - case (EXEC) : return "EXEC"; - case (EDIT) : return "EDIT"; - default : printf("default in automaton.fsm_get_EXEC_EDIT ()\n"); return NULL; - } -} -static char *fsm_get_str_STATE_RULES_DATA (int value) -{ - switch (value) { - case (STATE) : return "STATE"; - case (RULES) : return "RULES"; - case (DATA) : return "DATA"; - default : printf("default in automaton.fsm_get_STATE_RULES_DATA ()\n"); return NULL; - } -} +/******************************************************************************/ +/* D E B U G G E R S */ +/******************************************************************************/ + +static char *tab[] = { "STATE", "RULES", "DATA" }; static void debug_printing (int value, int sub_automaton) { switch (sub_automaton) { // sub_automaton 0 is EXEC_EDIT and // sub_automaton 1 is STATE_RULES_DATA case (0) : printf("switch %5s x %5s > %5s x %5s\n", - fsm_get_str_EXEC_EDIT (choice_EXEC_EDIT), - fsm_get_str_STATE_RULES_DATA (choice_STATE_RULES_DATA), - fsm_get_str_EXEC_EDIT (value), - fsm_get_str_STATE_RULES_DATA (choice_STATE_RULES_DATA)); + tab [choice_EXEC_EDIT], + tab [choice_STATE_RULES_DATA], + tab [value], + tab [choice_STATE_RULES_DATA]); break; case (1) : printf("switch %5s x %5s > %5s x %5s\n", - fsm_get_str_EXEC_EDIT (choice_EXEC_EDIT), - fsm_get_str_STATE_RULES_DATA (choice_STATE_RULES_DATA), - fsm_get_str_EXEC_EDIT (choice_EXEC_EDIT), - fsm_get_str_STATE_RULES_DATA (value)); + tab [choice_EXEC_EDIT], + tab [choice_STATE_RULES_DATA], + tab [choice_EXEC_EDIT], + tab [value]); break; case (2) : printf("automat.fsm_set_OBJECTS_box_RESET_VALUE : %2d > %2d\n", fsm_get_OBJECTS_box_RESET_VALUE(), value); diff --git a/src/main.c b/src/main.c index d041641..ddda3e8 100644 --- a/src/main.c +++ b/src/main.c @@ -101,8 +101,8 @@ * Exemple, muni des deux 'sous-automates' : * > { EXEC, EDIT }; // xor * > { STATE, RULES, DATA }; // xor - * la 'state machine' peut se trouver dans 2 x 3 = 6 états. - * (voir automat.h lignes 39-40) + * la 'finite state machine' peut se trouver dans 2 x 3 = 6 états. + * (voir fsm.h lignes 40-41) * * * Les grandes fonctions du client seront lancées par cette state machine : @@ -129,7 +129,7 @@ * ***************************************************************************** * ******************************************************************************* - * L I S T E D E S A P P E L S D E F O N C T I O N S * + * L I S T E D E S A P P E L S D E F O N C T I O N S * * ***************************************************************************** */