Skip to content

Commit

Permalink
[NEW] EOF handling
Browse files Browse the repository at this point in the history
Handles end-of-files by requiring
a comment ('--<eof>') be made to
denote end-of-file. This end-of-file
denoter does not get included in
the final file.
  • Loading branch information
XDuskAshes authored Apr 26, 2024
1 parent 6fd8bce commit 5042d48
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions stitch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

local args = {...}

if args[1] == "--help" or args[1] == "-h" or args[1] == "-?" then
print("stitch | Cobbles files together efficiently.*")
print("--------------------------------------------")
print("--help/-h/-? | Show this help.")
end

local function e(s)
return s == "" or s == nil
end
Expand Down Expand Up @@ -51,7 +57,7 @@ handle.close()

handle = fs.open(args[1],"r")

repeat
repeat
local a = handle.readLine()
table.insert(instructions,a)
until e(a)
Expand All @@ -61,14 +67,16 @@ handle.close()
for k,v in pairs(instructions) do
print(k,v)
local toWrite = {}

handle = fs.open(v,"r")
repeat
repeat
local a = handle.readLine()
table.insert(toWrite,a)
until a == nil
until a == "--<eof>"
handle.close()

table.remove(toWrite,#toWrite)

handle = fs.open(args[2],"a")
for k,v in pairs(toWrite) do
handle.writeLine(v)
Expand Down

0 comments on commit 5042d48

Please sign in to comment.