Commit 3127f29e authored by Federico Mena Quintero's avatar Federico Mena Quintero Committed by Federico Mena Quintero

Fix #138807.

2004-06-02  Federico Mena Quintero  <federico@ximian.com>

	Fix #138807.

	* gtk/fnmatch.c (_gtk_fnmatch): Take a no_leading_period argument.
	(gtk_fnmatch_intern): Likewise; also implement this option.

	* gtk/gtkprivate.h (_gtk_fnmatch): Updated prototype.

	* gtk/gtkfilesel.c (find_completion_dir): Pass TRUE for the
	no_leading_period argument of _gtk_fnmatch().
	(attempt_file_completion): Likewise.

	* gtk/gtkfilefilter.c (gtk_file_filter_filter): Pass FALSE for the
	no_leading_period argument of _gtk_fnmatch().
parent 0f313841
2004-06-02 Federico Mena Quintero <federico@ximian.com>
Fix #138807.
* gtk/fnmatch.c (_gtk_fnmatch): Take a no_leading_period argument.
(gtk_fnmatch_intern): Likewise; also implement this option.
* gtk/gtkprivate.h (_gtk_fnmatch): Updated prototype.
* gtk/gtkfilesel.c (find_completion_dir): Pass TRUE for the
no_leading_period argument of _gtk_fnmatch().
(attempt_file_completion): Likewise.
* gtk/gtkfilefilter.c (gtk_file_filter_filter): Pass FALSE for the
no_leading_period argument of _gtk_fnmatch().
Wed Jun 2 00:47:11 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkselection.c (_gtk_selection_request): Remove leftover
......
2004-06-02 Federico Mena Quintero <federico@ximian.com>
Fix #138807.
* gtk/fnmatch.c (_gtk_fnmatch): Take a no_leading_period argument.
(gtk_fnmatch_intern): Likewise; also implement this option.
* gtk/gtkprivate.h (_gtk_fnmatch): Updated prototype.
* gtk/gtkfilesel.c (find_completion_dir): Pass TRUE for the
no_leading_period argument of _gtk_fnmatch().
(attempt_file_completion): Likewise.
* gtk/gtkfilefilter.c (gtk_file_filter_filter): Pass FALSE for the
no_leading_period argument of _gtk_fnmatch().
Wed Jun 2 00:47:11 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkselection.c (_gtk_selection_request): Remove leftover
......
2004-06-02 Federico Mena Quintero <federico@ximian.com>
Fix #138807.
* gtk/fnmatch.c (_gtk_fnmatch): Take a no_leading_period argument.
(gtk_fnmatch_intern): Likewise; also implement this option.
* gtk/gtkprivate.h (_gtk_fnmatch): Updated prototype.
* gtk/gtkfilesel.c (find_completion_dir): Pass TRUE for the
no_leading_period argument of _gtk_fnmatch().
(attempt_file_completion): Likewise.
* gtk/gtkfilefilter.c (gtk_file_filter_filter): Pass FALSE for the
no_leading_period argument of _gtk_fnmatch().
Wed Jun 2 00:47:11 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkselection.c (_gtk_selection_request): Remove leftover
......
2004-06-02 Federico Mena Quintero <federico@ximian.com>
Fix #138807.
* gtk/fnmatch.c (_gtk_fnmatch): Take a no_leading_period argument.
(gtk_fnmatch_intern): Likewise; also implement this option.
* gtk/gtkprivate.h (_gtk_fnmatch): Updated prototype.
* gtk/gtkfilesel.c (find_completion_dir): Pass TRUE for the
no_leading_period argument of _gtk_fnmatch().
(attempt_file_completion): Likewise.
* gtk/gtkfilefilter.c (gtk_file_filter_filter): Pass FALSE for the
no_leading_period argument of _gtk_fnmatch().
Wed Jun 2 00:47:11 2004 Matthias Clasen <maclas@gmx.de>
* gtk/gtkselection.c (_gtk_selection_request): Remove leftover
......
......@@ -79,7 +79,8 @@ get_unescaped_char (const char **str,
static gboolean
gtk_fnmatch_intern (const char *pattern,
const char *string,
gboolean component_start)
gboolean component_start,
gboolean no_leading_period)
{
const char *p = pattern, *n = string;
......@@ -97,7 +98,7 @@ gtk_fnmatch_intern (const char *pattern,
return FALSE;
else if (nc == G_DIR_SEPARATOR)
return FALSE;
else if (nc == '.' && component_start)
else if (nc == '.' && component_start && no_leading_period)
return FALSE;
break;
case '\\':
......@@ -107,7 +108,7 @@ gtk_fnmatch_intern (const char *pattern,
return FALSE;
break;
case '*':
if (nc == '.' && component_start)
if (nc == '.' && component_start && no_leading_period)
return FALSE;
{
......@@ -148,7 +149,7 @@ gtk_fnmatch_intern (const char *pattern,
for (p = last_p; nc != '\0';)
{
if ((c == '[' || nc == c) &&
gtk_fnmatch_intern (p, last_n, component_start))
gtk_fnmatch_intern (p, last_n, component_start, no_leading_period))
return TRUE;
component_start = (nc == G_DIR_SEPARATOR);
......@@ -168,7 +169,7 @@ gtk_fnmatch_intern (const char *pattern,
if (nc == '\0' || nc == G_DIR_SEPARATOR)
return FALSE;
if (nc == '.' && component_start)
if (nc == '.' && component_start && no_leading_period)
return FALSE;
not = (*p == '!' || *p == '^');
......@@ -245,116 +246,116 @@ gtk_fnmatch_intern (const char *pattern,
*
* FNM_FILE_NAME - always set
* FNM_LEADING_DIR - never set
* FNM_PERIOD - always set
* FNM_NOESCAPE - set only on windows
* FNM_CASEFOLD - set only on windows
*/
gboolean
_gtk_fnmatch (const char *pattern,
const char *string)
const char *string,
gboolean no_leading_period)
{
return gtk_fnmatch_intern (pattern, string, TRUE);
return gtk_fnmatch_intern (pattern, string, TRUE, no_leading_period);
}
#undef FNMATCH_TEST_CASES
#ifdef FNMATCH_TEST_CASES
#define TEST(pat, str, result) \
g_assert (_gtk_fnmatch ((pat), (str)) == result)
#define TEST(pat, str, no_leading_period, result) \
g_assert (_gtk_fnmatch ((pat), (str), (no_leading_period)) == result)
int main (int argc, char **argv)
{
TEST ("[a-]", "-", TRUE);
TEST ("[a-]", "-", TRUE, TRUE);
TEST ("a", "a", TRUE);
TEST ("a", "b", FALSE);
TEST ("a", "a", TRUE, TRUE);
TEST ("a", "b", TRUE, FALSE);
/* Test what ? matches */
TEST ("?", "a", TRUE);
TEST ("?", ".", FALSE);
TEST ("a?", "a.", TRUE);
TEST ("a/?", "a/b", TRUE);
TEST ("a/?", "a/.", FALSE);
TEST ("?", "/", FALSE);
TEST ("?", "a", TRUE, TRUE);
TEST ("?", ".", TRUE, FALSE);
TEST ("a?", "a.", TRUE, TRUE);
TEST ("a/?", "a/b", TRUE, TRUE);
TEST ("a/?", "a/.", TRUE, FALSE);
TEST ("?", "/", TRUE, FALSE);
/* Test what * matches */
TEST ("*", "a", TRUE);
TEST ("*", ".", FALSE);
TEST ("a*", "a.", TRUE);
TEST ("a/*", "a/b", TRUE);
TEST ("a/*", "a/.", FALSE);
TEST ("*", "/", FALSE);
TEST ("*", "a", TRUE, TRUE);
TEST ("*", ".", TRUE, FALSE);
TEST ("a*", "a.", TRUE, TRUE);
TEST ("a/*", "a/b", TRUE, TRUE);
TEST ("a/*", "a/.", TRUE, FALSE);
TEST ("*", "/", TRUE, FALSE);
/* Range tests */
TEST ("[ab]", "a", TRUE);
TEST ("[ab]", "c", FALSE);
TEST ("[^ab]", "a", FALSE);
TEST ("[!ab]", "a", FALSE);
TEST ("[^ab]", "c", TRUE);
TEST ("[!ab]", "c", TRUE);
TEST ("[a-c]", "b", TRUE);
TEST ("[a-c]", "d", FALSE);
TEST ("[a-]", "-", TRUE);
TEST ("[]]", "]", TRUE);
TEST ("[^]]", "a", TRUE);
TEST ("[!]]", "a", TRUE);
TEST ("[ab]", "a", TRUE, TRUE);
TEST ("[ab]", "c", TRUE, FALSE);
TEST ("[^ab]", "a", TRUE, FALSE);
TEST ("[!ab]", "a", TRUE, FALSE);
TEST ("[^ab]", "c", TRUE, TRUE);
TEST ("[!ab]", "c", TRUE, TRUE);
TEST ("[a-c]", "b", TRUE, TRUE);
TEST ("[a-c]", "d", TRUE, FALSE);
TEST ("[a-]", "-", TRUE, TRUE);
TEST ("[]]", "]", TRUE, TRUE);
TEST ("[^]]", "a", TRUE, TRUE);
TEST ("[!]]", "a", TRUE, TRUE);
/* Various unclosed ranges */
TEST ("[ab", "a", FALSE);
TEST ("[a-", "a", FALSE);
TEST ("[ab", "c", FALSE);
TEST ("[a-", "c", FALSE);
TEST ("[^]", "a", FALSE);
TEST ("[ab", "a", TRUE, FALSE);
TEST ("[a-", "a", TRUE, FALSE);
TEST ("[ab", "c", TRUE, FALSE);
TEST ("[a-", "c", TRUE, FALSE);
TEST ("[^]", "a", TRUE, FALSE);
/* Ranges and special no-wildcard matches */
TEST ("[.]", ".", FALSE);
TEST ("a[.]", "a.", TRUE);
TEST ("a/[.]", "a/.", FALSE);
TEST ("[/]", "/", FALSE);
TEST ("[^/]", "a", TRUE);
TEST ("[.]", ".", TRUE, FALSE);
TEST ("a[.]", "a.", TRUE, TRUE);
TEST ("a/[.]", "a/.", TRUE, FALSE);
TEST ("[/]", "/", TRUE, FALSE);
TEST ("[^/]", "a", TRUE, TRUE);
/* Basic tests of * (and combinations of * and ?) */
TEST ("a*b", "ab", TRUE);
TEST ("a*b", "axb", TRUE);
TEST ("a*b", "axxb", TRUE);
TEST ("a**b", "ab", TRUE);
TEST ("a**b", "axb", TRUE);
TEST ("a**b", "axxb", TRUE);
TEST ("a*?*b", "ab", FALSE);
TEST ("a*?*b", "axb", TRUE);
TEST ("a*?*b", "axxb", TRUE);
TEST ("a*b", "ab", TRUE, TRUE);
TEST ("a*b", "axb", TRUE, TRUE);
TEST ("a*b", "axxb", TRUE, TRUE);
TEST ("a**b", "ab", TRUE, TRUE);
TEST ("a**b", "axb", TRUE, TRUE);
TEST ("a**b", "axxb", TRUE, TRUE);
TEST ("a*?*b", "ab", TRUE, FALSE);
TEST ("a*?*b", "axb", TRUE, TRUE);
TEST ("a*?*b", "axxb", TRUE, TRUE);
/* Test of *[range] */
TEST ("a*[cd]", "ac", TRUE);
TEST ("a*[cd]", "axc", TRUE);
TEST ("a*[cd]", "axx", FALSE);
TEST ("a*[cd]", "ac", TRUE, TRUE);
TEST ("a*[cd]", "axc", TRUE, TRUE);
TEST ("a*[cd]", "axx", TRUE, FALSE);
TEST ("a/[.]", "a/.", FALSE);
TEST ("a*[.]", "a/.", FALSE);
TEST ("a/[.]", "a/.", TRUE, FALSE);
TEST ("a*[.]", "a/.", TRUE, FALSE);
/* Test of UTF-8 */
TEST ("ä", "ä", TRUE); /* TEST ("ä", "ä", TRUE); */
TEST ("?", "ä", TRUE); /* TEST ("?", "ä", TRUE); */
TEST ("*ö", "äö", TRUE); /* TEST ("*ö", "äö", TRUE); */
TEST ("*ö", "ääö", TRUE); /* TEST ("*ö", "ääö", TRUE); */
TEST ("[ä]", "ä", TRUE); /* TEST ("[ä]", "ä", TRUE); */
TEST ("[ä-ö]", "é", TRUE); /* TEST ("[ä-ö]", "é", TRUE); */
TEST ("[ä-ö]", "a", FALSE); /* TEST ("[ä-ö]", "a", FALSE); */
TEST ("ä", "ä", TRUE, TRUE); /* TEST ("ä", "ä", TRUE); */
TEST ("?", "ä", TRUE, TRUE); /* TEST ("?", "ä", TRUE); */
TEST ("*ö", "äö", TRUE, TRUE); /* TEST ("*ö", "äö", TRUE); */
TEST ("*ö", "ääö", TRUE, TRUE); /* TEST ("*ö", "ääö", TRUE); */
TEST ("[ä]", "ä", TRUE, TRUE); /* TEST ("[ä]", "ä", TRUE); */
TEST ("[ä-ö]", "é", TRUE, TRUE); /* TEST ("[ä-ö]", "é", TRUE); */
TEST ("[ä-ö]", "a", TRUE, FALSE); /* TEST ("[ä-ö]", "a", FALSE); */
#ifdef DO_ESCAPE
/* Tests of escaping */
TEST ("\\\\", "\\", TRUE);
TEST ("\\?", "?", TRUE);
TEST ("\\?", "a", FALSE);
TEST ("\\*", "*", TRUE);
TEST ("\\*", "a", FALSE);
TEST ("\\[a-b]", "[a-b]", TRUE);
TEST ("[\\\\]", "\\", TRUE);
TEST ("[\\^a]", "a", TRUE);
TEST ("[a\\-c]", "b", FALSE);
TEST ("[a\\-c]", "-", TRUE);
TEST ("[a\\]", "a", FALSE);
TEST ("\\\\", "\\", TRUE, TRUE);
TEST ("\\?", "?", TRUE, TRUE);
TEST ("\\?", "a", TRUE, FALSE);
TEST ("\\*", "*", TRUE, TRUE);
TEST ("\\*", "a", TRUE, FALSE);
TEST ("\\[a-b]", "[a-b]", TRUE, TRUE);
TEST ("[\\\\]", "\\", TRUE, TRUE);
TEST ("[\\^a]", "a", TRUE, TRUE);
TEST ("[a\\-c]", "b", TRUE, FALSE);
TEST ("[a\\-c]", "-", TRUE, TRUE);
TEST ("[a\\]", "a", TRUE, FALSE);
#endif /* DO_ESCAPE */
return 0;
......
......@@ -378,7 +378,7 @@ gtk_file_filter_filter (GtkFileFilter *filter,
break;
case FILTER_RULE_PATTERN:
if (filter_info->display_name != NULL &&
_gtk_fnmatch (rule->u.pattern, filter_info->display_name))
_gtk_fnmatch (rule->u.pattern, filter_info->display_name, FALSE))
return TRUE;
break;
case FILTER_RULE_CUSTOM:
......
......@@ -3694,7 +3694,7 @@ find_completion_dir (gchar *text_to_complete,
for (i = 0; i < dir->sent->entry_count; i += 1)
{
if (dir->sent->entries[i].is_dir &&
_gtk_fnmatch (pat_buf, dir->sent->entries[i].entry_name))
_gtk_fnmatch (pat_buf, dir->sent->entries[i].entry_name, TRUE))
{
if (found)
{
......@@ -3844,7 +3844,7 @@ attempt_file_completion (CompletionState *cmpl_state)
{
if (dir->sent->entries[dir->cmpl_index].is_dir)
{
if (_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name))
if (_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name, TRUE))
{
CompletionDir* new_dir;
......@@ -3892,7 +3892,7 @@ attempt_file_completion (CompletionState *cmpl_state)
append_completion_text (dir->sent->entries[dir->cmpl_index].entry_name, cmpl_state);
cmpl_state->the_completion.is_a_completion =
_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name);
_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name, TRUE);
cmpl_state->the_completion.is_directory = dir->sent->entries[dir->cmpl_index].is_dir;
if (dir->sent->entries[dir->cmpl_index].is_dir)
......
......@@ -100,7 +100,8 @@ const gchar *_gtk_get_data_prefix ();
#endif /* G_OS_WIN32 */
gboolean _gtk_fnmatch (const char *pattern,
const char *string);
const char *string,
gboolean no_leading_period);
#ifdef __cplusplus
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment