summaryrefslogtreecommitdiffstats
path: root/src/gen-manpage.lua
blob: d19f4b198da0c33f6da5b47e696b2f9142e1dce6 (plain)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
print[[
.\" Copyright (c) 2018-2024 OARC, Inc.
.\" All rights reserved.
.\"
.\" This file is part of dnsjit.
.\"
.\" dnsjit is free software: you can redistribute it and/or modify
.\" it under the terms of the GNU General Public License as published by
.\" the Free Software Foundation, either version 3 of the License, or
.\" (at your option) any later version.
.\"
.\" dnsjit is distributed in the hope that it will be useful,
.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
.\" GNU General Public License for more details.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with dnsjit.  If not, see <http://www.gnu.org/licenses/>.
.\"]]

sh_syn = false
sh_desc = false
ss_func = false
doc = {}
funcs = {}
for line in io.lines(arg[1]) do
    if line:match("^[-][-]") then
        table.insert(doc, line:sub(4))
    elseif line:match("^module") then
        if table.maxn(doc) < 2 then
            error("Minimum required module doc missing")
        end
        print(".TH "..doc[1].." 3 \"@PACKAGE_VERSION@\" \"dnsjit\"")
        print(".SH NAME")
        print(doc[1].." \\- "..doc[2])
        n, line = next(doc, 2)
        if n and n > 2 then
            local n2 = n
            while line and line > "" do
                if not sh_syn then
                    print(".SH SYNOPSIS")
                    sh_syn = true
                end
                if line == "." then
                    line = ""
                end
                print(line)
                n2 = n
                n, line = next(doc, n)
            end
            n, line = next(doc, n)
            if n and n > n2 then
                while line and line > "" do
                    if not sh_desc then
                        print(".SH DESCRIPTION")
                        sh_desc = true
                    end
                    if line == "." then
                        line = ""
                    end
                    print(line)
                    n, line = next(doc, n)
                end
            end
        end
    elseif line:match("^function") then
        if table.maxn(doc) > 0 then
            if not ss_func then
                if not sh_desc then
                    print(".SH DESCRIPTION")
                    sh_desc = true
                end
                print(".SS Functions")
                ss_func = true
            end
            print(".TP")
            local fn,fd = line:match("(%S+)(%(.+)")
            if fn and fd then
                print(".BR "..fn.." \""..fd.."\"")
            else
                print(".B "..line:sub(10))
            end
            for _, line in pairs(doc) do
                if line == "." then
                    line = ""
                end
                print(line)
            end
        end
    elseif line:match("^return") then
        if table.maxn(doc) > 0 then
            print(".SH SEE ALSO")
            for _, line in pairs(doc) do
                print(".BR "..line)
            end
        end
    else
        doc = {}
    end
end

print[[
.SH AUTHORS and CONTRIBUTORS
Jerry Lundström (DNS-OARC),
Tomáš Křížek (CZ.NIC),
Petr Špaček (ISC)
.LP
Maintained by DNS-OARC
.LP
.RS
.I https://www.dns-oarc.net/
.RE
.LP
.SH BUGS
For issues and feature requests please use:
.LP
.RS
\fI@PACKAGE_URL@\fP
.RE
.LP
For question and help please use:
.LP
.RS
\fI@PACKAGE_BUGREPORT@\fP
.RE
.LP]]