]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/tools/bregtest.c
ebl Add program to validate TCDBM lib with accurate mode
[bacula/bacula] / bacula / src / tools / bregtest.c
index edf7604e7d9bb34c1da4ee808e71da19b3577a79..326d6f654bd5673a8caedeaabf708375a9d2666e 100644 (file)
@@ -13,8 +13,8 @@
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
    modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -50,9 +50,12 @@ static void usage()
 {
    fprintf(stderr,
 "\n"
-"Usage: bregex [-d debug_level] -f <data-file> -e /test/test2/\n"
+"Usage: bregtest [-d debug_level] [-s] -f <data-file> -e /test/test2/\n"
 "       -f          specify file of data to be matched\n"
 "       -e          specify expression\n"
+"       -s          sed output\n"
+"       -d <nn>     set debug level to <nn>\n"
+"       -dt         print timestamp in debug output\n"
 "       -?          print this message.\n"
 "\n");
 
@@ -65,6 +68,7 @@ int main(int argc, char *const *argv)
    char *fname = NULL;
    char *expr = NULL;
    int ch;
+   bool sed=false;
    char data[1000];
    FILE *fd;
 
@@ -72,12 +76,16 @@ int main(int argc, char *const *argv)
    bindtextdomain("bacula", LOCALEDIR);
    textdomain("bacula");
 
-   while ((ch = getopt(argc, argv, "d:f:e:")) != -1) {
+   while ((ch = getopt(argc, argv, "sd:f:e:")) != -1) {
       switch (ch) {
       case 'd':                       /* set debug level */
-         debug_level = atoi(optarg);
-         if (debug_level <= 0) {
-            debug_level = 1;
+         if (*optarg == 't') {
+            dbg_timestamp = true;
+         } else {
+            debug_level = atoi(optarg);
+            if (debug_level <= 0) {
+               debug_level = 1;
+            }
          }
          break;
 
@@ -89,6 +97,10 @@ int main(int argc, char *const *argv)
          expr = optarg;
          break;
 
+      case 's':
+        sed=true;
+        break;
+
       case '?':
       default:
          usage();
@@ -129,7 +141,11 @@ int main(int argc, char *const *argv)
    while (fgets(data, sizeof(data)-1, fd)) {
       strip_trailing_newline(data);
       apply_bregexps(data, list, &p);
-      printf("%s => %s\n", data, p);
+      if (sed) {
+        printf("%s\n", p);
+      } else {
+        printf("%s => %s\n", data, p);
+      }
    }
    fclose(fd);
    free_bregexps(list);