yd: Use yt-dlp instead of youtube-dl
[sunny256-utils.git] / irc-conn
blob7eb0416f71bbbc7344727af77ef8abb8dc6798d9
1 #!/usr/bin/env perl
3 #=======================================================================
4 # irc-conn
5 # File ID: 421f1a82-483d-11e4-9469-c80aa9e67bbd
7 # Show IRC connections, output Graphviz data
9 # Character set: UTF-8
10 # ©opyleft 2014– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
15 use strict;
16 use warnings;
17 use Getopt::Long;
19 local $| = 1;
21 our $Debug = 0;
23 our %Opt = (
25 'count' => 1,
26 'debug' => 0,
27 'help' => 0,
28 'verbose' => 0,
29 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = '0.00';
37 Getopt::Long::Configure('bundling');
38 GetOptions(
40 'count|c=i' => \$Opt{'count'},
41 'debug' => \$Opt{'debug'},
42 'help|h' => \$Opt{'help'},
43 'verbose|v+' => \$Opt{'verbose'},
44 'version' => \$Opt{'version'},
46 ) || die("$progname: Option error. Use -h for help.\n");
48 $Opt{'debug'} && ($Debug = 1);
49 $Opt{'help'} && usage(0);
50 if ($Opt{'version'}) {
51 print_version();
52 exit(0);
54 $Opt{'count'} < 1 && die("$progname: -c/--count value has to be at least 1\n");
56 exit(main(%Opt));
58 sub main {
59 # {{{
60 my %Opt = @_;
61 my $Retval = 0;
62 my %used = ();
64 print("digraph g {\n");
65 while (my $curr = <>) {
66 # 20140829T003022Z < HisaoNakai> marmalodak: wat o_
67 if ($curr =~ /^\S+ <.(\S+?)> (\S+?):\s/) {
68 my ($from, $to) = ($1, $2);
69 $from =~ s/\\/&#92;/g;
70 $from =~ s/"/\\"/g;
71 $to =~ s/\\/&#92;/g;
72 $to =~ s/"/\\"/g;
73 $used{"$from $to"}++;
74 ($used{"$from $to"} == $Opt{'count'}) && print("\"$from\" -> \"$to\";\n");
77 print("}\n");
79 return($Retval);
80 # }}}
81 } # main()
83 sub print_version {
84 # Print program version {{{
85 print("$progname v$VERSION\n");
86 return;
87 # }}}
88 } # print_version()
90 sub usage {
91 # Send the help message to stdout {{{
92 my $Retval = shift;
94 if ($Opt{'verbose'}) {
95 print("\n");
96 print_version();
98 print(<<"END");
100 Usage: $progname [options] [file [files [...]]]
102 Create Graphviz data from IRC logs.
104 Options:
106 -c X, --count X
107 Show only connections that have been repeated at least X times.
108 -h, --help
109 Show this help.
110 -v, --verbose
111 Increase level of verbosity. Can be repeated.
112 --version
113 Print version information.
114 --debug
115 Print debugging messages.
117 Examples:
118 irc-conn irc/2014/09/*.log | xdot
119 zcat irc/2014/09/*.log.gz | irc-conn -c 50 | dot -o conn.svg -Tsvg
120 zcat irc/2014/09/*.log.gz | irc-conn -c 50 | dot -Tx11
123 exit($Retval);
124 # }}}
125 } # usage()
127 sub msg {
128 # Print a status message to stderr based on verbosity level {{{
129 my ($verbose_level, $Txt) = @_;
131 if ($Opt{'verbose'} >= $verbose_level) {
132 print(STDERR "$progname: $Txt\n");
134 return;
135 # }}}
136 } # msg()
138 sub D {
139 # Print a debugging message {{{
140 $Debug || return;
141 my @call_info = caller;
142 chomp(my $Txt = shift);
143 my $File = $call_info[1];
144 $File =~ s#\\#/#g;
145 $File =~ s#^.*/(.*?)$#$1#;
146 print(STDERR "$File:$call_info[2] $$ $Txt\n");
147 return('');
148 # }}}
149 } # D()
151 __END__
153 # Plain Old Documentation (POD) {{{
155 =pod
157 =head1 NAME
161 =head1 SYNOPSIS
163 [options] [file [files [...]]]
165 =head1 DESCRIPTION
169 =head1 OPTIONS
171 =over 4
173 =item B<-h>, B<--help>
175 Print a brief help summary.
177 =item B<-v>, B<--verbose>
179 Increase level of verbosity. Can be repeated.
181 =item B<--version>
183 Print version information.
185 =item B<--debug>
187 Print debugging messages.
189 =back
191 =head1 BUGS
195 =head1 AUTHOR
197 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
199 =head1 COPYRIGHT
201 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
202 This is free software; see the file F<COPYING> for legalese stuff.
204 =head1 LICENCE
206 This program is free software: you can redistribute it and/or modify it
207 under the terms of the GNU General Public License as published by the
208 Free Software Foundation, either version 2 of the License, or (at your
209 option) any later version.
211 This program is distributed in the hope that it will be useful, but
212 WITHOUT ANY WARRANTY; without even the implied warranty of
213 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
214 See the GNU General Public License for more details.
216 You should have received a copy of the GNU General Public License along
217 with this program.
218 If not, see L<http://www.gnu.org/licenses/>.
220 =head1 SEE ALSO
222 =cut
224 # }}}
226 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :