/usr/share/vile/perl/Glob2re.pm is in vile-common 9.8q-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | package Glob2re;
require 5.000;
require Exporter;
use strict;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(glob2re);
sub glob2re {
my ($glob) = @_;
my $re = '(^|\/)';
while ( $glob ne '' ) {
if ( $glob =~ /^\*(.*)$/ ) {
$re .= '.*';
$glob = $1;
}
elsif ( $glob =~ /^\?(.*)$/ ) {
$re .= '.';
$glob = $1;
}
elsif ( $glob =~ /^\[(.+?)\](.*)$/ ) {
$re .= "[$1]";
$glob = $2;
}
elsif ( $glob =~ /^\{(.*?,.*?)\}(.*)$/ ) {
my ($alts) = $1;
$glob = $2;
$re .=
'(' . join( '|', map( quotemeta, split( /,/, $alts ) ) ) . ')';
}
elsif ( $glob =~ /^(.[^[{*?]*)(.*)$/ ) {
$re .= quotemeta($1);
$glob = $2;
}
else {
# shouldn't get here. If we do, give up
$glob = '';
}
}
$re .= '$';
return $re;
}
1;
__DATA__
=head1 NAME
Glob2re - convert glob/wildcard to regular expression
=head1 SYNOPSIS
The module exports one function, B<glob2re>:
use Glob2re;
my $re = glob2re($glob);
=head1 DESCRIPTION
The B<glob2re> function converts a Unix-style file-globbing string to
a regular expression. It is used by the B<dirlist> and B<hgrep> commands.
Unix-style file-globbing uses "*" to match zero or more characters of
any type, and "?" to match any single character. Prefix "*" or "?" with
"\" if you want to use those literally, rather than as a metacharacter.
=head1 EXAMPLE
my $glob = "*.*";
my $re = glob2re($glob);
=head1 AUTHOR
Kevin Buettner
=cut
|