]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/match.c
Fix typos/errors/... in file comments
[ngircd-alex.git] / src / ngircd / match.c
index 88872f0d9102353b83e79cc6274be451acc58f45..940a5d9e9fef4137906dca7d8857ddf352163452 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2018 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Wildcard pattern matching
  */
 
-#include "imp.h"
 #include <assert.h>
 #include <string.h>
 
-#include "exp.h"
-#include "match.h"
 #include "defines.h"
 #include "tool.h"
 
+#include "match.h"
+
 /*
  * 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
@@ -51,8 +50,10 @@ static int Matche_After_Star PARAMS(( const char *p, const char *t ));
 GLOBAL bool
 Match( const char *Pattern, const char *String )
 {
-       if( Matche( Pattern, String ) == MATCH_VALID ) return true;
-       else return false;
+       if (Matche(Pattern, String) == MATCH_VALID)
+               return true;
+       else
+               return false;
 } /* Match */
 
 /**
@@ -65,16 +66,18 @@ Match( const char *Pattern, const char *String )
 GLOBAL bool
 MatchCaseInsensitive(const char *Pattern, const char *String)
 {
-       char haystack[COMMAND_LEN];
+       char needle[COMMAND_LEN], haystack[COMMAND_LEN];
 
+       strlcpy(needle, Pattern, sizeof(needle));
        strlcpy(haystack, String, sizeof(haystack));
-       return Match(Pattern, ngt_LowerStr(haystack));
+
+       return Match(ngt_LowerStr(needle), ngt_LowerStr(haystack));
 } /* MatchCaseInsensitive */
 
 /**
  * Match string with pattern case-insensitive.
  *
- * @param pattern Pattern to match with
+ * @param Pattern Pattern to match with
  * @param String Input string, at most COMMAND_LEN-1 characters long
  * @param Separator Character separating the individual patterns in the list
  * @return true if pattern matches
@@ -83,16 +86,14 @@ GLOBAL bool
 MatchCaseInsensitiveList(const char *Pattern, const char *String,
                     const char *Separator)
 {
-       char tmp_pattern[COMMAND_LEN], haystack[COMMAND_LEN], *ptr;
+       char tmp_pattern[COMMAND_LEN], *ptr;
 
        strlcpy(tmp_pattern, Pattern, sizeof(tmp_pattern));
-       strlcpy(haystack, String, sizeof(haystack));
-       ngt_LowerStr(haystack);
 
        ptr = strtok(tmp_pattern, Separator);
        while (ptr) {
                ngt_TrimStr(ptr);
-               if (Match(ptr, haystack))
+               if (MatchCaseInsensitive(ptr, String))
                        return true;
                ptr = strtok(NULL, Separator);
        }