-
Notifications
You must be signed in to change notification settings - Fork 0
/
Odinfile
143 lines (135 loc) · 4.2 KB
/
Odinfile
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
glib.so == %glib-so
glib-test.mo == () +cmd=msgfmt -c (glib-test.po) -o glib-test.mo :output/glib-test.mo
%glib-so == lua-glib.c +cc_flags=-fPIC -Werror +(%glib) +(%lua) +ld_flags=-shared +debug :exe
%glib-doc ! == <<
lua-glib.html
README.rst
ldoc.css
%lua-ldoc == () +cmd='input=trim[['(lua-glib.c)']]' +cmdfile=(%mk-html) \
:lua_output
ldoc.css == %lua-ldoc/ldoc.css
lua-glib.html == (%lua-ldoc/lua-glib.html) +cmd='tidy||:' :stdout
%mk-html == <<
os.execute('ldoc.lua -p lua-glib -o lua-glib -d . -f discount ' .. input)
local l, lastl -- lastl is for lookahead
lastl = ''
io.input('lua-glib.html')
for l in io.lines() do
-- change empty ul and ol to blockquote
-- otherwise pandoc will just ignore them
if lastl:find('<[ou]l>') and not l:find('<li>') then
lastl = lastl:gsub('<[ou]l>', '<blockquote>') .. '\n' .. l
local nest = 0
while true do
l = io.read()
if l:find('<[ou]l>') then
nest = nest + 1
elseif l:find('</[ou]l>') then
if nest > 0 then
nest = nest - 1
else
l = l:gsub('</[ou]l>', '</blockquote>')
break
end
end
lastl = lastl .. '\n' .. l
end
end
io.write(lastl .. '\n')
lastl = l
end
io.write(lastl .. '\n')
README.html == (README.rst) +cmd='rst2html.py' :stdout
README.rst == (lua-glib.html) +cmdfile=(%mk-rst) :lua_stdout
%mk-rst == <<
-- --columns 500 provides consistent tables; --wrap=none does not
-- io.input() must be specified because pipe.lua just reassigns that
-- but does not actually reasign the program's stdin, or even io.stdin
-- local f = glib.spawn{cmd="pandoc -f html -t rst --columns 500", stdin=io.input()}
-- on the other hand, this is an opportunity to filter the HTML more
local f = glib.spawn{cmd="pandoc -f html -t rst --columns 500", stdin=true}
local lastl -- lastl is for lookahead
for l in io.lines() do
-- I used to strip these later, but may as well make self-refs pure
l = l:gsub('lua%-glib%.html', '')
-- pandoc will not use sections if divs are present
l = l:gsub('<(/?div[^>]*)>', '<!-- %1 -->')
f:write(l .. '\n');
end
f:close()
-- skip TOC; the table below serves just as well
for l in f:lines() do
if l:find('^Module ') then
lastl = l .. '\n'
break
end
end
for l in f:lines() do
-- pandoc's hyperlinks don't work
-- strip out old section anchors
if l:find('^ *%.%. _[a-z].*:$') then
l = (f:lines())(f)
l = (f:lines())(f)
end
-- strip out old section links
local didsub, newlen
lastl, didsub = lastl:gsub('^(`[^<`]*) <#[^>]*>`__\n',
function(s)
newlen = #s + 2
return s .. '`_\n'
end)
if didsub then
l = l:sub(0, newlen)
end
-- strip out old detail links
lastl = lastl:gsub('((`[^ ]*)([^<`]*) <#[^>]*>`__)', function(a, s, s2)
return s .. '`_' .. s2 ..
string.rep(' ', #a - #s - #s2 - 2)
end)
-- add new section anchors
if l:find('^%-%-%-%-') and lastl:sub(0, 1) ~= '`' then
lastl = '_`' .. lastl:sub(0, -2) .. '`\n'
l = l .. '---'
end
-- add new detail anchors
if l:find('^ %*%*.*%*%*$') then
lastl = lastl .. '\n .. _`' .. l:sub(4, -3):gsub(' .*', '') .. '`:\n\n'
end
-- remove Unicode nbsp
l = l:gsub(' ', ' ')
-- use ASCII '
l = l:gsub('’', '\'') -- '
-- unescaped *
l = l:gsub('‘%*', '‘\\*')
-- fix module link
if l:find('====') and lastl:find('^Module ') then
l = l .. '\n.. _glib:'
end
-- fix getenv link
l = l:gsub('`glib%.', 'glib%.`')
-- fix sections following literal block
if lastl:find('_`random`')
or lastl:find('_`markup_escape_text`') then
lastl = '\n..\n' .. lastl
end
-- fix class links, broken above
lastl = lastl:gsub('(_?)`Class ', 'Class %1`')
-- fix LDoc link
l = l:gsub('%*\\ `LD', '* `LD')
io.write(lastl)
lastl = l .. '\n'
end
io.write(lastl)
%lua-script == <<
-- there is no way in Odin to select this at build-time without clearing cache
if false then
io.write("+lib_sp='/usr/local/lib'")
io.write("+inc_sp='/usr/local/include/lua-5.2'")
lua = 'lua52'
else
lua = getenv('LUA_LIBNAME')
if lua == '' then lua = 'lua' end
io.write('+lib=' .. lua)
end
%lua == () +cmdfile=(%lua-script) :lua_stdout
%glib == () +cmd='io.write(pkg_cflags("glib-2.0") or "")' :lua_stdout