]> Sergey Matveev's repositories - public-inbox.git/blob - Documentation/common.perl
doc: lei-q: document SEARCH TERMS prefixes
[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         next if $s eq $orig;
38         seek($fh, 0, SEEK_SET) or die "seek: $!";
39         truncate($fh, 0) or die "truncate: $!";
40         print $fh $s or die "print: $!";
41         close $fh or die "close: $!";
42 }
43
44 sub search_terms {
45         my $help = eval('\@PublicInbox::Search::HELP');
46         my $s = '';
47         my $pad = 0;
48         my $i;
49         for ($i = 0; $i < @$help; $i += 2) {
50                 my $pfx = $help->[$i];
51                 my $n = length($pfx);
52                 $pad = $n if $n > $pad;
53                 $s .= $pfx . "\0";
54                 $s .= $help->[$i + 1];
55                 $s .= "\f\n";
56         }
57         $pad += 2;
58         my $padding = ' ' x ($pad + 4);
59         $s =~ s/^/$padding/gms;
60         $s =~ s/^$padding(\S+)\0/"    $1".(' ' x ($pad - length($1)))/egms;
61         $s =~ s/\f\n/\n/gs;
62         $s =~ s/^  //gms;
63         substr($s, 0, 0, "=for comment\nAUTO-GENERATED-SEARCH-TERMS-BEGIN\n\n");
64         $s .= "\n=for comment\nAUTO-GENERATED-SEARCH-TERMS-END\n";
65 }