From 4a883be09ec5485c20d20f7c08376f0e9402790e Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 17 Mar 1998 00:24:52 +0000 Subject: [PATCH] 1998-03-16 Federico Mena Quintero * gscreen.c (filter_item_activate): Make it convert the glob pattern to a regexp if appropriate. 1998-03-16 Federico Mena Quintero * util.c (convert_pattern): Now the internal buffer is malloc()ed instead of being static. This is required for long patterns. (regexp_match): Free the pattern after calling convert_pattern(). * file.c (file_mask_dialog): Free the source_mask after calling convert_pattern(). --- gnome/ChangeLog | 5 ++++ gnome/gscreen.c | 69 ++++++++++++++++++++++--------------------------- src/ChangeLog | 9 +++++++ src/file.c | 1 + src/util.c | 11 +++++--- 5 files changed, 53 insertions(+), 42 deletions(-) diff --git a/gnome/ChangeLog b/gnome/ChangeLog index b4d63ba52..53bc8a574 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,8 @@ +1998-03-16 Federico Mena Quintero + + * gscreen.c (filter_item_activate): Make it convert the glob + pattern to a regexp if appropriate. + Sat Mar 14 17:13:26 1998 Miguel de Icaza * gmain.c (gnome_dlg_send_destroy): New signal handler for diff --git a/gnome/gscreen.c b/gnome/gscreen.c index 24ce165bb..35387d422 100644 --- a/gnome/gscreen.c +++ b/gnome/gscreen.c @@ -935,65 +935,45 @@ panel_change_filter (GtkWidget *entry, WPanel *panel) /* FIXME: for now, this list is hardcoded. We want a way to let the user configure it. */ -/* FIXME!!! fill in regexps */ - static struct filter_item { char *text; char *glob; - char *regexp; } filter_items [] = { { "All files", - "*", - "." }, + "*" }, { "Archives and compressed files", - "*.(tar|gz|tgz|taz|zip|lha|zoo|pak|sit|arc|arj|rar|huf|lzh)", - "." }, + "*.(tar|gz|tgz|taz|zip|lha|zoo|pak|sit|arc|arj|rar|huf|lzh)" }, { "RPM/DEB files", - "*.(rpm|deb)", - "." }, + "*.(rpm|deb)" }, { "Text/Document files", - "*.(txt|tex|doc|rtf)", - "." }, + "*.(txt|tex|doc|rtf)" }, { "HTML and SGML files", - "*.{html|htm|sgml|sgm", - "." }, + "*.(html|htm|sgml|sgm)" }, { "Postscript and PDF files", - "*.(ps|pdf)", - "." }, + "*.(ps|pdf)" }, { "Spreadsheet files", - "*.(xls|wks|wk1)", - "." }, + "*.(xls|wks|wk1)" }, { "Image files", "*.(png|jpg|jpeg|xcf|gif|tif|tiff|xbm|xpm|pbm|pgm|ppm|tga|rgb|iff|lbm|ilbm|" - "bmp|pcx|pic|pict|psd|gbr|pat|ico|fig|cgm|rle|fits)", - "." }, + "bmp|pcx|pic|pict|psd|gbr|pat|ico|fig|cgm|rle|fits)" }, { "Video/animation files", - "*.(mpg|mpeg|mov|avi|fli|flc|flh|flx|dl)", - "." }, + "*.(mpg|mpeg|mov|avi|fli|flc|flh|flx|dl)" }, { "Audio files", - "*.(au|wav|mp3|snd|mod|s3m|ra)", - "." }, + "*.(au|wav|mp3|snd|mod|s3m|ra)" }, { "C program files", - "*.[ch]", - "." }, + "*.[ch]" }, { "C++ program files", - "*.(cc|C|cpp|cxx|h|H)", - "." }, + "*.(cc|C|cpp|cxx|h|H)" }, { "Objective-C program files", - "*.[mh]", - "." }, + "*.[mh]" }, { "Scheme program files", - "*.scm", - "." }, + "*.scm" }, { "Assembler program files", - "*.(s|S|asm)", - "." }, + "*.(s|S|asm)" }, { "Misc. program files", - "*.(awk|sed|lex|l|y|sh|idl|pl|py|am|in|f|el|bas|pas|java|sl|p|m4|tcl|pov)", - "." }, + "*.(awk|sed|lex|l|y|sh|idl|pl|py|am|in|f|el|bas|pas|java|sl|p|m4|tcl|pov)" }, { "Font files", - "*.(pfa|pfb|afm|ttf|fon|pcf|pcf.gz|spd)", - "." } + "*.(pfa|pfb|afm|ttf|fon|pcf|pcf.gz|spd)" } }; static GtkWidget *filter_menu; @@ -1003,6 +983,7 @@ filter_item_select (GtkWidget *widget, gpointer data) { struct filter_item *fi = gtk_object_get_user_data (GTK_OBJECT (widget)); + /* FIXME: the hintbar resizes horribly and screws the panel */ /* set_hintbar (easy_patterns ? fi->glob : fi->regexp); */ } @@ -1017,8 +998,20 @@ filter_item_activate (GtkWidget *widget, gpointer data) { struct filter_item *fi = gtk_object_get_user_data (GTK_OBJECT (widget)); WPanel *panel = data; + int tmp; + char *pattern; - set_panel_filter_to (panel, g_strdup (easy_patterns ? fi->glob : fi->regexp)); + if (easy_patterns) + pattern = g_strdup (fi->glob); + else { + /* This is sort of a hack to force convert_pattern() to actually convert the thing */ + + easy_patterns = 1; + pattern = convert_pattern (fi->glob, match_file, 0); + easy_patterns = 0; + } + + set_panel_filter_to (panel, pattern); } static void diff --git a/src/ChangeLog b/src/ChangeLog index 2ac8979ed..94822c87f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +1998-03-16 Federico Mena Quintero + + * util.c (convert_pattern): Now the internal buffer is malloc()ed + instead of being static. This is required for long patterns. + (regexp_match): Free the pattern after calling convert_pattern(). + + * file.c (file_mask_dialog): Free the source_mask after calling + convert_pattern(). + Mon Mar 16 13:03:45 1998 Pavel Roskin * cmd.c: Internal edit is used by default. vi may be diff --git a/src/file.c b/src/file.c index 7722f4fe4..6bbab6289 100644 --- a/src/file.c +++ b/src/file.c @@ -2025,6 +2025,7 @@ ask_file_mask: } error = re_compile_pattern (source_mask, strlen (source_mask), &rx); + free (source_mask); if (error) { message_3s (1, " Error ", "Invalid source pattern `%s' \n %s ", orig_mask, error); diff --git a/src/util.c b/src/util.c index d875cf7ba..3913e4c7a 100644 --- a/src/util.c +++ b/src/util.c @@ -436,10 +436,11 @@ static char *maybe_end_group (char *d, int do_group, int *was_wildcard) char *convert_pattern (char *pattern, int match_type, int do_group) { char *s, *d; - static char new_pattern [100]; + char *new_pattern; int was_wildcard = 0; if (easy_patterns){ + new_pattern = malloc (sizeof (char) * strlen (pattern) * 4); /* times 4 to be safe */ d = new_pattern; if (match_type == match_file) *d++ = '^'; @@ -474,7 +475,7 @@ char *convert_pattern (char *pattern, int match_type, int do_group) *d = 0; return new_pattern; } else - return pattern; + return strdup (pattern); } int regexp_match (char *pattern, char *string, int match_type) @@ -490,9 +491,11 @@ int regexp_match (char *pattern, char *string, int match_type) free (old_pattern); } pattern = convert_pattern (pattern, match_type, 0); - if (regcomp (&r, pattern, REG_EXTENDED|REG_NOSUB|MC_ARCH_FLAGS)) + if (regcomp (&r, pattern, REG_EXTENDED|REG_NOSUB|MC_ARCH_FLAGS)) { + free (pattern); return -1; - old_pattern = strdup (pattern); + } + old_pattern = pattern; old_type = match_type; } rval = !regexec (&r, string, 0, NULL, 0);