From ed57185faa4d7a53d953cf74a6f8626f44ce9b75 Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Tue, 14 May 2024 22:00:12 +0200 Subject: Restore some logging facilities with automatic switch to the GUI. --- src/Makefile.am | 23 ++++++++++++++---- src/common/Makefile.am | 9 ++++++- src/common/extstr.c | 14 +++++------ src/core/Makefile.am | 8 +++++- src/core/logs.c | 32 ++++++------------------ src/gui/Makefile.am | 14 ++++++++--- src/gui/core/Makefile.am | 10 ++++++-- src/gui/core/logs.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/core/logs.h | 37 ++++++++++++++++++++++++++++ 9 files changed, 166 insertions(+), 44 deletions(-) create mode 100644 src/gui/core/logs.c create mode 100644 src/gui/core/logs.h diff --git a/src/Makefile.am b/src/Makefile.am index 89721b9..4a81282 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,5 +1,5 @@ -lib_LTLIBRARIES = libchrysacoreui.la # libchrysacore.la +lib_LTLIBRARIES = libchrysacore4.la libchrysacoreui.la # libchrysacore.la bin_PROGRAMS = framework # chrysalide chrysalide-hub rost @@ -74,6 +74,16 @@ libchrysacore_la_LDFLAGS += $(LIBMAGIC_LIBS) endif +libchrysacore4_la_SOURCES = + +libchrysacore4_la_LIBADD = \ + common/libcommon4.la \ + core/libcore4.la + +libchrysacore4_la_LDFLAGS = \ + $(TOOLKIT_LIBS) + + #--- libchrysacoreui if BUILD_GTK_SUPPORT @@ -81,7 +91,8 @@ if BUILD_GTK_SUPPORT libchrysacoreui_la_SOURCES = libchrysacoreui_la_LIBADD = \ - gtkext/libgtkext4.la + gtkext/libgtkext4.la \ + gui/libgui4.la libchrysacoreui_la_LDFLAGS = \ $(LIBGTK4_CFLAGS) @@ -110,7 +121,7 @@ chrysalide_LDADD = $(LIBINTL) -EXTRA_framework_DEPENDENCIES = libchrysacoreui.la +EXTRA_framework_DEPENDENCIES = libchrysacore4.la libchrysacoreui.la framework_SOURCES = \ framework.h framework.c @@ -118,7 +129,7 @@ framework_SOURCES = \ framework_CFLAGS = $(TOOLKIT4_CFLAGS) framework_LDFLAGS = $(TOOLKIT4_LIBS) \ - -L.libs -lchrysacoreui + -L.libs -lchrysacore4 -lchrysacoreui framework_LDADD = @@ -162,4 +173,6 @@ rost_LDFLAGS = $(LIBGOBJ_LIBS) -L.libs -lchrysacore # glibext doit être traité en premier, à cause des marshals GLib -SUBDIRS = core glibext $(GTKEXT_SUBDIR) analysis arch format common debug $(GUI_SUBDIR) mangling plugins schemas +#SUBDIRS = core glibext $(GTKEXT_SUBDIR) analysis arch format common debug $(GUI_SUBDIR) mangling plugins schemas + +SUBDIRS = common core glibext gtkext gui diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 1a8f8c4..53d3627 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -1,5 +1,5 @@ -noinst_LTLIBRARIES = libcommon.la +noinst_LTLIBRARIES = libcommon4.la # libcommon.la libcommon_la_SOURCES = \ alloc.h alloc.c \ @@ -51,6 +51,13 @@ libcommon_la_CFLAGS += $(LIBCURL_CFLAGS) endif + +libcommon4_la_SOURCES = \ + extstr.h extstr.c + +libcommon4_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) + + devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libcommon_la_SOURCES:%c=) diff --git a/src/common/extstr.c b/src/common/extstr.c index ac93f5d..bd3491f 100644 --- a/src/common/extstr.c +++ b/src/common/extstr.c @@ -55,7 +55,7 @@ char *stradd(char *str1, const char *str2) else { - result = (char *)realloc(str1, (strlen(str1) + strlen(str2) + 1) * sizeof(char)); + result = realloc(str1, (strlen(str1) + strlen(str2) + 1) * sizeof(char)); strcat(result, str2); } @@ -87,7 +87,7 @@ char *strnadd(char *str1, const char *str2, size_t n) else { - result = (char *)realloc(str1, (strlen(str1) + n + 1) * sizeof(char)); + result = realloc(str1, (strlen(str1) + n + 1) * sizeof(char)); strncat(result, str2, n); } @@ -155,7 +155,7 @@ char *strprep(char *str1, const char *str2) char *result; /* Chaîne à renvoyer */ size_t len2; /* Taille de la seconde chaîne */ - result = (char *)realloc(str1, (strlen(str1) + strlen(str2) + 1) * sizeof(char)); + result = realloc(str1, (strlen(str1) + strlen(str2) + 1) * sizeof(char)); len2 = strlen(str2); @@ -261,7 +261,7 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2) { inlen += (len2 - len1); - haystack = (char *)realloc(haystack, inlen * sizeof(char *)); + haystack = realloc(haystack, inlen * sizeof(char *)); found = haystack + index; memmove(found + len2, found + len1, inlen - len2 - index); @@ -274,7 +274,7 @@ char *strrpl(char *haystack, const char *needle1, const char *needle2) inlen -= (len1 - len2); - haystack = (char *)realloc(haystack, inlen * sizeof(char *)); + haystack = realloc(haystack, inlen * sizeof(char *)); found = haystack + index; } @@ -390,7 +390,7 @@ char **strtoka(const char *str, const char *delim, size_t *count) for (word = strtok(tmp, delim); word != NULL; word = strtok(NULL, delim)) { - result = (char **)realloc(result, ++(*count) * sizeof(char *)); + result = realloc(result, ++(*count) * sizeof(char *)); result[*count - 1] = strdup(word); } @@ -428,7 +428,7 @@ char *escape_crlf(char *input) for (curpos = 0; regexec(&preg, &input[curpos], 2, pmatch, 0) != REG_NOMATCH; ) { inlen += 1 + 1; - input = (char *)realloc(input, inlen * sizeof(char *)); + input = realloc(input, inlen * sizeof(char *)); memmove(&input[curpos + pmatch[1].rm_eo + 1], &input[curpos + pmatch[1].rm_eo], inlen - 1 - curpos - pmatch[1].rm_eo); diff --git a/src/core/Makefile.am b/src/core/Makefile.am index ac1ae14..f329a09 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -1,5 +1,5 @@ -noinst_LTLIBRARIES = libcore.la +noinst_LTLIBRARIES = libcore4.la # libcore.la libcore_la_SOURCES = \ collections.h collections.c \ @@ -17,6 +17,12 @@ libcore_la_SOURCES = \ libcore_la_CFLAGS = $(TOOLKIT_CFLAGS) $(LIBXML_CFLAGS) +libcore4_la_SOURCES = \ + logs.h logs.c + +libcore4_la_CFLAGS = $(TOOLKIT_CFLAGS) + + devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libcore_la_SOURCES:%c=) diff --git a/src/core/logs.c b/src/core/logs.c index 2b2b1ab..453eaff 100644 --- a/src/core/logs.c +++ b/src/core/logs.c @@ -29,10 +29,6 @@ #include "../common/extstr.h" -#ifdef INCLUDE_GTK_SUPPORT -# include "../gui/core/items.h" -# include "../gui/panels/log.h" -#endif @@ -45,9 +41,11 @@ /* Conserve le niveau de filtre des messages */ static LogMessageType _verbosity = LMT_COUNT; +/* Affiche un message dans le terminal courant. */ +__attribute__((weak)) void do_log_message_alt(LogMessageType, const char *); /* Affiche un message dans le terminal courant. */ -static void print_message_without_gui(LogMessageType, const char *); +static void do_log_message_nox(LogMessageType, const char *); @@ -109,28 +107,12 @@ void set_log_verbosity(LogMessageType level) void log_simple_message(LogMessageType type, const char *msg) { -#ifdef INCLUDE_GTK_SUPPORT - GEditorItem *item; /* Eventuel affichage présent */ -#endif - if (type >= _verbosity) { -#ifdef INCLUDE_GTK_SUPPORT - - item = find_editor_item_by_type(G_TYPE_LOG_PANEL); - - if (item != NULL) - { - g_log_panel_add_message(G_LOG_PANEL(item), type, msg); - g_object_unref(G_OBJECT(item)); - } - + if (do_log_message_alt != NULL) + do_log_message_alt(type, msg); else - -#endif - - print_message_without_gui(type, msg); - + do_log_message_nox(type, msg); } } @@ -236,7 +218,7 @@ void log_variadic_message(LogMessageType type, const char *fmt, ...) * * ******************************************************************************/ -static void print_message_without_gui(LogMessageType type, const char *msg) +static void do_log_message_nox(LogMessageType type, const char *msg) { char *formatted; /* Copie formatée du message */ const char *prefix; /* Introduction de la ligne */ diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 058b36e..f4a682c 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -1,7 +1,7 @@ -BUILT_SOURCES = resources.h resources.c +#BUILT_SOURCES = resources.h resources.c -noinst_LTLIBRARIES = libgui.la +noinst_LTLIBRARIES = libgui4.la #libgui.la UI_FILES = \ editor.ui @@ -28,12 +28,20 @@ libgui_la_LIBADD = \ libgui_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) +libgui4_la_SOURCES = + +libgui4_la_LIBADD = \ + core/libguicore4.la + +libgui4_la_CFLAGS = $(LIBGTK4_CFLAGS) + + devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libgui_la_SOURCES:%c=) -SUBDIRS = core dialogs menus panels tb +SUBDIRS = core # dialogs menus panels tb resources.c: gresource.xml $(UI_FILES) diff --git a/src/gui/core/Makefile.am b/src/gui/core/Makefile.am index 2077c4b..c219655 100644 --- a/src/gui/core/Makefile.am +++ b/src/gui/core/Makefile.am @@ -1,7 +1,7 @@ -BUILT_SOURCES = resources.h resources.c +#BUILT_SOURCES = resources.h resources.c -noinst_LTLIBRARIES = libguicore.la +noinst_LTLIBRARIES = libguicore4.la # libguicore.la RES_FILES = \ ../../../pixmaps/palette.png \ @@ -23,6 +23,12 @@ libguicore_la_SOURCES = \ libguicore_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) +libguicore4_la_SOURCES = \ + logs.h logs.c + +libguicore4_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS) + + devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%) dev_HEADERS = $(libguicore_la_SOURCES:%c=) diff --git a/src/gui/core/logs.c b/src/gui/core/logs.c new file mode 100644 index 0000000..59910f1 --- /dev/null +++ b/src/gui/core/logs.c @@ -0,0 +1,63 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs.h - prototypes pour la diffusion graphique de messages d'alerte ou informatifs + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see . + */ + + +#include "logs.h" + + + +/****************************************************************************** +* * +* Paramètres : type = espèce du message à ajouter. * +* msg = message à faire apparaître à l'écran. * +* * +* Description : Affiche un message dans le terminal courant. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void do_log_message_alt2(LogMessageType type, const char *msg) +{ +#if 0 + +#ifdef INCLUDE_GTK_SUPPORT + + GEditorItem *item; /* Eventuel affichage présent */ + + item = find_editor_item_by_type(G_TYPE_LOG_PANEL); + + if (item != NULL) + { + g_log_panel_add_message(G_LOG_PANEL(item), type, msg); + g_object_unref(G_OBJECT(item)); + } + +#endif + +#endif + + printf("[log GUI] [%u] %s\n", type, msg); + +} diff --git a/src/gui/core/logs.h b/src/gui/core/logs.h new file mode 100644 index 0000000..b489339 --- /dev/null +++ b/src/gui/core/logs.h @@ -0,0 +1,37 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * logs.h - prototypes pour la diffusion graphique de messages d'alerte ou informatifs + * + * Copyright (C) 2024 Cyrille Bagard + * + * This file is part of Chrysalide. + * + * Chrysalide is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Chrysalide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chrysalide. If not, see . + */ + + +#ifndef _GUI_CORE_LOGS_H +#define _GUI_CORE_LOGS_H + + +#include "../../core/logs.h" + + + +/* Affiche un message dans le terminal courant. */ +void do_log_message_alt(LogMessageType, const char *); + + + +#endif /* _GUI_CORE_LOGS_H */ -- cgit v0.11.2-87-g4458