CVSROOT    : /cvsroot/undernet-ircu
Module     : ircu2.10
Commit time: 2003-08-13 15:01:54 UTC

Modified files:
     ChangeLog ircd/match.c

Log message:

Author: netski (By Spike)
Log message: Rewrite of ircd/match.c

---------------------- diff included ----------------------
Index: ircu2.10/ChangeLog
diff -u ircu2.10/ChangeLog:1.386 ircu2.10/ChangeLog:1.387
--- ircu2.10/ChangeLog:1.386    Tue Aug 12 02:41:16 2003
+++ ircu2.10/ChangeLog  Wed Aug 13 08:01:44 2003
@@ -1,3 +1,8 @@
+2003-08-12 Timothy Vogelsang <[EMAIL PROTECTED]>
+
+        * ircd/match.c: (match) rewrote function based on existing
+          code from the hybrid ircd -- death to goto
+
 2003-07-07  Bas Steendijk <[EMAIL PROTECTED]>
 
         * ircd/s_user.c: invalidate ban cache for user on host hiding/account
Index: ircu2.10/ircd/match.c
diff -u ircu2.10/ircd/match.c:1.3 ircu2.10/ircd/match.c:1.4
--- ircu2.10/ircd/match.c:1.3   Sat Apr 21 14:49:13 2001
+++ ircu2.10/ircd/match.c       Wed Aug 13 08:01:44 2003
@@ -16,7 +16,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: match.c,v 1.3 2001/04/21 21:49:13 kev Exp $
+ * $Id: match.c,v 1.4 2003/08/13 15:01:44 denspike Exp $
  */
 #include "config.h"
 
@@ -151,96 +151,68 @@
  *
  * return  0, if match
  *         1, if no match
- */
-
-/*
- * match
- *
- * Rewritten by Andrea Cocito (Nemesi), November 1998.
  *
+ *  Originally by Douglas A Lewis ([EMAIL PROTECTED])
+ *  Rewritten by Timothy Vogelsang (netski), [EMAIL PROTECTED]
  */
 
-/****************** Nemesi's match() ***************/
-
-int match(const char *mask, const char *string)
+int match(const char *mask, const char *name)
 {
-  const char *m = mask, *s = string;
-  char ch;
-  const char *bm, *bs;          /* Will be reg anyway on a decent CPU/compiler */
-
-  /* Process the "head" of the mask, if any */
-  while ((ch = *m++) && (ch != '*'))
-    switch (ch)
-    {
-      case '\\':
-        if (*m == '?' || *m == '*')
-          ch = *m++;
-      default:
-        if (ToLower(*s) != ToLower(ch))
-          return 1;
-      case '?':
-        if (!*s++)
-          return 1;
-    };
-  if (!ch)
-    return *s;
-
-  /* We got a star: quickly find if/where we match the next char */
-got_star:
-  bm = m;                       /* Next try rollback here */
-  while ((ch = *m++))
-    switch (ch)
-    {
-      case '?':
-        if (!*s++)
-          return 1;
-      case '*':
-        bm = m;
-        continue;               /* while */
-      case '\\':
-        if (*m == '?' || *m == '*')
-          ch = *m++;
-      default:
-        goto break_while;       /* C is structured ? */
-    };
-break_while:
-  if (!ch)
-    return 0;                   /* mask ends with '*', we got it */
-  ch = ToLower(ch);
-  while (ToLower(*s++) != ch)
-    if (!*s)
-      return 1;
-  bs = s;                       /* Next try start from here */
+  const char *m = mask, *n = name;
+  const char *m_tmp = mask, *n_tmp = name;
+  int wild = 0;
 
-  /* Check the rest of the "chunk" */
-  while ((ch = *m++))
-  {
-    switch (ch)
-    {
-      case '*':
-        goto got_star;
-      case '\\':
-        if (*m == '?' || *m == '*')
-          ch = *m++;
-      default:
-        if (ToLower(*s) != ToLower(ch))
-        {
-          m = bm;
-          s = bs;
-          goto got_star;
-        };
-      case '?':
-        if (!*s++)
-          return 1;
-    };
-  };
-  if (*s)
+  for (;;)
   {
-    m = bm;
-    s = bs;
-    goto got_star;
-  };
-  return 0;
+    if (*m == '*') {
+      while (*m == '*')  /* clean up any additional wildcards */
+        m++;
+
+      m_tmp = m;
+      n_tmp = n;
+      wild = 1;
+    }
+    if (*m == '\\')  /* next wildcard is disregarded */
+      *m++;
+
+    if (!*m) {
+      if (!*n)
+        return 0;  /* match */
+
+      for (m--; (m > mask) && (*m == '?'); m--);
+        ;
+
+      if (*m == '*' && (m > mask))
+        return 0;  /* match */
+
+      if (!wild)
+        return 1;
+
+      m = m_tmp;
+      n = ++n_tmp;
+    }
+    else if (!*n) {
+      while (*m == '*')  /* clean up any additional wildcards */
+        m++;
+
+      return (*m != 0);
+    }
+    if (tolower(*m) != tolower(*n) && *m != '?') {
+      if (!wild)
+        return 1;  /* failure! */
+
+      m = m_tmp;
+      n = ++n_tmp;
+    }
+    else {
+      if (*m)
+        m++;
+      if (*n)
+        n++;
+    }
+  }
+
+  return 1;  /* no match! */
 }
 
 /*
----------------------- End of diff -----------------------

Reply via email to