]> granicus.if.org Git - graphviz/commitdiff
lefty SFcompareEntries: replace case-insensitive alternative with 'strcasecmp'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 18 Sep 2021 01:16:15 +0000 (18:16 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 19 Sep 2021 18:00:07 +0000 (11:00 -0700)
This functionality is built in to libc these days.

cmd/lefty/ws/x11/libfilereq/Dir.c

index 07e6007a06bf116713e437cb2e989b29401d3799..04193f4f5b37f869a3ce650037a8d9ce660e6775 100644 (file)
 
 #include "config.h"
 #include <stdio.h>
+#include <string.h>
+#ifndef _MSC_VER
+#include <strings.h>
+#endif
 
 #ifdef SEL_FILE_IGNORE_CASE
 #include <ctype.h>
@@ -58,44 +62,18 @@ extern void qsort ();
 
 #include "SFDecls.h"
 
-#ifdef SEL_FILE_IGNORE_CASE
 int SFcompareEntries (const void *vp, const void *vq) {
     const SFEntry *p = vp, *q = vq;
-    char *r, *s;
-    char c1, c2;
-
-    r = p->real;
-    s = q->real;
-    c1 = *r++;
-    if (islower (c1)) {
-        c1 = toupper (c1);
-    }
-    c2 = *s++;
-    if (islower (c2)) {
-        c2 = toupper (c2);
-    }
-    while (c1 == c2) {
-        if (!c1) {
-            return strcmp (p->real, q->real);
-        }
-        c1 = *r++;
-        if (islower (c1)) {
-            c1 = toupper (c1);
-        }
-        c2 = *s++;
-        if (islower (c2)) {
-            c2 = toupper (c2);
-        }
-    }
-    return c1 - c2;
-}
+#ifdef SEL_FILE_IGNORE_CASE
+#ifdef _MSC_VER
+    return _stricmp(p->real, q->real);
+#else
+    return strcasecmp(p->real, q->real);
+#endif
 #else /* def SEL_FILE_IGNORE_CASE */
-int SFcompareEntries (const void *vp, const void *vq) {
-    const SFEntry *p = vp, *q = vq;
-
     return strcmp (p->real, q->real);
-}
 #endif /* def SEL_FILE_IGNORE_CASE */
+}
 
 int SFgetDir (SFDir *dir) {
     SFEntry       *result = NULL;