2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2015 Kern Sibbald
5 Copyright (C) 2006-2014 Free Software Foundation Europe e.V.
7 The original author of Bacula is Kern Sibbald, with contributions
8 from many others, a complete list can be found in the file AUTHORS.
10 You may use this file and others of this release according to the
11 license defined in the LICENSE file, which includes the Affero General
12 Public License, v3.0 ("AGPLv3") and some additional permissions and
13 terms pursuant to its AGPLv3 Section 7.
15 This notice must be preserved when any source code is
16 conveyed and/or propagated.
18 Bacula(R) is a registered trademark of Kern Sibbald.
21 * Test program for testing regular expressions.
30 * If you define BACULA_REGEX, bregex will be built with the
31 * Bacula bregex library, which is the same code that we
32 * use on Win32, thus using Linux, you can test your Win32
33 * expressions. Otherwise, this program will link with the
34 * system library routines.
36 //#define BACULA_REGEX
40 #include "lib/bregex.h"
44 #include "lib/bregex.h"
56 "Usage: bregex [-d debug_level] -f <data-file>\n"
57 " -f specify file of data to be matched\n"
58 " -l suppress line numbers\n"
59 " -n print lines that do not match\n"
60 " -d <nn> set debug level to <nn>\n"
61 " -dt print timestamp in debug output\n"
62 " -? print this message.\n"
69 int main(int argc, char *const *argv)
78 bool match_only = true;
80 bool no_linenos = false;
83 setlocale(LC_ALL, "");
84 bindtextdomain("bacula", LOCALEDIR);
87 while ((ch = getopt(argc, argv, "d:f:n?")) != -1) {
89 case 'd': /* set debug level */
93 debug_level = atoi(optarg);
94 if (debug_level <= 0) {
122 printf("A data file must be specified.\n");
129 printf("Enter regex pattern: ");
130 if (fgets(pat, sizeof(pat)-1, stdin) == NULL) {
133 strip_trailing_newline(pat);
137 rc = regcomp(&preg, pat, REG_EXTENDED);
139 regerror(rc, &preg, prbuf, sizeof(prbuf));
140 printf("Regex compile error: %s\n", prbuf);
143 fd = fopen(fname, "r");
145 printf(_("Could not open data file: %s\n"), fname);
149 while (fgets(data, sizeof(data)-1, fd)) {
150 const int nmatch = 30;
151 regmatch_t pmatch[nmatch];
152 strip_trailing_newline(data);
154 rc = regexec(&preg, data, nmatch, pmatch, 0);
155 if ((match_only && rc == 0) || (!match_only && rc != 0)) {
157 printf("%s\n", data);
159 printf("%5d: %s\n", lineno, data);