fsm_get_time()

This commit is contained in:
Jean Sirmai 2024-09-11 09:05:10 +02:00
parent 7f7c390b61
commit 5aa8c84ade
Signed by: jean
GPG Key ID: FB3115C340E057E3
2 changed files with 26 additions and 4 deletions

View File

@ -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 data_list {int value; struct data_list *suiv;} data_list ;
typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ; typedef struct disp_list {int value; struct disp_list *suiv;} disp_list ;
// --------------------------------------------------------------- WIP ------
void fsm_get_time();
// --------------------------------------------------------------- WIP ------ // --------------------------------------------------------------- WIP ------
typedef struct unit {int event; struct unit *prev; struct unit *next;} unit; 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 typedef struct {unit *first; unit *last;} journal; // structure d'accès au journal

View File

@ -26,6 +26,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "../../include/fsm.h" #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(&current_time));
}
void fsm_journal_init (journal *jj) void fsm_journal_init (journal *jj)
{ {
jj->first = NULL; jj->first = NULL;
jj->last = NULL; jj->last = NULL;
fsm_get_time();
} }
void fsm_journal_clear (journal *jj) void fsm_journal_clear (journal *jj)
@ -122,12 +138,15 @@ int fsm_journal_length (journal jj)
void fsm_journal_seek (journal jj, int event) void fsm_journal_seek (journal jj, int event)
{ {
unit *a_unit = jj.first; unit *a_unit = jj.first;
int nb = 0;
while (a_unit) while (a_unit)
{ {
if (event == a_unit->event) if (event == a_unit->event) nb++;
printf ("> event %d found in journal\n", a_unit->event);
a_unit = a_unit->next; 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) 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)); printf ("push front > %d\n", fsm_journal_push_front (&exemple, 1));
fsm_journal_view (exemple); 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));
printf ("pop back > %d\n", fsm_journal_pop_back (&exemple)); printf ("pop back > %d\n", fsm_journal_pop_back (&exemple));