From 2c55d933fc8883717c59c2e7d25dc82d63e3f507 Mon Sep 17 00:00:00 2001 From: djk Date: Sun, 23 May 1999 14:03:13 +0000 Subject: [PATCH] added regex to sh/files fixed dir --- cmd/directory.pl | 59 ++++++++++++++++++++++++++++++++++++----------- cmd/show/files.pl | 4 ++++ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/cmd/directory.pl b/cmd/directory.pl index e4bf57bc..1581041c 100644 --- a/cmd/directory.pl +++ b/cmd/directory.pl @@ -12,7 +12,18 @@ my @ref; my $ref; my @out; my $f; -my $n; +my $n = 10; + +if (!@f) { + my @all = (DXMsg::get_all()); + my ($i, $count); + for ($i = $#all; $i > 0; $i--) { + $ref = $all[$i]; + next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call; + unshift @ref, $ref; + last if ++$count >= $n; + } +} while (@f) { $f = uc shift @f; @@ -21,6 +32,7 @@ while (@f) { next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call; push @ref, $ref; } + last; } elsif ($f =~ /^O/o) { # dir/own foreach $ref (DXMsg::get_all()) { push @ref, $ref if $ref->private && ($ref->to eq $self->call || $ref->from eq $self->call); @@ -29,22 +41,41 @@ while (@f) { foreach $ref (DXMsg::get_all()) { push @ref, $ref if $ref->private && !$ref->read && $ref->to eq $self->call; } - } elsif ($f > 0) { # a number of items - $n = $f; - } else { - my @all = (DXMsg::get_all()); - my ($i, $count); - for ($i = $#all; $i > 0; $i--) { - $ref = $all[$i]; - next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call; - unshift @ref, $ref; - last if ++$count > $n; + } elsif ($f eq '>' || $f eq 'TO'){ + $f = uc shift @f; + if ($f) { + $f = shellregex($f); + foreach $ref (DXMsg::get_all()) { + next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call; + next unless $ref->to =~ m{$f}; + push @ref, $ref; + } } + } elsif ($f eq '<' || $f eq 'FROM'){ + $f = uc shift @f; + if ($f) { + $f = shellregex($f); + foreach $ref (DXMsg::get_all()) { + next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call; + next unless $ref->from =~ m{$f}; + push @ref, $ref; + } + } + } elsif ($f =~ /^\d+$/ && $f > 0) { # a number of items + $n = $f; } } -foreach $ref (@ref) { - push @out, $ref->dir; +if (@ref) { + my $i = @ref - $n; + $i = 0 unless $i > 0; + my $count; + while ($i < @ref) { + $ref = $ref[$i++]; + push @out, $ref->dir; + last if ++$count >= $n; + } +} else { + push @out, $self->msg('e3', 'directory', $line); } - return (1, @out); diff --git a/cmd/show/files.pl b/cmd/show/files.pl index 68526a49..c57accc1 100644 --- a/cmd/show/files.pl +++ b/cmd/show/files.pl @@ -15,6 +15,7 @@ my @out; my @file; my @d; my @slot; +my $patt = '^.*$'; if (@f) { my $fn = lc $f[0]; @@ -22,6 +23,8 @@ if (@f) { $fn =~ s/\.//og; $fn =~ s/^\///og; $root = "$root/$fn"; + + $patt = shellregex(lc $f[1]) if defined $f[1]; } opendir(DIR, $root) or return (1, $self->msg('e3', 'show/files', $f[0])); @@ -31,6 +34,7 @@ closedir(DIR); my $flag = 0; for (@file) { next if /^\./; + next unless m{$patt}; my $fn = "$root/$_"; my $size; -- 2.43.0