|
Warning: this is an htmlized version!
The original is across this link, and the conversion rules are here. |
-- options.lua - process command-line options.
-- This is part of blogme3.
--
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2007may29
-- <http://angg.twu.net/blogme3/options.lua>
-- <http://angg.twu.net/blogme3/options.lua.html>
-- License: GPL.
-- «.htmlization_head» (to "htmlization_head")
-- «.htmlization_warning» (to "htmlization_warning")
-- «.htmlizefile» (to "htmlizefile")
-- «.dooptions» (to "dooptions")
-- «.basic-options» (to "basic-options")
-- «._O» (to "_O")
--------[ experimental ]--------
-- «htmlization_head» (to ".htmlization_head")
mdef [[ htmlization_head 1 fname
<head>
<title>[$ fname] (htmlized)
</title>
</head>
]]
--------[ htmlization_warning ]--------
-- «htmlization_warning» (to ".htmlization_warning")
mdef [[ htmlization_warning_ 2 original,htmlizer
<table><tr><td bgcolor="#CC0000"><font color="#FFCC00" size=-1>
Warning: this is an htmlized version!
<br>The original is across <a href="[$ original]">this link</a>,
<br>and the conversion rules are <a href="[$ htmlizer]">here</a>.
</font></td></tr></table>
]]
def [[ htmlization_warning 1 fname
htmlization_warning_(
fnamenondirectory(fname),
pathto "blogme3/escripts.lua.html"
)
]]
--------[ htmlizefile ]--------
-- «htmlizefile» (to ".htmlizefile")
-- (find-blogme3file "anggdefs.lua" "MYL 2 fname,text")
-- (find-fline "~/TH/L/bin/fastcmp.lua.html")
-- (find-blogme3file "escripts.lua")
-- (find-blogme3file "escripts.lua" "htmlizefile =")
htmlizefile = function (fname, outfname, htmlizer)
outfname = outfname or fname..".html"
htmlizer = htmlizer or htmlizelines
local fcontents = readfile(fname)
local fnamestem = fnamenondirectory(fname)
local warning = htmlization_warning(fname)
local head = htmlization_head(fname)
local body = BODY(warning .. PRE(htmlizer(fcontents)))
writefile(outfname, sgmlify(HTML(head .. body)))
end
--------[ dooptions ]--------
-- «dooptions» (to ".dooptions")
-- input = readfile(fname_input)
-- output = doblogme(input)
-- writefile(fname_output, output)
-- _O = _O or {}
dooptions = function (...)
if arg.n < 1 then return end
local optionname = arg[1]
if not _O[optionname] then
error(format("Not in _O (for dooptions): %q", optionname))
end
table.remove(arg, 1)
_O[optionname](unpack(arg))
end
--------[ basic options ]--------
-- «basic-options» (to ".basic-options")
-- (find-blogme3file "defs.lua" "blogme_output")
dooption_i = function (fname)
doblogme(readfile(fname))
writefile(outputfile, blogme_output)
end
dooption_o = function (fname)
outputfile = fname
pathtoroot = getpathtoroot(fname)
eevarticle = pathto("eev-article.html")
require "angglisp" -- (find-blogme3 "angglisp.lua")
-- If I supported "lazy urls" in the _EHELP table then I wouldn't
-- need to wait until "-o" to load angglisp. This is ridiculous.
-- experimental, 2007oct15: loada2html always
end
dooption_a2html = function (fname) htmlizefile(fname, outputfile) end
dooption_e = function (luacode) assert(loadstring(luacode))() end
dooption_dd = function (fname) writefile(fname, defs_as_lua().."\n") end
-- «_O» (to "._O")
_O = _O or {}
_O["-o"] = function (fn, ...) dooption_o(fn); dooptions(unpack(arg)) end
_O["-i"] = function (fn, ...) dooption_i(fn); dooptions(unpack(arg)) end
_O["-a2html"] = function (fn, ...) dooption_a2html(fn); dooptions(unpack(arg)) end
_O["-e"] = function (lc, ...) dooption_e(lc); dooptions(unpack(arg)) end
_O["-dd"] = function (fn, ...) dooption_dd(fn); dooptions(unpack(arg)) end
-- Other options, not implemented: run doblogme inside a xpcall; ...
-- Local Variables:
-- coding: raw-text-unix
-- End: