File: gps

package info (click to toggle)
arename 4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,112 kB
  • sloc: perl: 640; sh: 585; makefile: 147
file content (122 lines) | stat: -rw-r--r-- 2,707 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/perl
use warnings;
use strict;

use File::Find;

my (%cfg, %replaces, $arename_version);
sub make_executable;
sub generate;

%cfg = (
    'arename.in' => {
        post => \&make_executable },
    'ataglist.in' => {
        post => \&make_executable },
    'ARename.pm.in' => {
        output => 'modules/ARename.pm' });

%replaces = (
    arenameversioninfo => sub { return $arename_version; },
    perl => sub {
        if (defined $ENV{PERL}) {
            return $ENV{PERL};
        } else {
            return q{/usr/bin/perl};
        }});

sub line_filter {
    my ($line) = @_;

    foreach my $p (keys %replaces) {
        my $r = $replaces{$p}->();
        $line =~ s,\@\@$p\@\@,$r,g
    }
    return "$line";
}

sub make_executable {
    my ($conf) = @_;

    my $file = $conf->{output};
    print " -!- Making `$file' executable.\n";
    my $mode = (stat($file))[2] or die "Couldn't stat `$file': $!\n";
    chmod((($mode & 07777) | ($mode & 0444) >> 2), $file)
        or die "Couldn't chmod `$file': $!\n";
    return 1;
}

sub remove_in {
    my ($in) = @_;
    $in =~ s,\.in$,,;
    return $in;
}

sub uptodate {
    my ($files) = @_;

    my $i = $files->{in};
    my $o = $files->{out};
    return 0 if (! -e $o);
    my $ti = (stat($i))[9] or die "Couldn't stat `$i': $!\n";
    my $to = (stat($o))[9] or die "Couldn't stat `$o': $!\n";

    return 0 if ($ti > $to);
    printf "`$o' is up-to-date. Leaving it alone.\n";
    return 1;
}

sub generate {
    my ($file, $conf) = @_;
    my ($in, $out);

    return 0 if (uptodate({ in => $file, out => $conf->{output} }));

    print "Generating `" . $conf->{output} . "' from `$file'...\n";

    open $in, q{<}, $file or die "Couldn't open `$file': $!\n";
    open $out, q{>}, $conf->{output}
        or die "Couldn't open `" . $conf->{output} . "': $!\n";

    while (my $line = <$in>) {
        chomp $line;
        print {$out} line_filter($line), "\n";
    }

    close $in;
    close $out;

    $conf->{post}->($conf);
    return 1;
}

sub filter {
    my $f = $File::Find::name;
    return 0 if ($f !~ m/.*\.in$/);
    $f =~ s,^\./,,;
    my %c = (
        post => sub { return 1; },
        output => remove_in($f));
    foreach my $k (sort keys %c) {
        my $thing = $cfg{$f}->{$k};
        $c{$k} = $thing if (defined $thing);
    }
    return generate($f, \%c);
}

my ($pipe);
open $pipe, q{./bin/getversion.sh build |}
    or die "Couldn't generate build version: $!\n";
$arename_version = <$pipe>;
chomp $arename_version;
close $pipe;

find({ wanted => \&filter,
       no_chdir => 1,
       follow => 0,
       follow_fast => 0,
       follow_skip => 2,
       dangling_symlinks => 0},
     ( q{.} ));

exit 0;