2 * Test program for testing wild card expressions
8 Bacula® - The Network Backup Solution
10 Copyright (C) 2006-2006 Free Software Foundation Europe e.V.
12 The main author of Bacula is Kern Sibbald, with contributions from
13 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark of John Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
32 Switzerland, email:ftf@fsfeurope.org.
36 #include "lib/fnmatch.h"
42 "Usage: bwild [-d debug_level] -f <data-file>\n"
43 " -f specify file of data to be matched\n"
44 " -i use case insenitive match\n"
45 " -l suppress line numbers\n"
46 " -n print lines that do not match\n"
47 " -? print this message.\n"
53 int main(int argc, char *const *argv)
60 bool match_only = true;
62 bool no_linenos = false;
66 setlocale(LC_ALL, "");
67 bindtextdomain("bacula", LOCALEDIR);
70 while ((ch = getopt(argc, argv, "d:f:in?")) != -1) {
72 case 'd': /* set debug level */
73 debug_level = atoi(optarg);
74 if (debug_level <= 0) {
83 case 'i': /* ignore case */
105 printf("A data file must be specified.\n");
112 printf("Enter a wild-card: ");
113 if (fgets(pat, sizeof(pat)-1, stdin) == NULL) {
116 strip_trailing_newline(pat);
120 fd = fopen(fname, "r");
122 printf(_("Could not open data file: %s\n"), fname);
126 while (fgets(data, sizeof(data)-1, fd)) {
127 strip_trailing_newline(data);
129 rc = fnmatch(pat, data, ic);
130 if ((match_only && rc == 0) || (!match_only && rc != 0)) {
132 printf("%s\n", data);
134 printf("%5d: %s\n", lineno, data);