#!/usr/bin/perl # # Alex Linke # # The filter's license is available here: # http://www.use-strict.de/files/software/LICENSE.txt # There's no warranty at all - Use at own risk! use strict; my $VERSION = '0.04'; usage() unless ( @ARGV == 1 ); usage(0) if ( $ARGV[0] =~ /^-(h|-help)$/ ); my $Fin = $ARGV[0]; # handle STDIN (piped data) $Fin = "/dev/stdin" if ( $Fin eq '-' ); my ( @finalStates, $result ); open FH, "$Fin" or die "Error opening '$Fin': '$!'\n"; my $lastState = ""; # extract states foreach( ) { chomp; next unless ( s/^(f?s\d+):// || $lastState ); my $originState; # already found a state in the last loop that isn't finished yet? if ( $lastState eq "" ) { $originState = $1; } else { $originState = $lastState; } # is another loop needed for _this_ state? if ( /,$/ ) { $lastState = $originState; } else { $lastState = ""; } while( s/^(?:\s+)]+)>?\s+-\>\s+(f?s\d+)[\.,]?// ) { my ( $trigger, $destState ) = ( $1, $2 ); $result .= "\t$originState -> $destState [label=\"$trigger\"];\n"; } # remeber if originState is final: push @finalStates, $originState if ( $originState =~ /^f/ ); } # final states -> doublecircle $result .= "\t$_ [shape=\"doublecircle\"];\n" foreach @finalStates; # print results or notify unless ( $result =~ /^$/ ) { print <