2 # Generates index files from examples .meta file info.
3 # Copyright (C) 2008 Red Hat Inc.
5 # This file is part of systemtap, and is free software. You can
6 # redistribute it and/or modify it under the terms of the GNU General
7 # Public License (GPL); either version 2, or (at your option) any
27 $outputdir = $ARGV[1];
29 $outputdir = $inputdir;
33 print "Parsing .meta files in $inputdir...\n";
34 find
(\
&parse_meta_files
, $inputdir);
42 # Adds a formatted meta entry to a given file handle as text.
43 sub add_meta_txt
(*;$) {
46 print $file "$scripts{$meta}{name} - $scripts{$meta}{title}\n";
48 print $file "output: $scripts{$meta}{output}, ";
49 print $file "exits: $scripts{$meta}{exit}, ";
50 print $file "status: $scripts{$meta}{status}\n";
52 print $file "subsystem: $scripts{$meta}{subsystem}, ";
53 print $file "keywords: $scripts{$meta}{keywords}\n\n";
55 $Text::Wrap::columns = 72;
56 my $description = wrap
(' ', ' ', $scripts{$meta}{description
});
57 print $file "$description\n\n\n";
60 # Adds a formatted meta entry to a given file handle as text.
61 sub add_meta_html
(*;$) {
64 my $name = $scripts{$meta}{name
};
65 print $file "<li><a href=\"$name\">$name</a
> ";
66 print $file "- $scripts{$meta}{title
}<br
>\n";
68 print $file "output
: $scripts{$meta}{output
}, ";
69 print $file "exits
: $scripts{$meta}{exit}, ";
70 print $file "status
: $scripts{$meta}{status
}<br
>\n";
72 print $file "subsystem
: $scripts{$meta}{subsystem
}, ";
73 print $file "keywords
: $scripts{$meta}{keywords
}<br
>\n";
75 print $file "<p
>$scripts{$meta}{description
}";
76 print $file "</p></li>\n";
79 my $HEADER = "SYSTEMTAP EXAMPLES INDEX
\n"
80 . "(see also subsystem-index
.txt
, keyword-index
.txt
)\n\n";
82 my $header_tmpl = "$inputdir/html/html_header.tmpl
";
83 open(TEMPLATE, "<$header_tmpl")
84 || die "couldn
't open $header_tmpl, $!";
85 my $HTMLHEADER = do { local $/; <TEMPLATE> };
87 my $footer_tmpl = "$inputdir/html/html_footer.tmpl";
88 open(TEMPLATE, "<$footer_tmpl")
89 || die "couldn't
open $footer_tmpl, $!";
90 my $HTMLFOOTER = do { local $/; <TEMPLATE> };
93 # Output full index and collect subsystems and keywords
94 my $fullindex = "$outputdir/index.txt
";
95 open (FULLINDEX, ">$fullindex")
96 || die "couldn
't open $fullindex: $!";
97 print "Creating $fullindex...\n";
98 print FULLINDEX $HEADER;
100 my $fullhtml = "$outputdir/index.html";
101 open (FULLHTML, ">$fullhtml")
102 || die "couldn't
open $fullhtml: $!";
103 print "Creating
$fullhtml...\n";
104 print FULLHTML $HTMLHEADER;
105 print FULLHTML "<h2
>All Examples
</h2
>\n";
106 print FULLHTML "<ul
>\n";
108 foreach $meta (sort keys %scripts) {
110 add_meta_txt(\*FULLINDEX, $meta);
111 add_meta_html(\*FULLHTML, $meta);
114 foreach $subsystem (split(/ /, $scripts{$meta}{subsystem})) {
115 if (defined $subsystems{$subsystem}) {
116 push(@{$subsystems{$subsystem}}, $meta);
118 $subsystems{$subsystem} = [ $meta ];
123 foreach $keyword (split(/ /, $scripts{$meta}{keywords})) {
124 if (defined $keywords{$keyword}) {
125 push(@{$keywords{$keyword}}, $meta);
127 $keywords{$keyword} = [ $meta ];
131 print FULLHTML "</ul
>\n";
132 print FULLHTML $HTMLFOOTER;
136 my $SUBHEADER = "SYSTEMTAP EXAMPLES INDEX BY SUBSYSTEM
\n"
137 . "(see also
index.txt
, keyword-index
.txt
)\n\n";
139 # Output subsystem index
140 my $subindex = "$outputdir/subsystem-index
.txt
";
141 open (SUBINDEX, ">$subindex")
142 || die "couldn
't open $subindex: $!";
143 print "Creating $subindex...\n";
144 print SUBINDEX $SUBHEADER;
146 my $subhtml = "$outputdir/subsystem-index.html";
147 open (SUBHTML, ">$subhtml")
148 || die "couldn't
open $subhtml: $!";
149 print "Creating
$subhtml...\n";
150 print SUBHTML $HTMLHEADER;
151 print SUBHTML "<h2
>Examples by Subsystem
</h2
>\n";
153 foreach $subsystem (sort keys %subsystems) {
154 print SUBINDEX "= " . (uc $subsystem) . " =\n\n";
155 print SUBHTML "<h3
>" . (uc $subsystem) . "</h3
>\n";
156 print SUBHTML "<ul
>\n";
158 foreach $meta (sort @{$subsystems{$subsystem}}) {
159 add_meta_txt(\*SUBINDEX,$meta);
160 add_meta_html(\*SUBHTML,$meta);
162 print SUBHTML "</ul
>\n";
164 print SUBHTML $HTMLFOOTER;
168 my $KEYHEADER = "SYSTEMTAP EXAMPLES INDEX BY KEYWORD
\n"
169 . "(see also
index.txt
, subsystem-index
.txt
)\n\n";
171 # Output subsystem index
172 my $keyindex = "$outputdir/keyword-index
.txt
";
173 open (KEYINDEX, ">$keyindex")
174 || die "couldn
't open $keyindex: $!";
175 print "Creating $keyindex...\n";
176 print KEYINDEX $KEYHEADER;
178 my $keyhtml = "$outputdir/keyword-index.html";
179 open (KEYHTML, ">$keyhtml")
180 || die "couldn't
open $keyhtml: $!";
181 print "Creating
$keyhtml...\n";
182 print KEYHTML $HTMLHEADER;
183 print KEYHTML "<h2
>Examples by Keyword
</h2
>\n";
185 foreach $keyword (sort keys %keywords) {
186 print KEYINDEX "= " . (uc $keyword) . " =\n\n";
187 print KEYHTML "<h3
>" . (uc $keyword) . "</h3
>\n";
188 print KEYHTML "<ul
>\n";
190 foreach $meta (sort @{$keywords{$keyword}}) {
191 add_meta_txt(\*KEYINDEX,$meta);
192 add_meta_html(\*KEYHTML,$meta);
194 print KEYHTML "</ul
>\n";
196 print KEYHTML $HTMLFOOTER;
201 = ("systemtapcorner
.gif
",
203 "systemtaplogo
.png
");
204 if ($inputdir ne $outputdir) {
206 print "Copying support files
...\n";
207 foreach $file (@supportfiles) {
208 my $orig = "$inputdir/$file";
209 my $dest = "$outputdir/$file";
210 print "Copying
$file to
$dest...\n";
211 copy("$orig", $dest) or die "$file cannot be copied to
$dest, $!";
215 sub parse_meta_files {
217 my $filename = $File::Find::name;
219 if (-f $file && $file =~ /\.meta$/) {
220 open FILE, $file or die "couldn
't open '$file': $!\n";
222 print "Parsing $filename...\n";
233 if (/^title: (.*)/) { $title = $1; }
234 if (/^name: (.*)/) { $name = $1; }
235 if (/^keywords: (.*)/) { $keywords = $1; }
236 if (/^subsystem: (.*)/) { $subsystem = $1; }
237 if (/^status: (.*)/) { $status = $1; }
238 if (/^exit: (.*)/) { $exit = $1; }
239 if (/^output: (.*)/) { $output = $1; }
240 if (/^description: (.*)/) { $description = $1; }
244 # Remove extra whitespace
245 $keywords =~ s/^\s*//;
246 $keywords =~ s/\s*$//;
247 $subsystem =~ s/^\s*//;
248 $subsystem =~ s/\s*$//;
250 # The subdir without the inputdir prefix, nor any slashes.
251 my $subdir = substr $File::Find::dir, (length $inputdir);
254 $name = "$subdir/$name";
260 keywords => $keywords,
261 subsystem => $subsystem,
265 description => $description
268 # chop off the search dir prefix.
269 $inputdir =~ s/\/$//;
270 $meta = substr $filename, (length $inputdir) + 1;
271 $scripts{$meta} = $script;
273 # Put .stp script in output dir if necessary and create
274 # subdirs if they don't exist yet
.
275 if ($inputdir ne $outputdir) {
276 # The subdir without the inputdir prefix, nor any slashes.
277 my $destdir = substr $File::Find::dir, (length $inputdir);
280 if (! -d
"$outputdir/$subdir") {
281 mkpath
("$outputdir/$subdir", 1, 0711);
284 my $orig = substr $name, (length $subdir);
286 my $dest = "$outputdir/$name";
287 print "Copying $orig to $dest...\n";
288 copy
($orig, $dest) or die "$orig cannot be copied to $dest, $!";