added regex to sh/files
[spider.git] / cmd / directory.pl
index ab81798585a9008158abf54982f199ec1dad8e42..1581041cb4ce5d6d6149fdcc9457c2462731b396 100644 (file)
@@ -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);