]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - tools/mkdescriptions
Remove the DANE record hint from genssl.
[user/henk/code/inspircd.git] / tools / mkdescriptions
1 #!/usr/bin/env perl
2 #
3 # InspIRCd -- Internet Relay Chat Daemon
4 #
5 #   Copyright (C) 2020 Sadie Powell <sadie@witchery.services>
6 #
7 # This file is part of InspIRCd.  InspIRCd is free software: you can
8 # redistribute it and/or modify it under the terms of the GNU General Public
9 # License as published by the Free Software Foundation, version 2.
10 #
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14 # details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20
21 BEGIN {
22         require 5.10.0;
23         unless (-f 'configure') {
24                 print "Error: $0 must be run from the main source directory!\n";
25                 exit 1;
26         }
27 }
28
29 use feature ':5.10';
30 use strict;
31 use warnings FATAL => qw(all);
32
33 use File::Basename          qw(basename dirname);
34 use File::Spec::Functions   qw(catdir catfile rel2abs);
35 use FindBin                 qw($RealDir);
36 use HTML::FormatText        ();
37 use HTML::TreeBuilder       ();
38 use Text::Markdown::Hoedown qw(HOEDOWN_HTML_SKIP_HTML markdown);
39 use Text::Sentence          qw(split_sentences);
40
41 use lib dirname $RealDir;
42 use make::common;
43 use make::console;
44
45 if (scalar @ARGV < 1) {
46         print_format "<|GREEN Usage:|> $0 <<|UNDERLINE DOCS-SITE|>>\n", *STDERR;
47         exit 1;
48 }
49
50 my %version = get_version();
51 my $docdir = rel2abs catdir $ARGV[0], 'docs', $version{MAJOR}, 'modules';
52 print_error "unable to find the module directory at $docdir!" unless -d $docdir;
53
54 for my $module (<src/modules/extra/m_*.cpp>, <src/modules/m_*.cpp>, <src/modules/m_*/main.cpp>) {
55         print_error "unable to extract module name from $module!" unless $module =~ /m_(\w+)[.\/]/;
56         my $docfile = catfile $docdir, "$1.md";
57         print_error "unable to find the module documentation at $docfile!" unless -f $docfile;
58
59         open(my $dh, $docfile) or print_error "unable to read from $docfile: $!";
60         my $docdata = do { local $/; <$dh> };
61         close $dh;
62         print_error "unable to find the module description in $docfile!" unless $docdata =~ /\#\#\# Description\n\n(?:This module )?([^\n]+)/;
63
64         my $docrendered = markdown ucfirst $1, extensions => HOEDOWN_HTML_SKIP_HTML;
65         my $docplain = HTML::FormatText->new(leftmargin => 0, rightmargin => ~0)->format(HTML::TreeBuilder->new->parse($docrendered));
66
67         my $description = (split_sentences $docplain)[0] =~ s/"/\\"/gr;
68         chomp($description);
69
70         open(my $mih, $module) or print_error "unable to read from $module: $!";
71         my @lines;
72         for my $line (<$mih>) {
73                 chomp $line;
74                 if ($line =~ /(\t+return Version\(")[^"]+(",.+)/) {
75                         push @lines, join '', $1, $description, $2;
76                 } else {
77                         push @lines, $line;
78                 }
79         }
80         close $mih;
81
82         open(my $moh, '>', $module) or print_error "unable to write to $module: $!";
83         for my $line (@lines) {
84                 say $moh $line;
85         }
86         close $moh;
87 }