Patch to add the "-iname" option to find
Bernhard Fischer
rep.dot.nop at gmail.com
Thu Dec 6 11:04:59 UTC 2007
On Thu, Dec 06, 2007 at 10:07:13AM +0100, Alexander Griesser wrote:
>Hi!
>
>I always wondered why the "-iname" option isn't supported by busybox's
>find and as I'm using it heavily I've written a small patch to get it in.
>
>I'm sure that this patch isn't optimal as it simply duplicates the
>action function for the "-name" parameter, but I don't know of any
>other way to do that. The significant change is to add the flag
>FNM_CASEFOLD to the fnmatch function call.
>
>Any objections?
>
>ciao,
>--
>Alexander Griesser (Netzwerkadministration)
>E-Mail: alexander.griesser at lkh-vil.or.at | Web: http://www.lkh-vil.or.at
>KABEG LKH Villach | Nikolaigasse 43 | 9500 Villach
>Tel.: +43 4242 208 3061 | Fax.: +43 4242 971 3061
>diff -Nur old/findutils/find.c new/findutils/find.c
>--- old/findutils/find.c 2007-12-06 10:04:10.000000000 +0100
>+++ new/findutils/find.c 2007-12-06 10:04:25.000000000 +0100
>@@ -77,6 +77,7 @@
> #define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
> ACTS(print)
> ACTS(name, const char *pattern;)
>+ ACTS(iname, const char *pattern;)
> USE_FEATURE_FIND_PATH( ACTS(path, const char *pattern;))
> USE_FEATURE_FIND_REGEX( ACTS(regex, regex_t compiled_pattern;))
> USE_FEATURE_FIND_PRINT0( ACTS(print0))
>@@ -190,6 +191,20 @@
> }
> return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0;
> }
>+
>+ACTF(iname)
>+{
>+ const char *tmp = bb_basename(fileName);
>+ if (tmp != fileName && !*tmp) {
>+ tmp--;
>+ while (tmp != fileName && *--tmp != '/')
>+ continue;
>+ if (*tmp == '/')
>+ tmp++;
>+ }
>+ return fnmatch(ap->pattern, tmp, FNM_PERIOD | FNM_CASEFOLD) == 0;
>+}
>+
> #if ENABLE_FEATURE_FIND_PATH
> ACTF(path)
> {
>@@ -458,6 +473,7 @@
> USE_FEATURE_FIND_PAREN( PARM_char_brace,)
> /* All options starting from here require argument */
> PARM_name ,
>+ PARM_iname ,
> USE_FEATURE_FIND_PATH( PARM_path ,)
> USE_FEATURE_FIND_REGEX( PARM_regex ,)
> USE_FEATURE_FIND_TYPE( PARM_type ,)
>@@ -490,6 +506,7 @@
> USE_FEATURE_FIND_PAREN( "(\0" )
> /* All options starting from here require argument */
> "-name\0"
>+ "-iname\0"
> USE_FEATURE_FIND_PATH( "-path\0" )
> USE_FEATURE_FIND_REGEX( "-regex\0" )
> USE_FEATURE_FIND_TYPE( "-type\0" )
>@@ -659,6 +676,11 @@
> ap = ALLOC_ACTION(name);
> ap->pattern = arg1;
> }
>+ else if (parm == PARM_iname) {
>+ action_iname *ap;
>+ ap = ALLOC_ACTION(iname);
>+ ap->pattern = arg1;
>+ }
> #if ENABLE_FEATURE_FIND_PATH
> else if (parm == PARM_path) {
> action_path *ap;
>diff -Nur old/include/usage.h new/include/usage.h
>--- old/include/usage.h 2007-12-06 10:04:02.000000000 +0100
>+++ new/include/usage.h 2007-12-06 10:04:20.000000000 +0100
>@@ -998,6 +998,7 @@
> "\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \
> "\n tests/actions to command line arguments only") \
> "\n -name PATTERN File name (w/o directory name) matches PATTERN" \
->+ "\n -iname PATTERN File name (w/o directory name) matches PATTERN (case insensitive)" \
+>+ "\n -iname PATTERN Like -name but case insensitive" \
Is shorter and as easy to understand.
What's the bloatcheck for this change?
Not sure if reusing ACTF(name) and trying to deduce FNM_CASEFOLD somehow
would be smaller or cleaner..
More information about the busybox
mailing list