Permalink
Switch branches/tags
Find file
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (30 sloc) 783 Bytes
#!/usr/bin/perl
# Copyright (C) 2008-2011, The Perl Foundation.
use strict;
use warnings;
use 5.008;
binmode STDOUT, ':utf8';
my ($backend, @files) = @ARGV;
print <<"END_HEAD";
# This file automatically generated by $0
END_HEAD
foreach my $file (@files) {
print "# From $file\n\n";
open(my $fh, "<:utf8", $file) or die "$file: $!";
my $in_omit = 0;
my @conds;
while (<$fh>) {
if (/^#\?if\s+(!)?\s*(\w+)\s*$/) {
push @conds,$in_omit;
$in_omit = $in_omit || ($1 && $2 eq $backend || !$1 && $2 ne $backend);
}
elsif (/^#\?endif\s*$/) {
$in_omit = pop @conds;
}
elsif (!$in_omit) {
print;
}
}
close $fh;
}
print "\n# vim: set ft=perl6 nomodifiable :\n";