File: addtailcalls.pl

package info (click to toggle)
notion 4.0.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,676 kB
  • sloc: ansic: 47,508; sh: 2,096; makefile: 603; perl: 270
file content (33 lines) | stat: -rwxr-xr-x 726 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl

use strict;
use warnings;

my @stack = ();

sub firstfield {
  my $arg = shift;
  if (!defined($arg)) { return undef; }
  $arg =~ /([^\t]*)/;
  return $1;
}

while (<STDIN> =~ /(\w)\t([^\t]*)\t(.*)/) {
  my ($action, $called, $rest) = ($1, $2, $3);
  if ($action eq "e") {
    push(@stack, "$called\t$rest");
    print "e\t$called\t$rest\n";
  }
  elsif ($action eq "x") {
    my $parent = pop(@stack);
    if (defined $parent) {
      my $parentcalled = firstfield($parent);
      while (defined $parent and $parentcalled ne $called) {
        print "x\t$parentcalled\t$rest\n";
        $parent = pop(@stack);
        $parentcalled = firstfield($parent);
      }
    }
    print "x\t$called\t$rest\n";
  }
}