assume regex.h exists
authorMatthias Braun <matze@braunis.de>
Thu, 14 Apr 2011 13:40:08 +0000 (15:40 +0200)
committerMatthias Braun <matze@braunis.de>
Fri, 15 Apr 2011 14:11:24 +0000 (16:11 +0200)
ir/stat/statev.c
win32/regex.h [new file with mode: 0644]

index 4d5c9e1..96e20a6 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <regex.h>
 
 #include "util.h"
 #include "stat_timing.h"
 
 #include "util.h"
 #include "stat_timing.h"
 
 #ifndef DISABLE_STATEV
 
 
 #ifndef DISABLE_STATEV
 
-#ifdef HAVE_REGEX_H
-#define FIRM_HAVE_REGEX
-#endif
-
 #define MAX_TIMER 256
 
 static FILE* stat_ev_file  = NULL;
 #define MAX_TIMER 256
 
 static FILE* stat_ev_file  = NULL;
@@ -54,8 +51,6 @@ int            stat_ev_timer_sp = 0;
 timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
 timing_ticks_t stat_ev_timer_start[MAX_TIMER];
 
 timing_ticks_t stat_ev_timer_elapsed[MAX_TIMER];
 timing_ticks_t stat_ev_timer_start[MAX_TIMER];
 
-#ifdef FIRM_HAVE_REGEX
-#include <regex.h>
 static regex_t regex;
 static regex_t *filter = NULL;
 static inline int key_matches(const char *key)
 static regex_t regex;
 static regex_t *filter = NULL;
 static inline int key_matches(const char *key)
@@ -66,22 +61,6 @@ static inline int key_matches(const char *key)
        return regexec(filter, key, 0, NULL, 0) == 0;
 }
 
        return regexec(filter, key, 0, NULL, 0) == 0;
 }
 
-#else
-static char filter[128] = { '\0' };
-static inline int key_matches(const char *key)
-{
-       int i = 0;
-
-       for (i = 0; filter[i] != '\0'; ++i) {
-               if (key[i] != filter[i])
-                       return 0;
-       }
-
-       return 1;
-}
-#endif /* FIRM_HAVE_REGEX */
-
-
 void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
 {
        if (!key_matches(key))
 void stat_ev_printf(char ev, const char *key, const char *fmt, ...)
 {
        if (!key_matches(key))
@@ -108,13 +87,9 @@ void stat_ev_begin(const char *prefix, const char *filt)
        stat_ev_file = fopen(buf, "wt");
 
        if (filt && filt[0] != '\0') {
        stat_ev_file = fopen(buf, "wt");
 
        if (filt && filt[0] != '\0') {
-#ifdef FIRM_HAVE_REGEX
                filter = NULL;
                if (regcomp(&regex, filt, REG_EXTENDED) == 0)
                        filter = &regex;
                filter = NULL;
                if (regcomp(&regex, filt, REG_EXTENDED) == 0)
                        filter = &regex;
-#else
-               strncpy(filter, filt, sizeof(filter) - sizeof(filter[0]));
-#endif /* FIRM_HAVE_REGEX */
        }
 
        stat_ev_enabled = stat_ev_file != NULL;
        }
 
        stat_ev_enabled = stat_ev_file != NULL;
@@ -125,6 +100,9 @@ void stat_ev_end(void)
        if (stat_ev_file) {
                fclose(stat_ev_file);
        }
        if (stat_ev_file) {
                fclose(stat_ev_file);
        }
+       if (filter != NULL)
+               regfree(filter);
+       regfree(filter);
 }
 
 #endif
 }
 
 #endif
diff --git a/win32/regex.h b/win32/regex.h
new file mode 100644 (file)
index 0000000..e7337bc
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef REGEX_H
+#define REGEX_H
+
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* naive and wrong regex stubs */
+typedef struct regex_t {
+       char *pattern;
+} regex_t;
+
+#define REG_EXTENDED 1
+#define REG_ICASE    2
+#define REG_NOSUB    4
+#define REG_NEWLINE  8
+
+int regcomp(regex_t *regex, const char *pattern, int cflags)
+{
+       size_t len = strlen(pattern)+1;
+       (void) cflags;
+       regex->pattern = malloc(len);
+       memcpy(regex->pattern, pattern, len);
+}
+
+int regexec(const regex_t *regex, const char *haystack, int flags)
+{
+       size_t i = 0;
+       const char *pattern = regex->pattern;
+       for (i = 0; pattern[i] != '\0'; ++i) {
+               if (pattern[i] != haystack[i])
+                       return 0;
+       }
+       return 1;
+}
+
+void regfree(regex_t *regex)
+{
+       free(regex->pattern);
+}
+
+#endif