File: gen-cat.pl

package info (click to toggle)
nqp 2024.09%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,972 kB
  • sloc: java: 28,087; perl: 3,479; ansic: 451; makefile: 202; javascript: 68; sh: 1
file content (47 lines) | stat: -rwxr-xr-x 1,083 bytes parent folder | download
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
#!/usr/bin/env perl
# Copyright (C) 2008-2011, The Perl Foundation.

use strict;
use warnings;
use 5.008;

binmode STDOUT, ':utf8';

my ($backend, $stage, @files) = @ARGV;

if ($stage ne "stage1" && $stage ne "stage2") {
    unshift @files, $stage;
    $stage = "asdfgh";
}

print <<"END_HEAD";
# This file automatically generated by gen-cat.pl

END_HEAD


foreach my $file (@files) {
    print "#line 1 NQP::$file\n";
    open(my $fh, "<:utf8",  $file) or die "$file: $!";
    my $in_omit = 0;
    my @conds;
    while (<$fh>) {
        if (/^#\?if\s+(!)?\s*(stage\d)\s*$/) {
            push @conds,$in_omit;
            $in_omit = $in_omit || ($1 && $2 eq $stage || !$1 && $2 ne $stage);
        }
        elsif (/^#\?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";