Advertisement
CrazedProgrammer

CCBox

Aug 19th, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 42.37 KB | None | 0 0
  1. if not table.pack then table.pack = function(...) return { n = select("#", ...), ... } end end
  2. if not table.unpack then table.unpack = unpack end
  3. local load = load if _VERSION:find("5.1") then load = function(x, n, _, env) local f, e = loadstring(x, n) if not f then return f, e end if env then setfenv(f, env) end return f end end
  4. local _select, _unpack, _pack, _error = select, table.unpack, table.pack, error
  5. local _libs = {}
  6. local _3d_1, _2f3d_1, _3c_1, _3c3d_1, _3e_1, _3e3d_1, _2b_1, _2d_1, _25_1, _2e2e_1, _G1, arg_23_1, len_23_1, error1, getmetatable1, load1, next1, print1, getIdx1, setIdx_21_1, setmetatable1, tostring1, type_23_1, n1, slice1, find1, format1, gsub1, lower1, match1, sub1, upper1, concat1, remove1, unpack1, car1, cdr1, list1, _21_1, arg1, constVal1, apply1, first1, list_3f_1, empty_3f_1, string_3f_1, number_3f_1, key_3f_1, nil_3f_1, type1, neq_3f_1, map1, keys1, put_21_1, eq_3f_1, pretty1, min1, car2, cdr2, reduce1, map2, flatMap1, partition1, filter1, any1, elem_3f_1, last1, init1, nth1, nths1, pushCdr_21_1, removeNth_21_1, append1, flatten1, cadr1, caddr1, charAt1, split1, trim1, display1, assoc_2d3e_struct1, merge1, keys2, values1, exit1, getenv1, succ1, pred1, fail_21_1, exit_21_1, const1, self1, create1, resume1, open1, getName1, combine1, isReadOnly1, move1, copy1, delete1, isDir1, getFreeSpace1, getSize1, list2, exists1, makeDir1, getDir1, current1, day1, sleep1, setAlarm1, pullEventRaw1, clock1, time1, cancelTimer1, startTimer1, cancelAlarm1, queueEvent1, resolve1, log_21_1, createVfs1, mountPath1, canonicalise1, createRealfs1, create2, createCoroutine_21_1, eventWhitelist1, next_21_1, envWhitelist1, createEnv1, config1, coloredAnsi1, colored_3f_1, colored1, create3, setAction1, addAction1, addArgument_21_1, addHelp_21_1, usageNarg_21_1, usage_21_1, usageError_21_1, helpArgs_21_1, help_21_1, matcher1, parse_21_1, args1, run1
  7. _3d_1 = function(v1, v2) return v1 == v2 end
  8. _2f3d_1 = function(v1, v2) return v1 ~= v2 end
  9. _3c_1 = function(v1, v2) return v1 < v2 end
  10. _3c3d_1 = function(v1, v2) return v1 <= v2 end
  11. _3e_1 = function(v1, v2) return v1 > v2 end
  12. _3e3d_1 = function(v1, v2) return v1 >= v2 end
  13. _2b_1 = function(...) local t = ... for i = 2, _select('#', ...) do t = t + _select(i, ...) end return t end
  14. _2d_1 = function(...) local t = ... for i = 2, _select('#', ...) do t = t - _select(i, ...) end return t end
  15. _25_1 = function(...) local t = ... for i = 2, _select('#', ...) do t = t % _select(i, ...) end return t end
  16. _2e2e_1 = function(...) local n = _select('#', ...) local t = _select(n, ...) for i = n - 1, 1, -1 do t = _select(i, ...) .. t end return t end
  17. _G1 = _G
  18. arg_23_1 = arg or {...}
  19. len_23_1 = function(v1) return #v1 end
  20. error1 = error
  21. getmetatable1 = getmetatable
  22. load1 = load
  23. next1 = next
  24. print1 = print
  25. getIdx1 = function(v1, v2) return v1[v2] end
  26. setIdx_21_1 = function(v1, v2, v3) v1[v2] = v3 end
  27. setmetatable1 = setmetatable
  28. tostring1 = tostring
  29. type_23_1 = type
  30. n1 = (function(x)
  31.     if type_23_1(x) == "table" then
  32.         return x["n"]
  33.     else
  34.         return #x
  35.     end
  36. end)
  37. slice1 = (function(xs, start, finish)
  38.     if not finish then
  39.         finish = xs["n"]
  40.         if not finish then
  41.             finish = #xs
  42.         end
  43.     end
  44.     local len = (finish - start) + 1
  45.     if len < 0 then
  46.         len = 0
  47.     end
  48.     local out, i, j = ({["tag"]="list",["n"]=len}), 1, start
  49.     while j <= finish do
  50.         out[i] = xs[j]
  51.         i, j = i + 1, j + 1
  52.     end
  53.     return out
  54. end)
  55. find1 = string.find
  56. format1 = string.format
  57. gsub1 = string.gsub
  58. lower1 = string.lower
  59. match1 = string.match
  60. sub1 = string.sub
  61. upper1 = string.upper
  62. concat1 = table.concat
  63. remove1 = table.remove
  64. unpack1 = table.unpack
  65. car1 = (function(xs)
  66.     return xs[1]
  67. end)
  68. cdr1 = (function(xs)
  69.     return slice1(xs, 2)
  70. end)
  71. list1 = (function(...)
  72.     local xs = _pack(...) xs.tag = "list"
  73.     return xs
  74. end)
  75. _21_1 = (function(expr)
  76.     return not expr
  77. end)
  78. if nil == arg_23_1 then
  79.     arg1 = ({tag = "list", n = 0})
  80. else
  81.     arg_23_1["tag"] = "list"
  82.     if not arg_23_1["n"] then
  83.         arg_23_1["n"] = #arg_23_1
  84.     end
  85.     arg1 = arg_23_1
  86. end
  87. constVal1 = (function(val)
  88.     if type_23_1(val) == "table" then
  89.         local tag = val["tag"]
  90.         if tag == "number" then
  91.             return val["value"]
  92.         elseif tag == "string" then
  93.             return val["value"]
  94.         else
  95.             return val
  96.         end
  97.     else
  98.         return val
  99.     end
  100. end)
  101. apply1 = (function(f, ...)
  102.     local _n = _select("#", ...) - 1
  103.     local xss, xs
  104.     if _n > 0 then
  105.         xss = { tag="list", n=_n, _unpack(_pack(...), 1, _n)}
  106.         xs = select(_n + 1, ...)
  107.     else
  108.         xss = { tag="list", n=0}
  109.         xs = ...
  110.     end
  111.     local args = (function()
  112.         local _offset, _result, _temp = 0, {tag="list",n=0}
  113.         _temp = xss
  114.         for _c = 1, _temp.n do _result[0 + _c + _offset] = _temp[_c] end
  115.         _offset = _offset + _temp.n
  116.         _temp = xs
  117.         for _c = 1, _temp.n do _result[0 + _c + _offset] = _temp[_c] end
  118.         _offset = _offset + _temp.n
  119.         _result.n = _offset + 0
  120.         return _result
  121.     end)()
  122.     return f(unpack1(args, 1, n1(args)))
  123. end)
  124. first1 = (function(...)
  125.     local rest = _pack(...) rest.tag = "list"
  126.     return rest[1]
  127. end)
  128. list_3f_1 = (function(x)
  129.     return type1(x) == "list"
  130. end)
  131. empty_3f_1 = (function(x)
  132.     local xt = type1(x)
  133.     if xt == "list" then
  134.         return x["n"] == 0
  135.     elseif xt == "string" then
  136.         return #x == 0
  137.     else
  138.         return false
  139.     end
  140. end)
  141. string_3f_1 = (function(x)
  142.     return type_23_1(x) == "string" or type_23_1(x) == "table" and x["tag"] == "string"
  143. end)
  144. number_3f_1 = (function(x)
  145.     return type_23_1(x) == "number" or type_23_1(x) == "table" and x["tag"] == "number"
  146. end)
  147. key_3f_1 = (function(x)
  148.     return type1(x) == "key"
  149. end)
  150. nil_3f_1 = (function(x)
  151.     return type_23_1(x) == "nil"
  152. end)
  153. type1 = (function(val)
  154.     local ty = type_23_1(val)
  155.     if ty == "table" then
  156.         return val["tag"] or "table"
  157.     else
  158.         return ty
  159.     end
  160. end)
  161. neq_3f_1 = (function(x, y)
  162.     return _21_1(eq_3f_1(x, y))
  163. end)
  164. map1 = (function(f, x)
  165.     local out = ({tag = "list", n = 0})
  166.     local temp = n1(x)
  167.     local temp1 = 1
  168.     while temp1 <= temp do
  169.         out[temp1] = f(x[temp1])
  170.         temp1 = temp1 + 1
  171.     end
  172.     out["n"] = n1(x)
  173.     return out
  174. end)
  175. keys1 = (function(x)
  176.     local out, n = ({tag = "list", n = 0}), 0
  177.     local temp, _ = next1(x)
  178.     while temp ~= nil do
  179.         n = 1 + n
  180.         out[n] = temp
  181.         temp, _ = next1(x, temp)
  182.     end
  183.     out["n"] = n
  184.     return unpack1(out, 1, out["n"])
  185. end)
  186. put_21_1 = (function(t, typs, l)
  187.     while not (list_3f_1(typs) and n1(typs) == 1) do
  188.         local x, y = car1(typs), cdr1(typs)
  189.         if t[x] then
  190.             t, typs = t[x], y
  191.         else
  192.             t[x] = ({})
  193.             t, typs = t[x], y
  194.         end
  195.     end
  196.     t[car1(typs)] = l
  197.     return nil
  198. end)
  199. eq_3f_1 = setmetatable1(({["lookup"]=({})}), ({["__call"]=(function(temp_this, x, y)
  200.     local temp_method
  201.     local temp = temp_this["lookup"]
  202.     if temp then
  203.         local temp1 = temp[type1(x)]
  204.         if temp1 then
  205.             temp_method = temp1[type1(y)] or nil
  206.         else
  207.             temp_method = nil
  208.         end
  209.     else
  210.         temp_method = nil
  211.     end
  212.     if not temp_method then
  213.         if temp_this["default"] then
  214.             temp_method = temp_this["default"]
  215.         else
  216.             error1("No matching method to call for " .. (type1(x) .. " ") .. (type1(y) .. " ") .. "\nthere are methods to call for " .. keys1(temp_this["lookup"]))
  217.         end
  218.     end
  219.     return temp_method(x, y)
  220. end)}))
  221. put_21_1(eq_3f_1, list1("lookup", "list", "list"), (function(x, y)
  222.     if n1(x) ~= n1(y) then
  223.         return false
  224.     else
  225.         local equal = true
  226.         local temp = n1(x)
  227.         local temp1 = 1
  228.         while temp1 <= temp do
  229.             if neq_3f_1(x[temp1], y[temp1]) then
  230.                 equal = false
  231.             end
  232.             temp1 = temp1 + 1
  233.         end
  234.         return equal
  235.     end
  236. end))
  237. put_21_1(eq_3f_1, list1("lookup", "table", "table"), (function(x, y)
  238.     local equal = true
  239.     local temp, v = next1(x)
  240.     while temp ~= nil do
  241.         if neq_3f_1(v, y[temp]) then
  242.             equal = false
  243.         end
  244.         temp, v = next1(x, temp)
  245.     end
  246.     return equal
  247. end))
  248. put_21_1(eq_3f_1, list1("lookup", "symbol", "symbol"), (function(x, y)
  249.     return x["contents"] == y["contents"]
  250. end))
  251. put_21_1(eq_3f_1, list1("lookup", "string", "symbol"), (function(x, y)
  252.     return x == y["contents"]
  253. end))
  254. put_21_1(eq_3f_1, list1("lookup", "symbol", "string"), (function(x, y)
  255.     return x["contents"] == y
  256. end))
  257. put_21_1(eq_3f_1, list1("lookup", "key", "string"), (function(x, y)
  258.     return x["value"] == y
  259. end))
  260. put_21_1(eq_3f_1, list1("lookup", "string", "key"), (function(x, y)
  261.     return x == y["value"]
  262. end))
  263. put_21_1(eq_3f_1, list1("lookup", "key", "key"), (function(x, y)
  264.     return x["value"] == y["value"]
  265. end))
  266. put_21_1(eq_3f_1, list1("lookup", "number", "number"), (function(x, y)
  267.     return constVal1(x) == constVal1(y)
  268. end))
  269. put_21_1(eq_3f_1, list1("lookup", "string", "string"), (function(x, y)
  270.     return constVal1(x) == constVal1(y)
  271. end))
  272. eq_3f_1["default"] = (function(x, y)
  273.     return false
  274. end)
  275. local original = getmetatable1(eq_3f_1)["__call"]
  276. getmetatable1(eq_3f_1)["__call"] = (function(self, x, y)
  277.     if x == y then
  278.         return true
  279.     else
  280.         return original(self, x, y)
  281.     end
  282. end)
  283. pretty1 = setmetatable1(({["lookup"]=({})}), ({["__call"]=(function(temp_this, x)
  284.     local temp_method
  285.     local temp = temp_this["lookup"]
  286.     if temp then
  287.         temp_method = temp[type1(x)] or nil
  288.     else
  289.         temp_method = nil
  290.     end
  291.     if not temp_method then
  292.         if temp_this["default"] then
  293.             temp_method = temp_this["default"]
  294.         else
  295.             error1("No matching method to call for " .. (type1(x) .. " ") .. "\nthere are methods to call for " .. keys1(temp_this["lookup"]))
  296.         end
  297.     end
  298.     return temp_method(x)
  299. end)}))
  300. put_21_1(pretty1, list1("lookup", "list"), (function(xs)
  301.     return "(" .. concat1(map1(pretty1, xs), " ") .. ")"
  302. end))
  303. put_21_1(pretty1, list1("lookup", "symbol"), (function(x)
  304.     return x["contents"]
  305. end))
  306. put_21_1(pretty1, list1("lookup", "key"), (function(x)
  307.     return ":" .. x["value"]
  308. end))
  309. put_21_1(pretty1, list1("lookup", "number"), (function(x)
  310.     return tostring1(constVal1(x))
  311. end))
  312. put_21_1(pretty1, list1("lookup", "string"), (function(x)
  313.     return format1("%q", constVal1(x))
  314. end))
  315. put_21_1(pretty1, list1("lookup", "table"), (function(x)
  316.     local out = ({tag = "list", n = 0})
  317.     local temp, v = next1(x)
  318.     while temp ~= nil do
  319.         local _offset, _result, _temp = 0, {tag="list",n=0}
  320.         _result[1 + _offset] = pretty1(temp) .. " " .. pretty1(v)
  321.         _temp = out
  322.         for _c = 1, _temp.n do _result[1 + _c + _offset] = _temp[_c] end
  323.         _offset = _offset + _temp.n
  324.         _result.n = _offset + 1
  325.         out = _result
  326.         temp, v = next1(x, temp)
  327.     end
  328.     return "{" .. (concat1(out, " ") .. "}")
  329. end))
  330. pretty1["default"] = (function(x)
  331.     return tostring1(x)
  332. end)
  333. min1 = math.min
  334. car2 = (function(x)
  335.     local temp = type1(x)
  336.     if temp ~= "list" then
  337.         error1(format1("bad argument %s (expected %s, got %s)", "x", "list", temp), 2)
  338.     end
  339.     return car1(x)
  340. end)
  341. cdr2 = (function(x)
  342.     local temp = type1(x)
  343.     if temp ~= "list" then
  344.         error1(format1("bad argument %s (expected %s, got %s)", "x", "list", temp), 2)
  345.     end
  346.     if empty_3f_1(x) then
  347.         return ({tag = "list", n = 0})
  348.     else
  349.         return cdr1(x)
  350.     end
  351. end)
  352. reduce1 = (function(f, z, xs)
  353.     local temp = type1(f)
  354.     if temp ~= "function" then
  355.         error1(format1("bad argument %s (expected %s, got %s)", "f", "function", temp), 2)
  356.     end
  357.     local start = 1
  358.     if nil_3f_1(xs) and list_3f_1(z) then
  359.         start = 2
  360.         xs = z
  361.         z = car2(z)
  362.     end
  363.     local temp = type1(xs)
  364.     if temp ~= "list" then
  365.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  366.     end
  367.     local accum = z
  368.     local temp = n1(xs)
  369.     local temp1 = start
  370.     while temp1 <= temp do
  371.         accum = f(accum, nth1(xs, temp1))
  372.         temp1 = temp1 + 1
  373.     end
  374.     return accum
  375. end)
  376. map2 = (function(fn, ...)
  377.     local xss = _pack(...) xss.tag = "list"
  378.     local ns
  379.     local out = ({tag = "list", n = 0})
  380.     local temp = n1(xss)
  381.     local temp1 = 1
  382.     while temp1 <= temp do
  383.         if _21_1(list_3f_1(nth1(xss, temp1))) then
  384.             error1("not a list: " .. pretty1(nth1(xss, temp1)) .. " (it's a " .. type1(nth1(xss, temp1)) .. ")")
  385.         end
  386.         pushCdr_21_1(out, n1(nth1(xss, temp1)))
  387.         temp1 = temp1 + 1
  388.     end
  389.     ns = out
  390.     local out = ({tag = "list", n = 0})
  391.     local temp = apply1(min1, ns)
  392.     local temp1 = 1
  393.     while temp1 <= temp do
  394.         pushCdr_21_1(out, apply1(fn, nths1(xss, temp1)))
  395.         temp1 = temp1 + 1
  396.     end
  397.     return out
  398. end)
  399. flatMap1 = (function(fn, ...)
  400.     local xss = _pack(...) xss.tag = "list"
  401.     return flatten1(apply1(map2, fn, xss))
  402. end)
  403. partition1 = (function(p, xs)
  404.     local temp = type1(p)
  405.     if temp ~= "function" then
  406.         error1(format1("bad argument %s (expected %s, got %s)", "p", "function", temp), 2)
  407.     end
  408.     local temp = type1(xs)
  409.     if temp ~= "list" then
  410.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  411.     end
  412.     local passed, failed = ({tag = "list", n = 0}), ({tag = "list", n = 0})
  413.     local temp = n1(xs)
  414.     local temp1 = 1
  415.     while temp1 <= temp do
  416.         local x = nth1(xs, temp1)
  417.         pushCdr_21_1((function()
  418.             if p(x) then
  419.                 return passed
  420.             else
  421.                 return failed
  422.             end
  423.         end)(), x)
  424.         temp1 = temp1 + 1
  425.     end
  426.     return unpack1(list1(passed, failed), 1, 2)
  427. end)
  428. filter1 = (function(p, xs)
  429.     return first1(partition1(p, xs))
  430. end)
  431. any1 = (function(p, xs)
  432.     local temp = type1(p)
  433.     if temp ~= "function" then
  434.         error1(format1("bad argument %s (expected %s, got %s)", "p", "function", temp), 2)
  435.     end
  436.     local temp = type1(xs)
  437.     if temp ~= "list" then
  438.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  439.     end
  440.     local len = n1(xs)
  441.     local i = 1
  442.     while true do
  443.         if i > len then
  444.             return false
  445.         elseif p(nth1(xs, i)) then
  446.             return true
  447.         else
  448.             i = i + 1
  449.         end
  450.     end
  451. end)
  452. elem_3f_1 = (function(x, xs)
  453.     local temp = type1(xs)
  454.     if temp ~= "list" then
  455.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  456.     end
  457.     return any1((function(y)
  458.         return eq_3f_1(x, y)
  459.     end), xs)
  460. end)
  461. last1 = (function(xs)
  462.     local temp = type1(xs)
  463.     if temp ~= "list" then
  464.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  465.     end
  466.     return xs[n1(xs)]
  467. end)
  468. init1 = (function(xs)
  469.     local temp = type1(xs)
  470.     if temp ~= "list" then
  471.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  472.     end
  473.     return slice1(xs, 1, n1(xs) - 1)
  474. end)
  475. nth1 = (function(xs, idx)
  476.     if idx >= 0 then
  477.         return xs[idx]
  478.     else
  479.         return xs[xs["n"] + 1 + idx]
  480.     end
  481. end)
  482. nths1 = (function(xss, idx)
  483.     local out = ({tag = "list", n = 0})
  484.     local temp = n1(xss)
  485.     local temp1 = 1
  486.     while temp1 <= temp do
  487.         pushCdr_21_1(out, nth1(nth1(xss, temp1), idx))
  488.         temp1 = temp1 + 1
  489.     end
  490.     return out
  491. end)
  492. pushCdr_21_1 = (function(xs, val)
  493.     local temp = type1(xs)
  494.     if temp ~= "list" then
  495.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  496.     end
  497.     local len = n1(xs) + 1
  498.     xs["n"] = len
  499.     xs[len] = val
  500.     return xs
  501. end)
  502. removeNth_21_1 = (function(li, idx)
  503.     local temp = type1(li)
  504.     if temp ~= "list" then
  505.         error1(format1("bad argument %s (expected %s, got %s)", "li", "list", temp), 2)
  506.     end
  507.     li["n"] = li["n"] - 1
  508.     return remove1(li, idx)
  509. end)
  510. append1 = (function(xs, ys)
  511.     local _offset, _result, _temp = 0, {tag="list",n=0}
  512.     _temp = xs
  513.     for _c = 1, _temp.n do _result[0 + _c + _offset] = _temp[_c] end
  514.     _offset = _offset + _temp.n
  515.     _temp = ys
  516.     for _c = 1, _temp.n do _result[0 + _c + _offset] = _temp[_c] end
  517.     _offset = _offset + _temp.n
  518.     _result.n = _offset + 0
  519.     return _result
  520. end)
  521. flatten1 = (function(xss)
  522.     return reduce1(append1, ({tag = "list", n = 0}), xss)
  523. end)
  524. cadr1 = (function(xs)
  525.     local temp = type1(xs)
  526.     if temp ~= "list" then
  527.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  528.     end
  529.     return xs[2]
  530. end)
  531. caddr1 = (function(xs)
  532.     local temp = type1(xs)
  533.     if temp ~= "list" then
  534.         error1(format1("bad argument %s (expected %s, got %s)", "xs", "list", temp), 2)
  535.     end
  536.     return xs[3]
  537. end)
  538. charAt1 = (function(xs, x)
  539.     return sub1(xs, x, x)
  540. end)
  541. split1 = (function(text, pattern, limit)
  542.     local out, loop, start = ({tag = "list", n = 0}), true, 1
  543.     while loop do
  544.         local pos = list1(find1(text, pattern, start))
  545.         local nstart, nend = car2(pos), cadr1(pos)
  546.         if nstart == nil or limit and n1(out) >= limit then
  547.             loop = false
  548.             pushCdr_21_1(out, sub1(text, start, n1(text)))
  549.             start = n1(text) + 1
  550.         elseif nstart > #text then
  551.             if start <= #text then
  552.                 pushCdr_21_1(out, sub1(text, start, #text))
  553.             end
  554.             loop = false
  555.         elseif nend < nstart then
  556.             pushCdr_21_1(out, sub1(text, start, nstart))
  557.             start = nstart + 1
  558.         else
  559.             pushCdr_21_1(out, sub1(text, start, nstart - 1))
  560.             start = nend + 1
  561.         end
  562.     end
  563.     return out
  564. end)
  565. trim1 = (function(str)
  566.     return (gsub1(gsub1(str, "^%s+", ""), "%s+$", ""))
  567. end)
  568. display1 = (function(x)
  569.     if type_23_1(x) == "string" then
  570.         return x
  571.     elseif type_23_1(x) == "table" and x["tag"] == "string" then
  572.         return x["value"]
  573.     else
  574.         return pretty1(x)
  575.     end
  576. end)
  577. assoc_2d3e_struct1 = (function(list)
  578.     local temp = type1(list)
  579.     if temp ~= "list" then
  580.         error1(format1("bad argument %s (expected %s, got %s)", "list", "list", temp), 2)
  581.     end
  582.     local ret = ({})
  583.     local temp = n1(list)
  584.     local temp1 = 1
  585.     while temp1 <= temp do
  586.         local x = list[temp1]
  587.         local hd
  588.         if key_3f_1(car2(x)) then
  589.             hd = car2(x)["value"]
  590.         else
  591.             hd = car2(x)
  592.         end
  593.         if _21_1(ret[hd]) then
  594.             ret[hd] = cadr1(x)
  595.         end
  596.         temp1 = temp1 + 1
  597.     end
  598.     return ret
  599. end)
  600. merge1 = (function(...)
  601.     local structs = _pack(...) structs.tag = "list"
  602.     local out = ({})
  603.     local temp = n1(structs)
  604.     local temp1 = 1
  605.     while temp1 <= temp do
  606.         local st = structs[temp1]
  607.         local temp2, v = next1(st)
  608.         while temp2 ~= nil do
  609.             out[temp2] = v
  610.             temp2, v = next1(st, temp2)
  611.         end
  612.         temp1 = temp1 + 1
  613.     end
  614.     return out
  615. end)
  616. keys2 = (function(st)
  617.     local out = ({tag = "list", n = 0})
  618.     local temp, _ = next1(st)
  619.     while temp ~= nil do
  620.         pushCdr_21_1(out, temp)
  621.         temp, _ = next1(st, temp)
  622.     end
  623.     return out
  624. end)
  625. values1 = (function(st)
  626.     local out = ({tag = "list", n = 0})
  627.     local temp, v = next1(st)
  628.     while temp ~= nil do
  629.         pushCdr_21_1(out, v)
  630.         temp, v = next1(st, temp)
  631.     end
  632.     return out
  633. end)
  634. exit1 = os.exit
  635. getenv1 = os.getenv
  636. succ1 = (function(x)
  637.     return x + 1
  638. end)
  639. pred1 = (function(x)
  640.     return x - 1
  641. end)
  642. fail_21_1 = (function(x)
  643.     return error1(x, 0)
  644. end)
  645. exit_21_1 = (function(reason, code)
  646.     local code1
  647.     if string_3f_1(reason) then
  648.         code1 = code
  649.     else
  650.         code1 = reason
  651.     end
  652.     if exit1 then
  653.         if string_3f_1(reason) then
  654.             print1(reason)
  655.         end
  656.         return exit1(code1)
  657.     elseif string_3f_1(reason) then
  658.         return fail_21_1(reason)
  659.     else
  660.         return fail_21_1()
  661.     end
  662. end)
  663. const1 = (function(x)
  664.     return (function(y)
  665.         return x
  666.     end)
  667. end)
  668. self1 = (function(x, key, ...)
  669.     local args = _pack(...) args.tag = "list"
  670.     return x[key](x, unpack1(args, 1, n1(args)))
  671. end)
  672. create1 = coroutine.create
  673. resume1 = coroutine.resume
  674. open1 = fs.open
  675. getName1 = fs.getName
  676. combine1 = fs.combine
  677. isReadOnly1 = fs.isReadOnly
  678. move1 = fs.move
  679. copy1 = fs.copy
  680. delete1 = fs.delete
  681. isDir1 = fs.isDir
  682. getFreeSpace1 = fs.getFreeSpace
  683. getSize1 = fs.getSize
  684. list2 = fs.list
  685. exists1 = fs.exists
  686. makeDir1 = fs.makeDir
  687. getDir1 = fs.getDir
  688. current1 = term.current
  689. day1 = os.day
  690. sleep1 = os.sleep
  691. setAlarm1 = os.setAlarm
  692. pullEventRaw1 = os.pullEventRaw
  693. clock1 = os.clock
  694. time1 = os.time
  695. cancelTimer1 = os.cancelTimer
  696. startTimer1 = os.startTimer
  697. cancelAlarm1 = os.cancelAlarm
  698. queueEvent1 = os.queueEvent
  699. resolve1 = shell.resolve
  700. log_21_1 = (function(message)
  701.     return nil
  702. end)
  703. createVfs1 = (function(vfsMounts)
  704.     local mounts = ({})
  705.     local wrapFun = (function(_efunction)
  706.         return (function(path, ...)
  707.             local rest = _pack(...) rest.tag = "list"
  708.             local mount, localPath = mountPath1(mounts, path)
  709.             return mount[_efunction](localPath, unpack1(rest))
  710.         end)
  711.     end)
  712.     local dirList = (function(x)
  713.         local path = canonicalise1(x, true)
  714.         local entries = wrapFun("list")(path)
  715.         local temp = keys2(mounts)
  716.         local temp1 = n1(temp)
  717.         local temp2 = 1
  718.         while temp2 <= temp1 do
  719.             local mountPath = temp[temp2]
  720.             local mountPathParts = split1(mountPath, "%/")
  721.             if path == concat1(init1(mountPathParts), "/") and (mountPath ~= "" and _21_1(elem_3f_1(last1(mountPathParts), values1(entries)))) then
  722.                 entries[#entries + 1] = last1(mountPathParts)
  723.             end
  724.             temp2 = temp2 + 1
  725.         end
  726.         return entries
  727.     end)
  728.     local temp = n1(vfsMounts)
  729.     local temp1 = 1
  730.     while temp1 <= temp do
  731.         local vfsMount = vfsMounts[temp1]
  732.         local mountArgs = split1(vfsMount, "%:")
  733.         local attributes, mountPoint, dir = split1(car2(mountArgs), ""), canonicalise1(cadr1(mountArgs), true), canonicalise1(caddr1(mountArgs), false)
  734.         local fsType
  735.         if elem_3f_1("r", attributes) then
  736.             fsType = ({ tag="symbol", contents="realfs"})
  737.         elseif elem_3f_1("t", attributes) then
  738.             fsType = ({ tag="symbol", contents="tmpfs"})
  739.         else
  740.             fsType = error1("file system type not found.")
  741.         end
  742.         local readOnly = _21_1(elem_3f_1("w", attributes))
  743.         if eq_3f_1(fsType, ({ tag="symbol", contents="realfs"})) then
  744.             mounts[mountPoint] = createRealfs1(dir, readOnly)
  745.         else
  746.             error1("unimplemented.")
  747.         end
  748.         temp1 = temp1 + 1
  749.     end
  750.     return ({["list"]=dirList,["exists"]=wrapFun("exists"),["isDir"]=wrapFun("isDir"),["isReadOnly"]=wrapFun("isReadOnly"),["getName"]=getName1,["getDrive"]=(function(path)
  751.         return "hdd"
  752.     end),["getSize"]=wrapFun("getSize"),["getFreeSpace"]=wrapFun("getFreeSpace"),["makeDir"]=wrapFun("makeDir"),["move"]=(function(fromPath, toPath)
  753.         if wrapFun("isReadOnly")(fromPath) or wrapFun("isReadOnly")(toPath) then
  754.             return error1("permission denied.")
  755.         else
  756.             local mountFrom, localPathFrom = mountPath1(mounts, fromPath)
  757.             local mountTo, localPathTo = mountPath1(mounts, toPath)
  758.             if mountFrom ~= mountTo then
  759.                 return error1("copying across mounts is currently not implemented.")
  760.             else
  761.                 return mountFrom["move"](localPathFrom, localPathTo)
  762.             end
  763.         end
  764.     end),["copy"]=(function(fromPath, toPath)
  765.         if wrapFun("isReadOnly")(toPath) then
  766.             return error1("permission denied.")
  767.         else
  768.             local mountFrom, localPathFrom = mountPath1(mounts, fromPath)
  769.             local mountTo, localPathTo = mountPath1(mounts, toPath)
  770.             if mountFrom ~= mountTo then
  771.                 return error1("copying across mounts is currently not implemented.")
  772.             else
  773.                 return mountFrom["copy"](localPathFrom, localPathTo)
  774.             end
  775.         end
  776.     end),["delete"]=wrapFun("delete"),["combine"]=combine1,["open"]=wrapFun("open"),["find"]=(function(wildcard)
  777.         if wrapFun("exists")(wildcard) then
  778.             return list1(wildcard)
  779.         else
  780.             return ({tag = "list", n = 0})
  781.         end
  782.     end),["getDir"]=getDir1,["complete"]=(function(partialName, path, includeFiles, includeSlashes)
  783.         if _21_1(wrapFun("isDir")()) then
  784.             return ({})
  785.         else
  786.             local names = dirList(path)
  787.             return filter1((function(x)
  788.                 return x == "nil"
  789.             end), map2((function(name)
  790.                 if sub1(name, 1, n1(partialName)) == partialName then
  791.                     return name
  792.                 else
  793.                     return "nil"
  794.                 end
  795.             end)))
  796.         end
  797.     end)})
  798. end)
  799. mountPath1 = (function(mounts, path)
  800.     local absPath, mountName = canonicalise1(path, true), ""
  801.     local temp = keys2(mounts)
  802.     local temp1 = n1(temp)
  803.     local temp2 = 1
  804.     while temp2 <= temp1 do
  805.         local mountPoint = temp[temp2]
  806.         if n1(mountPoint) > n1(mountName) and sub1(absPath, 1, n1(mountPoint)) == mountPoint then
  807.             mountName = mountPoint
  808.         end
  809.         temp2 = temp2 + 1
  810.     end
  811.     return unpack1(list1(mounts[mountName], canonicalise1(sub1(absPath, 1 + n1(mountName)), true)))
  812. end)
  813. canonicalise1 = (function(path, abs)
  814.     local absPath = trim1((function()
  815.         if abs then
  816.             return path
  817.         else
  818.             return resolve1(path)
  819.         end
  820.     end)())
  821.     local parts, i = split1(absPath, "%/"), 1
  822.     while i <= n1(parts) do
  823.         if nth1(parts, i) == ".." then
  824.             removeNth_21_1(parts, i)
  825.             if n1(parts) == 0 then
  826.                 error1("invalid path.")
  827.             end
  828.             i = pred1(i)
  829.             removeNth_21_1(parts, i)
  830.         else
  831.             i = succ1(i)
  832.         end
  833.     end
  834.     return concat1(filter1((function(x)
  835.         return x ~= "" and x ~= "."
  836.     end), parts), "/")
  837. end)
  838. createRealfs1 = (function(dir, readOnly)
  839.     return ({["list"]=(function(path)
  840.         return list2(display1(dir) .. "/" .. display1(path))
  841.     end),["exists"]=(function(path)
  842.         return exists1(display1(dir) .. "/" .. display1(path))
  843.     end),["isDir"]=(function(path)
  844.         return isDir1(display1(dir) .. "/" .. display1(path))
  845.     end),["isReadOnly"]=(function(path)
  846.         return readOnly or isReadOnly1(display1(dir) .. "/" .. display1(path))
  847.     end),["getSize"]=(function(path)
  848.         return getSize1(display1(dir) .. "/" .. display1(path))
  849.     end),["getFreeSpace"]=(function(path)
  850.         return getFreeSpace1(display1(dir) .. "/" .. display1(path))
  851.     end),["makeDir"]=(function(path)
  852.         if readOnly then
  853.             return error1("permission denied.")
  854.         else
  855.             return makeDir1(display1(dir) .. "/" .. display1(path))
  856.         end
  857.     end),["delete"]=(function(path)
  858.         if readOnly then
  859.             return error1("permission denied.")
  860.         else
  861.             return delete1(display1(dir) .. "/" .. display1(path))
  862.         end
  863.     end),["move"]=(function(from, to)
  864.         return move1(display1(dir) .. "/" .. display1(from), display1(dir) .. "/" .. display1(to))
  865.     end),["copy"]=(function(from, to)
  866.         return copy1(display1(dir) .. "/" .. display1(from), display1(dir) .. "/" .. display1(to))
  867.     end),["open"]=(function(path, mode)
  868.         return open1(display1(dir) .. "/" .. display1(path), mode)
  869.     end)})
  870. end)
  871. create2 = (function(spec)
  872.     local computer = ({["id"]=0,["label"]="computer-0",["running"]=true,["spec"]=spec,["vfs"]=createVfs1(spec["vfs-mounts"])})
  873.     computer["env"] = (createEnv1(computer))
  874.     createCoroutine_21_1(computer)
  875.     return computer
  876. end)
  877. createCoroutine_21_1 = (function(computer)
  878.     local bootCodeHandle = open1(resolve1(computer["spec"]["boot-file"]), "r")
  879.     local bootCode
  880.     if bootCodeHandle then
  881.         bootCode = self1(bootCodeHandle, "readAll")
  882.     else
  883.         bootCode = error1("could not read boot file.")
  884.     end
  885.     local coroutine = create1(load1(bootCode, "ccjam-bios.lua", "t", computer["env"]))
  886.     self1(bootCodeHandle, "close")
  887.     computer["coroutine"] = coroutine
  888.     if n1(computer["spec"]["startup-command"]) > 0 then
  889.         next_21_1(computer, ({tag = "list", n = 2, "char", " "}))
  890.         local temp = split1(computer["spec"]["startup-command"], "")
  891.         local temp1 = n1(temp)
  892.         local temp2 = 1
  893.         while temp2 <= temp1 do
  894.             next_21_1(computer, list1("char", (temp[temp2])))
  895.             temp2 = temp2 + 1
  896.         end
  897.         return next_21_1(computer, ({tag = "list", n = 2, "key", 28}))
  898.     else
  899.         return nil
  900.     end
  901. end)
  902. eventWhitelist1 = ({tag = "list", n = 13, "timer", "alarm", "terminate", "http_success", "http_failure", "paste", "char", "key", "key_up", "mouse_click", "mouse_up", "mouse_scroll", "mouse_drag"})
  903. next_21_1 = (function(computer, args)
  904.     local event = car2(args)
  905.     if elem_3f_1(event, eventWhitelist1) then
  906.         local result = list1(resume1(computer["coroutine"], event, unpack1(cdr2(args))))
  907.         if car2(result) == false then
  908.             return error1("computer panicked! error: \n" .. cadr1(result))
  909.         else
  910.             log_21_1("event: " .. pretty1(args))
  911.             return unpack1(cdr2(result))
  912.         end
  913.     else
  914.         return nil
  915.     end
  916. end)
  917. envWhitelist1 = ({tag = "list", n = 33, "type", "setfenv", "string", "load", "loadstring", "pairs", "_VERSION", "ipairs", "rawequal", "xpcall", "_CC_DEFAULT_SETTINGS", "unpack", "bitop", "setmetatable", "rawset", "rawget", "table", "bit32", "_HOST", "bit", "assert", "error", "pcall", "tostring", "next", "tonumber", "math", "_RUNTIME", "coroutine", "biginteger", "getfenv", "select", "data"})
  918. createEnv1 = (function(computer)
  919.     local spec, global, term, constFunStruct = computer["spec"], assoc_2d3e_struct1(map2((function(name)
  920.         local contents = _G1[name]
  921.         return list1(name, (function()
  922.             if type1(contents) == "table" then
  923.                 return merge1(contents, ({}))
  924.             else
  925.                 return contents
  926.             end
  927.         end)())
  928.     end), envWhitelist1)), merge1(current1(), ({})), (function(xxs)
  929.         return assoc_2d3e_struct1(flatMap1((function(xs)
  930.             local value = const1(car2(xs))
  931.             return map2((function(name)
  932.                 return list1(name, value)
  933.             end), cdr2(xs))
  934.         end), xxs))
  935.     end)
  936.     global["_G"] = global
  937.     global["getmetatable"] = (function(a)
  938.         if type_23_1(a) == "string" then
  939.             return ({})
  940.         else
  941.             return getmetatable1(a)
  942.         end
  943.     end)
  944.     global["term"] = term
  945.     global["disk"] = (function()
  946.         if spec["enable-disk"] then
  947.             return _G1["disk"]
  948.         else
  949.             return constFunStruct(list1(list1(nil, "getMountPath", "setLabel", "getLabel", "getID", "getAudioTitle", "playAudio", "stopAudio", "eject"), list1(false, "isPresent", "hasData", "hasAudio")))
  950.         end
  951.     end)()
  952.     global["peripheral"] = (function()
  953.         if spec["enable-peripheral"] then
  954.             return _G1["peripheral"]
  955.         else
  956.             return constFunStruct(list1(list1(nil, "getType", "getMethods", "call", "wrap", "find"), list1(false, "isPresent"), list1(({}), "getNames")))
  957.         end
  958.     end)()
  959.     global["redstone"] = (function()
  960.         if spec["enable-redstone"] then
  961.             return _G1["redstone"]
  962.         else
  963.             return constFunStruct(list1(list1(nil, "setOutput", "setAnalogOutput", "setBundledOutput"), list1(false, "getInput", "testBundledInput"), list1(({}), "getSides"), list1(0, "getAnalogInput", "getAnalogOutput", "getBundledInput", "getBundledOutput")))
  964.         end
  965.     end)()
  966.     global["os"] = ({["getComputerID"]=(function()
  967.         return computer["id"]
  968.     end),["getComputerLabel"]=(function()
  969.         return computer["label"]
  970.     end),["setComputerLabel"]=(function(label)
  971.         computer["label"] = label
  972.         return nil
  973.     end),["queueEvent"]=queueEvent1,["clock"]=clock1,["startTimer"]=startTimer1,["cancelTimer"]=cancelTimer1,["time"]=time1,["day"]=day1,["setAlarm"]=setAlarm1,["cancelAlarm"]=cancelAlarm1,["shutdown"]=(function()
  974.         computer["running"] = false
  975.         return nil
  976.     end),["reboot"]=(function()
  977.         createCoroutine_21_1(computer)
  978.         return sleep1(0)
  979.     end)})
  980.     global["rs"] = global["redstone"]
  981.     if _21_1(computer["spec"]["disable-networking"]) then
  982.         global["http"] = (function()
  983.             if _G1["http"] then
  984.                 return merge1(_G1["http"], ({}))
  985.             else
  986.                 return nil
  987.             end
  988.         end)()
  989.         global["socket"] = (function()
  990.             if _G1["socket"] then
  991.                 return merge1(_G1["socket"], ({}))
  992.             else
  993.                 return nil
  994.             end
  995.         end)()
  996.     end
  997.     global["fs"] = computer["vfs"]
  998.     return global
  999. end)
  1000. config1 = package.config
  1001. coloredAnsi1 = (function(col, msg)
  1002.     return "\27[" .. col .. "m" .. msg .. "\27[0m"
  1003. end)
  1004. local termTy = lower1(getenv1 and getenv1("TERM") or "")
  1005. if termTy == "dumb" then
  1006.     colored_3f_1 = false
  1007. elseif find1(termTy, "xterm") then
  1008.     colored_3f_1 = true
  1009. elseif config1 and charAt1(config1, 1) == "/" then
  1010.     colored_3f_1 = true
  1011. elseif getenv1 and getenv1("ANSICON") ~= nil then
  1012.     colored_3f_1 = true
  1013. else
  1014.     colored_3f_1 = false
  1015. end
  1016. if colored_3f_1 then
  1017.     colored1 = coloredAnsi1
  1018. else
  1019.     colored1 = (function(col, msg)
  1020.         return msg
  1021.     end)
  1022. end
  1023. create3 = (function(description)
  1024.     return ({["desc"]=description,["flag-map"]=({}),["opt-map"]=({}),["cats"]=({tag = "list", n = 0}),["opt"]=({tag = "list", n = 0}),["pos"]=({tag = "list", n = 0})})
  1025. end)
  1026. setAction1 = (function(arg, data, value)
  1027.     data[arg["name"]] = value
  1028.     return nil
  1029. end)
  1030. addAction1 = (function(arg, data, value)
  1031.     local lst = data[arg["name"]]
  1032.     if not lst then
  1033.         lst = ({tag = "list", n = 0})
  1034.         data[arg["name"]] = lst
  1035.     end
  1036.     return pushCdr_21_1(lst, value)
  1037. end)
  1038. addArgument_21_1 = (function(spec, names, ...)
  1039.     local options = _pack(...) options.tag = "list"
  1040.     local temp = type1(names)
  1041.     if temp ~= "list" then
  1042.         error1(format1("bad argument %s (expected %s, got %s)", "names", "list", temp), 2)
  1043.     end
  1044.     if empty_3f_1(names) then
  1045.         error1("Names list is empty")
  1046.     end
  1047.     if not (n1(options) % 2 == 0) then
  1048.         error1("Options list should be a multiple of two")
  1049.     end
  1050.     local result = ({["names"]=names,["action"]=nil,["narg"]=0,["default"]=false,["help"]="",["value"]=true})
  1051.     local first = car2(names)
  1052.     if sub1(first, 1, 2) == "--" then
  1053.         pushCdr_21_1(spec["opt"], result)
  1054.         result["name"] = sub1(first, 3)
  1055.     elseif sub1(first, 1, 1) == "-" then
  1056.         pushCdr_21_1(spec["opt"], result)
  1057.         result["name"] = sub1(first, 2)
  1058.     else
  1059.         result["name"] = first
  1060.         result["narg"] = "*"
  1061.         result["default"] = ({tag = "list", n = 0})
  1062.         pushCdr_21_1(spec["pos"], result)
  1063.     end
  1064.     local temp = n1(names)
  1065.     local temp1 = 1
  1066.     while temp1 <= temp do
  1067.         local name = names[temp1]
  1068.         if sub1(name, 1, 2) == "--" then
  1069.             spec["opt-map"][sub1(name, 3)] = result
  1070.         elseif sub1(name, 1, 1) == "-" then
  1071.             spec["flag-map"][sub1(name, 2)] = result
  1072.         end
  1073.         temp1 = temp1 + 1
  1074.     end
  1075.     local temp = n1(options)
  1076.     local temp1 = 1
  1077.     while temp1 <= temp do
  1078.         result[nth1(options, temp1)] = (nth1(options, temp1 + 1))
  1079.         temp1 = temp1 + 2
  1080.     end
  1081.     if not result["var"] then
  1082.         result["var"] = upper1(result["name"])
  1083.     end
  1084.     if not result["action"] then
  1085.         result["action"] = (function()
  1086.             local temp
  1087.             if number_3f_1(result["narg"]) then
  1088.                 temp = result["narg"] <= 1
  1089.             else
  1090.                 temp = result["narg"] == "?"
  1091.             end
  1092.             if temp then
  1093.                 return setAction1
  1094.             else
  1095.                 return addAction1
  1096.             end
  1097.         end)()
  1098.     end
  1099.     return result
  1100. end)
  1101. addHelp_21_1 = (function(spec)
  1102.     return addArgument_21_1(spec, ({tag = "list", n = 2, "--help", "-h"}), "help", "Show this help message", "default", nil, "value", nil, "action", (function(arg, result, value)
  1103.         help_21_1(spec)
  1104.         return exit_21_1(0)
  1105.     end))
  1106. end)
  1107. usageNarg_21_1 = (function(buffer, arg)
  1108.     local temp = arg["narg"]
  1109.     if temp == "?" then
  1110.         return pushCdr_21_1(buffer, " [" .. arg["var"] .. "]")
  1111.     elseif temp == "*" then
  1112.         return pushCdr_21_1(buffer, " [" .. arg["var"] .. "...]")
  1113.     elseif temp == "+" then
  1114.         return pushCdr_21_1(buffer, " " .. arg["var"] .. " [" .. arg["var"] .. "...]")
  1115.     else
  1116.         local temp1 = 1
  1117.         while temp1 <= temp do
  1118.             pushCdr_21_1(buffer, " " .. arg["var"])
  1119.             temp1 = temp1 + 1
  1120.         end
  1121.         return nil
  1122.     end
  1123. end)
  1124. usage_21_1 = (function(spec, name)
  1125.     if not name then
  1126.         name = nth1(arg1, 0) or (arg1[-1] or "?")
  1127.     end
  1128.     local usage = list1("usage: ", name)
  1129.     local temp = spec["opt"]
  1130.     local temp1 = n1(temp)
  1131.     local temp2 = 1
  1132.     while temp2 <= temp1 do
  1133.         local arg = temp[temp2]
  1134.         pushCdr_21_1(usage, " [" .. car2(arg["names"]))
  1135.         usageNarg_21_1(usage, arg)
  1136.         pushCdr_21_1(usage, "]")
  1137.         temp2 = temp2 + 1
  1138.     end
  1139.     local temp = spec["pos"]
  1140.     local temp1 = n1(temp)
  1141.     local temp2 = 1
  1142.     while temp2 <= temp1 do
  1143.         usageNarg_21_1(usage, (temp[temp2]))
  1144.         temp2 = temp2 + 1
  1145.     end
  1146.     return print1(concat1(usage))
  1147. end)
  1148. usageError_21_1 = (function(spec, name, error)
  1149.     usage_21_1(spec, name)
  1150.     print1(error)
  1151.     return exit_21_1(1)
  1152. end)
  1153. helpArgs_21_1 = (function(pos, opt, format)
  1154.     if (empty_3f_1(pos) and empty_3f_1(opt)) then
  1155.         return nil
  1156.     else
  1157.         print1()
  1158.         local temp = n1(pos)
  1159.         local temp1 = 1
  1160.         while temp1 <= temp do
  1161.             local arg = pos[temp1]
  1162.             print1(format1(format, arg["var"], arg["help"]))
  1163.             temp1 = temp1 + 1
  1164.         end
  1165.         local temp = n1(opt)
  1166.         local temp1 = 1
  1167.         while temp1 <= temp do
  1168.             local arg = opt[temp1]
  1169.             print1(format1(format, concat1(arg["names"], ", "), arg["help"]))
  1170.             temp1 = temp1 + 1
  1171.         end
  1172.         return nil
  1173.     end
  1174. end)
  1175. help_21_1 = (function(spec, name)
  1176.     if not name then
  1177.         name = nth1(arg1, 0) or (arg1[-1] or "?")
  1178.     end
  1179.     usage_21_1(spec, name)
  1180.     if spec["desc"] then
  1181.         print1()
  1182.         print1(spec["desc"])
  1183.     end
  1184.     local max = 0
  1185.     local temp = spec["pos"]
  1186.     local temp1 = n1(temp)
  1187.     local temp2 = 1
  1188.     while temp2 <= temp1 do
  1189.         local arg = temp[temp2]
  1190.         local len = n1(arg["var"])
  1191.         if len > max then
  1192.             max = len
  1193.         end
  1194.         temp2 = temp2 + 1
  1195.     end
  1196.     local temp = spec["opt"]
  1197.     local temp1 = n1(temp)
  1198.     local temp2 = 1
  1199.     while temp2 <= temp1 do
  1200.         local arg = temp[temp2]
  1201.         local len = n1(concat1(arg["names"], ", "))
  1202.         if len > max then
  1203.             max = len
  1204.         end
  1205.         temp2 = temp2 + 1
  1206.     end
  1207.     local fmt = " %-" .. tostring1(max + 1) .. "s %s"
  1208.     helpArgs_21_1(filter1((function(x)
  1209.         return x["cat"] == nil
  1210.     end), spec["pos"]), filter1((function(x)
  1211.         return x["cat"] == nil
  1212.     end), spec["opt"]), fmt)
  1213.     local temp = spec["cats"]
  1214.     local temp1 = n1(temp)
  1215.     local temp2 = 1
  1216.     while temp2 <= temp1 do
  1217.         local cat = temp[temp2]
  1218.         print1()
  1219.         print1(colored1("4", cat["name"]))
  1220.         local desc = cat["desc"]
  1221.         if desc then
  1222.             print1(desc)
  1223.         end
  1224.         helpArgs_21_1(filter1((function(x)
  1225.             return x["cat"] == cat["id"]
  1226.         end), spec["pos"]), filter1((function(x)
  1227.             return x["cat"] == cat["id"]
  1228.         end), spec["opt"]), fmt)
  1229.         temp2 = temp2 + 1
  1230.     end
  1231.     return nil
  1232. end)
  1233. matcher1 = (function(pattern)
  1234.     return (function(x)
  1235.         local res = list1(match1(x, pattern))
  1236.         if car2(res) == nil then
  1237.             return nil
  1238.         else
  1239.             return res
  1240.         end
  1241.     end)
  1242. end)
  1243. parse_21_1 = (function(spec, args)
  1244.     if not args then
  1245.         args = arg1
  1246.     end
  1247.     local result, pos, idx, len, usage_21_ = ({}), spec["pos"], 1, n1(args), (function(msg)
  1248.         return usageError_21_1(spec, nth1(args, 0), msg)
  1249.     end)
  1250.     local action = (function(arg, value)
  1251.         return arg["action"](arg, result, value, usage_21_)
  1252.     end)
  1253.     local readArgs = (function(key, arg)
  1254.         local temp = arg["narg"]
  1255.         if temp == "+" then
  1256.             idx = succ1(idx)
  1257.             local elem = nth1(args, idx)
  1258.             if elem == nil then
  1259.                 usage_21_("Expected " .. arg["var"] .. " after --" .. key .. ", got nothing")
  1260.             elseif _21_1(arg["all"]) and find1(elem, "^%-") then
  1261.                 usage_21_("Expected " .. arg["var"] .. " after --" .. key .. ", got " .. nth1(args, idx))
  1262.             else
  1263.                 action(arg, elem)
  1264.             end
  1265.             local running = true
  1266.             while running do
  1267.                 idx = succ1(idx)
  1268.                 local elem = nth1(args, idx)
  1269.                 if elem == nil then
  1270.                     running = false
  1271.                 elseif _21_1(arg["all"]) and find1(elem, "^%-") then
  1272.                     running = false
  1273.                 else
  1274.                     action(arg, elem)
  1275.                 end
  1276.             end
  1277.             return nil
  1278.         elseif temp == "*" then
  1279.             local running = true
  1280.             while running do
  1281.                 idx = succ1(idx)
  1282.                 local elem = nth1(args, idx)
  1283.                 if elem == nil then
  1284.                     running = false
  1285.                 elseif _21_1(arg["all"]) and find1(elem, "^%-") then
  1286.                     running = false
  1287.                 else
  1288.                     action(arg, elem)
  1289.                 end
  1290.             end
  1291.             return nil
  1292.         elseif temp == "?" then
  1293.             idx = succ1(idx)
  1294.             local elem = nth1(args, idx)
  1295.             if elem == nil or _21_1(arg["all"]) and find1(elem, "^%-") then
  1296.                 return arg["action"](arg, result, arg["value"])
  1297.             else
  1298.                 idx = succ1(idx)
  1299.                 return action(arg, elem)
  1300.             end
  1301.         elseif temp == 0 then
  1302.             idx = succ1(idx)
  1303.             return action(arg, arg["value"])
  1304.         else
  1305.             local temp1 = 1
  1306.             while temp1 <= temp do
  1307.                 idx = succ1(idx)
  1308.                 local elem = nth1(args, idx)
  1309.                 if elem == nil then
  1310.                     usage_21_("Expected " .. temp .. " args for " .. key .. ", got " .. pred1(temp1))
  1311.                 elseif _21_1(arg["all"]) and find1(elem, "^%-") then
  1312.                     usage_21_("Expected " .. temp .. " for " .. key .. ", got " .. pred1(temp1))
  1313.                 else
  1314.                     action(arg, elem)
  1315.                 end
  1316.                 temp1 = temp1 + 1
  1317.             end
  1318.             idx = succ1(idx)
  1319.             return nil
  1320.         end
  1321.     end)
  1322.     while idx <= len do
  1323.         local temp = nth1(args, idx)
  1324.         local temp1
  1325.         local temp2 = matcher1("^%-%-([^=]+)=(.+)$")(temp)
  1326.         temp1 = list_3f_1(temp2) and (n1(temp2) >= 2 and (n1(temp2) <= 2 and true))
  1327.         if temp1 then
  1328.             local key, val = nth1(matcher1("^%-%-([^=]+)=(.+)$")(temp), 1), nth1(matcher1("^%-%-([^=]+)=(.+)$")(temp), 2)
  1329.             local arg = spec["opt-map"][key]
  1330.             if arg == nil then
  1331.                 usage_21_("Unknown argument " .. key .. " in " .. nth1(args, idx))
  1332.             elseif _21_1(arg["many"]) and nil ~= result[arg["name"]] then
  1333.                 usage_21_("Too may values for " .. key .. " in " .. nth1(args, idx))
  1334.             else
  1335.                 local narg = arg["narg"]
  1336.                 if number_3f_1(narg) and narg ~= 1 then
  1337.                     usage_21_("Expected " .. tostring1(narg) .. " values, got 1 in " .. nth1(args, idx))
  1338.                 end
  1339.                 action(arg, val)
  1340.             end
  1341.             idx = succ1(idx)
  1342.         else
  1343.             local temp1
  1344.             local temp2 = matcher1("^%-%-(.*)$")(temp)
  1345.             temp1 = list_3f_1(temp2) and (n1(temp2) >= 1 and (n1(temp2) <= 1 and true))
  1346.             if temp1 then
  1347.                 local key = nth1(matcher1("^%-%-(.*)$")(temp), 1)
  1348.                 local arg = spec["opt-map"][key]
  1349.                 if arg == nil then
  1350.                     usage_21_("Unknown argument " .. key .. " in " .. nth1(args, idx))
  1351.                 elseif _21_1(arg["many"]) and nil ~= result[arg["name"]] then
  1352.                     usage_21_("Too may values for " .. key .. " in " .. nth1(args, idx))
  1353.                 else
  1354.                     readArgs(key, arg)
  1355.                 end
  1356.             else
  1357.                 local temp1
  1358.                 local temp2 = matcher1("^%-(.+)$")(temp)
  1359.                 temp1 = list_3f_1(temp2) and (n1(temp2) >= 1 and (n1(temp2) <= 1 and true))
  1360.                 if temp1 then
  1361.                     local flags, i = nth1(matcher1("^%-(.+)$")(temp), 1), 1
  1362.                     local s = n1(flags)
  1363.                     while i <= s do
  1364.                         local key = charAt1(flags, i)
  1365.                         local arg = spec["flag-map"][key]
  1366.                         if arg == nil then
  1367.                             usage_21_("Unknown flag " .. key .. " in " .. nth1(args, idx))
  1368.                         elseif _21_1(arg["many"]) and nil ~= result[arg["name"]] then
  1369.                             usage_21_("Too many occurances of " .. key .. " in " .. nth1(args, idx))
  1370.                         else
  1371.                             local narg = arg["narg"]
  1372.                             if i == s then
  1373.                                 readArgs(key, arg)
  1374.                             elseif narg == 0 then
  1375.                                 action(arg, arg["value"])
  1376.                             else
  1377.                                 action(arg, sub1(flags, succ1(i)))
  1378.                                 i = succ1(s)
  1379.                                 idx = succ1(idx)
  1380.                             end
  1381.                         end
  1382.                         i = succ1(i)
  1383.                     end
  1384.                 else
  1385.                     local arg = car2(spec["pos"])
  1386.                     if arg then
  1387.                         action(arg, temp)
  1388.                     else
  1389.                         usage_21_("Unknown argument " .. arg)
  1390.                     end
  1391.                     idx = succ1(idx)
  1392.                 end
  1393.             end
  1394.         end
  1395.     end
  1396.     local temp = spec["opt"]
  1397.     local temp1 = n1(temp)
  1398.     local temp2 = 1
  1399.     while temp2 <= temp1 do
  1400.         local arg = temp[temp2]
  1401.         if result[arg["name"]] == nil then
  1402.             result[arg["name"]] = arg["default"]
  1403.         end
  1404.         temp2 = temp2 + 1
  1405.     end
  1406.     local temp = spec["pos"]
  1407.     local temp1 = n1(temp)
  1408.     local temp2 = 1
  1409.     while temp2 <= temp1 do
  1410.         local arg = temp[temp2]
  1411.         if result[arg["name"]] == nil then
  1412.             result[arg["name"]] = arg["default"]
  1413.         end
  1414.         temp2 = temp2 + 1
  1415.     end
  1416.     return result
  1417. end)
  1418. local spec = create3()
  1419. addHelp_21_1(spec)
  1420. addArgument_21_1(spec, ({tag = "list", n = 1, "vfs-mounts"}), "help", "The virtual file system mounts.\n  `<attrs>:<mount>:[dir]`\n  attr: attributes. w (write), t (tempfs), r (realfs)\n  Temp doesn't require a dir argument.\n  mount: mount point (has to start with /)\n  dir: host file system directory\n  Can be relative to the current directory.\n  Default: rw:/:. r:/rom:/rom", "default", ({tag = "list", n = 2, "rw:/:.", "r:/rom:/rom"}))
  1421. addArgument_21_1(spec, ({tag = "list", n = 2, "--boot", "-b"}), "name", "boot-file", "help", "        The boot file. Default: ./bios.lua", "default", "bios.lua", "narg", 1)
  1422. addArgument_21_1(spec, ({tag = "list", n = 2, "--command", "-c"}), "name", "startup-command", "help", "     The startup command.", "default", "", "narg", 1)
  1423. addArgument_21_1(spec, ({tag = "list", n = 2, "--disable-net", "-n"}), "name", "disable-networking", "help", " Disables networking (http, socket).")
  1424. addArgument_21_1(spec, ({tag = "list", n = 2, "--enable-rs", "-R"}), "name", "enable-redstone", "help", "   Enables redstone passthrough.")
  1425. addArgument_21_1(spec, ({tag = "list", n = 2, "--enable-per", "-P"}), "name", "enable-peripheral", "help", "  Enables peripheral passthrough.")
  1426. addArgument_21_1(spec, ({tag = "list", n = 2, "--enable-disk", "-D"}), "name", "enable-disk", "help", " Enables disk drive passthrough.")
  1427. args1 = parse_21_1(spec)
  1428. run1 = (function()
  1429.     local comp = create2(args1)
  1430.     while comp["running"] do
  1431.         next_21_1(comp, list1(pullEventRaw1()))
  1432.     end
  1433.     return nil
  1434. end)
  1435. return run1()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement