[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

apt utilities and regexs (Re: Debian Package Finder, where? SUCCESS !!)



On Wed, Dec 03, 2003 at 08:56:03PM +0000, Chema wrote:
> On Wed, 3 Dec 2003 17:30:07 -0600 > Bill Goudie <bgoudie@mail.com> wrote:
> BG> On Wed, Dec 03, 2003 at 01:26:22AM +0000, Chema wrote:
> BG> > Anyway, apt-file works nice, but "zgrep file Contents-i386.gz"
> BG> > works better! (note to apt-* developers: I'm still waiting... ;-).
> BG> >  Thanks
> BG> > people.
> BG> 
> BG> Uh? No difference -- this is what apt-file does.  Download and
> BG> zgrepping Contents-<arch>.gz is only useful because
> BG> packages.debian.org is unavailable and apt-file was uninstallable.
> 
> Of course there is difference: apt-file (and any other apt-*, I think)
> uses quotemeta in your pattern, effectively disabling the use of
> regular expressions, so it just does a substring search.  With zgrep
> (and any other grep, I think ;-), of course you can use regexps.

Yes, you are right it does modify the expressions.  In shell_pattern()
the following substitutions are made:
    '*' => '\\([^ ]*\\)'
    '?' => '.'

So, '?' loeses its meaning and '*' becomes zero or more non-spaces.
Everything else works fine:

    $ apt-file search '[ejg]\+vim'
    vim
    jvim-canna

    $ apt-file search 'j\(macs\|star\)'
    joe

Also, apt-file looks like it uses zgrep.  The routine grep_file() in
apt-file does this:

    print "Searching in `$file'\n" if $Conf{'verbose'};
    open(GREP, "zgrep $options $file |") || die "Can't search in `$file': $!\n";
    while (<GREP>) {
       /^([^ \t]+)[ \t]+(.*)$/;
       foreach (split /,/, $2) {
          my $pack = basename($_);
          push @packages, $pack;
       }
    }

Out of the other apt-* utilities apt-cache search does respect regular
expressions:

   search search performs a full text search on all available
          package  files  for  the  regex  pattern  given. It
          searchs the package names and the descriptions  for
          an occurance of the string and prints out the pack­
          age name and the short description.  If  --full  is
          given then output identical to show is produced for
          each matched package and if --names-only  is  given
          then the long description is not searched, only the
          package name is.

-- 
If you are honest because honesty is the best policy, your honesty is corrupt.



Reply to: