gstreamer/tests/old/examples/manual/extract.pl
Thomas Vander Stichele bba6ac4b74 docs/: restructure so that common stuff is shown first
Original commit message from CVS:
* docs/Makefile.am:
* docs/manual/elements-api.xml:
restructure so that common stuff is shown first
* docs/manual/init-api.xml:
convert to examples
* docs/manual/manual.xml:
* docs/manuals.mak:
* docs/url.entities:
link to API on the website, possibly override later in build
* examples/manual/.cvsignore:
ignore more
* examples/manual/Makefile.am:
add more examples
* examples/manual/extract.pl:
error out on failure
2004-09-08 23:18:55 +00:00

60 lines
1.1 KiB
Perl
Executable file

#!/usr/bin/perl
# extract code fragments from xml program listings
# first argument: source code file to find
# second argument: xml files to extract code from
# main
# decodes xml by translating & < > back to what they should be
sub
xml_decode ($)
{
my $input = shift;
$input =~ s/\&/&/g;
$input =~ s/&lt;/</g;
$input =~ s/&gt;/>/g;
return $input;
}
# main
my $output = shift @ARGV;
$found = 0;
foreach $file (@ARGV)
{
open FILE, $file or die "Cannot open file $file";
while ($line = <FILE>)
{
if ($line =~ /\/\* example-begin $output \*\//)
{
print "Extracting $output from $file\n";
$found = 1;
open OUTPUT, ">$output";
print OUTPUT xml_decode ($line);
my $example = 1;
while (($line = <FILE>) && $example)
{
if ($line =~ /\/\* example-end/)
{
print OUTPUT xml_decode ($line);
close OUTPUT;
$example = 0;
}
else
{
print OUTPUT xml_decode ($line);
}
}
}
}
}
if (!$found)
{
print "Could not find $output example !\n";
exit(1);
}