mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-12 20:00:09 +00:00
Use UTF-8-clean version from GTK+ 2.2.0, with entry point _gtk_fnmatch().
2002-12-22 Tor Lillqvist <tml@iki.fi> * gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with entry point _gtk_fnmatch(). One change: On Win32, casefold *all* characters, not just the ASCII ones. * gtk/fnmatch.h: Remove. * gtk/gtkprivate.h: Declate _gtk_fnmatch() here. * gtk/gtkfilesel.c: Change accordingly. Add some assertions to make sure that we don't confuse UTF-8 and system codepage strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
This commit is contained in:
parent
94e6913a28
commit
ab0b717cb8
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
||||
2002-12-22 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with
|
||||
entry point _gtk_fnmatch(). One change: On Win32, casefold *all*
|
||||
characters, not just the ASCII ones.
|
||||
|
||||
* gtk/fnmatch.h: Remove.
|
||||
|
||||
* gtk/gtkprivate.h: Declate _gtk_fnmatch() here.
|
||||
|
||||
* gtk/gtkfilesel.c: Change accordingly. Add some assertions to
|
||||
make sure that we don't confuse UTF-8 and system codepage
|
||||
strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
|
||||
|
||||
2002-12-21 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gdk/win32/gdkinput-win32.c: Initialise wintab_window as NULL.
|
||||
|
@ -1,3 +1,17 @@
|
||||
2002-12-22 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with
|
||||
entry point _gtk_fnmatch(). One change: On Win32, casefold *all*
|
||||
characters, not just the ASCII ones.
|
||||
|
||||
* gtk/fnmatch.h: Remove.
|
||||
|
||||
* gtk/gtkprivate.h: Declate _gtk_fnmatch() here.
|
||||
|
||||
* gtk/gtkfilesel.c: Change accordingly. Add some assertions to
|
||||
make sure that we don't confuse UTF-8 and system codepage
|
||||
strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
|
||||
|
||||
2002-12-21 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gdk/win32/gdkinput-win32.c: Initialise wintab_window as NULL.
|
||||
|
@ -1,3 +1,17 @@
|
||||
2002-12-22 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with
|
||||
entry point _gtk_fnmatch(). One change: On Win32, casefold *all*
|
||||
characters, not just the ASCII ones.
|
||||
|
||||
* gtk/fnmatch.h: Remove.
|
||||
|
||||
* gtk/gtkprivate.h: Declate _gtk_fnmatch() here.
|
||||
|
||||
* gtk/gtkfilesel.c: Change accordingly. Add some assertions to
|
||||
make sure that we don't confuse UTF-8 and system codepage
|
||||
strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
|
||||
|
||||
2002-12-21 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gdk/win32/gdkinput-win32.c: Initialise wintab_window as NULL.
|
||||
|
@ -1,3 +1,17 @@
|
||||
2002-12-22 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with
|
||||
entry point _gtk_fnmatch(). One change: On Win32, casefold *all*
|
||||
characters, not just the ASCII ones.
|
||||
|
||||
* gtk/fnmatch.h: Remove.
|
||||
|
||||
* gtk/gtkprivate.h: Declate _gtk_fnmatch() here.
|
||||
|
||||
* gtk/gtkfilesel.c: Change accordingly. Add some assertions to
|
||||
make sure that we don't confuse UTF-8 and system codepage
|
||||
strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
|
||||
|
||||
2002-12-21 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gdk/win32/gdkinput-win32.c: Initialise wintab_window as NULL.
|
||||
|
@ -1,3 +1,17 @@
|
||||
2002-12-22 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with
|
||||
entry point _gtk_fnmatch(). One change: On Win32, casefold *all*
|
||||
characters, not just the ASCII ones.
|
||||
|
||||
* gtk/fnmatch.h: Remove.
|
||||
|
||||
* gtk/gtkprivate.h: Declate _gtk_fnmatch() here.
|
||||
|
||||
* gtk/gtkfilesel.c: Change accordingly. Add some assertions to
|
||||
make sure that we don't confuse UTF-8 and system codepage
|
||||
strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
|
||||
|
||||
2002-12-21 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gdk/win32/gdkinput-win32.c: Initialise wintab_window as NULL.
|
||||
|
@ -1,3 +1,17 @@
|
||||
2002-12-22 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gtk/fnmatch.c: Use UTF-8-clean version from GTK+ 2.2.0, with
|
||||
entry point _gtk_fnmatch(). One change: On Win32, casefold *all*
|
||||
characters, not just the ASCII ones.
|
||||
|
||||
* gtk/fnmatch.h: Remove.
|
||||
|
||||
* gtk/gtkprivate.h: Declate _gtk_fnmatch() here.
|
||||
|
||||
* gtk/gtkfilesel.c: Change accordingly. Add some assertions to
|
||||
make sure that we don't confuse UTF-8 and system codepage
|
||||
strings. Remove CMPL_ERRNO_TOO_LONG handling, was never used.
|
||||
|
||||
2002-12-21 Tor Lillqvist <tml@iki.fi>
|
||||
|
||||
* gdk/win32/gdkinput-win32.c: Initialise wintab_window as NULL.
|
||||
|
404
gtk/fnmatch.c
404
gtk/fnmatch.c
@ -1,228 +1,354 @@
|
||||
/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
|
||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
/*
|
||||
* Stripped down, converted to UTF-8 and test cases added
|
||||
*
|
||||
* Owen Taylor, 13 December 2002;
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Added for GTK. We need to make sure that all constants are defined
|
||||
* to properly compile this file */
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
#include "fnmatch.h"
|
||||
|
||||
/* We need glib.h for G_DIR_SEPARATOR and G_OS_WIN32 */
|
||||
#include <glib.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static gunichar
|
||||
get_char (const char **str)
|
||||
{
|
||||
gunichar c = g_utf8_get_char (*str);
|
||||
*str = g_utf8_next_char (*str);
|
||||
|
||||
/* Comment out all this code if we are using the GNU C Library, and are not
|
||||
actually compiling the library itself. This code is part of the GNU C
|
||||
Library, but also included in many other GNU distributions. Compiling
|
||||
and linking in this code is a waste when using the GNU C library
|
||||
(especially if it is a shared library). Rather than having every GNU
|
||||
program understand `configure --with-gnu-libc' and omit the object files,
|
||||
it is simpler to just do this in the source for each such file. */
|
||||
|
||||
#if defined (_LIBC) || !defined (__GNU_LIBRARY__)
|
||||
|
||||
#if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
|
||||
extern int errno;
|
||||
#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
|
||||
c = g_unichar_tolower (c);
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
#if defined(G_OS_WIN32) || defined(G_WITH_CYGWIN)
|
||||
#define DO_ESCAPE 0
|
||||
#else
|
||||
#define DO_ESCAPE 1
|
||||
#endif
|
||||
|
||||
static gunichar
|
||||
get_unescaped_char (const char **str,
|
||||
gboolean *was_escaped)
|
||||
{
|
||||
gunichar c = get_char (str);
|
||||
|
||||
*was_escaped = DO_ESCAPE && c == '\\';
|
||||
if (*was_escaped)
|
||||
c = get_char (str);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Match STRING against the filename pattern PATTERN, returning zero if
|
||||
it matches, nonzero if not. */
|
||||
int
|
||||
fnmatch (pattern, string, flags)
|
||||
const char *pattern;
|
||||
const char *string;
|
||||
int flags;
|
||||
|
||||
static gboolean
|
||||
gtk_fnmatch_intern (const char *pattern,
|
||||
const char *string,
|
||||
gboolean component_start)
|
||||
{
|
||||
register const char *p = pattern, *n = string;
|
||||
register char c;
|
||||
|
||||
/* Note that this evalutes C many times. */
|
||||
#if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN)
|
||||
#define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c))
|
||||
#else
|
||||
#define FOLD(c) (tolower (c))
|
||||
#endif
|
||||
|
||||
while ((c = *p++) != '\0')
|
||||
const char *p = pattern, *n = string;
|
||||
|
||||
while (*p)
|
||||
{
|
||||
c = FOLD (c);
|
||||
|
||||
const char *last_n = n;
|
||||
|
||||
gunichar c = get_char (&p);
|
||||
gunichar nc = get_char (&n);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '?':
|
||||
if (*n == '\0')
|
||||
return FNM_NOMATCH;
|
||||
else if ((flags & FNM_FILE_NAME) && *n == G_DIR_SEPARATOR)
|
||||
return FNM_NOMATCH;
|
||||
else if ((flags & FNM_PERIOD) && *n == '.' &&
|
||||
(n == string || ((flags & FNM_FILE_NAME) && n[-1] == G_DIR_SEPARATOR)))
|
||||
return FNM_NOMATCH;
|
||||
case '?':
|
||||
if (nc == '\0')
|
||||
return FALSE;
|
||||
else if (nc == G_DIR_SEPARATOR)
|
||||
return FALSE;
|
||||
else if (nc == '.' && component_start)
|
||||
return FALSE;
|
||||
break;
|
||||
#ifndef G_OS_WIN32
|
||||
case '\\':
|
||||
if (!(flags & FNM_NOESCAPE))
|
||||
{
|
||||
c = *p++;
|
||||
c = FOLD (c);
|
||||
}
|
||||
if (FOLD (*n) != c)
|
||||
return FNM_NOMATCH;
|
||||
if (DO_ESCAPE)
|
||||
c = get_char (&p);
|
||||
if (nc != c)
|
||||
return FALSE;
|
||||
break;
|
||||
#endif
|
||||
case '*':
|
||||
if ((flags & FNM_PERIOD) && *n == '.' &&
|
||||
(n == string || ((flags & FNM_FILE_NAME) && n[-1] == G_DIR_SEPARATOR)))
|
||||
return FNM_NOMATCH;
|
||||
|
||||
for (c = *p++; c == '?' || c == '*'; c = *p++, ++n)
|
||||
if (((flags & FNM_FILE_NAME) && *n == G_DIR_SEPARATOR) ||
|
||||
(c == '?' && *n == '\0'))
|
||||
return FNM_NOMATCH;
|
||||
|
||||
if (c == '\0')
|
||||
return 0;
|
||||
if (nc == '.' && component_start)
|
||||
return FALSE;
|
||||
|
||||
{
|
||||
#ifndef G_OS_WIN32
|
||||
char c1 = (!(flags & FNM_NOESCAPE) && c == '\\') ? *p : c;
|
||||
#else
|
||||
char c1 = c;
|
||||
#endif
|
||||
c1 = FOLD (c1);
|
||||
for (--p; *n != '\0'; ++n)
|
||||
if ((c == '[' || FOLD (*n) == c1) &&
|
||||
fnmatch (p, n, flags & ~FNM_PERIOD) == 0)
|
||||
return 0;
|
||||
return FNM_NOMATCH;
|
||||
const char *last_p = p;
|
||||
|
||||
for (last_p = p, c = get_char (&p);
|
||||
c == '?' || c == '*';
|
||||
last_p = p, c = get_char (&p))
|
||||
{
|
||||
if (c == '?')
|
||||
{
|
||||
if (nc == '\0')
|
||||
return FALSE;
|
||||
else if (nc == G_DIR_SEPARATOR)
|
||||
return FALSE;
|
||||
else
|
||||
{
|
||||
last_n = n; nc = get_char (&n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If the pattern ends with wildcards, we have a
|
||||
* guaranteed match unless there is a dir separator
|
||||
* in the remainder of the string.
|
||||
*/
|
||||
if (c == '\0')
|
||||
{
|
||||
if (strchr (last_n, G_DIR_SEPARATOR) != NULL)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (DO_ESCAPE && c == '\\')
|
||||
c = get_char (&p);
|
||||
|
||||
for (p = last_p; nc != '\0';)
|
||||
{
|
||||
if ((c == '[' || nc == c) &&
|
||||
gtk_fnmatch_intern (p, last_n, component_start))
|
||||
return TRUE;
|
||||
|
||||
component_start = (nc == G_DIR_SEPARATOR);
|
||||
last_n = n;
|
||||
nc = get_char (&n);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
case '[':
|
||||
{
|
||||
/* Nonzero if the sense of the character class is inverted. */
|
||||
register int not;
|
||||
gboolean not;
|
||||
gboolean was_escaped;
|
||||
|
||||
if (*n == '\0')
|
||||
return FNM_NOMATCH;
|
||||
if (nc == '\0' || nc == G_DIR_SEPARATOR)
|
||||
return FALSE;
|
||||
|
||||
if ((flags & FNM_PERIOD) && *n == '.' &&
|
||||
(n == string || ((flags & FNM_FILE_NAME) && n[-1] == G_DIR_SEPARATOR)))
|
||||
return FNM_NOMATCH;
|
||||
if (nc == '.' && component_start)
|
||||
return FALSE;
|
||||
|
||||
not = (*p == '!' || *p == '^');
|
||||
if (not)
|
||||
++p;
|
||||
|
||||
c = *p++;
|
||||
c = get_unescaped_char (&p, &was_escaped);
|
||||
for (;;)
|
||||
{
|
||||
register char cstart = c, cend = c;
|
||||
#ifndef G_OS_WIN32
|
||||
if (!(flags & FNM_NOESCAPE) && c == '\\')
|
||||
cstart = cend = *p++;
|
||||
#endif
|
||||
cstart = cend = FOLD (cstart);
|
||||
|
||||
register gunichar cstart = c, cend = c;
|
||||
if (c == '\0')
|
||||
/* [ (unterminated) loses. */
|
||||
return FNM_NOMATCH;
|
||||
return FALSE;
|
||||
|
||||
c = *p++;
|
||||
c = FOLD (c);
|
||||
|
||||
if ((flags & FNM_FILE_NAME) && c == G_DIR_SEPARATOR)
|
||||
/* [/] can never match. */
|
||||
return FNM_NOMATCH;
|
||||
|
||||
if (c == '-' && *p != ']')
|
||||
c = get_unescaped_char (&p, &was_escaped);
|
||||
|
||||
if (!was_escaped && c == '-' && *p != ']')
|
||||
{
|
||||
cend = *p++;
|
||||
#ifndef G_OS_WIN32
|
||||
if (!(flags & FNM_NOESCAPE) && cend == '\\')
|
||||
cend = *p++;
|
||||
#endif
|
||||
cend = get_unescaped_char (&p, &was_escaped);
|
||||
if (cend == '\0')
|
||||
return FNM_NOMATCH;
|
||||
cend = FOLD (cend);
|
||||
return FALSE;
|
||||
|
||||
c = *p++;
|
||||
c = get_char (&p);
|
||||
}
|
||||
|
||||
if (FOLD (*n) >= cstart && FOLD (*n) <= cend)
|
||||
if (nc >= cstart && nc <= cend)
|
||||
goto matched;
|
||||
|
||||
if (c == ']')
|
||||
if (!was_escaped && c == ']')
|
||||
break;
|
||||
}
|
||||
if (!not)
|
||||
return FNM_NOMATCH;
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
matched:;
|
||||
/* Skip the rest of the [...] that already matched. */
|
||||
while (c != ']')
|
||||
/* XXX 1003.2d11 is unclear if was_escaped is right. */
|
||||
while (was_escaped || c != ']')
|
||||
{
|
||||
if (c == '\0')
|
||||
/* [... (unterminated) loses. */
|
||||
return FNM_NOMATCH;
|
||||
return FALSE;
|
||||
|
||||
c = *p++;
|
||||
#ifndef G_OS_WIN32
|
||||
if (!(flags & FNM_NOESCAPE) && c == '\\')
|
||||
/* XXX 1003.2d11 is unclear if this is right. */
|
||||
++p;
|
||||
#endif
|
||||
c = get_unescaped_char (&p, &was_escaped);
|
||||
}
|
||||
if (not)
|
||||
return FNM_NOMATCH;
|
||||
return FALSE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (c != FOLD (*n))
|
||||
return FNM_NOMATCH;
|
||||
if (c != nc)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
++n;
|
||||
component_start = (nc == G_DIR_SEPARATOR);
|
||||
}
|
||||
|
||||
if (*n == '\0')
|
||||
return 0;
|
||||
return TRUE;
|
||||
|
||||
if ((flags & FNM_LEADING_DIR) && *n == G_DIR_SEPARATOR)
|
||||
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
|
||||
return 0;
|
||||
|
||||
return FNM_NOMATCH;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif /* _LIBC or not __GNU_LIBRARY__. */
|
||||
/* Match STRING against the filename pattern PATTERN, returning zero if
|
||||
* it matches, nonzero if not.
|
||||
*
|
||||
* GTK+ used to use a old version of GNU fnmatch() that was buggy
|
||||
* in various ways and didn't handle UTF-8. The following is
|
||||
* converted to UTF-8. To simplify the process of making it
|
||||
* correct, this is special-cased to the combinations of flags
|
||||
* that gtkfilesel.c uses.
|
||||
*
|
||||
* 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)
|
||||
{
|
||||
return gtk_fnmatch_intern (pattern, string, TRUE);
|
||||
}
|
||||
|
||||
#ifdef FNMATCH_TEST_CASES
|
||||
|
||||
#define TEST(pat, str, result) \
|
||||
g_assert (_gtk_fnmatch ((pat), (str)) == result)
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
TEST ("[a-]", "-", TRUE);
|
||||
|
||||
TEST ("a", "a", TRUE);
|
||||
TEST ("a", "b", 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 what * matches */
|
||||
TEST ("*", "a", TRUE);
|
||||
TEST ("*", ".", FALSE);
|
||||
TEST ("a*", "a.", TRUE);
|
||||
TEST ("a/*", "a/b", TRUE);
|
||||
TEST ("a/*", "a/.", FALSE);
|
||||
TEST ("*", "/", 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);
|
||||
|
||||
/* Various unclosed ranges */
|
||||
TEST ("[ab", "a", FALSE);
|
||||
TEST ("[a-", "a", FALSE);
|
||||
TEST ("[ab", "c", FALSE);
|
||||
TEST ("[a-", "c", FALSE);
|
||||
TEST ("[^]", "a", FALSE);
|
||||
|
||||
/* Ranges and special no-wildcard matches */
|
||||
TEST ("[.]", ".", FALSE);
|
||||
TEST ("a[.]", "a.", TRUE);
|
||||
TEST ("a/[.]", "a/.", FALSE);
|
||||
TEST ("[/]", "/", FALSE);
|
||||
TEST ("[^/]", "a", 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 of *[range] */
|
||||
TEST ("a*[cd]", "ac", TRUE);
|
||||
TEST ("a*[cd]", "axc", TRUE);
|
||||
TEST ("a*[cd]", "axx", FALSE);
|
||||
|
||||
TEST ("a/[.]", "a/.", FALSE);
|
||||
TEST ("a*[.]", "a/.", 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); */
|
||||
|
||||
#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);
|
||||
#endif /* DO_ESCAPE */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* FNMATCH_TEST_CASES */
|
||||
|
@ -1,75 +0,0 @@
|
||||
/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef _FNMATCH_H
|
||||
|
||||
#define _FNMATCH_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined (__cplusplus) || (defined (__STDC__) && __STDC__)
|
||||
#undef __P
|
||||
#define __P(protos) protos
|
||||
#else /* Not C++ or ANSI C. */
|
||||
#undef __P
|
||||
#define __P(protos) ()
|
||||
/* We can get away without defining `const' here only because in this file
|
||||
it is used only inside the prototype for `fnmatch', which is elided in
|
||||
non-ANSI C where `const' is problematical. */
|
||||
#endif /* C++ or ANSI C. */
|
||||
|
||||
|
||||
/* We #undef these before defining them because some losing systems
|
||||
(HP-UX A.08.07 for example) define these in <unistd.h>. */
|
||||
#undef FNM_PATHNAME
|
||||
#undef FNM_NOESCAPE
|
||||
#undef FNM_PERIOD
|
||||
|
||||
/* Bits set in the FLAGS argument to `fnmatch'. */
|
||||
#define FNM_PATHNAME (1 << 0) /* No wildcard can ever match `/'. */
|
||||
#define FNM_NOESCAPE (1 << 1) /* Backslashes don't quote special chars. */
|
||||
#define FNM_PERIOD (1 << 2) /* Leading `.' is matched only explicitly. */
|
||||
|
||||
#if !defined (_POSIX_C_SOURCE) || _POSIX_C_SOURCE < 2 || defined (_GNU_SOURCE)
|
||||
#define FNM_FILE_NAME FNM_PATHNAME /* Preferred GNU name. */
|
||||
#define FNM_LEADING_DIR (1 << 3) /* Ignore `/...' after a match. */
|
||||
#define FNM_CASEFOLD (1 << 4) /* Compare without regard to case. */
|
||||
#endif
|
||||
|
||||
/* Value returned by `fnmatch' if STRING does not match PATTERN. */
|
||||
#define FNM_NOMATCH 1
|
||||
|
||||
/* Match STRING against the filename pattern PATTERN,
|
||||
returning zero if it matches, FNM_NOMATCH if not. */
|
||||
extern int fnmatch __P ((const char *__pattern, const char *__string,
|
||||
int __flags));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* fnmatch.h */
|
110
gtk/gtkfilesel.c
110
gtk/gtkfilesel.c
@ -46,8 +46,6 @@
|
||||
#include <pwd.h>
|
||||
#endif
|
||||
|
||||
#include "fnmatch.h"
|
||||
|
||||
#include "gdk/gdkkeysyms.h"
|
||||
#include "gtkbutton.h"
|
||||
#include "gtkentry.h"
|
||||
@ -58,6 +56,7 @@
|
||||
#include "gtklist.h"
|
||||
#include "gtklistitem.h"
|
||||
#include "gtkmain.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkscrolledwindow.h"
|
||||
#include "gtksignal.h"
|
||||
#include "gtkvbox.h"
|
||||
@ -117,11 +116,6 @@ typedef struct _PossibleCompletion PossibleCompletion;
|
||||
* match by first_diff_index()
|
||||
*/
|
||||
#define PATTERN_MATCH -1
|
||||
/* The arguments used by all fnmatch() calls below
|
||||
*/
|
||||
#define FNMATCH_FLAGS (FNM_PATHNAME | FNM_PERIOD)
|
||||
|
||||
#define CMPL_ERRNO_TOO_LONG ((1<<16)-1)
|
||||
|
||||
/* This structure contains all the useful information about a directory
|
||||
* for the purposes of filename completion. These structures are cached
|
||||
@ -366,6 +360,30 @@ static GtkWindowClass *parent_class = NULL;
|
||||
/* Saves errno when something cmpl does fails. */
|
||||
static gint cmpl_errno;
|
||||
|
||||
/* Check that a string does not have UTF-8 encoded non-ASCII characters */
|
||||
static gboolean
|
||||
is_not_utf8 (const gchar *string)
|
||||
{
|
||||
gunichar c;
|
||||
|
||||
while (*string)
|
||||
{
|
||||
c = g_utf8_get_char (string);
|
||||
if (c & 0x80000000)
|
||||
return TRUE;
|
||||
if (c > 0x7F)
|
||||
return FALSE;
|
||||
string = g_utf8_next_char (string);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_utf8 (const gchar *string)
|
||||
{
|
||||
return g_utf8_validate (string, -1, NULL);
|
||||
}
|
||||
|
||||
#ifdef G_WITH_CYGWIN
|
||||
/*
|
||||
* Take the path currently in the file selection
|
||||
@ -696,19 +714,21 @@ gtk_file_selection_hide_fileop_buttons (GtkFileSelection *filesel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
gtk_file_selection_set_filename (GtkFileSelection *filesel,
|
||||
const gchar *filename)
|
||||
{
|
||||
gchar *buf;
|
||||
gchar *buf, *utf8_buf;
|
||||
const char *name, *last_slash;
|
||||
|
||||
g_return_if_fail (filesel != NULL);
|
||||
g_return_if_fail (GTK_IS_FILE_SELECTION (filesel));
|
||||
g_return_if_fail (filename != NULL);
|
||||
|
||||
#ifdef G_PLATFORM_WIN32
|
||||
g_return_if_fail (is_not_utf8 (filename));
|
||||
#endif
|
||||
|
||||
last_slash = strrchr (filename, G_DIR_SEPARATOR);
|
||||
|
||||
if (!last_slash)
|
||||
@ -723,11 +743,13 @@ gtk_file_selection_set_filename (GtkFileSelection *filesel,
|
||||
name = last_slash + 1;
|
||||
}
|
||||
|
||||
gtk_file_selection_populate (filesel, buf, FALSE);
|
||||
utf8_buf = g_filename_to_utf8 (buf, -1, NULL, NULL, NULL);
|
||||
gtk_file_selection_populate (filesel, utf8_buf, FALSE);
|
||||
|
||||
if (filesel->selection_entry)
|
||||
gtk_entry_set_text (GTK_ENTRY (filesel->selection_entry), name);
|
||||
g_free (buf);
|
||||
g_free (utf8_buf);
|
||||
}
|
||||
|
||||
gchar*
|
||||
@ -1466,12 +1488,8 @@ win32_gtk_add_drives_to_dir_list(GtkWidget *the_dir_list)
|
||||
NULL, &maxComponentLength,
|
||||
&flags, NULL, 0);
|
||||
/* Build the actual displayable string */
|
||||
|
||||
sprintf(formatBuffer, "%c:\\", toupper(textPtr[0]));
|
||||
#if 0 /* HB: removed to allow drive change AND directory update with one click */
|
||||
if (strlen(volumeNameBuf) > 0)
|
||||
sprintf(formatBuffer, "%s (%s)", formatBuffer, volumeNameBuf);
|
||||
#endif
|
||||
|
||||
/* Add to the list */
|
||||
text[0] = formatBuffer;
|
||||
row = gtk_clist_append (GTK_CLIST (the_dir_list), text);
|
||||
@ -1501,7 +1519,10 @@ gtk_file_selection_populate (GtkFileSelection *fs,
|
||||
|
||||
g_return_if_fail (fs != NULL);
|
||||
g_return_if_fail (GTK_IS_FILE_SELECTION (fs));
|
||||
|
||||
#ifdef G_PLATFORM_WIN32
|
||||
g_return_if_fail (is_utf8 (rel_path));
|
||||
#endif
|
||||
|
||||
cmpl_state = (CompletionState*) fs->cmpl_state;
|
||||
poss = cmpl_completion_matches (rel_path, &rem_path, cmpl_state);
|
||||
|
||||
@ -2071,7 +2092,7 @@ open_ref_dir(gchar* text_to_complete,
|
||||
-1, NULL, NULL, NULL);
|
||||
|
||||
g_free (sys_curdir);
|
||||
|
||||
|
||||
new_dir = open_dir(utf8_curdir, cmpl_state);
|
||||
|
||||
if (new_dir)
|
||||
@ -2202,45 +2223,38 @@ open_new_dir(gchar* dir_name, struct stat* sbuf, gboolean stat_subdirs)
|
||||
path = g_string_sized_new (2*MAXPATHLEN + 10);
|
||||
|
||||
sys_dir_name = g_filename_from_utf8 (dir_name, -1, NULL, NULL, NULL);
|
||||
directory = opendir(sys_dir_name);
|
||||
directory = opendir (sys_dir_name);
|
||||
|
||||
if(!directory)
|
||||
if (!directory)
|
||||
{
|
||||
cmpl_errno = errno;
|
||||
g_free (sys_dir_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while((dirent_ptr = readdir(directory)) != NULL)
|
||||
{
|
||||
entry_count++;
|
||||
}
|
||||
|
||||
while ((dirent_ptr = readdir (directory)) != NULL)
|
||||
entry_count++;
|
||||
rewinddir(directory);
|
||||
|
||||
sent->entries = g_new(CompletionDirEntry, entry_count);
|
||||
sent->entry_count = entry_count;
|
||||
|
||||
rewinddir(directory);
|
||||
|
||||
for(i = 0; i < entry_count; i += 1)
|
||||
{
|
||||
dirent_ptr = readdir(directory);
|
||||
|
||||
if(!dirent_ptr)
|
||||
dirent_ptr = readdir (directory);
|
||||
if (!dirent_ptr)
|
||||
{
|
||||
cmpl_errno = errno;
|
||||
closedir(directory);
|
||||
closedir (directory);
|
||||
g_free (sys_dir_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sent->entries[i].entry_name = g_filename_to_utf8 (dirent_ptr->d_name,
|
||||
-1, NULL, NULL, NULL);
|
||||
|
||||
g_string_assign (path, sys_dir_name);
|
||||
if (path->str[path->len-1] != G_DIR_SEPARATOR)
|
||||
{
|
||||
g_string_append_c (path, G_DIR_SEPARATOR);
|
||||
}
|
||||
g_string_append_c (path, G_DIR_SEPARATOR);
|
||||
|
||||
g_string_append (path, dirent_ptr->d_name);
|
||||
|
||||
if (stat_subdirs)
|
||||
@ -2724,11 +2738,12 @@ find_completion_dir(gchar* text_to_complete,
|
||||
strncpy(pat_buf, *remaining_text, len);
|
||||
pat_buf[len] = 0;
|
||||
|
||||
g_assert (is_utf8 (pat_buf));
|
||||
|
||||
for(i = 0; i < dir->sent->entry_count; i += 1)
|
||||
{
|
||||
if(dir->sent->entries[i].is_dir &&
|
||||
fnmatch(pat_buf, dir->sent->entries[i].entry_name,
|
||||
FNMATCH_FLAGS)!= FNM_NOMATCH)
|
||||
if (dir->sent->entries[i].is_dir &&
|
||||
_gtk_fnmatch (pat_buf, dir->sent->entries[i].entry_name))
|
||||
{
|
||||
if(found)
|
||||
{
|
||||
@ -2873,12 +2888,13 @@ attempt_file_completion(CompletionState *cmpl_state)
|
||||
strcpy(pat_buf + len, "*");
|
||||
}
|
||||
|
||||
g_assert (is_utf8 (pat_buf));
|
||||
|
||||
if(first_slash)
|
||||
{
|
||||
if(dir->sent->entries[dir->cmpl_index].is_dir)
|
||||
{
|
||||
if(fnmatch(pat_buf, dir->sent->entries[dir->cmpl_index].entry_name,
|
||||
FNMATCH_FLAGS) != FNM_NOMATCH)
|
||||
if (_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name))
|
||||
{
|
||||
CompletionDir* new_dir;
|
||||
|
||||
@ -2926,8 +2942,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 =
|
||||
(fnmatch(pat_buf, dir->sent->entries[dir->cmpl_index].entry_name,
|
||||
FNMATCH_FLAGS) != FNM_NOMATCH);
|
||||
_gtk_fnmatch (pat_buf, dir->sent->entries[dir->cmpl_index].entry_name);
|
||||
|
||||
cmpl_state->the_completion.is_directory = dir->sent->entries[dir->cmpl_index].is_dir;
|
||||
if(dir->sent->entries[dir->cmpl_index].is_dir)
|
||||
@ -3052,8 +3067,9 @@ cmpl_state_okay(CompletionState* cmpl_state)
|
||||
static gchar*
|
||||
cmpl_strerror(gint err)
|
||||
{
|
||||
if(err == CMPL_ERRNO_TOO_LONG)
|
||||
return "Name too long";
|
||||
else
|
||||
return g_strerror (err);
|
||||
static gchar *buf = NULL;
|
||||
|
||||
g_free (buf);
|
||||
buf = g_strdup (g_strerror (err));
|
||||
return buf;
|
||||
}
|
||||
|
@ -97,4 +97,7 @@ const gchar *_gtk_get_data_prefix ();
|
||||
|
||||
#endif
|
||||
|
||||
gboolean _gtk_fnmatch (const char *pattern,
|
||||
const char *string);
|
||||
|
||||
#endif /* __GTK_PRIVATE_H__ */
|
||||
|
Loading…
Reference in New Issue
Block a user