Improve M$ Windows compatibility
[spider.git] / cmd / show / groups.pl
index f91e66caa9ed653faa6030c5b1458b82da52ffd5..aaa9d4cf334ac640d8f423abc860f86d080b48df 100644 (file)
 #
 
 use Time::Local;
-my $self = shift;
-my $to = shift;
 
-if ($to =~ /\D/) {
-    return (1, "try sh/chatgroups xxx where xxx is the number of chat messages to search.");
-}
+my $to;
+
+sub handle
+{
+       my $self = shift;
+       $to = shift;
+
+       if ($to =~ /\D/) {
+               return (1, "try sh/chatgroups xxx where xxx is the number of chat messages to search.");
+       }
+       $to = 500 unless $to;
 
-my @out;
-my $g= {};
+       if ($self->{_nospawn} || $main::is_win == 1) {
+               return (1, doit($self, DXLog::print(undef, $to, $main::systime, 'chat', undef)));
+       }
+       return (1, $self->spawn_cmd("show/groups $to", \&DXLog::print, args => [0, $to, $main::systime, 'chat', undef], cb => \&doit));
+}
 
-$to = 500 unless $to;
+sub doit {
+       my $self = shift;
+       
+               my @chatlog = @_;
 
-my @chatlog = DXLog::print(undef, $to, $main::systime, 'chat', undef);
-my $row;
-my ($time, $call, $group);
-my $found;
-my %month = (
-                        Jan => 0,
-                        Feb => 1,
-                        Mar => 2,
-                        Apr => 3,
-                        May => 4,
-                        Jun => 5,
-                        Jul => 6,
-                        Aug => 7,
-                        Sep => 8,
-                        Oct => 9,
-                        Nov => 10,
-                        Dec => 11,
-                       );
+               my $g= {};
+               my @out;
+               my $row;
+               my ($time, $call, $group);
+               my $found;
+               my %month = (
+                                        Jan => 0,
+                                        Feb => 1,
+                                        Mar => 2,
+                                        Apr => 3,
+                                        May => 4,
+                                        Jun => 5,
+                                        Jul => 6,
+                                        Aug => 7,
+                                        Sep => 8,
+                                        Oct => 9,
+                                        Nov => 10,
+                                        Dec => 11,
+                                       );
 
-@chatlog = reverse @chatlog;
-foreach $row(@chatlog) {
-    ($time, $call, $group) = ($row =~ m/^(\S+) (\S+) -> (\S+) /o);
-    if (!exists $g->{$group}) {
-               $time =~ m/^(\d\d)(\w{3})(\d{4})\@(\d\d):(\d\d):(\d\d)/o;
-               $g->{$group}->{sec} = timegm($6, $5, $4, $1, $month{$2}, $3-1900);
-               $time =~ s/\@/ at /;
-               $g->{$group}->{last} = $time;
-               push @{ $g->{$group}->{calls} }, $call;
-    } else {
-               $found = 0;
-               foreach (@{ $g->{$group}->{calls} }) {
-                       if (/$call/) {
-                               $found = 1;
-                               last;
+               @chatlog = reverse @chatlog;
+               foreach $row(@chatlog) {
+                       ($time, $call, $group) = ($row =~ m/^(\S+) (\S+) -> (\S+) /o);
+                       if (!exists $g->{$group}) {
+                               $time =~ m/^(\d\d)(\w{3})(\d{4})\@(\d\d):(\d\d):(\d\d)/o;
+                               $g->{$group}->{sec} = timegm($6, $5, $4, $1, $month{$2}, $3-1900);
+                               $time =~ s/\@/ at /;
+                               $g->{$group}->{last} = $time;
+                               push @{ $g->{$group}->{calls} }, $call;
+                       }
+                       else {
+                               $found = 0;
+                               foreach (@{ $g->{$group}->{calls} }) {
+                                       if (/$call/) {
+                                               $found = 1;
+                                               last;
+                                       }
+                               }
+                               push @{ $g->{$group}->{calls} }, $call unless $found;
                        }
+                       $g->{$group}->{msgcount}++;
                }
-               push @{ $g->{$group}->{calls} }, $call unless $found;
-    }
-    $g->{$group}->{msgcount}++;
-}
 
-push (@out, "Chat groups recently used:");
-push (@out, "($to messages searched)");
-push (@out, "--------------------------");
-my @calls;
-my @l;
-my $max = 6;
-my $mtext;
-foreach $group (sort { $g->{$b}->{sec}  <=> $g->{$a}->{sec} } keys %$g) {
-    @calls = sort( @{ $g->{$group}->{calls} } );
-    $mtext = "  " . $g->{$group}->{msgcount} . " messages by:";
-    push (@out, "$group: Last active " . $g->{$group}->{last});
-    if (@calls <= $max) {
-               push (@out, "$mtext @calls");
-    } else {
-               foreach $call(@calls) {
-                       push @l, $call;
-                       if (@l >= $max) {
-                               if ($max == 6) {
-                                       push (@out, "$mtext @l");
-                               } else {
-                                       push (@out, "  @l");
+               push (@out, "Chat groups recently used:");
+               push (@out, "($to messages searched)");
+               push (@out, "--------------------------");
+               my @calls;
+               my @l;
+               my $max = 6;
+               my $mtext;
+               foreach $group (sort { $g->{$b}->{sec}  <=> $g->{$a}->{sec} } keys %$g) {
+                       @calls = sort( @{ $g->{$group}->{calls} } );
+                       $mtext = "  " . $g->{$group}->{msgcount} . " messages by:";
+                       push (@out, "$group: Last active " . $g->{$group}->{last});
+                       if (@calls <= $max) {
+                               push (@out, "$mtext @calls");
+                       }
+                       else {
+                               foreach $call(@calls) {
+                                       push @l, $call;
+                                       if (@l >= $max) {
+                                               if ($max == 6) {
+                                                       push (@out, "$mtext @l");
+                                               }
+                                               else {
+                                                       push (@out, "  @l");
+                                               }
+                                               @l = ();
+                                               $max = 8;
+                                       }
                                }
+                               push (@out, "  @l") if (@l);
+                               $max = 6;
                                @l = ();
-                               $max = 8;
                        }
+                       push (@out, "-");
                }
-               push (@out, "  @l") if (@l);
-               $max = 6;
-               @l = ();
-    }
-    push (@out, "-");
-}
-return (1, @out);
+               return @out;
+       }
+
+