summaryrefslogtreecommitdiffstats
path: root/usr.bin/locate
diff options
context:
space:
mode:
authorwosch <wosch@FreeBSD.org>1996-10-09 00:33:34 +0000
committerwosch <wosch@FreeBSD.org>1996-10-09 00:33:34 +0000
commitf7abebc6e2c0e6c168bb4376dcceb3ed263c1ccc (patch)
treed7c893b33b1130f027f2979fb822af6b61985ab4 /usr.bin/locate
parent28e40e3bc6a3ad09dbb13f62579877b676cf5755 (diff)
downloadFreeBSD-src-f7abebc6e2c0e6c168bb4376dcceb3ed263c1ccc.zip
FreeBSD-src-f7abebc6e2c0e6c168bb4376dcceb3ed263c1ccc.tar.gz
Fix searching for shell quoting characters. I guess it was
broken since locate exists. This works now $ locate '*\[' $ locate '*i386-\**' $ locate '*[C\[]'
Diffstat (limited to 'usr.bin/locate')
-rw-r--r--usr.bin/locate/locate/fastfind.c12
-rw-r--r--usr.bin/locate/locate/locate.h2
-rw-r--r--usr.bin/locate/locate/util.c50
3 files changed, 43 insertions, 21 deletions
diff --git a/usr.bin/locate/locate/fastfind.c b/usr.bin/locate/locate/fastfind.c
index e191704..a83b660 100644
--- a/usr.bin/locate/locate/fastfind.c
+++ b/usr.bin/locate/locate/fastfind.c
@@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: fastfind.c,v 1.2 1996/08/29 22:39:41 wosch Exp wosch $
+ * $Id: fastfind.c,v 1.1 1996/08/31 23:14:52 wosch Exp $
*/
@@ -160,8 +160,16 @@ fastfind
#endif
/* find optimal (last) char for searching */
+ for (p = pathpart; *p != '\0'; p++)
+ if (index(LOCATE_REG, *p) != NULL)
+ break;
+
+ if (*p == '\0')
+ globflag = 0;
+ else
+ globflag = 1;
+
p = pathpart;
- globflag = index(p, '*') || index(p, '?') || index(p, '[');
patend = patprep(p);
cc = *patend;
diff --git a/usr.bin/locate/locate/locate.h b/usr.bin/locate/locate/locate.h
index c3a7845..cb7d087 100644
--- a/usr.bin/locate/locate/locate.h
+++ b/usr.bin/locate/locate/locate.h
@@ -65,3 +65,5 @@ u_char myctype[UCHAR_MAX + 1];
#endif
#define INTSIZE (sizeof(int))
+
+#define LOCATE_REG "*?[]\\" /* fnmatch(3) meta characters */
diff --git a/usr.bin/locate/locate/util.c b/usr.bin/locate/locate/util.c
index 313939b..84dc12a 100644
--- a/usr.bin/locate/locate/util.c
+++ b/usr.bin/locate/locate/util.c
@@ -34,7 +34,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: util.c,v 1.2 1996/08/29 22:39:41 wosch Exp wosch $
+ * $Id: util.c,v 1.1 1996/08/31 23:14:54 wosch Exp $
*/
@@ -156,31 +156,43 @@ patprep(name)
register char *endmark, *p, *subp;
subp = globfree;
- *subp++ = '\0';
+ *subp++ = '\0'; /* set first element to '\0' */
p = name + strlen(name) - 1;
- /* skip trailing metacharacters (and [] ranges) */
+
+ /* skip trailing metacharacters */
for (; p >= name; p--)
- if (index("*?", *p) == 0)
+ if (index(LOCATE_REG, *p) == NULL)
break;
- if (p < name)
- p = name;
- if (*p == ']')
- for (p--; p >= name; p--)
- if (*p == '[') {
- p--;
- break;
- }
- if (p < name)
- p = name;
- /*
- * if pattern has only metacharacters, check every path (force '/'
- * search)
+
+ /*
+ * check if maybe we are in a character class
+ *
+ * 'foo.[ch]'
+ * |----< p
*/
- if ((p == name) && index("?*[]", *p) != 0)
+ if (p >= name &&
+ (index(p, '[') != NULL || index(p, ']') != NULL)) {
+ for (p = name; *p != '\0'; p++)
+ if (*p == ']' || *p == '[')
+ break;
+ p--;
+
+ /*
+ * cannot find a non-meta character, give up
+ * '*\*[a-z]'
+ * |-------< p
+ */
+ if (p >= name && index(LOCATE_REG, *p) != NULL)
+ p = name - 1;
+ }
+
+ if (p < name)
+ /* only meta chars: "???", force '/' search */
*subp++ = '/';
+
else {
for (endmark = p; p >= name; p--)
- if (index("]*?", *p) != 0)
+ if (index(LOCATE_REG, *p) != NULL)
break;
for (++p;
(p <= endmark) && subp < (globfree + sizeof(globfree));)
OpenPOWER on IntegriCloud