Merge the two copies of strcmp_underscore().
authorChristoph Mallon <christoph.mallon@gmx.de>
Wed, 14 Sep 2011 08:38:18 +0000 (10:38 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Wed, 14 Sep 2011 08:38:18 +0000 (10:38 +0200)
adt/strutil.c [new file with mode: 0644]
adt/strutil.h
attribute.c
parser.c

diff --git a/adt/strutil.c b/adt/strutil.c
new file mode 100644 (file)
index 0000000..7dd219a
--- /dev/null
@@ -0,0 +1,15 @@
+#include "strutil.h"
+
+
+int strcmp_underscore(const char *const s1, const char *const s2)
+{
+       if (s2[0] == '_' && s2[1] == '_') {
+               size_t len2 = strlen(s2);
+               size_t len1 = strlen(s1);
+               if (len1 == len2 - 4 && s2[len2 - 2] == '_' && s2[len2 - 1] == '_') {
+                       return strncmp(s1, s2 + 2, len2 - 4);
+               }
+       }
+
+       return strcmp(s1, s2);
+}
index 6c4f6fb..ca0ec45 100644 (file)
@@ -18,4 +18,9 @@ static inline char const* strstart(char const* str, char const* start)
        return NULL;
 }
 
+/**
+ * compare two strings, ignoring double underscores on the second.
+ */
+int strcmp_underscore(const char *s1, const char *s2);
+
 #endif
index 9dec22d..a7deee5 100644 (file)
@@ -20,6 +20,7 @@
 #include <config.h>
 
 #include <assert.h>
+#include "adt/strutil.h"
 #include "diagnostic.h"
 #include "warning.h"
 #include "attribute_t.h"
@@ -119,22 +120,6 @@ const char *get_attribute_name(attribute_kind_t kind)
        return attribute_names[kind];
 }
 
-/**
- * compare two string, ignoring double underscores on the second.
- */
-static int strcmp_underscore(const char *s1, const char *s2)
-{
-       if (s2[0] == '_' && s2[1] == '_') {
-               size_t len2 = strlen(s2);
-               size_t len1 = strlen(s1);
-               if (len1 == len2-4 && s2[len2-2] == '_' && s2[len2-1] == '_') {
-                       return strncmp(s1, s2+2, len2-4);
-               }
-       }
-
-       return strcmp(s1, s2);
-}
-
 type_t *handle_attribute_mode(const attribute_t *attribute, type_t *orig_type)
 {
        type_t *type = skip_typeref(orig_type);
index 3c59f9e..65aa04e 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -23,6 +23,7 @@
 #include <stdarg.h>
 #include <stdbool.h>
 
+#include "adt/strutil.h"
 #include "parser.h"
 #include "diagnostic.h"
 #include "format_check.h"
@@ -1071,22 +1072,6 @@ static string_t parse_string_literals(void)
        return result;
 }
 
-/**
- * compare two string, ignoring double underscores on the second.
- */
-static int strcmp_underscore(const char *s1, const char *s2)
-{
-       if (s2[0] == '_' && s2[1] == '_') {
-               size_t len2 = strlen(s2);
-               size_t len1 = strlen(s1);
-               if (len1 == len2-4 && s2[len2-2] == '_' && s2[len2-1] == '_') {
-                       return strncmp(s1, s2+2, len2-4);
-               }
-       }
-
-       return strcmp(s1, s2);
-}
-
 static attribute_t *allocate_attribute_zero(attribute_kind_t kind)
 {
        attribute_t *attribute = allocate_ast_zero(sizeof(*attribute));