Debian Codegraph @

debian/template-subst

raw
1 #!/usr/bin/perl -wn
2 #
3 # Implements the rudimentary templating for *.vsn-in files,
4 # see the comment in debian/rules.
5
6 use strict;
7 our %v;
8 $v{''} = '@';
9 BEGIN {
10 $v{version} = shift @ARGV;
11 $v{flavour} = shift @ARGV;
12 }
13 sub printwarning () {
14 our $printedwarning;
15 return if $printedwarning++;
16 print "# autogenerated, do not edit\n" if $.==1;
17 }
18 sub v {
19 my ($k) = @_;
20 $v{$k} // die "unknown $k";
21 }
22 our @yes;
23 printwarning unless m{^\#!};
24 if (m/^\s*\?\s*(\w+)\s*(!?)=\s*(.*?)\s*$/) {
25 my @rhs = split /\s*\|\s*/, $3;
26 push @yes, (!!(grep { v($1) eq $_ } @rhs) xor !!$2);
27 next;
28 } elsif (m/^\s*\?\s*$/) {
29 defined pop @yes or die "too many lone ? (endings)";
30 next;
31 } elsif (m/^\s*\?/) {
32 die "syntax";
33 }
34 next if grep { !$_ } @yes;
35 s{\@(\w*)\@}{ v($1) }ge;
36 print or die $!;
37 printwarning;
38 END {
39 printwarning;
40 die "too few lone ? (endings)" if @yes;
41 }