Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
998B

  1. local minitel = require "minitel"
  2. local tA = {...}
  3. local function parseURL(url)
  4. local proto,addr = url:match("(.-)://(.+)")
  5. addr = addr or url
  6. local hp, path = addr:match("(.-)(/.*)")
  7. hp, path = hp or addr, path or "/"
  8. local host, port = hp:match("(.+):(.+)")
  9. host = host or hp
  10. return proto, host, port, path
  11. end
  12. local proto, host, port, path = parseURL(tA[1])
  13. proto,port = proto or "fget", port or 70
  14. local fname, rtype = tA[2] or "-", tA[3] or "t"
  15. local sock = minitel.open(host,port)
  16. local f = nil
  17. if fname ~= "-" then
  18. f = io.open(fname,"w")
  19. if not f then error("couldn't open file for writing") end
  20. else
  21. f = io.open(os.getenv("t"))
  22. f.close = function() end
  23. end
  24. if not sock then error("couldn't open connection to host") end
  25. sock:write(string.format("%s%s\n",rtype,path))
  26. local rtype, buf = "", ""
  27. repeat
  28. coroutine.yield()
  29. rtype = sock:read(1)
  30. until rtype ~= ""
  31. repeat
  32. coroutine.yield()
  33. buf = sock:read("*a")
  34. f:write(buf)
  35. until sock.state == "closed" and buf == ""
  36. f:close()