]> git.ipfire.org Git - thirdparty/vectorscan.git/commitdiff
limex_dump: use StdioFile, tidy
authorJustin Viiret <justin.viiret@intel.com>
Thu, 29 Jun 2017 03:03:52 +0000 (13:03 +1000)
committerMatthew Barr <matthew.barr@intel.com>
Mon, 21 Aug 2017 01:12:16 +0000 (11:12 +1000)
src/nfa/limex_dump.cpp

index 797e87ba2580be3a4091f81e0b01518290145a34..9256c841cbdf387a4dac29544078e83259e32354 100644 (file)
@@ -487,25 +487,24 @@ void dumpLimDotInfo(const limex_type *limex, u32 state, FILE *f) {
     }
 }
 
+template<typename limex_type>
+static
+void dumpLimexDot(const NFA *nfa, const limex_type *limex, FILE *f) {
+    dumpDotPreamble(f);
+    u32 state_count = nfa->nPositions;
+    dumpVertexDotInfo(limex, state_count, f, limex_labeller<limex_type>(limex));
+    for (u32 i = 0; i < state_count; i++) {
+        dumpLimDotInfo(limex, i, f);
+        dumpExDotInfo(limex, i, f);
+    }
+    dumpDotTrailer(f);
+}
+
 #define LIMEX_DUMP_FN(size)                                                    \
     void nfaExecLimEx##size##_dump(const NFA *nfa, const string &base) {       \
         auto limex = (const LimExNFA##size *)getImplNfa(nfa);                  \
-                                                                               \
-        FILE *f = fopen_or_throw((base + ".txt").c_str(), "w");                \
-        dumpLimexText(limex, f);                                               \
-        fclose(f);                                                             \
-                                                                               \
-        f = fopen_or_throw((base + ".dot").c_str(), "w");                      \
-        dumpDotPreamble(f);                                                    \
-        u32 state_count = nfa->nPositions;                                     \
-        dumpVertexDotInfo(limex, state_count, f,                               \
-                          limex_labeller<LimExNFA##size>(limex));              \
-        for (u32 i = 0; i < state_count; i++) {                                \
-            dumpLimDotInfo(limex, i, f);                                       \
-            dumpExDotInfo(limex, i, f);                                        \
-        }                                                                      \
-        dumpDotTrailer(f);                                                     \
-        fclose(f);                                                             \
+        dumpLimexText(limex, StdioFile(base + ".txt", "w"));                   \
+        dumpLimexDot(nfa, limex, StdioFile(base + ".dot", "w"));               \
     }
 
 LIMEX_DUMP_FN(32)