Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
#!/usr/bin/env lua5.1 -- Several utilities. -- «.inet_addr» (to "inet_addr") -- «.cleanindex» (to "cleanindex") -- «.date_to_yyyymmmdd» (to "date_to_yyyymmmdd") -- «.run» (to "run") -- «inet_addr» (to ".inet_addr") -- (find-angg ".emacs" "inet-addr") -- (find-sh "/sbin/ifconfig") -- (find-sh "/sbin/ifconfig" "wlan0" "inet addr:") -- (find-sh "/sbin/ifconfig wlan0") -- (find-sh0 "/sbin/ifconfig | etc.lua inet_addr") -- (find-sh0 "/sbin/ifconfig wlan0 | etc.lua inet_addr") -- inet_addr_ = function (str) local m = str:match("inet addr:([0-9.]+)") if m then print(m) end end inet_addr = function () for li in io.lines() do inet_addr_(li) end end --[[ * (eepitch-lua51) * (eepitch-kill) * (eepitch-lua51) dofile "etc.lua" inet_addr_("belp inet addr:1.2.3.4 foo bar") --]] -- «cleanindex» (to ".cleanindex") -- (find-angg ".emacs" "cleanindex") rmdots_ = function (li) return (li:gsub(" . ", " ")) end rmdots = function (li) for i=1,10 do li = rmdots_(li) end return li end cleanindexline = function (li) li = rmdots(li) li = li:gsub(" +", " ") li = li:gsub("^ +", "") li = li:gsub(" +$", "") return li end cleanindexline2 = function (li) local left, page = li:match("^ *(.-) +([0-9]+)$") if page then return format(";; (find-%spage (+ %s %s) %q)", stem, offset, page, left) end end cleanindexline3 = function (li) return cleanindexline2(li) or ";; "..li end stem = stem or "{stem}" offset = offset or "{offset}" maplines = function (f, bigstr) return (bigstr:gsub("[\f\t]", " "):gsub("([^\n]+)", f)) end cleanindex = function (_stem, _offset) stem, offset = _stem or "{stem}", _offset or "{offset}" io.write(maplines(cleanindexline3, io.read("*a"))) end -- «date_to_yyyymmmdd» (to ".date_to_yyyymmmdd") -- (find-sh0 "etc.lua date_to_yyyymmmdd 120345a") date_to_yyyymmmdd = function (str) local yy, mm, dd = str:match("^(..)(..)(..)") local months = split "jan feb mar apr may jun jul aug sep oct nov dec" print("20"..yy .. months[mm+0] .. dd) end -- «run» (to ".run") runetc = function (prog, ...) -- if prog then PP(prog, {...}) end if prog then _G[prog](...) end end runetc(...) -- Local Variables: -- coding: raw-text-unix -- End: