]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/common.perl
3a6617c474304ab598ac85964be00f27861aeef3
[public-inbox.git] / Documentation / common.perl
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use Fcntl qw(SEEK_SET);
6 my $have_search = eval { require PublicInbox::Search; 1 };
7 my $addr = 'meta@public-inbox.org';
8 for my $pod (@ARGV) {
9         open my $fh, '+<', $pod or die "open($pod): $!";
10         my $s = do { local $/; <$fh> } // die "read $!";
11         my $orig = $s;
12         $s =~ s!^=head1 COPYRIGHT\n.+?^=head1([^\n]+)\n!=head1 COPYRIGHT
13
14 Copyright all contributors L<mailto:$addr>
15
16 License: AGPL-3.0+ L<https://www.gnu.org/licenses/agpl-3.0.txt>
17
18 =head1$1
19                 !ms;
20
21         $s =~ s!^=head1 CONTACT\n.+?^=head1([^\n]+)\n!=head1 CONTACT
22
23 Feedback welcome via plain-text mail to L<mailto:$addr>
24
25 The mail archives are hosted at L<https://public-inbox.org/meta/> and
26 L<http://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/meta/>
27
28 =head1$1
29                 !ms;
30         $have_search and $s =~ s!^=for\scomment\n
31                         ^AUTO-GENERATED-SEARCH-TERMS-BEGIN\n
32                         .+?
33                         ^=for\scomment\n
34                         ^AUTO-GENERATED-SEARCH-TERMS-END\n
35                         !search_terms()!emsx;
36         $s =~ s/[ \t]+$//sgm;
37         if ($s eq $orig) {
38                 my $t = time;
39                 utime($t, $t, $fh);
40         } else {
41                 seek($fh, 0, SEEK_SET) or die "seek: $!";
42                 truncate($fh, 0) or die "truncate: $!";
43                 print $fh $s or die "print: $!";
44                 close $fh or die "close: $!";
45         }
46 }
47
48 sub search_terms {
49         my $help = eval('\@PublicInbox::Search::HELP');
50         my $s = '';
51         my $pad = 0;
52         my $i;
53         for ($i = 0; $i < @$help; $i += 2) {
54                 my $pfx = $help->[$i];
55                 my $n = length($pfx);
56                 $pad = $n if $n > $pad;
57                 $s .= $pfx . "\0";
58                 $s .= $help->[$i + 1];
59                 $s .= "\f\n";
60         }
61         $pad += 2;
62         my $padding = ' ' x ($pad + 4);
63         $s =~ s/^/$padding/gms;
64         $s =~ s/^$padding(\S+)\0/"    $1".(' ' x ($pad - length($1)))/egms;
65         $s =~ s/\f\n/\n/gs;
66         $s =~ s/^  //gms;
67         substr($s, 0, 0, "=for comment\nAUTO-GENERATED-SEARCH-TERMS-BEGIN\n\n");
68         $s .= "\n=for comment\nAUTO-GENERATED-SEARCH-TERMS-END\n";
69 }