]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/match.c
Rename ShowInvitesBans() to ShowChannelList(), make it more flexible
[ngircd-alex.git] / src / ngircd / match.c
index 2748a3e4569e3fa5631ba82060a76afa6921f718..79699ea0d8740b7cf555af732d3c22ec1dfc9861 100644 (file)
@@ -7,14 +7,14 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
- *
- * Wildcard pattern matching
  */
 
-
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: match.c,v 1.4 2005/07/31 20:13:08 alex Exp $";
+/**
+ * @file
+ * Wildcard pattern matching
+ */
 
 #include "imp.h"
 #include <assert.h>
@@ -22,30 +22,38 @@ static char UNUSED id[] = "$Id: match.c,v 1.4 2005/07/31 20:13:08 alex Exp $";
 
 #include "exp.h"
 #include "match.h"
+#include "defines.h"
+#include "tool.h"
 
 
 /*
- * Die Pattern-Matching-Funkionen [Matche(), Matche_After_Star()] basieren
- * auf Versionen von J. Kercheval. Die Version 1.1 wurde am 12.03.1991 als
- * "public domain" freigegeben:
- * <http://www.snippets.org/snippets/portable/MATCH+C.php3>
+ * The pattern matching functions [Matche(), Matche_After_Star()] are based
+ * on code of J. Kercheval. Version 1.1 has been released on 1991-03-12 as
+ * "public domain": <http://c.snippets.org/snip_lister.php?fname=match.c>
  */
 
 
-static int Matche PARAMS(( char *p, char *t ));
-static int Matche_After_Star PARAMS(( char *p, char *t ));
+static int Matche PARAMS(( const char *p, const char *t ));
+static int Matche_After_Star PARAMS(( const char *p, const char *t ));
 
 
-#define MATCH_PATTERN  6       /* bad pattern */
-#define MATCH_LITERAL  5       /* match failure on literal match */
-#define MATCH_RANGE    4       /* match failure on [..] construct */
-#define MATCH_ABORT    3       /* premature end of text string */
-#define MATCH_END      2       /* premature end of pattern string */
-#define MATCH_VALID    1       /* valid match */
+#define MATCH_PATTERN  6       /**< bad pattern */
+#define MATCH_LITERAL  5       /**< match failure on literal match */
+#define MATCH_RANGE    4       /**< match failure on [..] construct */
+#define MATCH_ABORT    3       /**< premature end of text string */
+#define MATCH_END      2       /**< premature end of pattern string */
+#define MATCH_VALID    1       /**< valid match */
 
 
+/**
+ * Match string with pattern.
+ *
+ * @param Pattern      Pattern to match with
+ * @param String       Input string
+ * @return             true if pattern matches
+ */
 GLOBAL bool
-Match( char *Pattern, char *String )
+Match( const char *Pattern, const char *String )
 {
        /* Pattern mit String vergleichen */
        if( Matche( Pattern, String ) == MATCH_VALID ) return true;
@@ -53,8 +61,25 @@ Match( char *Pattern, char *String )
 } /* Match */
 
 
+/**
+ * Match string with pattern case-insensitive.
+ *
+ * @param pattern      Pattern to match with
+ * @param searchme     Input string, at most COMMAND_LEN-1 characters long
+ * @return             true if pattern matches
+ */
+GLOBAL bool
+MatchCaseInsensitive(const char *pattern, const char *searchme)
+{
+       char haystack[COMMAND_LEN];
+
+       strlcpy(haystack, searchme, sizeof(haystack));
+       return Match(pattern, ngt_LowerStr(haystack));
+} /* MatchCaseInsensitive */
+
+
 static int
-Matche( char *p, char *t )
+Matche( const char *p, const char *t )
 {
        register char range_start, range_end;
        bool invert;
@@ -201,7 +226,7 @@ Matche( char *p, char *t )
 
 
 static int
-Matche_After_Star( char *p, char *t )
+Matche_After_Star( const char *p, const char *t )
 {
        register int nextp, match = 0;