Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Feb 2001 18:08:25 +0200
From:      Peter Pentchev <roam@orbitel.bg>
To:        Maxim Sobolev <sobomax@FreeBSD.org>
Cc:        Jordan Hubbard <jkh@winston.osd.bsdi.com>, ports@FreeBSD.org, jkh@FreeBSD.org, Edwin Groothuis <mavetju@chello.nl>
Subject:   Re: Request for comments [Fwd: bin/24695: [patch] pkg_info: prefix search for a package]
Message-ID:  <20010206180825.A406@ringworld.oblivion.bg>
In-Reply-To: <3A801D32.DE73F780@FreeBSD.org>; from sobomax@FreeBSD.org on Tue, Feb 06, 2001 at 05:50:10PM %2B0200
References:  <10197.981450491@winston.osd.bsdi.com> <3A7FC36A.1434D2CC@FreeBSD.org> <3A801D32.DE73F780@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 06, 2001 at 05:50:10PM +0200, Maxim Sobolev wrote:
> Maxim Sobolev wrote:
> 
> > Jordan Hubbard wrote:
> >
> > > > but was away from e-mail) ;). What do you think if I reimplement 'fuzzy' and
> > > > 'prefix' options from original proposal into `glob' and `regex' options? So
> > > > regex kidz would be able say "-x .*foo.*", while glob-lovers "-g *foo*".
> > >
> > > I love it.  You could even make -g "implicit", e.g. I don't see any
> > > reason why "pkg_info emacs*" shouldn't just work, right?  The only
> > > time you really need to pass a flag is to indicate a particular type
> > > of globbing, e.g. regex.
> >
> > Agreed. I already have globbing in place, so expect patches soon ;).
> 
> Here it is. With this patch pkg_install treats any arguments as shell globs by
> default and as regexs with -x, so for example the following is equivalent:
> $ pkg_info foo\*
> $ pkg_info -x ^foo.\*
> 
> Please let me know what do you think about those patches.
> 
> -Maxim

The patches look great!  I'll test them in an hour or two..
Just a minor comment: in the rexs_match() function, you compile
each pattern time and again, for each package.  Not that it would
matter a lot (the actual performance bottleneck would be disk I/O,
I suppose), but it could fasten things a bit if you precompiled
all patterns into a regex_t array at the start.

G'luck,
Peter

-- 
If the meanings of 'true' and 'false' were switched, then this sentence wouldn't be false.

[snip]
> Index: perform.c
> ===================================================================
> RCS file: /home/ncvs/src/usr.sbin/pkg_install/info/perform.c,v
> retrieving revision 1.33
[snip]
> +/*
> + * Return 1 if specified pkgname matches at least one
> + * of the RE from patterns. Otherwise return 0 if no
> + * matches were found or -1 if RE engine reported an
> + * error (usually invalid syntax).
> + */
> +static int
> +rexs_match(char **patterns, char *pkgname)
> +{
> +    Boolean matched;
> +    char errbuf[128];
> +    int i;
> +    int errcode;
> +    int retval;
> +    regex_t rex;
> +
> +    errcode = 0;
> +    retval = 0;
> +    matched = FALSE;
> +    for (i = 0; patterns[i]; i++) {
> +	errcode = regcomp(&rex, patterns[i], REG_BASIC | REG_NOSUB);
> +	if (errcode != 0)
> +	    break;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010206180825.A406>