Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("TapeFS v0.1 by OctoNezd(a.k.a. Nezd)")
- tape = require("component").proxy(require("component").list("tape")())
- shell = require("shell")
- u = require("unicode")
- beep = require("computer").beep
- function verbprint(a)
- if verbosity == true then
- print("D:" .. a)
- end
- end
- function read(count)
- verbprint(string.format("Reading %s symbols", count))
- a = ""
- for i = 1, count do
- print(string.format("I:Symbol num %s/%s", i, count))
- b = tape.read()
- if b == 0 then
- verbprint("Found end symbol. Seeking to next position.")
- tape.read(count - i)
- return a
- end
- verbprint(string.format("Byte value %s. Unicode value:%s", b, u.char(b)))
- a = a .. u.char(b)
- end
- return a
- end
- args, ops = shell.parse(...)
- if ops["h"] == true then
- print(" -h Displays this message")
- print(" --save=path Save file from path to tape")
- print(" -l Loads file from tape")
- print(" --dump=path Dumps file from tape to path")
- print(" -v Enable verbosity")
- print(" -f Disables questions")
- end
- if tape.isReady() == false then
- print("E:No tape inserted")
- os.exit()
- end
- print("I:Tape found.")
- if next(ops) == nil then
- print("E:No arguments passed\nType 'tapefs -h' for help")
- end
- if ops["v"] == true then
- verbosity = true
- end
- if ops["f"] == true then
- force = true
- else
- force = false
- end
- if verbosity == true then
- print(ops["s"])
- print(ops["l"])
- end
- if ops["l"] == true then
- tape.seek(-999999999999999)
- print("I:Checking tape...")
- if read(6) == "TAPEFS" then
- print("I:Checktape passed OK. Loading file...")
- else
- print("E:Checktape NOT passed. Did you inserted right tape?")
- os.exit()
- end
- size = read(20)
- print(string.format("I:File size is %s symbols", size))
- tape.setSpeed(2.0)
- code = read(tonumber(size))
- beep(1500,0.5)
- os.sleep(0.5)
- beep(1500,0.5)
- if force == false then
- print("I:Code is loaded. Press enter to start it, or hit ^C to cancel loading")
- io.read()
- end
- print("I:Loading code!")
- verbprint("Rewiding tape.")
- tape.seek(-999999999999999)
- load(code)()
- os.exit()
- end
- if ops["save"] ~= nil then
- if ops["save"] == true then
- print("E:No file passed in arguments!")
- os.exit()
- else
- tape.seek(-999999999999999)
- f = io.open(ops["save"], "r")
- if f == nil then
- print("E:Non-existing file passed")
- end
- contents = f:read("*all*")
- size = string.len(contents)
- if string.len(size) > 20 then
- print("E:File size is too big for TapeFS")
- else
- verbprint("Writing validator")
- tape.write("TAPEFS")
- verbprint("Writing size data")
- tape.write(tostring(size))
- --Seek space left
- tape.seek(20 - string.len(size))
- verbprint(string.format("Space left in TFS data:%s", 20-string.len(size)))
- print("I:Writing...")
- tape.write(contents)
- print("I:Writed data. Validating")
- tape.seek(-9999999999999)
- if read(6) == "TAPEFS" then
- print("I:Succesfully validated! Setting label...")
- tape.setLabel("[TAPEFS]" .. ops["save"])
- print("I:Done writing.")
- os.exit()
- else
- print("E:Cant validate tape! Looks like there is no enough space on it!")
- os.exit()
- end
- end
- end
- end
- if ops["dump"] ~= nil then
- if ops["dump"] == true then
- print("E:No file passed in arguments!")
- else
- tape.seek(-9999999999999)
- print("I:Checking tape")
- if read(6) == "TAPEFS" then
- print("I:Checktape passed OK. Loading file...")
- else
- print("E:Checktape NOT passed. Did you inserted right tape?")
- os.exit()
- end
- size = read(20)
- print(string.format("I:File size is %s symbols", size))
- tape.setSpeed(2.0)
- code = read(tonumber(size))
- tape.seek(-9999999999999)
- f = io.open(ops["dump"], "w")
- io.output(f)
- io.write(code)
- io.close(f)
- print("I:Dump:Success")
- end
- end
- if ops["h"] == true then
- print(" -h Displays this message")
- print(" --save=path Save file from path to tape")
- print(" -l Loads file from tape")
- print(" --dump=path Dumps file from tape to path")
- print(" -v Enable verbosity")
- print(" -f Disables questions")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement