X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=cmd%2Fdirectory.pl;h=1581041cb4ce5d6d6149fdcc9457c2462731b396;hb=2c55d933fc8883717c59c2e7d25dc82d63e3f507;hp=ab81798585a9008158abf54982f199ec1dad8e42;hpb=6a0068ec3df1dca0c6ae2714af3c0a4a62998dcf;p=spider.git diff --git a/cmd/directory.pl b/cmd/directory.pl index ab817985..1581041c 100644 --- a/cmd/directory.pl +++ b/cmd/directory.pl @@ -11,34 +11,71 @@ my @f = split /\s+/, $line; my @ref; my $ref; my @out; +my $f; +my $n = 10; -$f[0] = uc $f[0]; -if ($f[0] eq 'ALL') { - foreach $ref (DXMsg::get_all()) { - next if $self->priv < 5 && $ref->private && $ref->to ne $self->call && $ref->from ne $self->call; - push @ref, $ref; - } -} elsif ($f[0] =~ /^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); - } -} elsif ($f[0] =~ /^N/o) { # dir/new - foreach $ref (DXMsg::get_all()) { - push @ref, $ref if $ref->private && !$ref->read && $ref->to eq $self->call; - } -} 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 > 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; + } } -foreach $ref (@ref) { - push @out, $ref->dir; +while (@f) { + $f = uc shift @f; + if ($f eq 'ALL') { + foreach $ref (DXMsg::get_all()) { + 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); + } + } elsif ($f =~ /^N/o) { # dir/new + foreach $ref (DXMsg::get_all()) { + push @ref, $ref if $ref->private && !$ref->read && $ref->to eq $self->call; + } + } 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; + } } +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);