]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
Add support for approximate matching in other tools
authorAnatoly Burakov <anatoly.burakov@intel.com>
Fri, 10 Feb 2017 15:45:09 +0000 (15:45 +0000)
committerMatthew Barr <matthew.barr@intel.com>
Wed, 26 Apr 2017 05:15:12 +0000 (15:15 +1000)
tools/hsbench/common.h
tools/hsbench/engine_hyperscan.cpp
tools/hsbench/main.cpp

index a4d60021a409164f92139ee23455ba05ff9277fa..efff3f99da558b39b217a18488b03435770b3314 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Intel Corporation
+ * Copyright (c) 2016-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -38,5 +38,7 @@ extern bool saveDatabases;
 extern bool loadDatabases;
 extern std::string serializePath;
 extern unsigned int somPrecisionMode;
+extern bool forceEditDistance;
+extern unsigned editDistance;
 
 #endif // COMMON_H
index f5abb9fafb29014147e0d6bb4e89df05d4e22513..eadc1cc4c75aadb07dee0db27235a4a1cba807f7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Intel Corporation
+ * Copyright (c) 2016-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -289,6 +289,10 @@ buildEngineHyperscan(const ExpressionMap &expressions, ScanMode scan_mode,
                        m.first);
                 return nullptr;
             }
+            if (forceEditDistance) {
+                extparam.flags |= HS_EXT_FLAG_EDIT_DISTANCE;
+                extparam.edit_distance = editDistance;
+            }
 
             exprs.push_back(expr);
             ids.push_back(m.first);
index 4298963b933e70d8eda062e813acf7f18a2aa417..a99760a2e4e5ccde451138773956b6871be508b1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Intel Corporation
+ * Copyright (c) 2016-2017, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -72,6 +72,8 @@ bool saveDatabases = false;
 bool loadDatabases = false;
 string serializePath("");
 unsigned int somPrecisionMode = HS_MODE_SOM_HORIZON_LARGE;
+bool forceEditDistance = false;
+unsigned editDistance = 0;
 
 namespace /* anonymous */ {
 
@@ -169,6 +171,8 @@ void usage(const char *error) {
            " instead.\n");
     printf("  -w DIR          After compiling, save to files in DIR.\n");
     printf("  -d NUMBER       Set SOM precision mode (default: 8 (large)).\n");
+    printf("  -E DISTANCE     Match all patterns within edit distance"
+           " DISTANCE.\n");
     printf("\n");
     printf("  --per-scan      Display per-scan Mbit/sec results.\n");
     printf("  --echo-matches  Display all matches that occur during scan.\n");
@@ -191,7 +195,7 @@ struct BenchmarkSigs {
 static
 void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
                  UNUSED Grey &grey) {
-    const char options[] = "-b:c:Cd:e:G:hi:n:No:p:sT:Vw:z:";
+    const char options[] = "-b:c:Cd:e:E:G:hi:n:No:p:sT:Vw:z:";
     int in_sigfile = 0;
     int do_per_scan = 0;
     int do_echo_matches = 0;
@@ -237,6 +241,14 @@ void processArgs(int argc, char *argv[], vector<BenchmarkSigs> &sigSets,
         case 'e':
             exprPath.assign(optarg);
             break;
+        case 'E':
+            if (!fromString(optarg, editDistance)) {
+                usage("Couldn't parse argument to -E flag, should be"
+                      " a non-negative integer.");
+                exit(1);
+            }
+            forceEditDistance = true;
+            break;
 #ifndef RELEASE_BUILD
         case 'G':
             applyGreyOverrides(&grey, string(optarg));