[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Patch] Locate: New option: --and
From: |
Bas van Gompel |
Subject: |
[Patch] Locate: New option: --and |
Date: |
Sat, 11 Jun 2005 21:22:01 +0200 (MET DST) |
User-agent: |
slrn/0.9.8.1 (Win32) Hamster/2.0.6.0 KorrNews/4.2 |
Hi,
Here is the aforementioned patch, to allow a --and (-a) option to
locate. I hope you like it...
Suggested ChangeLog-entry:
2005-06-11 Bas van Gompel <address@hidden>
* NEWS, doc/find.texi, locate/locate.1: Document locate --and (-a)
* locate/locate.c: Implement --and (-a).
diff --exclude='*~' -Ndrup curr/findutils/NEWS mine2/findutils/NEWS
--- findutils/NEWS 2005-06-09 04:21:00.000000000 +0200
+++ findutils/NEWS 2005-06-11 20:02:00.000000000 +0200
@@ -7,7 +7,9 @@ A locate database can now be supplied on
of the database-path. If more than one database-path element is '-',
later instances are ignored.
-
+A new option to locate, `--and' (`-a') causes matches to be limited to
+entries which match all given patterns, not entries which match
+one or more patterns.
* Major changes in release 4.2.21
** Functional Changes to find
diff --exclude='*~' -Ndrup curr/findutils/doc/find.texi
mine2/findutils/doc/find.texi
--- findutils/doc/find.texi 2005-06-09 04:21:08.000000000 +0200
+++ findutils/doc/find.texi 2005-06-11 19:58:30.000000000 +0200
@@ -2723,6 +2723,12 @@ locate @address@hidden@address@hidden @va
@end example
@table @code
address@hidden --and
address@hidden -a
+Print only names which match all non-option arguments, not those matching
+one or more non-option arguments.
+
address@hidden @code
@item --basename
@itemx -b
The specified pattern is matched against just the last component of
diff --exclude='*~' -Ndrup curr/findutils/locate/locate.1
mine2/findutils/locate/locate.1
--- findutils/locate/locate.1 2005-06-09 04:21:10.000000000 +0200
+++ findutils/locate/locate.1 2005-06-11 20:13:12.000000000 +0200
@@ -7,7 +7,7 @@ locate \- list files in databases that m
| \-\-ignore-case] [\-0 | \-\-null] [\-c | \-\-count] [\-w | \-\-wholename]
|\-b | \-\-basename] [\-l N | \-\-limit=N] [\-S | \-\-statistics] [\-r
| \-\-regex ] [\-P | \-H | \-\-nofollow] [\-L | \-\-follow] [\-\-version]
-[\-p | \-\-print] [\-\-help] pattern...
+[\-a | \-\-and] [\-p | \-\-print] [\-\-help] pattern...
.SH DESCRIPTION
This manual page
documents the GNU version of
@@ -50,6 +50,10 @@ printed exactly as-is.
.SH OPTIONS
.TP
+.I "\-a, \-\-and"
+Print only names which match all non-option arguments, not those matching
+one or more non-option arguments.
+.TP
.I "\-c, \-\-count"
Instead of printing the matched filenames, just print the total
number of matches we found, unless \-\-\fIprint\fP (\-p) is also present.
diff --exclude='*~' -Ndrup curr/findutils/locate/locate.c
mine2/findutils/locate/locate.c
--- findutils/locate/locate.c 2005-06-09 04:21:12.000000000 +0200
+++ findutils/locate/locate.c 2005-06-11 20:15:00.000000000 +0200
@@ -389,6 +389,39 @@ process_or (struct process_data *procdat
return result;
}
+/* Accept if all pattern match. */
+static int
+process_and (struct process_data *procdata)
+{
+ int result = VISIT_CONTINUE;
+ const struct visitor *p = inspectors;
+
+ while ( ((VISIT_CONTINUE | VISIT_ACCEPTED) & result) && (past_pat_inspector
!= p) )
+ {
+ result = (p->inspector)(procdata, p->context);
+ p = p->next;
+ }
+
+ if (result == VISIT_CONTINUE)
+ result = VISIT_REJECTED;
+ if (result & (VISIT_ABORT | VISIT_REJECTED))
+ return result;
+
+ p = past_pat_inspector;
+ result = VISIT_CONTINUE;
+
+ while ( (VISIT_CONTINUE == result) && (NULL != p) )
+ {
+ result = (p->inspector)(procdata, p->context);
+ p = p->next;
+ }
+
+ if (VISIT_CONTINUE == result)
+ return VISIT_ACCEPTED;
+ else
+ return result;
+}
+
typedef int (*processfunc)(struct process_data *procdata);
static processfunc mainprocessor = NULL;
@@ -765,6 +798,7 @@ locate (int argc,
int use_limit,
struct locate_limits *plimit,
int stats,
+ int op_and,
int regex)
{
char *pathpart; /* A pattern to consider. */
@@ -960,7 +994,10 @@ locate (int argc,
if (argc > 1)
{
past_pat_inspector = pvis->next;
- mainprocessor = process_or;
+ if (op_and)
+ mainprocessor = process_and;
+ else
+ mainprocessor = process_or;
}
else
mainprocessor = process_simple;
@@ -1024,7 +1061,8 @@ Usage: %s [-d path | --database=path] [-
[-i | --ignore-case] [-w | --wholename] [-b | --basename] \n\
[--limit=N | -l N] [-S | --statistics] [-0 | --null] [-c | --count]\n\
[-P | -H | --nofollow] [-L | --follow] [-m | --mmap ] [ -s | --stdio ]\n\
- [-p | --print] [-r | --regex ] [--version] [--help] pattern...\n"),
+ [-a | --and] [-p | --print] [-r | --regex ] [--version] [--help]\n\
+ pattern...\n"),
program_name);
fputs (_("\nReport bugs to <address@hidden>.\n"), stream);
}
@@ -1035,6 +1073,7 @@ static struct option const longopts[] =
{"existing", no_argument, NULL, 'e'},
{"non-existing", no_argument, NULL, 'E'},
{"ignore-case", no_argument, NULL, 'i'},
+ {"and", no_argument, NULL, 'a'},
{"help", no_argument, NULL, 'h'},
{"version", no_argument, NULL, 'v'},
{"null", no_argument, NULL, '0'},
@@ -1066,6 +1105,7 @@ main (int argc, char **argv)
int use_limit = 0;
int regex = 0;
int stats = 0;
+ int op_and = 0;
char *e;
program_name = argv[0];
@@ -1089,7 +1129,7 @@ main (int argc, char **argv)
check_existence = ACCEPT_EITHER;
- while ((optc = getopt_long (argc, argv, "bcd:eEil:prsm0SwHPL", longopts,
(int *) 0)) != -1)
+ while ((optc = getopt_long (argc, argv, "abcd:eEil:prsm0SwHPL", longopts,
(int *) 0)) != -1)
switch (optc)
{
case '0':
@@ -1097,6 +1137,10 @@ main (int argc, char **argv)
print_quoted_filename = false; /* print filename 'raw'. */
break;
+ case 'a':
+ op_and = 1;
+ break;
+
case 'b':
basename_only = 1;
break;
@@ -1225,7 +1269,7 @@ main (int argc, char **argv)
e = LOCATE_DB;
}
- found = locate (argc - optind, &argv[optind], e, ignore_case, print,
basename_only, use_limit, &limits, stats, regex);
+ found = locate (argc - optind, &argv[optind], e, ignore_case, print,
basename_only, use_limit, &limits, stats, op_and, regex);
}
if (just_count)
L8r,
Buzz [was strangely happy for days when finding his name in AUTHORS].
--
) | | ---/ ---/ Yes, this | This message consists of true | I do not
-- | | / / really is | and false bits entirely. | mail for
) | | / / a 72 by 4 +-------------------------------+ any1 but
-- \--| /--- /--- .sigfile. | |perl -pe "s.u(z)\1.as." | me. 4^re
- [Patch] Locate: New option: --and,
Bas van Gompel <=