3 #=======================================================================
5 # File ID: acd2d3a2-4610-11e4-9bb4-c80aa9e67bbd
7 # Create a directed graph for Graphviz by reading plain text lines from
8 # files or stdin, each line is a node label. Adjacent lines are
9 # connected in the graph, an empty line splits the graph.
11 # Character set: UTF-8
12 # ©opyleft 2014– Øyvind A. Holm <sunny@sunbase.org>
13 # License: GNU General Public License version 2 or later, see end of
14 # file for legal stuff.
15 #=======================================================================
36 $progname =~ s/^.*\/(.*?)$/$1/;
37 our $VERSION = '0.00';
39 Getopt
::Long
::Configure
('bundling');
42 'count|c=i' => \
$Opt{'count'},
43 'debug' => \
$Opt{'debug'},
44 'help|h' => \
$Opt{'help'},
45 'verbose|v+' => \
$Opt{'verbose'},
46 'version' => \
$Opt{'version'},
48 ) || die("$progname: Option error. Use -h for help.\n");
50 $Opt{'debug'} && ($Debug = 1);
51 $Opt{'help'} && usage
(0);
52 if ($Opt{'version'}) {
56 $Opt{'count'} < 1 && die("$progname: -c/--count argument must be higher than zero\n");
64 my ($curr, $prev) = ('', '');
67 print("digraph g {\n");
68 while (my $line = <>) {
72 if ($line =~ /^(.+)$/) {
74 if (length($prev) && $prev ne $curr) {
75 $used{"$prev $curr"}++;
76 ($used{"$prev $curr"} == $Opt{'count'}) && (
77 print("\"$prev\" -> \"$curr\";\n")
91 # Print program version {{{
92 print("$progname v$VERSION\n");
98 # Send the help message to stdout {{{
101 if ($Opt{'verbose'}) {
107 Usage: $progname [options] [file [files [...]]]
109 Create a directed graph for Graphviz by reading plain text lines from
110 files or stdin, each line is a node label. Adjacent lines are connected
111 in the graph, an empty line splits the graph.
116 Only display connections that have been repeated at least X times.
120 Increase level of verbosity. Can be repeated.
122 Print version information.
124 Print debugging messages.
132 # Print a status message to stderr based on verbosity level {{{
133 my ($verbose_level, $Txt) = @_;
135 if ($Opt{'verbose'} >= $verbose_level) {
136 print(STDERR
"$progname: $Txt\n");
143 # Print a debugging message {{{
145 my @call_info = caller;
146 chomp(my $Txt = shift);
147 my $File = $call_info[1];
149 $File =~ s
#^.*/(.*?)$#$1#;
150 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
157 # Plain Old Documentation (POD) {{{
167 [options] [file [files [...]]]
177 =item B<-h>, B<--help>
179 Print a brief help summary.
181 =item B<-v>, B<--verbose>
183 Increase level of verbosity. Can be repeated.
187 Print version information.
191 Print debugging messages.
201 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
205 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
206 This is free software; see the file F<COPYING> for legalese stuff.
210 This program is free software: you can redistribute it and/or modify it
211 under the terms of the GNU General Public License as published by the
212 Free Software Foundation, either version 2 of the License, or (at your
213 option) any later version.
215 This program is distributed in the hope that it will be useful, but
216 WITHOUT ANY WARRANTY; without even the implied warranty of
217 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
218 See the GNU General Public License for more details.
220 You should have received a copy of the GNU General Public License along
222 If not, see L<http://www.gnu.org/licenses/>.
230 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :