find: add -iname support (Alexander Griesser <alexander.griesser@lkh-vil.or.at>)
This commit is contained in:
parent
9cb220be9d
commit
75aa615bef
@ -76,7 +76,7 @@ typedef struct {
|
|||||||
#define ACTS(name, arg...) typedef struct { action a; arg; } action_##name;
|
#define ACTS(name, arg...) typedef struct { action a; arg; } action_##name;
|
||||||
#define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
|
#define ACTF(name) static int func_##name(const char *fileName, struct stat *statbuf, action_##name* ap)
|
||||||
ACTS(print)
|
ACTS(print)
|
||||||
ACTS(name, const char *pattern;)
|
ACTS(name, const char *pattern; bool iname;)
|
||||||
USE_FEATURE_FIND_PATH( ACTS(path, 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_REGEX( ACTS(regex, regex_t compiled_pattern;))
|
||||||
USE_FEATURE_FIND_PRINT0( ACTS(print0))
|
USE_FEATURE_FIND_PRINT0( ACTS(print0))
|
||||||
@ -188,8 +188,9 @@ ACTF(name)
|
|||||||
if (*tmp == '/')
|
if (*tmp == '/')
|
||||||
tmp++;
|
tmp++;
|
||||||
}
|
}
|
||||||
return fnmatch(ap->pattern, tmp, FNM_PERIOD) == 0;
|
return fnmatch(ap->pattern, tmp, FNM_PERIOD | (ap->iname ? FNM_CASEFOLD : 0)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_FEATURE_FIND_PATH
|
#if ENABLE_FEATURE_FIND_PATH
|
||||||
ACTF(path)
|
ACTF(path)
|
||||||
{
|
{
|
||||||
@ -458,6 +459,7 @@ static action*** parse_params(char **argv)
|
|||||||
USE_FEATURE_FIND_PAREN( PARM_char_brace,)
|
USE_FEATURE_FIND_PAREN( PARM_char_brace,)
|
||||||
/* All options starting from here require argument */
|
/* All options starting from here require argument */
|
||||||
PARM_name ,
|
PARM_name ,
|
||||||
|
PARM_iname ,
|
||||||
USE_FEATURE_FIND_PATH( PARM_path ,)
|
USE_FEATURE_FIND_PATH( PARM_path ,)
|
||||||
USE_FEATURE_FIND_REGEX( PARM_regex ,)
|
USE_FEATURE_FIND_REGEX( PARM_regex ,)
|
||||||
USE_FEATURE_FIND_TYPE( PARM_type ,)
|
USE_FEATURE_FIND_TYPE( PARM_type ,)
|
||||||
@ -490,6 +492,7 @@ static action*** parse_params(char **argv)
|
|||||||
USE_FEATURE_FIND_PAREN( "(\0" )
|
USE_FEATURE_FIND_PAREN( "(\0" )
|
||||||
/* All options starting from here require argument */
|
/* All options starting from here require argument */
|
||||||
"-name\0"
|
"-name\0"
|
||||||
|
"-iname\0"
|
||||||
USE_FEATURE_FIND_PATH( "-path\0" )
|
USE_FEATURE_FIND_PATH( "-path\0" )
|
||||||
USE_FEATURE_FIND_REGEX( "-regex\0" )
|
USE_FEATURE_FIND_REGEX( "-regex\0" )
|
||||||
USE_FEATURE_FIND_TYPE( "-type\0" )
|
USE_FEATURE_FIND_TYPE( "-type\0" )
|
||||||
@ -654,10 +657,11 @@ static action*** parse_params(char **argv)
|
|||||||
argv = endarg;
|
argv = endarg;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (parm == PARM_name) {
|
else if (parm == PARM_name || parm == PARM_iname) {
|
||||||
action_name *ap;
|
action_name *ap;
|
||||||
ap = ALLOC_ACTION(name);
|
ap = ALLOC_ACTION(name);
|
||||||
ap->pattern = arg1;
|
ap->pattern = arg1;
|
||||||
|
ap->iname = (parm == PARM_iname);
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_FIND_PATH
|
#if ENABLE_FEATURE_FIND_PATH
|
||||||
else if (parm == PARM_path) {
|
else if (parm == PARM_path) {
|
||||||
|
@ -1008,6 +1008,7 @@
|
|||||||
"\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \
|
"\n -maxdepth N Descend at most N levels. -maxdepth 0 applies" \
|
||||||
"\n tests/actions to command line arguments only") \
|
"\n tests/actions to command line arguments only") \
|
||||||
"\n -name PATTERN File name (w/o directory name) matches PATTERN" \
|
"\n -name PATTERN File name (w/o directory name) matches PATTERN" \
|
||||||
|
"\n -iname PATTERN Case insensitive -name" \
|
||||||
USE_FEATURE_FIND_PATH( \
|
USE_FEATURE_FIND_PATH( \
|
||||||
"\n -path PATTERN Path matches PATTERN") \
|
"\n -path PATTERN Path matches PATTERN") \
|
||||||
USE_FEATURE_FIND_REGEX( \
|
USE_FEATURE_FIND_REGEX( \
|
||||||
|
Loading…
Reference in New Issue
Block a user