From 7b8296cfa5c33fbc73c34c4fe1ff6d7bfbaaba01 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 12 Nov 2006 01:05:51 +0100 Subject: [PATCH 1/1] move a function into rx.[hc] Signed-off-by: Pierre Habouzit --- lib-lib/debug.h | 6 +++--- lib-lib/rx.c | 24 ++++++++++++++++++++++++ lib-lib/rx.h | 8 +++++--- lib.c | 22 ---------------------- lib.h | 2 -- muttlib.c | 2 +- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/lib-lib/debug.h b/lib-lib/debug.h index ece3823..bdb9d8f 100644 --- a/lib-lib/debug.h +++ b/lib-lib/debug.h @@ -27,8 +27,8 @@ /* 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 @@ -94,4 +94,4 @@ void _debug_print_msg (const char*, ...); #endif /* !DEBUG */ -#endif /* !_LIB_DEBUG_H */ +#endif /* MUTT_LIB_LIB_DEBUG_H */ diff --git a/lib-lib/rx.c b/lib-lib/rx.c index 6413f69..975ed52 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -81,3 +81,27 @@ int rx_lookup (list2_t *l, const char *pat) 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; +} diff --git a/lib-lib/rx.h b/lib-lib/rx.h index 48e295b..0341a19 100644 --- a/lib-lib/rx.h +++ b/lib-lib/rx.h @@ -26,8 +26,8 @@ * 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 #include @@ -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 */ +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) -#endif /* !_LIB_RX_H */ +#endif /* !MUTT_LIB_LIB_RX_H */ diff --git a/lib.c b/lib.c index 2d0ec11..d07878a 100644 --- 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) { diff --git a/lib.h b/lib.h index 457ab92..44a793a 100644 --- a/lib.h +++ b/lib.h @@ -37,8 +37,6 @@ void mutt_exit (int); /* 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); diff --git a/muttlib.c b/muttlib.c index 6d8b874..729c050 100644 --- 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) { - mutt_rx_sanitize_string (q, sizeof (q), p); + rx_sanitize_string (q, sizeof (q), p); snprintf (tmp, sizeof (tmp), "%s%s", q, tail); } else -- 2.20.1