From 5aa8c84adea65f3505162fb450572f0d13b4a082 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 11 Sep 2024 09:05:10 +0200 Subject: [PATCH] fsm_get_time() --- include/fsm.h | 2 ++ src/fsm/journal.c | 28 ++++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) 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));