File: callhtml.pl

package info (click to toggle)
espresso 5.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 146,004 kB
  • ctags: 17,245
  • sloc: f90: 253,041; sh: 51,271; ansic: 27,494; tcl: 15,570; xml: 14,508; makefile: 2,958; perl: 2,035; fortran: 1,924; python: 337; cpp: 200; awk: 57
file content (147 lines) | stat: -rwxr-xr-x 2,916 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/perl -w

use strict;

{
    # $basedir is directory where this script is
    my $basedir = $0;
    $basedir =~ s/(.*)\/.*/$1/;
    my @sources = split(/ /, `echo $basedir/*/*.f90`);

    # grab program, function and subroutine declarations
    my (%place, %fname, %pname, %sname);
    foreach my $file (@sources)
    {
	open(IN, "$file");
	while (<IN>)
	{
	    $_ = "\L$_"; # cast everything to lowercase
	    if (/^[^!'""']*\bfunction\s+(\w+)/o && ! /^\s*end\s+function\b/o)
	    {
		$fname{$1} = 1;
		insert_place(\%place, $1, $file);
	    }
	    elsif (/^\s*program\s+(\w+)/o)
	    {
		$pname{$1} = 1;
		insert_place(\%place, $1, $file);
	    }
	    elsif (/^\s*(?:(?:pure|recursive)\s+)?subroutine\s+(\w+)/o)
	    {
		$sname{$1} = 1;
		insert_place(\%place, $1, $file);
	    }
	}
	close(IN);
    }
    my @targets = sort keys %place;
    my @programs = sort keys %pname;
    my @functions = sort keys %fname;

    # html preamble
    print "<html>\n";
    print "<body>\n";
    print "\n";

    # list of programs
    print "<dl>\n";
    print "  <dt>list of programs:</dt>\n";
    print "  <dd><p>\n";
    foreach my $program (@programs)
    {
	print "    <a href=\"#$program\">$program</a>\n";
    }
    print "  </p></dd>\n";
    print "</dl>\n";
    print "\n";

    # list of all routines
    print "<dl>\n";
    foreach my $name (@targets)
    {
	print "  <dt><a name=\"$name\">";
	if (defined $pname{$name})
	{
	    print "program ";
	}
	elsif (defined $sname{$name})
	{
	    print "subroutine ";
	}
	elsif (defined $fname{$name})
	{
	    print "function ";
	}
	print "$name</a></dt>\n";

	my %cname;
	my @files = split(/ /, $place{$name});
	foreach my $file (@files)
	{
	    print "  <dd><p>defined in file: $file<br>\n";
	    print "    calls:\n";

	    my $current = "";
	    open(IN, $file);
	    while (<IN>)
	    {
		$_ = "\L$_";
		if (/^\s*program\s+(\w+)/o)
		{
		    $current = "$1";
		}
		elsif (/^\s*(?:(?:pure|recursive)\s+)?subroutine\s+(\w+)/o)
		{
		    $current = "$1";
		}
		elsif (/^[^!'""']*\bfunction\s+(\w+)/o)
		{
		    $current = "$1";
		}
		# here we are inside the relevant program/subroutine/function
		elsif ($current eq $name)
		{
		    # subroutine calls
		    if (/^\s*call\s+(\w+)/o)
		    {
			$cname{$1} = 1;
		    }
		    # function calls
		    foreach my $fun (@functions)
		    {
			if ($fun ne $name && /^[^!'""']*\b$fun\b/)
			{
			    $cname{$fun} = 1;
			}
		    }
		}
	    }
	    close(IN);
	    my @calls = sort keys %cname;
	    foreach my $call (@calls)
	    {
		print "    <a href=\"#$call\">$call</a>\n";
	    }
	    print "  </p></dd>\n";
	}
    }
    print "</dl>\n";

    # html postamble
    print "\n";
    print "</body>\n";
    print "</html>\n";
}

sub insert_place
{
    my ($place, $name, $file) = @_;
    if (defined $$place{$name})
    {
	$$place{$name} = "$$place{$name} $file";
    }
    else
    {
	$$place{$name} = "$file";
    }
}