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"
27 "Usage: bwild [-d debug_level] -f <data-file>\n"
28 " -f specify file of data to be matched\n"
29 " -i use case insenitive match\n"
30 " -l suppress line numbers\n"
31 " -n print lines that do not match\n"
32 " -? print this message.\n"
38 int main(int argc, char *const *argv)
45 bool match_only = true;
47 bool no_linenos = false;
51 setlocale(LC_ALL, "");
52 bindtextdomain("bacula", LOCALEDIR);
55 while ((ch = getopt(argc, argv, "d:f:in?")) != -1) {
57 case 'd': /* set debug level */
58 debug_level = atoi(optarg);
59 if (debug_level <= 0) {
68 case 'i': /* ignore case */
90 printf("A data file must be specified.\n");
95 printf("Enter a wild-card: ");
96 if (fgets(pat, sizeof(pat)-1, stdin) == NULL) {
99 strip_trailing_newline(pat);
103 fd = fopen(fname, "r");
105 printf(_("Could not open data file: %s\n"), fname);
109 while (fgets(data, sizeof(data)-1, fd)) {
110 strip_trailing_newline(data);
112 rc = fnmatch(pat, data, ic);
113 if ((match_only && rc == 0) || (!match_only && rc != 0)) {
115 printf("%s\n", data);
117 printf("%5d: %s\n", lineno, data);