2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2016 Kern Sibbald
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Test program for testing regular expressions.
29 * If you define BACULA_REGEX, bregex will be built with the
30 * Bacula bregex library, which is the same code that we
31 * use on Win32, thus using Linux, you can test your Win32
32 * expressions. Otherwise, this program will link with the
33 * system library routines.
35 //#define BACULA_REGEX
39 #include "lib/bregex.h"
43 #include "lib/bregex.h"
55 "Usage: bregex [-d debug_level] -f <data-file>\n"
56 " -f specify file of data to be matched\n"
57 " -l suppress line numbers\n"
58 " -n print lines that do not match\n"
59 " -d <nn> set debug level to <nn>\n"
60 " -dt print timestamp in debug output\n"
61 " -? print this message.\n"
68 int main(int argc, char *const *argv)
77 bool match_only = true;
79 bool no_linenos = false;
82 setlocale(LC_ALL, "");
83 bindtextdomain("bacula", LOCALEDIR);
86 while ((ch = getopt(argc, argv, "d:f:n?")) != -1) {
88 case 'd': /* set debug level */
92 debug_level = atoi(optarg);
93 if (debug_level <= 0) {
121 printf("A data file must be specified.\n");
128 printf("Enter regex pattern: ");
129 if (fgets(pat, sizeof(pat)-1, stdin) == NULL) {
132 strip_trailing_newline(pat);
136 rc = regcomp(&preg, pat, REG_EXTENDED);
138 regerror(rc, &preg, prbuf, sizeof(prbuf));
139 printf("Regex compile error: %s\n", prbuf);
142 fd = fopen(fname, "r");
144 printf(_("Could not open data file: %s\n"), fname);
148 while (fgets(data, sizeof(data)-1, fd)) {
149 const int nmatch = 30;
150 regmatch_t pmatch[nmatch];
151 strip_trailing_newline(data);
153 rc = regexec(&preg, data, nmatch, pmatch, 0);
154 if ((match_only && rc == 0) || (!match_only && rc != 0)) {
156 printf("%s\n", data);
158 printf("%5d: %s\n", lineno, data);