added Makefile
[TransparentIRC.git] / src / tools.c
diff --git a/src/tools.c b/src/tools.c
new file mode 100644 (file)
index 0000000..6478279
--- /dev/null
@@ -0,0 +1,42 @@
+/* tools.c - TransparentIRC 0.1
+ * Copyright (C) 2011-2012  Philipp Kreil (pk910)
+ * 
+ * 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. 
+ */
+#include "tools.h"
+
+int stricmp(const char *s1, const char *s2) {
+    if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
+    if (s2 == NULL) return *s1;
+    char c1, c2;
+    while ((c1 = tolower (*s1)) == (c2 = tolower (*s2))) {
+        if (*s1 == '\0') break;
+        ++s1; ++s2;
+    }
+    return c1 - c2;
+}
+
+int stricmplen(const char *s1, const char *s2, int len) {
+    if (s1 == NULL) return s2 == NULL ? 0 : -(*s2);
+    if (s2 == NULL) return *s1;
+    char c1, c2;
+    int i = 0;
+    while ((c1 = tolower (*s1)) == (c2 = tolower (*s2))) {
+        i++;
+        if (*s1 == '\0') break;
+        ++s1; ++s2;
+        if(i == len) break;
+    }
+    return c1 - c2;
+}
\ No newline at end of file