move a function into rx.[hc]
authorPierre Habouzit <madcoder@debian.org>
Sun, 12 Nov 2006 00:05:51 +0000 (01:05 +0100)
committerPierre Habouzit <madcoder@debian.org>
Sun, 12 Nov 2006 00:05:51 +0000 (01:05 +0100)
Signed-off-by: Pierre Habouzit <madcoder@debian.org>
lib-lib/debug.h
lib-lib/rx.c
lib-lib/rx.h
lib.c
lib.h
muttlib.c

index ece3823..bdb9d8f 100644 (file)
@@ -27,8 +27,8 @@
 
 /* generic interface for debug messages */
 
 
 /* generic interface for debug messages */
 
-#ifndef _LIB_DEBUG_H
-#define _LIB_DEBUG_H
+#ifndef MUTT_LIB_LIB_DEBUG_H
+#define MUTT_LIB_LIB_DEBUG_H
 
 #include <stdio.h>
 
 
 #include <stdio.h>
 
@@ -94,4 +94,4 @@ void _debug_print_msg (const char*, ...);
 
 #endif /* !DEBUG */
 
 
 #endif /* !DEBUG */
 
-#endif /* !_LIB_DEBUG_H */
+#endif /* MUTT_LIB_LIB_DEBUG_H */
index 6413f69..975ed52 100644 (file)
@@ -81,3 +81,27 @@ int rx_lookup (list2_t *l, const char *pat)
 
     return -1;
 }
 
     return -1;
 }
+
+int rx_sanitize_string(char *dst, ssize_t n, const char *src)
+{
+    while (*src) {
+        if (n <= 1)
+            break;
+
+        /* these characters must be escaped in regular expressions */
+        if (strchr("^.[$()|*+?{\\", *src)) {
+            if (n <= 2)
+                break;
+
+            *dst++ = '\\';
+            n--;
+        }
+
+        *dst++ = *src++;
+        n--;
+    }
+
+    *dst = '\0';
+
+    return *src ? -1 : 0;
+}
index 48e295b..0341a19 100644 (file)
@@ -26,8 +26,8 @@
  * this is an internal abstraction layer for regular expressions
  */
 
  * this is an internal abstraction layer for regular expressions
  */
 
-#ifndef _LIB_RX_H
-#define _LIB_RX_H
+#ifndef MUTT_LIB_LIB_RX_H
+#define MUTT_LIB_LIB_RX_H
 
 #include <sys/types.h>
 #include <regex.h>
 
 #include <sys/types.h>
 #include <regex.h>
@@ -53,8 +53,10 @@ void rx_delete(rx_t **);
 /* for handling lists */
 int rx_list_match(list2_t*, const char*);      /* match all items list agains string */
 int rx_lookup(list2_t*, const char*);          /* lookup pattern */
 /* for handling lists */
 int rx_list_match(list2_t*, const char*);      /* match all items list agains string */
 int rx_lookup(list2_t*, const char*);          /* lookup pattern */
+int rx_sanitize_string(char *, ssize_t, const char *);
+
 
 #define REGCOMP(X,Y,Z)  regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
 #define REGEXEC(X,Y)    regexec(X, Y, 0, NULL, 0)
 
 
 #define REGCOMP(X,Y,Z)  regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
 #define REGEXEC(X,Y)    regexec(X, Y, 0, NULL, 0)
 
-#endif /* !_LIB_RX_H */
+#endif /* !MUTT_LIB_LIB_RX_H */
diff --git a/lib.c b/lib.c
index 2d0ec11..d07878a 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -109,28 +109,6 @@ void mutt_nocurses_error (const char *fmt, ...)
 }
 
 
 }
 
 
-/* these characters must be escaped in regular expressions */
-
-static char rx_special_chars[] = "^.[$()|*+?{\\";
-
-int mutt_rx_sanitize_string (char *dest, size_t destlen, const char *src)
-{
-  while (*src && --destlen > 2) {
-    if (strchr (rx_special_chars, *src)) {
-      *dest++ = '\\';
-      destlen--;
-    }
-    *dest++ = *src++;
-  }
-
-  *dest = '\0';
-
-  if (*src)
-    return -1;
-  else
-    return 0;
-}
-
 const char *
 mutt_strsysexit(int e)
 {
 const char *
 mutt_strsysexit(int e)
 {
diff --git a/lib.h b/lib.h
index 457ab92..44a793a 100644 (file)
--- a/lib.h
+++ b/lib.h
@@ -37,8 +37,6 @@ void mutt_exit (int);
 
 /* The actual library functions. */
 
 
 /* The actual library functions. */
 
-int mutt_rx_sanitize_string (char *, size_t, const char *);
-
 void mutt_nocurses_error (const char *, ...);
 
 const char *mutt_strsysexit(int e);
 void mutt_nocurses_error (const char *, ...);
 
 const char *mutt_strsysexit(int e);
index 6d8b874..729c050 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -387,7 +387,7 @@ char *_mutt_expand_path (char *s, size_t slen, int rx)
     }
 
     if (rx && *p && !recurse) {
     }
 
     if (rx && *p && !recurse) {
-      mutt_rx_sanitize_string (q, sizeof (q), p);
+      rx_sanitize_string (q, sizeof (q), p);
       snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
     }
     else
       snprintf (tmp, sizeof (tmp), "%s%s", q, tail);
     }
     else