|
6 | 6 |
|
7 | 7 | if ($#ARGV < 1) { |
8 | 8 | die <<EOF |
9 | | -Usage: $0 <infile> <outfile> [<encoder>...] |
| 9 | +Usage: $0 <resourcedir> <outfile> [<encoder>...] |
10 | 10 |
|
11 | 11 | If encoders are not specified explicitly, the single encoder name is deduced |
12 | 12 | from the name of the output file. |
13 | 13 | EOF |
14 | 14 | } |
15 | 15 |
|
16 | | -my $infile = shift; |
| 16 | +my $resourcedir = shift; |
17 | 17 | my $outfile = shift; |
18 | 18 |
|
19 | 19 | ($outfile) = $outfile =~ /(.*)/; # Untaint |
|
37 | 37 | close $fh; |
38 | 38 | $head =~ s/XXXX-XX-XX/$version/; |
39 | 39 |
|
40 | | -open($fh, '<', $infile) || die "File not found: $infile"; |
41 | | -my $template = join('', <$fh>); |
42 | | -close($fh); |
| 40 | +open($fh, '<', 'src/uk.co.terryburton.bwipp.upr') || die 'Unable to open UPR file'; |
| 41 | +my $upr = join('', <$fh>); |
| 42 | +close $fh; |
43 | 43 |
|
44 | 44 | open($fh, '>', $outfile) || die "Failed to write $outfile"; |
45 | 45 | print $fh $head; |
46 | 46 |
|
47 | 47 | my %seen; |
48 | 48 | for my $encoder (@encoders) { |
49 | | - ($_, $_, my $meta, $_) = $template =~ / |
| 49 | + my $srcfile = "src/$encoder.ps.src"; |
| 50 | + my $src_fh; |
| 51 | + open($src_fh, '<', $srcfile) || die "Unable to open source file: $srcfile"; |
| 52 | + my $src = join('', <$src_fh>); |
| 53 | + close($src_fh); |
| 54 | + |
| 55 | + ($_, $_, my $meta, $_) = $src =~ / |
50 | 56 | ^%\ --BEGIN\ (ENCODER|RENDERER|RESOURCE)\ ($encoder)--$ |
51 | 57 | (.*?) |
52 | 58 | (^[^%].*?) |
53 | 59 | ^%\ --END\ \1\ \2--$ |
54 | | - /msgx or die 'Encoder unknown'; |
| 60 | + /msgx or die "Encoder unknown: $encoder"; |
| 61 | + |
55 | 62 | (my $reqs) = $meta =~ /^% --REQUIRES (.*)--$/mg; |
56 | 63 | $reqs = '' unless defined $reqs; |
57 | | - my %reqs = ($encoder => 1); |
58 | | - $reqs{$_} = 1 foreach split ' ', $reqs; |
59 | 64 |
|
60 | | - while ($template =~ / |
61 | | - ^%\ --BEGIN\ (ENCODER|RENDERER|RESOURCE)\ ([\w-]+?)--$ |
62 | | - (.*?) |
63 | | - (^%%.*?) |
64 | | - (^[^%].*?) |
65 | | - ^%\ --END\ \1\ \2--$ |
66 | | - /msgx) { |
67 | | - my $resource = $2; |
68 | | - my $meta = $3; |
69 | | - my $dsc = $4; |
70 | | - my $body = $5; |
71 | | - next unless $reqs{$resource}; |
72 | | - next if $seen{$resource}++; |
73 | | - print $fh "$dsc$body\n"; |
| 65 | + # Build set of resources to include: dependencies + encoder itself |
| 66 | + my %reqs_set; |
| 67 | + $reqs_set{$_} = 1 foreach split(' ', $reqs); |
| 68 | + $reqs_set{$encoder} = 1; |
| 69 | + |
| 70 | + # Output resources in UPR order (matching monolithic behavior) |
| 71 | + my @resources; |
| 72 | + while ($upr =~ /^(.*)=(.*)$/mg) { |
| 73 | + my $name = $1; |
| 74 | + $name = 'preamble' if $name eq 'uk.co.terryburton.bwipp'; |
| 75 | + push @resources, $name if $reqs_set{$name}; |
| 76 | + } |
| 77 | + |
| 78 | + for my $resource (@resources) { |
| 79 | + next if $seen{$resource}++; |
| 80 | + |
| 81 | + # Map resource name to file path via UPR |
| 82 | + my $lookup = $resource eq 'preamble' ? 'uk.co.terryburton.bwipp' : $resource; |
| 83 | + (my $relpath) = $upr =~ /^$lookup=(.*)$/m; |
| 84 | + die "Resource not found in UPR: $resource" unless $relpath; |
| 85 | + |
| 86 | + my $respath = "$resourcedir/$relpath"; |
| 87 | + ($respath) = $respath =~ /(.*)/; # Untaint |
| 88 | + |
| 89 | + my $res_fh; |
| 90 | + open($res_fh, '<', $respath) || die "Unable to open resource file: $respath"; |
| 91 | + my $res = join('', <$res_fh>); |
| 92 | + close($res_fh); |
| 93 | + |
| 94 | + # Extract body from resource file (same pattern as make_monolithic.pl) |
| 95 | + $res =~ / |
| 96 | + (^%%BeginResource:\ [\w\.]+\ [\w\.-]+?\ .*?$) |
| 97 | + .*? |
| 98 | + (^%%BeginData:.*?$ |
| 99 | + .*? |
| 100 | + ^%%EndResource$) |
| 101 | + /msgx or die "Failed to parse resource: $respath"; |
| 102 | + my $body = "$1\n$2\n"; |
| 103 | + |
| 104 | + print $fh "$body\n"; |
74 | 105 | } |
75 | 106 | } |
76 | 107 |
|
|
0 commit comments