added shellregex
[spider.git] / cmd / directory.pl
index ab81798585a9008158abf54982f199ec1dad8e42..e4bf57bc5bb61714a61dba4460f98524d2aab100 100644 (file)
@@ -11,34 +11,40 @@ my @f = split /\s+/, $line;
 my @ref;
 my $ref;
 my @out;
+my $f;
+my $n;
 
-$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;
-  }
+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;
+               }
+       } 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 > 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;
+               }
+       }
 }
 
 foreach $ref (@ref) {
-  push @out, $ref->dir;
+       push @out, $ref->dir;
 }
 
 return (1, @out);