Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- options.lua: process command-line options.
-- This file:
--   http://angg.twu.net/blogme4/options.lua.html
--   http://angg.twu.net/blogme4/options.lua
--                    (find-blogme4 "options.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
-- Version: 2011aug07
-- License: GPL3
--
-- Based on: (find-blogme3 "options.lua")

-- «.dooption_o»	(to "dooption_o")
-- «.dooption_i»	(to "dooption_i")
-- «.dooption_a2html»	(to "dooption_a2html")
-- «.dooption_e»	(to "dooption_e")
-- «.dooptions»		(to "dooptions")


require "eoo"         -- (find-blogme4 "eoo.lua")



-- «dooption_o»  (to ".dooption_o")
-- (find-blogme4 "common.lua" "pathto")
-- Example: in      blogme4.lua -o e/lua5.e.html ...
-- the "-o" does:    outputfile = "e/lua5.e.html"
--                   pathtoroot = "../"   -- to cancel the "e/"
-- and so:           pathto("foo/bar/plic.html")
-- yields:               "../foo/bar/plic.html"
dooption_o = function (fname)
    outputfile = fname
    pathtoroot = pathtoroot_(fname)
    eevarticle = pathto("eev-article.html")
  end

-- «dooption_i»  (to ".dooption_i")
-- (find-blogme4 "eval.lua" "blogme_eval")
-- Example: in           blogme4.lua ... -i TH/emacs.blogme
-- the "-i" evals the contents of the file "TH/emacs.blogme"
-- using blogme_eval, discards the result of the expansion (!!!),
-- then writes the contents of the variable "blogme_output" into
-- the file whose filename is stored in the variable "outputfile".
-- Usually blogme_output is set by htmlize - see:
--   (find-blogme4 "anggdefs.lua" "htmlize")
-- and outputfile is set by the command-line option "-o" (see above).
dooption_i = function (fname)
    blogme_eval(readfile(fname))
    writefile(outputfile, blogme_output)
  end

-- «dooption_a2html»  (to ".dooption_a2html")
-- (find-blogme4 "anggdefs.lua" "htmlizefile")
-- Example: in      blogme4.lua -o README.html -a2html README
-- the "-a2html" htmlizes the ascii file "README" in the standard way
-- and stores the result in "README.html".
dooption_a2html = function (fname) htmlizefile(fname, outputfile) end

-- «dooption_e»  (to ".dooption_e")
-- Example:    blogme4.lua -e 'PP(sorted(keys(_B)))'
dooption_e = function (luacode) assert(loadstring(luacode))() end



-- «dooptions»  (to ".dooptions")
-- Process all command-line arguments (by recursion).
-- Example: dooptions("-o", "foo.html", "-i", "foo.blogme")
-- calls:        dooption_o("foo.html")
--                            dooptions("-i", "foo.blogme")
--                                 dooption_i("foo.blogme")
--                                                dooptions()
_O = _O or {}
_O["-o"]      = function (fname, ...) dooption_o(fname);     dooptions(...) end
_O["-i"]      = function (fname, ...) dooption_i(fname);     dooptions(...) end
_O["-a2html"] = function (fname, ...) dooption_a2html(fname);dooptions(...) end
_O["-e"]      = function (code,  ...) dooption_e(code);      dooptions(...) end

dooptions = function (optionname, ...)
    if not    optionname  then return end
    if not _O[optionname] then
      error(format("Not in _O (for dooptions): %q", optionname))
    end
    _O[optionname](...)
  end

-- Here is a subtle but important point.
-- (find-lua51manualw3m "#pdf-require" "argument" "modname")
-- (find-lua51manualw3m "#6" "Lua Stand-alone" "'...'")
--    blogme4.lua -e 'PP(B_)'    --> dooptions("-e", "PP(B_)")
--    blogme4.lua                --> dooptions()      -- no output!
--    dofile  "blogme4.lua"      --> dooptions()      -- load as a library
--    require "blogme4"          --> dooptions("blogme4")  -- yuck!
-- so 'dofile "blogme4.lua"' is a good way to load this as a library,
-- but 'require "blogme4"' wouldn't even work - because it would call
-- the non-existent command-line option "blogme4" - if it weren't by
-- this hack:
_O["blogme4"] = function () end

-- Process all command-line options,
-- or do nothing if this is being loaded as a library.
dooptions(...)




-- dump-to: tests
--[==[
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd ~/blogme4/ && make clean && make blogme4.lua
rm -Rv /tmp/blo/
mkdir  /tmp/blo/
cd     /tmp/blo/
cp -v ~/blogme4/options.lua .
# (find-blogme4 "Makefile")
# (find-fline "~/blogme4/blogme4.lua")
~/blogme4/blogme4.lua
~/blogme4/blogme4.lua -o options.lua.html -a2html options.lua
LUA_INIT= \
~/blogme4/blogme4.lua -o options.lua.html -a2html options.lua
laf
# file:///tmp/blo/options.lua.html


undollar = function (code)
    code = string.gsub(code, "%$([a-z]+)", "\"..%1..\"")
    code = string.gsub(code, "%$(%b())",   "\"..%1..\"")
    code = string.gsub(code, "%$(%b[])", function (s)
        return "]]..("..strsub(s, 2, -2)..")..[["
      end)
    return code
  end



--]==]

-- Local Variables:
-- coding:             raw-text-unix
-- ee-anchor-format:   "«%s»"
-- End: