File: lastlog.pl

package info (click to toggle)
sirc 2.211-5
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 372 kB
  • ctags: 356
  • sloc: perl: 4,254; ansic: 1,201; sh: 571; makefile: 66
file content (101 lines) | stat: -rw-r--r-- 2,391 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This defines an ircII-like /lastlog command.
# It was written by Dave Kamholz <davekam@sojourn.com>
# A few changes were made by Thomas Morgan <tmorgan@pobox.com>

$add_ons .= '+lastlog.pl' if $add_ons !~ /\+lastlog\.pl/;

push (@hooks, 'print');
$lastlog_len = 40;

# This is a modified version of the print found in dsirc.  It calls
# all print hooks.

sub print {
  local($what)=@_;
  $what =~ s/\s+$//;
  # thanks to Toy (wacren@obspm.fr) for this translation
  $what =~ tr/\x80-\xff/\x00-\x1f !cLxY|$_ca<\-\-R_o+23\'mp.,1o>123?AAAAAAACEEEEIIIIDNOOOOO*0UUUUYPBaaaaaaaceeeeiiiidnooooo:0uuuuypy/
    if $seven_bit;
  if ($raw_mode) {
    $logging && print LOG $what."\n";
    if ($add_ons =~ /\+beep/)
      {
	$what =~ s/\cg/\cvG\cv/g
	  unless ($beepmode==2 || ($canbeep && $beepmode==1));
      }
    print $what, "\n" || &exit;
    &dohooks("print", $what);
  } elsif ($ansi) {
    # this is buggy if you combine effects
    $what =~ s/([\ca\cc-\ch\cj-\cu\cw-\c^])/&enhance($1)/eg;
    while ($what =~ /\cb/) {
      ($what =~ s/\cb([^\cb]*)\cb/$bold$1$normal/) || 
      $what =~ s/\cb/$bold/g;
    }
    while ($what =~ /\c_/) {
      ($what =~ s/\c_([^\c_]*)\c_/$underline$1$normal/) ||
      $what =~ s/\c_/$underline/g;
    }
    while ($what =~ /\cv/) {
      ($what =~ s/\cv([^\cv]*)\cv/$reverse$1$normal/) ||
      $what =~ s/\cv/$reverse/g;
    }
    $logging && print LOG $what."\n";
    print $what, $normal, "\n" || &exit;
  } else {
    $what =~ tr/\ca-\ch\cj-\c_//d;
    $logging && print LOG $what."\n";
    print $what, "\n" || &exit;
  }
}

sub hook_lastlog
{
  splice (@lastlog, 0, ($#lastlog + 1) - $lastlog_len)
      if $#lastlog + 1 >= $lastlog_len; 
  push (@lastlog, "@_\n");
}

&addhook ('print', 'lastlog');

sub cmd_lastlog
{
  print ("*\cbL\cb* Start of lastlog.\n");

  if ($args)
    {
      print (grep (/$args/, @lastlog));
    }
  else
    {
      print (join ('', @lastlog));
    }

  print ("*\cbL\cb* End of lastlog.\n");
}		      

&addcmd ('lastlog');

sub cmd_lastloglen
{
  if (!$args)
    {
      &tell ("*\cbL\cb* Lastlog length is $lastlog_len");
    }
  else
    {
      if ($args == $lastlog_len)
	{
	  # Nothing to do.
	}
      elsif ($args < $lastlog_len)
	{
	  splice (@lastlog, 0, ($#lastlog + 1) - $args);
	}

      $lastlog_len = $args;
      &tell ("*\cbL\cb* Lastlog length set to $lastlog_len");
    }
}

&addcmd ('lastloglen');