-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.pl
80 lines (58 loc) · 1.74 KB
/
version.pl
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
#!/usr/bin/perl
########################################################
#
# This script is part of the biblatex-archaeology
# package by Ingram Braun. It sole purpose is to
# mark biblatex-archaeology documentation files with
# version and date.
#
# https://www.ctan.org/help/upload-pkg
# https://www.ctan.org/help/pkg-readme
# https://www.ctan.org/help/markdown
#
########################################################
use strict;
use Carp::Assert;
use FileHandle;
use utf8::all;
use feature 'say';
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$year += 1900;
$mon++;
$mon = '0' . $mon if $mon <= 9; # trailing zero
my $date = $year . '/' . $mon . '/' . $mday;
my $version = 'v2.2';
assert( $version =~ /v\d\.\d{1,3}[a-z]?/ );
my @files = qw/
biblatex-archaeology.dtx
README.md
biblatex-archaeology_example.tex
/;
grep { version_file( $_ ) } @files;
sub version_file {
my $file = shift;
assert( $version =~ /v\d\.\d{1,2}[a-z]?/ );
my $text = '';
my $fh = FileHandle->new($file, O_RDONLY);
if (defined $fh) {
read( $fh, $text, -s $file);
undef $fh;
}
else {die "Could not open $file: $!"}
my $bak = $text;
$text =~ s/(biblatex-archaeology`?(\spackage|\sstyles)?\s\[)v\d\.\d{1,3}[a-z]?(\])/$1$version$3/gs;
$text =~ s/\[\d{4}\/\d{2}\/\d{2}\sv\d\.\d{1,3}[a-z]?\sbiblatex-archaeology/'[' . $date . ' ' . $version . ' biblatex-archaeology'/egs;
$text =~ s/(archbib\sstyles\s\[)v\d\.\d{1,3}[a-z]?(\])/$1$version$2/gs;
$text =~ s/(biblatex-archaeology-)v\d\.\d{1,3}[a-z]?/$1$version/g;
if ($text ne $bak) {
$fh = FileHandle->new($file, O_WRONLY|O_TRUNC);
if (defined $fh) {
print $fh $text;
undef $fh;
}
else {die "Could not open $file: $!"}
}
else {
say "$file not changed!";
}
}