date and time created 91/03/07 20:28:05 by bostic
[unix-history] / usr / src / bin / csh / glob.c
index f253565..4234730 100644 (file)
@@ -5,11 +5,10 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char *sccsid = "@(#)glob.c      5.2 (Berkeley) %G%";
+static char *sccsid = "@(#)glob.c      5.5 (Berkeley) %G%";
 #endif
 
 #include "sh.h"
 #endif
 
 #include "sh.h"
-#include "sh.char.h"
 #include <sys/dir.h>
 
 /*
 #include <sys/dir.h>
 
 /*
@@ -24,6 +23,11 @@ bool noglob;
 bool   nonomatch;
 char   *entp;
 char   **sortbas;
 bool   nonomatch;
 char   *entp;
 char   **sortbas;
+int    sortscmp();
+
+#define sort() qsort((char *)sortbas, &gargv[gargc] - sortbas, \
+                     sizeof(*sortbas), sortscmp), sortbas = &gargv[gargc]
+
 
 char **
 glob(v)
 
 char **
 glob(v)
@@ -108,20 +112,14 @@ acollect(as)
                sort();
 }
 
                sort();
 }
 
-sort()
+/*
+ * String compare for qsort.  Also used by filec code in sh.file.c.
+ */
+sortscmp(a1, a2)
+       char **a1, **a2;
 {
 {
-       register char **p1, **p2, *c;
-       char **Gvp = &gargv[gargc];
-
-       p1 = sortbas;
-       while (p1 < Gvp-1) {
-               p2 = p1;
-               while (++p2 < Gvp)
-                       if (strcmp(*p1, *p2) > 0)
-                               c = *p1, *p1 = *p2, *p2 = c;
-               p1++;
-       }
-       sortbas = Gvp;
+
+        return (strcmp(*a1, *a2));
 }
 
 expand(as)
 }
 
 expand(as)
@@ -148,7 +146,7 @@ expand(as)
                        gpathp = strend(gpath);
                }
        }
                        gpathp = strend(gpath);
                }
        }
-       while (!cmap(*cs, _GLOB)) {
+       while (!isglob(*cs)) {
                if (*cs == 0) {
                        if (!globbed)
                                Gcat(gpath, "");
                if (*cs == 0) {
                        if (!globbed)
                                Gcat(gpath, "");
@@ -259,7 +257,6 @@ pend:
                }
                goto doit;
 
                }
                goto doit;
 
-       case ','|QUOTE:
        case ',':
                if (brclev)
                        continue;
        case ',':
                if (brclev)
                        continue;
@@ -510,7 +507,7 @@ tglob(t)
                else if (*p == '{' && (p[1] == '\0' || p[1] == '}' && p[2] == '\0'))
                        continue;
                while (c = *p++)
                else if (*p == '{' && (p[1] == '\0' || p[1] == '}' && p[2] == '\0'))
                        continue;
                while (c = *p++)
-                       if (cmap(c, _GLOB))
+                       if (isglob(c))
                                gflag |= c == '{' ? 2 : 1;
        }
 }
                                gflag |= c == '{' ? 2 : 1;
        }
 }