2 * Test program for testing wild card expressions
5 Copyright (C) 2006 Kern Sibbald
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as amended with additional clauses defined in the
10 file LICENSE in the main source directory.
12 This program 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
15 the file LICENSE for additional details.
20 #include "lib/fnmatch.h"
26 "Usage: bwild [-d debug_level] -f <data-file>\n"
27 " -f specify file of data to be matched\n"
28 " -i use case insenitive match\n"
29 " -l suppress line numbers\n"
30 " -n print lines that do not match\n"
31 " -? print this message.\n"
37 int main(int argc, char *const *argv)
44 bool match_only = true;
46 bool no_linenos = false;
50 setlocale(LC_ALL, "");
51 bindtextdomain("bacula", LOCALEDIR);
54 while ((ch = getopt(argc, argv, "d:f:in?")) != -1) {
56 case 'd': /* set debug level */
57 debug_level = atoi(optarg);
58 if (debug_level <= 0) {
67 case 'i': /* ignore case */
89 printf("A data file must be specified.\n");
94 printf("Enter a wild-card: ");
95 if (fgets(pat, sizeof(pat)-1, stdin) == NULL) {
98 strip_trailing_newline(pat);
102 fd = fopen(fname, "r");
104 printf(_("Could not open data file: %s\n"), fname);
108 while (fgets(data, sizeof(data)-1, fd)) {
109 strip_trailing_newline(data);
111 rc = fnmatch(pat, data, ic);
112 if ((match_only && rc == 0) || (!match_only && rc != 0)) {
114 printf("%s\n", data);
116 printf("%5d: %s\n", lineno, data);