source: trunk/third/gnome-vfs/libgnomevfs/gnome-vfs-shellpattern-filter.c @ 17128

Revision 17128, 2.5 KB checked in by ghudson, 23 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r17127, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2/* gnome-vfs-shellpattern-filter.c - fnmatch()-based filter for the
3   GNOME Virtual File System.
4
5   Copyright (C) 1999 Free Software Foundation
6
7   The Gnome Library is free software; you can redistribute it and/or
8   modify it under the terms of the GNU Library General Public License as
9   published by the Free Software Foundation; either version 2 of the
10   License, or (at your option) any later version.
11
12   The Gnome Library is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   Library General Public License for more details.
16
17   You should have received a copy of the GNU Library General Public
18   License along with the Gnome Library; see the file COPYING.LIB.  If not,
19   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20   Boston, MA 02111-1307, USA.
21
22   Author: Ettore Perazzoli <ettore@comm2000.it> */
23
24#include <config.h>
25#include "gnome-vfs-shellpattern-filter.h"
26
27#include "gnome-vfs.h"
28#include "gnome-vfs-private.h"
29
30#ifdef _POSIX_SOURCE
31#include <fnmatch.h>
32#else
33/* This enables the `FNM_CASEFOLD' #define on GNU libc. */
34/* FIXME bugzilla.eazel.com 1195: OK to use a GNU extension? */
35#define _POSIX_SOURCE
36#include <fnmatch.h>
37/* On Solaris 2.7 we need to undef this again.  */
38#undef _POSIX_SOURCE
39#endif
40
41
42struct GnomeVFSShellpatternFilter {
43        gchar *pattern;
44        gint fnmatch_flags;
45};
46
47
48GnomeVFSShellpatternFilter *
49gnome_vfs_shellpattern_filter_new (const gchar *pattern,
50                                   GnomeVFSDirectoryFilterOptions options)
51{
52        GnomeVFSShellpatternFilter *new;
53
54        new = g_new (GnomeVFSShellpatternFilter, 1);
55
56        new->fnmatch_flags = 0;
57        /* FIXME bugzilla.eazel.com 1195: OK to use a GNU extension? */
58        if (options & GNOME_VFS_DIRECTORY_FILTER_IGNORECASE)
59                new->fnmatch_flags |= FNM_CASEFOLD;
60
61        /* FIXME bugzilla.eazel.com 1196: What about `\' quoting and other fnmatch options?  */
62
63        new->pattern = g_strdup (pattern);
64       
65        return new;
66}
67
68void
69gnome_vfs_shellpattern_filter_destroy (GnomeVFSShellpatternFilter *filter)
70{
71        g_return_if_fail (filter != NULL);
72
73        g_free (filter->pattern);
74        g_free (filter);
75}
76
77gboolean
78gnome_vfs_shellpattern_filter_apply (GnomeVFSShellpatternFilter *filter,
79                                     GnomeVFSFileInfo *info)
80{
81        g_return_val_if_fail (filter != NULL, FALSE);
82        g_return_val_if_fail (info != NULL, FALSE);
83
84        if (fnmatch (filter->pattern, info->name, filter->fnmatch_flags) != 0)
85                return FALSE;
86        else
87                return TRUE;
88}
Note: See TracBrowser for help on using the repository browser.