Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local root
- local output
- local outlines = nil
- local out_dir
- local function getLines(dir)
- local lines = {}
- if fs.exists(dir) then
- local file = fs.open(dir, "r")
- local line = file.readLine()
- while line ~= nil do
- lines[#lines + 1] = line
- line = file.readLine()
- end
- file.close()
- end
- return lines
- end
- local function writeClass(dir)
- local fdir = root.."/"..dir
- local import = string.gsub(out_dir.."/"..dir, "/", ".")
- local lines = getLines(fdir)
- if #lines > 1 then
- if outlines ~= nil then
- outlines[#outlines + 1] = "++"..import
- for i=1,#lines do
- local line = lines[i]
- if string.sub(line, 1, 8) == "inherit " then
- local impt = string.sub(line, 9, -1)
- local imp = classy.import(impt)
- if imp ~= nil then
- local chunk = imp[1]
- for j=1,#chunk do
- outlines[#outlines + 1] = chunk[j]
- end
- end
- else
- outlines[#outlines + 1] = lines[i]
- end
- end
- outlines[#outlines + 1] = "--"..import
- end
- end
- end
- local function writeList(odir, list, tab)
- for i=1,#list do
- local name = list[i]
- print(tab..name)
- if fs.isDir(root.."/"..odir..name) then
- local path = odir..name
- writeList(path.."/", fs.list(root.."/"..path), tab.." ")
- else
- writeClass(odir..name)
- end
- end
- end
- local function writeProject(dir, odir)
- root = dir
- outlines = {}
- local list = fs.list(dir)
- writeList("", list, " ")
- if fs.exists(odir..".cmp") then fs.delete(odir..".cmp") end
- output = fs.open(odir..".cmp", "a")
- print("Writing to output...")
- local tx,ty = term.getSize()
- local erase = ""
- for i=1,tx do erase = erase.." " end
- local x,y = term.getCursorPos()
- for i=1,#outlines do
- local line = outlines[i]
- if line ~= nil and string.len(line) > 0 then
- output.writeLine(outlines[i])
- end
- local p = math.floor(tonumber((i/#outlines)*100))
- term.setCursorPos(x, y)
- term.write(erase)
- term.setCursorPos(x, y)
- term.write("%"..p.." done!")
- end
- print("")
- output.close()
- end
- local function getInput()
- local tx,ty = term.getSize()
- local erase = ""
- for i=1,tx do erase = erase.." " end
- local x,y = term.getCursorPos()
- local input = read()
- while input == "" or input == nil do
- term.setCursorPos(x, y)
- term.write(erase)
- term.setCursorPos(x, y)
- input = read()
- end
- return input
- end
- print("Enter project directory:")
- local root_dir = getInput()
- print("Enter output directory:")
- out_dir = getInput()
- print(" ")
- print("Writing project...")
- writeProject(root_dir, out_dir)
- print("Finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement