journal: a good place to start from

This commit is contained in:
Jean Sirmai 2024-09-16 08:06:08 +02:00
parent 23724de26e
commit ba17b5c023
Signed by: jean
GPG Key ID: FB3115C340E057E3
4 changed files with 14 additions and 37 deletions

View File

@ -67,13 +67,13 @@ void fsm_journal_push_front_from_fsm (char *message); // id fro
long fsm_journal_pop_back (journal *jj, char *message); // retire un évènement en fin de journal long fsm_journal_pop_back (journal *jj, char *message); // retire un évènement en fin de journal
int fsm_journal_length (journal jj); // nombre d'évènements dans le journal int fsm_journal_length (journal jj); // nombre d'évènements dans le journal
void fsm_journal_seek (journal jj, long usec, char *message); // recherche un évènement dans le journal void fsm_journal_seek (journal jj, long usec, char *message); // recherche un évènement dans le journal
void fsm_journal_publish (journal jj, char *message); // affiche tout le journal void fsm_journal_publish (journal jj); // affiche tout le journal
void fsm_journal_test (char *message); void fsm_journal_test (char *message);
// --------------------------------------------------------------- WIP ------ // --------------------------------------------------------------- WIP ------
// ref: sudo cat /var/log/messages // ref: sudo cat /var/log/messages
// journal fsm_get_journal(); // def: fsm/dispatch call: fsm/prefer/fsm_store_restore_reset() // journal fsm_get_journal(); // def: fsm/dispatch call: fsm/prefer/fsm_store_restore_reset()
void fsm_journal_publication_request (char *message); // def: fsm/dispatch call: widget/dispatch; void fsm_journal_publication_request (); // def: fsm/dispatch call: main;
void fsm_journal_widget_event (char *message, int priority); // def: fsm/dispatch call: widget/dispatch; void fsm_journal_widget_event (char *message, int priority); // def: fsm/dispatch call: widget/dispatch;
// --------------------------------------------------------------- WIP ------ // --------------------------------------------------------------- WIP ------

View File

@ -74,7 +74,7 @@ void fsm_init()
fsm_journal_push_front (&gologos, "fsm fsm_init() end"); fsm_journal_push_front (&gologos, "fsm fsm_init() end");
} }
void fsm_journal_publication_request (char *message) {fsm_journal_publish (gologos, message);} void fsm_journal_publication_request () {fsm_journal_publish (gologos);}
void fsm_journal_widget_event (char *message, int priority) void fsm_journal_widget_event (char *message, int priority)
{ {
if (priority > PRIORITY_0) // consider: >= instead 😄️ if (priority > PRIORITY_0) // consider: >= instead 😄️

View File

@ -123,50 +123,25 @@ void fsm_journal_seek (journal jj, long usec, char *message)
} }
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Format time, "ddd yyyy-mm-dd hh:mm:ss zzz" "%Y-%m-%d %H:%M:%S"
// https://www.man7.org/linux/man-pages/man3/strftime.3.html
// https://en.cppreference.com/w/c/io/fprintf
// https://nicolasj.developpez.com/articles/libc/string/
// https://thelinuxcode.com/pass-string-function-c-language/
//------------------------------------------------------------------------------
#define __STDC_WANT_LIB_EXT1__ 1 void fsm_journal_publish (journal jj)
void fsm_journal_publish (journal jj, char *message)
{ {
unit *a_unit = jj.last; unit *a_unit = jj.last;
char buf [JOURNAL_DATE_MAX_LENGTH]; char buf [JOURNAL_DATE_MAX_LENGTH];
int nb = 0; int nb = 0;
while (a_unit) while (a_unit)
{ {
// Format time, "ddd yyyy-mm-dd hh:mm:ss zzz" "%Y-%m-%d %H:%M:%S"
// https://www.man7.org/linux/man-pages/man3/strftime.3.html
// https://en.cppreference.com/w/c/io/fprintf
// https://nicolasj.developpez.com/articles/libc/string/
// https://thelinuxcode.com/pass-string-function-c-language/
strftime(buf, sizeof(buf), "%D %T", localtime(&a_unit->yy_dd_mm)); strftime(buf, sizeof(buf), "%D %T", localtime(&a_unit->yy_dd_mm));
printf ("%s + %6ld %6d %s\n", buf, a_unit->usec, nb, a_unit->message); printf ("%s + %6ld %6d %s\n", buf, a_unit->usec, nb, a_unit->message);
a_unit = a_unit->prev; a_unit = a_unit->prev;
nb ++; nb ++;
} }
struct timeval tv;
gettimeofday(&tv, NULL);
long yy_dd_mm = tv.tv_sec;
// long usec = tv.tv_usec; << how to use if (format)
strftime(buf, sizeof(buf), "%D %T", localtime(&yy_dd_mm));
printf ("%s + %6d %s\n", buf, nb, message);
} }
//
/*
void modifyString(char *str) {
*str = J; // Dereference to change first char
}
int fonction_appelante() {
char myString[] = "Hello World";
modifyString(myString);
printf("%s", myString); // Prints Jello World
}
Because modifyString receives a pointer to the string,
it can modify the original by dereferencing.
*/

View File

@ -145,7 +145,9 @@ int main (int argc, char **argv)
int status = g_application_run (G_APPLICATION (app), argc, argv); int status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app); g_object_unref (app);
fsm_journal_publication_request ("main That'all folks ! 👋️😄️"); fsm_journal_push_front_from_fsm ("main That'all folks ! 👋️😄️");
fsm_journal_publication_request();
return status; return status;
} }