#!/usr/bin/env lua -- -- Yoink -- Run this script to convert the manual page to html. -- function showhelp() print("Usage: "..arg[0].." [-eh] [-i manpage] [-o htmlfile]") print(" Convert the manual page to html with groff.") print("") print(" -e Hide email addresses in the manual page.") print(" -h Show this help an exit.") print(" -i Specify the manual page to convert.") print(" -o Specify output path of html file.") end ----- function die(...) print("die:", ...); os.exit(1) end function isReadable(file) return os.execute("test -r "..file) == 0 end arg.hideEmail = false arg.output = "yoink.html" arg.input = "yoink.6" if not isReadable(arg.input) then arg.input = "doc/yoink.6" end do local t = { ["-e"] = function(a,i) a.hideEmail = true end, ["-h"] = function(a,i) showhelp(); os.exit() end, ["-i"] = function(a,i) a.input = a[i+1]; return 1 end, ["-o"] = function(a,i) a.output = a[i+1]; return 1 end } function parseArgs(args) local skip = 0 for i,v in ipairs(args) do if skip <= 0 then if type(t[v]) ~= "function" then print("unknown option: "..v) showhelp(); os.exit(1) end skip = t[v](args, i) if tonumber(skip) then skip = skip + 1 else skip = 1 end end skip = skip - 1 end end end parseArgs(arg) filters = { function(t) -- 1. Edit page title return t:gsub("().*()", "%1Yoink Manual%2") end, function(t) -- 2. Insert footer before return t:gsub("", [[

This manual page was generated on ]]..os.date("%d %b %Y")..[[. For more information, go to the Yoink website.

]]) end, arg.hideEmail and function(t) -- 3. Hide email addresses return t:gsub("<.+@.+>", "<email address hidden>") end or nil } output, err = io.open(arg.output, "w") if not output then die("io.open", err) end input = io.popen("groff -t -e -mandoc -Thtml "..arg.input) for line in input:lines() do for _,filter in ipairs(filters) do line = filter(line) end output:write(line.."\n") end output:close() input:close()