diff options
Diffstat (limited to 'src/gui/panels/symbols.c')
-rw-r--r-- | src/gui/panels/symbols.c | 144 |
1 files changed, 9 insertions, 135 deletions
diff --git a/src/gui/panels/symbols.c b/src/gui/panels/symbols.c index 8c95bf6..e73a847 100644 --- a/src/gui/panels/symbols.c +++ b/src/gui/panels/symbols.c @@ -37,10 +37,10 @@ #include "panel-int.h" -#include "../../common/extstr.h" #include "../../format/format.h" #include "../../gtkext/easygtk.h" #include "../../gtkext/support.h" +#include "../../gtkext/tmgt.h" @@ -153,10 +153,7 @@ static void on_symbols_filter_changed(GtkSearchEntry *, GSymbolsPanel *); static void do_filtering_on_symbols(GSymbolsPanel *); /* Détermine si un nom de symbole doit être filtré ou non. */ -static bool is_symbol_filtered(GSymbolsPanel *, const GBinSymbol *, regmatch_t *); - -/* Met en évidence le texte recherché en cas de correspondance. */ -static char *build_highlighted_name(const char *, const regmatch_t *, size_t); +static bool is_symbol_matching(GSymbolsPanel *, const GBinSymbol *, regmatch_t *); @@ -670,7 +667,7 @@ static void reload_symbols_for_new_list_view(GSymbolsPanel *panel) for (i = 0; i < sym_count; i++) { - if (is_symbol_filtered(panel, symbols[i], &match)) + if (!is_symbol_matching(panel, symbols[i], &match)) continue; switch (g_binary_symbol_get_target_type(symbols[i])) @@ -872,7 +869,7 @@ static void reload_symbols_for_new_tree_view(GSymbolsPanel *panel) for (i = 0; i < sym_count; i++) { - if (is_symbol_filtered(panel, symbols[i], &match)) + if (!is_symbol_matching(panel, symbols[i], &match)) continue; if (find_parent_for_symbol(panel, symbols[i], &parent, &match, &last)) @@ -1017,42 +1014,7 @@ static gboolean show_all_classes_in_tree_view(GtkTreeModel *model, GtkTreePath * static void on_symbols_filter_changed(GtkSearchEntry *entry, GSymbolsPanel *panel) { - const gchar *text; /* Texte de l'utilisateur */ - int ret; /* Bilan de mise en place */ - GdkRGBA error; /* Couleur d'erreur */ - - if (panel->filter != NULL) - { - regfree(panel->filter); - free(panel->filter); - panel->filter = NULL; - } - - text = gtk_entry_get_text(GTK_ENTRY(entry)); - - if (strlen(text) > 0) - { - panel->filter = (regex_t *)calloc(1, sizeof(regex_t)); - ret = regcomp(panel->filter, text, REG_EXTENDED | REG_ICASE); - - if (ret != 0) - { - free(panel->filter); - panel->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); + update_regex_on_search_entry_changed(entry, &panel->filter); do_filtering_on_symbols(panel); @@ -1094,106 +1056,18 @@ static void do_filtering_on_symbols(GSymbolsPanel *panel) * * ******************************************************************************/ -static bool is_symbol_filtered(GSymbolsPanel *panel, const GBinSymbol *symbol, regmatch_t *match) +static bool is_symbol_matching(GSymbolsPanel *panel, const GBinSymbol *symbol, regmatch_t *match) { + bool result; /* Bilan à retourner */ SymbolType type; /* Type associé au symbole */ - int ret; /* Bilan du filtrage */ type = g_binary_symbol_get_target_type(symbol); if (type != STP_ROUTINE && type != STP_ENTRY_POINT && type != STP_OBJECT) - return true; - - memset(match, 0, sizeof(regmatch_t)); - - if (panel->filter == NULL) - return false; - - ret = regexec(panel->filter, g_binary_symbol_get_label(symbol), 1, match, 0); - if (ret == REG_NOMATCH) - return true; - - return false; - -} - - -/****************************************************************************** -* * -* 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 : - * -* * -******************************************************************************/ - -static 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 ! */ + result = false; 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); - - } + result = is_content_matching(panel->filter, g_binary_symbol_get_label(symbol), match); return result; |