[augeas-devel] [PATCH 5/8] regexp: add make_regexp_from_glob to convert globs to regexps

David Lutterkort lutter at redhat.com
Wed May 11 00:08:50 UTC 2011


On Fri, 2011-05-06 at 18:12 -0700, lutter at redhat.com wrote:
> From: David Lutterkort <lutter at redhat.com>
> 
> ---
>  src/regexp.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/regexp.h |    3 +++
>  2 files changed, 51 insertions(+), 0 deletions(-)
> 
> diff --git a/src/regexp.c b/src/regexp.c
> index b5978d2..f351799 100644
> --- a/src/regexp.c
> +++ b/src/regexp.c
> @@ -134,6 +134,54 @@ struct regexp *make_regexp(struct info *info, char *pat, int nocase) {
>      return regexp;
>  }
>  
> +/* Take a POSIX glob and turn it into a regexp. The regexp is constructed
> + * by doing the following translations of characters in the string:
> + *  * -> .*
> + *  ? -> .
> + *  leave characters escaped with a backslash alone
> + *  escape any of ".|{}()+^$" with a backslash
> + *
> + * Note that that ignores some of the finer points of globs, like
> + * complementation.
> + */
> +struct regexp *make_regexp_from_glob(struct info *info, const char *glob) {

This incorrectly led to the '*' in a glob to match across '/'; I've
changed the code so that a '*' in a glob is synonymous to the regexp
[^/]*

David





More information about the augeas-devel mailing list