From f3f76ef053209627411679247df750327eada3c7 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Wed, 18 Sep 2024 10:25:55 +0200 Subject: [PATCH] journal exercices strcat/strncat &co (/util/tests) --- src/fsm/dispatch.c | 8 ++++---- src/main.c | 3 ++- src/signal.c | 8 ++++---- src/util/tests.c | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/fsm/dispatch.c b/src/fsm/dispatch.c index a3ad557..3be10c3 100644 --- a/src/fsm/dispatch.c +++ b/src/fsm/dispatch.c @@ -66,7 +66,7 @@ void fsm_journal_event (char *message, int priority, int filter) // CRITICAL ERROR WARNING INFO MESSAGE DEBUG SPEW 😄️ // 0 1 2 3 4 5 6 - if (priority <= DEBUG + if (priority == 0 //<= DEBUG /* * * * * * * - F I L T E R S - * * * * * * * * This list is duplicated in both /fsm.h and /fsm/dispatch * @@ -99,7 +99,8 @@ void fsm_journal_event (char *message, int priority, int filter) * This list is duplicated in both /fsm.h and /fsm/dispatch * * * * * * * * - F I L T E R S - * * * * * * */ - && filter == FSM) + || filter == 16 + || filter == 41) fsm_journal_push (message); } #define _CRITICAL___ERROR____WARNING___INFO____MESSAGE___DEBUG ___SPEW____👋️ 0 @@ -145,8 +146,7 @@ void fsm_set_preferences_modified (bool value) fsm_journal_event (str1, 4, 90); fsm_journal_event ("fsm/dispatch preferences modified value = ?\n\ - > Je ne sais ni concatener les strings ni utiliser 'itoa'\n\ - > et les 'toggle' buttons envoient probablement deux events", 4, 90); + > Je ne sais ni concatener les strings ni utiliser 'itoa'", 4, 90); preferences_have_been_modified = value; /* if (value) fsm_journal_event ( diff --git a/src/main.c b/src/main.c index 7a77635..92b227b 100644 --- a/src/main.c +++ b/src/main.c @@ -148,7 +148,7 @@ int main (int argc, char **argv) int status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); - fsm_journal_event ("main g object unref (app)", 3, 0); + fsm_journal_event ("main g_object unref (app)", 3, 0); fsm_journal_event ("main That'all folks ! 👋️😄️", 3, 0); fsm_journal_publication_request(); @@ -213,3 +213,4 @@ TODO (bottlenecks) Des 'runs' de longue durée n'ont de sens qu'une fois ce débuggage effectué. Il y a donc peu de problèmes à craindre du fait de la limite de la bande passante. */ + diff --git a/src/signal.c b/src/signal.c index 3b1efa3..f2d1256 100644 --- a/src/signal.c +++ b/src/signal.c @@ -76,7 +76,7 @@ void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data) { - fsm_journal_event ("signal bind user tree factory() has began", DEBUG, 23); + fsm_journal_event ("signal bind user tree factory() has began", SPEW, 23); GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item); @@ -96,15 +96,15 @@ void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, row); gtk_widget_set_margin_start (expander, gtk_tree_list_row_get_depth(row) * 20); - fsm_journal_event ("signal bind user tree factory() has ended", DEBUG, 23); + fsm_journal_event ("signal bind user tree factory() has ended", SPEW, 23); } void on_setup_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){ - fsm_journal_event ("signal setup user tree factory() has began", DEBUG, 23); + fsm_journal_event ("signal setup user tree factory() has began", SPEW, 23); GtkWidget* expander = gtk_expander_new (NULL); gtk_list_item_set_child (GTK_LIST_ITEM (object), expander); - fsm_journal_event ("signal setup user tree factory() has ended", DEBUG, 23); + fsm_journal_event ("signal setup user tree factory() has ended", SPEW, 23); } diff --git a/src/util/tests.c b/src/util/tests.c index 93ab276..85d16b6 100644 --- a/src/util/tests.c +++ b/src/util/tests.c @@ -29,12 +29,28 @@ #include "../../include/util.h" +#include "../../include/base.h" + +static const char *util_str_concat_test (char *a, char *b, int len_a, int len_b) { + char *c = malloc (len_a + len_b + 2); // char c[255]; *c = 'K'; c[1] = 'O'; *(c+1) = 'U'; c[2] = '\0'; a[len_a] = '\0'; b[len_b] = '\0'; + strcpy(c, a); + strcpy(c + len_a + 1, b); + c[2] = '9'; c[3] = '9'; + *(c + len_a + len_b) = '\0'; +// printf ("static void current concat test (%s%s) > %s\n", a, b, c); + return c; +} void util_trigger_test () { if (0) util_pile_test(); if (0) util_double_list_test(); if (0) util_sorted_list_test(); + //int len_a = 11, len_b = 14; + char aaa [] = "Hello World", bbb [] = ", what's new ?"; + char *c = strcat (aaa, bbb); //c[11 + 14] = '\0'; + if (1) printf("%s <--- strcat () (would 'like to use: strncat() instead...)\n", c); + if (1) printf("%s <--- util_str_concat_test()\n", util_str_concat_test(aaa, bbb, 11, 14)); } void util_pile_test()