aboutsummaryrefslogtreecommitdiff
path: root/src/regex/perf-regex.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-12-17 12:35:19 +0000
committerBart Polot <bart@net.in.tum.de>2012-12-17 12:35:19 +0000
commit11cc044427e734c83af65ee340dd10ec70c97b1c (patch)
tree2c807dc234644519ff2f341cf6ca2f1cb2a084f2 /src/regex/perf-regex.c
parent07ce0aaf09b4bcdf37b1524a9a497d4a185aba91 (diff)
downloadgnunet-11cc044427e734c83af65ee340dd10ec70c97b1c.tar.gz
gnunet-11cc044427e734c83af65ee340dd10ec70c97b1c.zip
- move regex_from_file and combine to separate lib file
Diffstat (limited to 'src/regex/perf-regex.c')
-rw-r--r--src/regex/perf-regex.c50
1 files changed, 3 insertions, 47 deletions
diff --git a/src/regex/perf-regex.c b/src/regex/perf-regex.c
index e0ac7b3d2..f1d21f564 100644
--- a/src/regex/perf-regex.c
+++ b/src/regex/perf-regex.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file regex/prof-regex.c 22 * @file src/regex/prof-regex.c
23 * @brief Test how long it takes to create a automaton from a string regex. 23 * @brief Test how long it takes to create a automaton from a string regex.
24 * @author Bartlomiej Polot 24 * @author Bartlomiej Polot
25 */ 25 */
@@ -27,6 +27,7 @@
27#include <time.h> 27#include <time.h>
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_regex_lib.h" 29#include "gnunet_regex_lib.h"
30#include "regex_test_lib.h"
30 31
31static const char *exe; 32static const char *exe;
32 33
@@ -54,8 +55,6 @@ main (int argc, char *const *argv)
54 unsigned int i; 55 unsigned int i;
55 int compression; 56 int compression;
56 long size; 57 long size;
57 size_t len;
58 FILE *f;
59 58
60 GNUNET_log_setup ("perf-regex", "DEBUG", NULL); 59 GNUNET_log_setup ("perf-regex", "DEBUG", NULL);
61 exe = argv[0]; 60 exe = argv[0];
@@ -64,50 +63,7 @@ main (int argc, char *const *argv)
64 usage(); 63 usage();
65 return 1; 64 return 1;
66 } 65 }
67 f = fopen (argv[1], "r"); 66 regexes = GNUNET_REGEX_read_from_file (argv[1]);
68 if (NULL == f)
69 {
70 fprintf (stderr, "Can't open file %s\n", argv[1]);
71 usage();
72 return 2;
73 }
74 fseek (f, 0, SEEK_END);
75 size = ftell (f);
76 fprintf (stderr, "using file %s, size %ld\n", argv[1], size);
77 fseek (f, 0, SEEK_SET);
78 buffer = GNUNET_malloc (size + 1);
79 regexes = GNUNET_malloc (sizeof (char *));
80 nr = 1;
81 do
82 {
83 if (NULL == fgets (buffer, size + 1, f))
84 {
85 fprintf (stderr, "Can't read file %s\n", argv[1]);
86 usage();
87 return 3;
88 }
89 len = strlen (buffer);
90 if (len < 1)
91 continue;
92 if ('\n' == buffer[len - 1])
93 {
94 len--;
95 buffer[len] = '\0';
96 }
97 if (len < 6 || strncmp (&buffer[len - 6], "(0|1)*", 6) != 0)
98 {
99 fprintf (stderr, "\nWARNING:\n");
100 fprintf (stderr, "%s (line %u) does not end in (0|1)*\n", buffer, nr);
101 }
102 else
103 {
104 buffer[len - 6] = '\0';
105 }
106 GNUNET_array_grow (regexes, nr, nr+1);
107 regexes[nr - 2] = GNUNET_strdup (buffer);
108 regexes[nr - 1] = NULL;
109 } while (ftell(f) < size);
110 GNUNET_free (buffer);
111 67
112 buffer = GNUNET_REGEX_combine (regexes); 68 buffer = GNUNET_REGEX_combine (regexes);
113 69