help
Rev | Line | |
---|
[0214596] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | #package: UAM Text Tools |
---|
| 4 | #component: gph |
---|
| 5 | #version: 1.0 |
---|
| 6 | #author: Tomasz Obrebski |
---|
| 7 | |
---|
| 8 | use strict; |
---|
| 9 | use Getopt::Long; |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | my @process; |
---|
| 13 | my $help=0; |
---|
| 14 | my $reset; |
---|
| 15 | my $interactive=1; |
---|
| 16 | |
---|
| 17 | GetOptions("process|p=s" => \@process, |
---|
| 18 | "help|h" => \$help, |
---|
| 19 | "reset|r=s" => \$reset, |
---|
| 20 | "interactive|i" => \$interactive); |
---|
| 21 | |
---|
| 22 | if($help) |
---|
| 23 | { |
---|
| 24 | print <<'END' |
---|
| 25 | Usage: gph [OPTIONS] |
---|
| 26 | |
---|
| 27 | Options: |
---|
| 28 | -p tag Process segments with this tag as nodes. |
---|
| 29 | -r tag Start new graph at this tag. |
---|
| 30 | -f filename Input file (NIE DZIALA). |
---|
| 31 | -o filename Output file (NIE DZIALA). |
---|
| 32 | -i Toggle interactive mode (default=on). |
---|
| 33 | END |
---|
| 34 | ; |
---|
| 35 | exit 0; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | $|=1 if $interactive; |
---|
| 40 | |
---|
| 41 | my @prev; |
---|
| 42 | my $gph; |
---|
| 43 | |
---|
| 44 | my $n=0; |
---|
| 45 | |
---|
| 46 | while(<>) |
---|
| 47 | { |
---|
| 48 | chomp; |
---|
| 49 | my $do=0; |
---|
| 50 | |
---|
| 51 | my @line = split /\s+/; |
---|
| 52 | |
---|
| 53 | if($line[2] eq $reset) |
---|
| 54 | { |
---|
| 55 | $n=0; |
---|
| 56 | @prev = (); |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | for my $p (@process) |
---|
| 60 | { |
---|
| 61 | $do=1 if $line[2] eq $p; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | if($do) |
---|
| 65 | { |
---|
| 66 | my @preds = (); |
---|
| 67 | shift @prev while @prev+0 && $prev[0]->[1] + $prev[0]->[2] < $line[0]; |
---|
| 68 | for my $p (@prev) |
---|
| 69 | { |
---|
| 70 | push(@preds, $p->[0]) if $p->[1] + $p->[2] == $line[0]; |
---|
| 71 | } |
---|
| 72 | push @prev, [$n, $line[0], $line[1]]; |
---|
| 73 | |
---|
| 74 | $gph=' gph:'.$n.':'.join(',',@preds); |
---|
| 75 | |
---|
| 76 | $n++; |
---|
| 77 | } |
---|
| 78 | else |
---|
| 79 | { |
---|
| 80 | for my $p (@prev) |
---|
| 81 | { |
---|
| 82 | if($p->[1]+$p->[2] == $line[0]) |
---|
| 83 | { |
---|
| 84 | $p->[2] += $line[1]; |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | $gph=''; |
---|
| 89 | |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | print $_.$gph."\n"; |
---|
| 93 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.