shithub: sox

Download patch

ref: 42bd9a0c01da335d4db474acf153bf1e36f72068
parent: 174c54431e517378a4648819d9a798d5eebdee4b
author: robs <robs>
date: Sat Dec 2 06:53:22 EST 2006

Rationalise use of strcasecmp.

--- a/src/sox.c
+++ b/src/sox.c
@@ -192,7 +192,7 @@
     /* Loop over arguments and filenames, stop when an effect name is 
      * found.
      */
-    while (optind < argc && st_checkeffect(argv[optind]) != ST_SUCCESS)
+    while (optind < argc && !is_effect_name(argv[optind]))
     {
         if (file_count >= MAX_FILES)
         {
--- a/src/util.c
+++ b/src/util.c
@@ -130,13 +130,6 @@
         ft->st_errstr[255] = '\0';
 }
 
-int strcmpcase(const char *s1, const char *s2)
-{
-        while(*s1 && *s2 && (tolower(*s1) == tolower(*s2)))
-                s1++, s2++;
-        return *s1 - *s2;
-}
-
 /*
  * Check that we have a known format suffix string.
  */
@@ -158,7 +151,7 @@
           continue; /* don't match special device names in real file names */
         for (list = f->names; *list; list++) {
             const char *s1 = *list, *s2 = formp->filetype;
-            if (! strcmpcase(s1, s2))
+            if (! strcasecmp(s1, s2))
                 break;  /* not a match */
         }
         if (! *list)
@@ -184,48 +177,27 @@
 
     for (i = 0; st_effect_fns[i]; i++)
     {
-        char *s1, *s2;
         const st_effect_t *e = st_effect_fns[i]();
 
-        if (!e || !e->name)
-            continue;
-
-        s1 = e->name;
-        s2 = argv[0];
-
-        while(*s1 && *s2 && (tolower(*s1) == tolower(*s2)))
-            s1++, s2++;
-        if (*s1 || *s2)
-            continue;       /* not a match */
-
-        /* Found it! */
-        effp->name = e->name;
-        effp->h = e;
-
-        optind = 1;
-
-        while (optind < argc)
-        {
-            for (i = 0; st_effect_fns[i]; i++)
-            {
-                const st_effect_t *e = st_effect_fns[i]();
-                char *s1 = e->name, *s2 = argv[optind];
-                while (*s1 && *s2 && (tolower(*s1) == tolower(*s2)))
-                    s1++, s2++;
-                if (*s1 || *s2)
-                    continue;
-
-                /* Found it! */
-                return (optind - 1);
-            }
-            /* Didn't find a match, try the next argument. */
-            optind++;
+        if (e && e->name && strcasecmp(e->name, argv[0]) == 0) {
+          effp->name = e->name;
+          effp->h = e;
+          for (optind = 1; optind < argc; optind++)
+          {
+              for (i = 0; st_effect_fns[i]; i++)
+              {
+                  const st_effect_t *e = st_effect_fns[i]();
+                  if (e && e->name && strcasecmp(e->name, argv[optind]) == 0)
+                    return (optind - 1);
+              }
+              /* Didn't find a match, try the next argument. */
+          }
+          /*
+           * No matches found, all the following arguments are
+           * for this effect passed in.
+           */
+          return (optind - 1);
         }
-        /*
-         * No matches found, all the following arguments are
-         * for this effect passed in.
-         */
-        return (optind - 1);
     }
 
     return (ST_EOF);
@@ -242,25 +214,13 @@
     int i;
 
     for(i = 0; st_effect_fns[i]; i++) {
-        const char *s1, *s2;
         const st_effect_t *e = st_effect_fns[i]();
 
-        if (!e || !e->name)
-            continue;
-
-        s1 = e->name;
-        s2 = effect_name;
-
-        while(*s1 && *s2 && (tolower(*s1) == tolower(*s2)))
-            s1++, s2++;
-        if (*s1 || *s2)
-            continue;       /* not a match */
-
-        /* Found it! */
-        effp->name = e->name;
-        effp->h = e;
-
-        return ST_SUCCESS;
+        if (e && e->name && strcasecmp(e->name, effect_name) == 0) {
+          effp->name = e->name;
+          effp->h = e;
+          return ST_SUCCESS;
+        }
     }
 
     return (ST_EOF);
@@ -267,31 +227,20 @@
 }
 
 /*
- * Check that we have a known effect name.  Return ST_SUCESS if found, else
- * return ST_EOF.
+ * Check if we have a known effect name.
  */
-int st_checkeffect(const char *effect_name)
+bool is_effect_name(char const * text)
 {
     int i;
 
     for(i = 0; st_effect_fns[i]; i++) {
-        const char *s1, *s2;
         const st_effect_t *e = st_effect_fns[i]();
 
-        if (!e || !e->name)
-            continue;
-
-        s1 = e->name;
-        s2 = effect_name;
-        while(*s1 && *s2 && (tolower(*s1) == tolower(*s2)))
-            s1++, s2++;
-        if (*s1 || *s2)
-            continue;       /* not a match */
-
-        return ST_SUCCESS;
+        if (e && e->name && strcasecmp(e->name, text) == 0)
+          return true;
     }
 
-    return (ST_EOF);
+    return false;
 }
 
 /*