[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [findutils] suggestion for locate
From: |
Kevin Dalley |
Subject: |
Re: [findutils] suggestion for locate |
Date: |
12 Oct 2000 14:19:41 -0700 |
User-agent: |
Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands) |
Thanks for your suggestion.
I can't remember if I already responded to you. alpha release
findutils-4.1.6 has this option. It will be on
ftp://alpha.gnu.org/gnu as soon as I can get a few more bugs worked
out of the build procedure.
Gaël Roualland <address@hidden> writes:
> Hi,
>
> I often thought it would nice to be able to do a case insensitive search
> with locate. Here's a simple patch to do that.
>
> Gaël.
>
> --
> Gaël Roualland - address@hidden
> Ingénieur ENSERB Informatique--- findutils-4.1/locate/locate.c Mon Sep
> 26 23:06:14 1994
> +++ findutils-4.1-gr/locate/locate.c Sun Sep 3 11:53:13 2000
> @@ -158,12 +158,34 @@
> return subp;
> }
>
> +/* Case Insensitive fnmatch
> + If the fnmatch is always the GNU one, FNM_CASEFOLD could be used */
> +
> +static int
> +fnimatch (pattern, string, flags)
> + const char * pattern, * string;
> + int flags;
> +{
> + char * lstring, * s;
> + int len;
> +
> + s = lstring = (char *) alloca(strlen(string) + 1);
> + if (!lstring) return -1;
> +
> + while (*string)
> + *s++ = tolower(*string++);
> + *s = '\0';
> +
> + return fnmatch(pattern, lstring, flags);
> +}
> +
> /* Print the entries in DBFILE that match shell globbing pattern PATHPART.
> Return the number of entries printed. */
>
> static int
> -locate (pathpart, dbfile)
> +locate (pathpart, dbfile, igncase)
> char *pathpart, *dbfile;
> + int igncase;
> {
> /* The pathname database. */
> FILE *fp;
> @@ -294,20 +316,22 @@
> in PATHPART. */
> for (prev_fast_match = false; s >= cutoff; s--)
> /* Fast first char check. */
> - if (*s == *patend)
> + if ((igncase ? tolower(*s) : *s) == *patend)
> {
> char *s2; /* Scan the path we read in. */
> register char *p2; /* Scan `patend'. */
>
> - for (s2 = s - 1, p2 = patend - 1; *p2 != '\0' && *s2 == *p2;
> - s2--, p2--)
> + for (s2 = s - 1, p2 = patend - 1; *p2 != '\0' &&
> + (igncase ? tolower(*s2) : *s2) == *p2; s2--, p2--)
> ;
> if (*p2 == '\0')
> {
> /* Success on the fast match. Compare the whole pattern
> if it contains globbing characters. */
> prev_fast_match = true;
> - if (globflag == false || fnmatch (pathpart, path, 0) == 0)
> + if (globflag == false ||
> + (igncase ? fnimatch(pathpart, path, 0) :
> + fnmatch (pathpart, path, 0)) == 0)
> {
> puts (path);
> ++printed;
> @@ -342,7 +366,8 @@
> int status;
> {
> fprintf (stream, "\
> -Usage: %s [-d path] [--database=path] [--version] [--help] pattern...\n",
> +Usage: %s [-d path] [--database=path] [-i] [--ignore-case]\n\
> + [--version] [--help] pattern...\n",
> program_name);
> exit (status);
> }
> @@ -350,6 +375,7 @@
> static struct option const longopts[] =
> {
> {"database", required_argument, NULL, 'd'},
> + {"ignore-case", no_argument, NULL, 'i'},
> {"help", no_argument, NULL, 'h'},
> {"version", no_argument, NULL, 'v'},
> {NULL, no_argument, NULL, 0}
> @@ -361,7 +387,7 @@
> char **argv;
> {
> char *dbpath;
> - int found = 0, optc;
> + int found = 0, optc, igncase = 0;
>
> program_name = argv[0];
>
> @@ -369,7 +395,7 @@
> if (dbpath == NULL)
> dbpath = LOCATE_DB;
>
> - while ((optc = getopt_long (argc, argv, "d:", longopts, (int *) 0)) != -1)
> + while ((optc = getopt_long (argc, argv, "id:", longopts, (int *) 0)) != -1)
> switch (optc)
> {
> case 'd':
> @@ -383,6 +409,10 @@
> printf ("GNU locate version %s\n", version_string);
> exit (0);
>
> + case 'i':
> + igncase = 1;
> + break;
> +
> default:
> usage (stderr, 1);
> }
> @@ -393,9 +423,14 @@
> for (; optind < argc; optind++)
> {
> char *e;
> +
> + if (igncase)
> + for (e = argv[optind]; *e; e++)
> + *e = tolower(*e);
> +
> next_element (dbpath); /* Initialize. */
> while ((e = next_element ((char *) NULL)) != NULL)
> - found |= locate (argv[optind], e);
> + found |= locate (argv[optind], e, igncase);
> }
>
> exit (!found);
--
Kevin Dalley
SETI Institute
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [findutils] suggestion for locate,
Kevin Dalley <=