Debian Codegraph @

helper/update-date

raw
1 #! /usr/bin/perl
2 use warnings;
3 use strict;
4 use integer;
5 use FindBin;
6 use lib $FindBin::RealBin;
7 use Def;
8
9 # This helper script automatically updates debram's issue date in
10 # several files (the files are named in the following block). The
11 # script accepts date and time in any format the date(1) command
12 # understands, but it writes the date (and time) to each file in that
13 # file's appropriate format. Example usage:
14 #
15 # $ update-date '24 Jan 2005 21:00'
16 #
17 # When also running the helper/update-ver script, you probably want to
18 # run that script first, then this one. Otherwise debian/changelog is
19 # updated in a different manner than you probably thought to update it.
20 #
21 # (Bug: This script, like helper/update-ver, uses far too much memory
22 # when it runs. Because the script is only a development helper,
23 # because few people will ever run the script, because the memory waste
24 # is theoretically inaesthetic but practically probably inconsequential,
25 # there is no plan to fix the bug.)
26 #
27 #
28
29 my $warn_msg = "$0: cannot find date line in ";
30
31 my $ind;
32 @ARGV == 1 && ( $ind = `date -ud'$ARGV[0]'`, !$? )
33 or die "usage: $0 date\n";
34 my $dtd = `date -ud'$ind' +'%e %B %Y'`; $dtd =~ s/^\s*//; chomp $dtd;
35 my $cld = `date -ud'$ind' -R` ; $cld =~ s/^\s*//; chomp $cld;
36
37 open DT, '<', $Def::debram_txt;
38 open D1, '<', $Def::debram_1;
39 open DL, '<', $Def::descloc;
40 open CL, '<', $Def::changelog;
41 open RM, '<', $Def::readme;
42 my @dt = <DT>;
43 my @d1 = <D1>;
44 my @dl = <DL>;
45 my @cl = <CL>;
46 my @rm = <RM>;
47 close DT;
48 close D1;
49 close DL;
50 close CL;
51 close RM;
52
53 my $str_authe = "${Def::author} <${Def::email}>";
54 my $pat_authe;
55 {
56 my $qm = quotemeta $str_authe;
57 $pat_authe = qr/$qm/;
58 }
59
60 $dt[8] =~
61 s/^(Version )(\d+\.\d+\.\d+[a-z]?)(, )(\S(?:.*?\S)??)\s*$/$1$2$3$dtd\n/
62 or warn "$warn_msg${Def::debram_txt}\n";
63 $d1[1] =~ s/^( ")([^"]*?)(")/$1$dtd$3/
64 or warn "$warn_msg${Def::debram_1}\n";
65 {
66 my $i = 0;
67 ++$i until $i > $#dl || $dl[$i] =~ /^DATA\s*$/;
68 ++$i until $i > $#dl || $dl[$i] =~ /^The issue date is\s*$/;
69 $i += 2;
70 $i <= $#dl && $dl[$i] =~ s/^( )(\S(?:.*?\S)??)\s*$/$1$dtd\n/
71 or warn "$warn_msg${Def::descloc}\n";
72 }
73 {
74 my $i = 0;
75 ++$i until $i > $#cl ||
76 $cl[$i] =~ s/^( -- $pat_authe )(\S(?:.*?\S)??)\s*$/$1$cld\n/;
77 $i <= $#cl or warn "$warn_msg${Def::changelog}\n";
78 }
79 {
80 my $i = $#rm;
81 --$i until $i < 0 ||
82 $rm[$i] =~ s/^.*\S.*\n/$str_authe, $cld\n/;
83 $i >= 0 or warn "$warn_msg${Def::readme}\n"
84 }
85
86 open DT, '>', $Def::debram_txt;
87 open D1, '>', $Def::debram_1;
88 open DL, '>', $Def::descloc;
89 open CL, '>', $Def::changelog;
90 open RM, '>', $Def::readme;
91 print DT @dt;
92 print D1 @d1;
93 print DL @dl;
94 print CL @cl;
95 print RM @rm;
96 close DT;
97 close D1;
98 close DL;
99 close CL;
100 close RM;
101