diff --git a/include/fsm.h b/include/fsm.h index 700fe08..27e7950 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -46,6 +46,8 @@ typedef struct tool_list {int value; struct tool_list *suiv;} tool_list ; typedef struct data_list {int value; struct data_list *suiv;} data_list ; typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ; +// --------------------------------------------------------------- WIP ------ +void fsm_get_time(); // --------------------------------------------------------------- WIP ------ typedef struct unit {int event; struct unit *prev; struct unit *next;} unit; typedef struct {unit *first; unit *last;} journal; // structure d'accès au journal diff --git a/src/fsm/journal.c b/src/fsm/journal.c index 1baae17..384ac72 100644 --- a/src/fsm/journal.c +++ b/src/fsm/journal.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include "../../include/fsm.h" /******************************************************************************/ @@ -34,11 +36,25 @@ /******************************************************************************/ +void fsm_get_time() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + printf(" Seconds since Jan. 1, 1970: %ld\n", tv.tv_sec); + + time_t current_time = time(NULL); + // Check if the time retrieval was successful + if (current_time == ((time_t)-1)) printf("Error getting current time.\n"); + // Convert to local time format and print + printf(" Current timestamp: %ld\n", current_time); + printf(" Current time: %s", ctime(¤t_time)); +} void fsm_journal_init (journal *jj) { - jj->first = NULL; - jj->last = NULL; + jj->first = NULL; + jj->last = NULL; + fsm_get_time(); } void fsm_journal_clear (journal *jj) @@ -122,12 +138,15 @@ int fsm_journal_length (journal jj) void fsm_journal_seek (journal jj, int event) { unit *a_unit = jj.first; + int nb = 0; while (a_unit) { - if (event == a_unit->event) - printf ("> event %d found in journal\n", a_unit->event); + if (event == a_unit->event) nb++; a_unit = a_unit->next; } + if (nb > 0) printf ("> event %d found %d times in journal\n", event, nb); + else printf ("> event %d not found in journal\n", event); + fsm_get_time(); } void fsm_journal_view (journal jj) @@ -154,6 +173,7 @@ void fsm_journal_test() printf ("push front > %d\n", fsm_journal_push_front (&exemple, 1)); fsm_journal_view (exemple); + fsm_journal_seek (exemple, 2); printf ("pop back > %d\n", fsm_journal_pop_back (&exemple)); printf ("pop back > %d\n", fsm_journal_pop_back (&exemple));