-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract.lua
More file actions
61 lines (59 loc) · 2.26 KB
/
Copy pathextract.lua
File metadata and controls
61 lines (59 loc) · 2.26 KB
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
local filename = "manual.of"
local file = io.open(filename)
if not file then
error(string.format("could not open %s", filename))
end
local content = file:read("a")
local function repl_func(what, cont)
cont = string.sub(cont, 2, -2)
local lut = {
apii = function(c) return "" end,
x = function(c) return c end,
id = function(c) return c end,
ANSI = function(c) return c end,
def = function(c) return c end,
defid = function(c) return c end,
idx = function(c) return c end,
Lid = function(c) return c end,
En = function(c) return c end,
emph = function(c) return c end,
emphx = function(c) return c end,
rep = function(c) return c end,
itemize = function(c) return c end,
verbatim = function(c) return c end,
Q = function(c) return c end,
M = function(c) return c end,
N = function(c) return c end,
T = function(c) return c end,
description = function(c) return c end,
see = function(c) return c end,
seeC = function(c) return c end,
seeF = function(c) return c end,
Char = function(c) return c end,
St = function(c) return c end,
}
if not lut[what] then
error(string.format("trying to format entry '%s', which is unknown", what))
end
return lut[what](cont)
end
for entry in string.gmatch(content, "APIEntry(%b{})") do
-- strip braces
entry = string.sub(entry, 2, -2)
entry = string.gsub(entry, "%@(%w+)(%b{})", repl_func)
if not string.match(entry, "typedef") then
local title = string.match(entry, "([%w_]+)%s*%b()")
local funcdef = string.sub(entry, 1, string.find(entry, "|") - 1)
local body = string.sub(entry, string.find(entry, "|") + 1)
string.gsub(body, "^(%s+)", "")
local filename = string.format("man3/%s.3", title)
print(string.format("writing %s", filename))
local entryfile = io.open(filename, "w")
entryfile:write(string.format('.TH %s 3l ""\n', title))
entryfile:write('.SH NAME\n')
entryfile:write(string.format('.B %s\n', funcdef))
entryfile:write('.SH DESCRIPTION\n')
entryfile:write(string.format('.PP\n%s\n', body))
entryfile:close()
end
end