|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- options.lua - process command-line options.
-- This is part of blogme3.
--
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2022may21
-- <http://anggtwu.net/blogme3/options.lua>
-- <http://anggtwu.net/blogme3/options.lua.html>
-- License: GPL.
-- «.htmlization_head» (to "htmlization_head")
-- «.htmlization_warning» (to "htmlization_warning")
-- «.htmlizefile» (to "htmlizefile")
-- «.htmlizefile_utf8» (to "htmlizefile_utf8")
-- «.dooptions» (to "dooptions")
-- «.basic-options» (to "basic-options")
-- «.basic-options-sandwich» (to "basic-options-sandwich")
-- «.basic-options-sep2021» (to "basic-options-sep2021")
-- «._O» (to "_O")
DBG = DBG or function () end
--------[ 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 <a href="[$ original]">here</a>, and
<br>the conversion rules are <a href="[$ htmlizer]">here</a>.
</font></td></tr></table>
]]
def [[ htmlization_warning 1 fname
htmlization_warning_(
fnamenondirectory(fname),
pathto "htmlize.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 =")
-- (find-angg "LUA/lua50init.lua" "u8_to_l1")
-- (find-angg "LUA/lua50init.lua" "u8_to_l1" "u8_to_l1_maybe =")
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
htmlizefile_with_u8_hack = function (fname, outfname, htmlizer)
outfname = outfname or fname..".html"
htmlizer = htmlizer or htmlizelines
-- local fcontents = readfile(fname)
DBG(74)
local fcontents = u8_to_l1_maybe(readfile(fname))
DBG(76)
local fnamestem = fnamenondirectory(fname)
DBG(78)
local warning = htmlization_warning(fname)
DBG(80)
local head = htmlization_head(fname)
DBG(82)
local body = BODY(warning .. PRE(htmlizer(fcontents)))
DBG(84)
writefile(outfname, sgmlify(HTML(head .. body)))
DBG(86)
end
-- «htmlizefile_utf8» (to ".htmlizefile_utf8")
-- Experimental, 2021sep12
--
loadhtmlize_utf8 = function ()
require "sandwiches-defs" -- (find-blogme3 "sandwiches-defs.lua")
require "htmlize-utf8" -- (find-blogme3 "htmlize-utf8.lua")
hl_utf8 = HtmlizeLine {
left = function (hl, str) return HtmlizeLeft :match(str) end,
plain = function (hl, str) return HtmlizeMiddle:match(str) end,
}
htmlizeline = function (linestr) return (hl_utf8:line(linestr)) end
html_dtd = dtd_transitional .. dtd_encoding_utf8
end
htmlizefile_utf8 = function (fname, outfname)
loadhtmlize_utf8()
outfname = outfname or fname..".html"
local fcontents = ee_readfile(fname)
local fnamestem = fnamenondirectory(fname)
local warning = htmlization_warning(fname)
local head = htmlization_head(fname)
local body = BODY(warning .. PRE(htmlizelines(fcontents)))
writefile(outfname, html_dtd .. HTML(head .. body))
end
--------[ dooptions ]--------
-- «dooptions» (to ".dooptions")
-- input = readfile(fname_input)
-- output = doblogme(input)
-- writefile(fname_output, output)
-- _O = _O or {}
dooptionss = function (args) dooptions(unpack(args)) end
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")
eepitchreadme = pathto("eev-current/eepitch.readme.html")
eepitch_el = pathto("eev-current/eepitch.el.html")
eevintrosdir = pathto("eev-intros/")
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_a2html = function (fname) htmlizefile_with_u8_hack(fname, outputfile) end
dooption_e = function (luacode) assert(loadstring(luacode))() end
dooption_dd = function (fname) writefile(fname, defs_as_lua().."\n") end
dooption_ei2html = function (fname)
require "eevintros" -- (find-blogme3 "eevintros.lua")
htmlizeeevintro(fname, outputfile)
end
dooption_sexptarget = function (s)
loadblogme3rest() -- (find-angg "LUA/lua50init.lua" "loadblogme3")
require "sexp" -- (find-blogme3 "sexp.lua")
print(STOT(s)) -- (find-blogme3 "sexp.lua" "STOH")
end
-- «basic-options-sandwich» (to ".basic-options-sandwich")
-- 2021jan16: Experimental variants of the basic options that use the
-- sandwich libraries.
-- (find-blogme3 "elisp.lua" "relative-links")
dooption_a2html_aug2021 = function (fname)
require "sandwiches-defs" -- (find-blogme3 "sandwiches-defs.lua")
use_sand_htmlizeline(fname)
htmlizefile_with_u8_hack(fname, outputfile)
end
dooption_ei2html = function (fname)
require "sandwiches-defs" -- (find-blogme3 "sandwiches-defs.lua")
use_sand_htmlizeline(fname)
require "eevintros" -- (find-blogme3 "eevintros.lua")
htmlizeeevintro(fname, outputfile)
end
-- «basic-options-sep2021» (to ".basic-options-sep2021")
dooption_a2html_sep2021 = function (fname)
require "detect-encoding" -- (find-blogme3 "detect-encoding.lua")
local enc = DetectEncoding.new(fname, "./"):guessencoding()
if enc == "raw-text-unix" then
dooption_a2html_aug2021(fname)
else
-- print("Using htmlizefile_utf8!")
htmlizefile_utf8(fname, outputfile)
end
end
-- (find-es "blogme" "debug-a2html")
-- Select one:
-- dooption_a2html = dooption_a2html_aug2021
dooption_a2html = dooption_a2html_sep2021
-- «_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
_O["-o"] = function (fn, ...) dooption_o(fn); dooptions(...) end
_O["-i"] = function (fn, ...) dooption_i(fn); dooptions(...) end
_O["-a2html"] = function (fn, ...) dooption_a2html(fn); dooptions(...) end
_O["-ei2html"] = function (fn, ...) dooption_ei2html(fn); dooptions(...) end
_O["-e"] = function (lc, ...) dooption_e(lc); dooptions(...) end
_O["-dd"] = function (fn, ...) dooption_dd(fn); dooptions(...) end
_O["-test"] = function (a, ...) print("TEST", a); dooptions(...) end
_O["-sexptarget"] = function (s, ...) dooption_sexptarget(s); dooptions(...) end
-- Other options, not implemented: run doblogme inside a xpcall; ...
-- Local Variables:
-- coding: raw-text-unix
-- End: