Gmatch did not trim the characters inside a range.
[unix-history] / usr / src / bin / csh / glob.c
index c20a80f..51214df 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)glob.c     5.18 (Berkeley) %G%";
+static char sccsid[] = "@(#)glob.c     5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -15,6 +15,12 @@ static char sccsid[] = "@(#)glob.c   5.18 (Berkeley) %G%";
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#if __STDC__
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
 #include "csh.h"
 #include "extern.h"
 
 #include "csh.h"
 #include "extern.h"
 
@@ -378,6 +384,10 @@ globone(str, action)
         */
        vo = globexpand(v);
        if (noglob || (gflag & G_GLOB) == 0) {
         */
        vo = globexpand(v);
        if (noglob || (gflag & G_GLOB) == 0) {
+           if (vo[0] == NULL) {
+               xfree((ptr_t) vo);
+               return (Strsave(STRNULL));
+           }
            if (vo[1] != NULL)
                return (handleone(str, vo, action));
            else {
            if (vo[1] != NULL)
                return (handleone(str, vo, action));
            else {
@@ -399,13 +409,17 @@ globone(str, action)
        setname(short2str(str));
        stderror(ERR_NAME | ERR_NOMATCH);
     }
        setname(short2str(str));
        stderror(ERR_NAME | ERR_NOMATCH);
     }
-    else if (vl[1])
+    if (vl[0] == NULL) {
+       xfree((ptr_t) vl);
+       return (Strsave(STRNULL));
+    }
+    if (vl[1] != NULL)
        return (handleone(str, vl, action));
     else {
        str = strip(*vl);
        xfree((ptr_t) vl);
        return (handleone(str, vl, action));
     else {
        str = strip(*vl);
        xfree((ptr_t) vl);
+       return (str);
     }
     }
-    return (str);
 }
 
 Char  **
 }
 
 Char  **
@@ -726,9 +740,9 @@ Gmatch(string, pattern)
                        return (0);
                if (match)
                    continue;
                        return (0);
                if (match)
                    continue;
-               if (rangec == '-') {
-                   match = (stringc <= *pattern &&
-                            *(pattern - 2) <= stringc);
+               if (rangec == '-' && *(pattern - 2) != '[' && *pattern != ']') {
+                   match = (stringc <= (*pattern & TRIM) &&
+                            (*(pattern - 2) & TRIM) <= stringc);
                    pattern++;
                }
                else
                    pattern++;
                }
                else