diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-04-09 07:52:59 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-04-09 07:59:29 (GMT) |
commit | acc7b5f33e93bae3bf43e8f029976b7f74260b52 (patch) | |
tree | c0ea91ef69efb8300e97dacb65b3eeebd95f112a /src/gtkext | |
parent | ebe248fe406de9565c8c7787187a1d439e68cd84 (diff) |
Provided a tree panel to inspect binary content.
Diffstat (limited to 'src/gtkext')
-rw-r--r-- | src/gtkext/Makefile.am | 3 | ||||
-rw-r--r-- | src/gtkext/tmgt.c | 204 | ||||
-rw-r--r-- | src/gtkext/tmgt.h | 45 |
3 files changed, 251 insertions, 1 deletions
diff --git a/src/gtkext/Makefile.am b/src/gtkext/Makefile.am index d874ac1..07fe3a9 100644 --- a/src/gtkext/Makefile.am +++ b/src/gtkext/Makefile.am @@ -15,7 +15,8 @@ libgtkext_la_SOURCES = \ gtkdockstation.h gtkdockstation.c \ gtkgraphdisplay.h gtkgraphdisplay.c \ gtkstatusstack.h gtkstatusstack.c \ - support.h support.c + support.h support.c \ + tmgt.h tmgt.c libgtkext_la_LIBADD = \ graph/libgtkextgraph.la diff --git a/src/gtkext/tmgt.c b/src/gtkext/tmgt.c new file mode 100644 index 0000000..ce6f9a8 --- /dev/null +++ b/src/gtkext/tmgt.c @@ -0,0 +1,204 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * tmgt.c - compléments utiles à la mise en place d'arborescences + * + * Copyright (C) 2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#include "tmgt.h" + + +#include <malloc.h> +#include <string.h> + + +#include "../common/extstr.h" + + + +/****************************************************************************** +* * +* Paramètres : entry = zone de texte avec un nouveau filtre d'affichage. * +* filter = expression régulière de filtrage à constituer. [OUT]* +* * +* Description : Met à jour un filtre selon un contenu recherché. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void update_regex_on_search_entry_changed(GtkSearchEntry *entry, regex_t **filter) +{ + const gchar *text; /* Texte de l'utilisateur */ + int ret; /* Bilan de mise en place */ + GdkRGBA error; /* Couleur d'erreur */ + + if (*filter != NULL) + { + regfree(*filter); + free(*filter); + *filter = NULL; + } + + text = gtk_entry_get_text(GTK_ENTRY(entry)); + + if (strlen(text) > 0) + { + *filter = (regex_t *)calloc(1, sizeof(regex_t)); + ret = regcomp(*filter, text, REG_EXTENDED | REG_ICASE); + + if (ret != 0) + { + free(*filter); + *filter = NULL; + + error.red = 1.0; + error.green = 0.0; + error.blue = 0.0; + error.alpha = 1.0; + gtk_widget_override_color(GTK_WIDGET(entry), GTK_STATE_NORMAL, &error); + + return; + + } + + } + + gtk_widget_override_color(GTK_WIDGET(entry), GTK_STATE_NORMAL, NULL); + +} + + +/****************************************************************************** +* * +* Paramètres : filter = expression régulière servant de filtre. * +* content = contenu textuel à analyser. * +* match = zone pointant vers une correspondance. [OUT] * +* * +* Description : Détermine si un contenu correspond à un filtre donné. * +* * +* Retour : true si le contenu est qualifié pour un affichage, ou false. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool is_content_matching(const regex_t *filter, const char *content, regmatch_t *match) +{ + bool result; /* Bilan à retourner */ + int ret; /* Bilan du filtrage */ + + memset( match, 0, sizeof(regmatch_t)); + + if (filter == NULL) + result = true; + + else + { + ret = regexec(filter, content, 1, match, 0); + result = (ret != REG_NOMATCH); + } + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : raw = bribe de texte à traiter. * +* match = portion de texte à mettre en évidence. * +* start = position du texte brute dans l'étiquette complète. * +* * +* Description : Met en évidence le texte recherché en cas de correspondance. * +* * +* Retour : Texte final destiné à être inséré, à libérer après usage. * +* * +* Remarques : - * +* * +******************************************************************************/ + +char *build_highlighted_name(const char *raw, const regmatch_t *match, size_t start) +{ + char *result; /* Construction à retourner */ + size_t len; /* Taille du texte d'entrée */ + regmatch_t selection; /* Sélection relative au texte */ + char *valid; /* Retouche partielle */ + + len = strlen(raw); + + /* Si aucune sélection ou texte hors champ... */ + + if ((match->rm_eo - match->rm_so) == 0 || (start + len) <= match->rm_so || match->rm_eo < start) + { + result = strdup(raw); + result = strrpl(result, "<", "<"); + } + + /* Sinon, il y a forcément correspondance quelque part ! */ + + else + { + /* Adaptations */ + + if (match->rm_so < start) + selection.rm_so = 0; + else + selection.rm_so = match->rm_so - start; + + selection.rm_eo = match->rm_eo - start; + + if (selection.rm_eo > len) + selection.rm_eo = len; + + /* Impressions */ + + if (selection.rm_so > 0) + { + result = strndup(raw, selection.rm_so); + result = strrpl(result, "<", "<"); + } + else + result = NULL; + + result = stradd(result, "<b>"); + + valid = strndup(&raw[selection.rm_so], selection.rm_eo - selection.rm_so); + valid = strrpl(valid, "<", "<"); + + result = stradd(result, valid); + + free(valid); + + result = stradd(result, "</b>"); + + valid = strdup(&raw[selection.rm_eo]); + valid = strrpl(valid, "<", "<"); + + result = stradd(result, valid); + + free(valid); + + } + + return result; + +} diff --git a/src/gtkext/tmgt.h b/src/gtkext/tmgt.h new file mode 100644 index 0000000..eeeb848 --- /dev/null +++ b/src/gtkext/tmgt.h @@ -0,0 +1,45 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * tmgt.h - prototypes pour des compléments utiles à la mise en place d'arborescences + * + * Copyright (C) 2017 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 Foobar. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef _COMMON_TMGT_H +#define _COMMON_TMGT_H + + +#include <regex.h> +#include <stdbool.h> +#include <gtk/gtk.h> + + + +/* Met à jour un filtre selon un contenu recherché. */ +void update_regex_on_search_entry_changed(GtkSearchEntry *, regex_t **); + +/* Détermine si un contenu correspond à un filtre donné. */ +bool is_content_matching(const regex_t *, const char *, regmatch_t *); + +/* Met en évidence le texte recherché en cas de correspondance. */ +char *build_highlighted_name(const char *, const regmatch_t *, size_t); + + + +#endif /* _COMMON_TMGT_H */ |