From d13fafdcc2bb28b76b12e5c00e029df1f6c2e95c Mon Sep 17 00:00:00 2001 From: plugd Date: Sat, 3 Aug 2024 07:17:41 +0200 Subject: [PATCH] Small restructuring. --- obbs | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/obbs b/obbs index 4c7e4b8..bcdaa85 100755 --- a/obbs +++ b/obbs @@ -46,6 +46,10 @@ function fs.exists(filename) return io.open(filename, "r") end +function fs.dir(path) + return posix.dir(path) +end + function fs.mkdir(dirname) posix.mkdir(dirname) end @@ -76,7 +80,9 @@ end local qwk = {} -function qwk.write_control(cf, obbs, user_name) +function qwk.write_control(target_dir, obbs, user_name) + local cf = assert(io.open(target_dir .. "/CONTROL.DAT", "w")) + cf:write(obbs.name .. "\r\n") cf:write("\r\n") -- BBS location cf:write("\r\n") -- BBS phone number @@ -96,23 +102,31 @@ function qwk.write_control(cf, obbs, user_name) cf:write("HELLO\r\n") cf:write("NEWS\r\n") cf:write("GOODBYE\r\n") + + cf:close() end -function qwk.write_message (mf, obbs) +function qwk.write_message (target_dir, obbs) + local mf = assert(io.open(target_dir .. "/MESSAGES.DAT", "w")) + mf:write(space_pad("Produced by Qmail...Copyright (c) 1987 by Sparkware." .. " All Rights Reserved", 128)) for cnum,cname in ipairs(obbs.conferences) do - for mnum,msg_fname in ipairs(posix.dir(obbs.path .. "/conferences/" .. cname)) do + for mnum,msg_fname in ipairs(fs.dir(obbs.path .. "/conferences/" .. cname)) do msg = io.open(obbs.path .. "/conferences/" .. cname .. "/" .. msg_fname, "r"):read("*all") qwk.write_message_header_block(mf, obbs, cnum, mnum, msg) qwk.write_message_blocks(mf, obbs, msg) end end + + mf:close() end function qwk.write_message_header_block(mf, obbs, conf_num, msg) + + end function qwk.write_message_blocks(mf, obbs, msg) @@ -176,47 +190,42 @@ function cmd.pack () local user_name = arg[1] - local dir = fs.mktempdir() + local target_dir = fs.mktempdir() -- CONTROL.DAT - - local cf = assert(io.open(dir .. "/CONTROL.DAT", "w")) - qwk.write_control(cf, obbs, user_name) - cf:close() + qwk.write_control(target_dir, obbs, user_name) -- Copy BBS welcome, news and goodbye files if obbs.hello and fs.exists(obbs.hello) then - fs.copy(obbs.hello, dir .. "/HELLO") + fs.copy(obbs.hello, target_dir .. "/HELLO") else - fs.touch(dir .. "/HELLO") + fs.touch(target_dir .. "/HELLO") end if obbs.news and fs.exists(obbs.news) then - fs.copy(obbs.news, dir .. "/NEWS") + fs.copy(obbs.news, target_dir .. "/NEWS") else - fs.touch(dir .. "/NEWS") + fs.touch(target_dir .. "/NEWS") end if obbs.news and fs.exists(obbs.goodbye) then - fs.copy(obbs.goodbye, dir .. "/GOODBYE") + fs.copy(obbs.goodbye, target_dir .. "/GOODBYE") else - fs.touch(dir .. "/GOODBYE") + fs.touch(target_dir .. "/GOODBYE") end -- Pack messages - local mf = assert(io.open(dir .. "/MESSAGES.DAT", "w")) - qwk.write_message(mf, obbs) - mf:close() + qwk.write_message(target_dir, obbs) -- Create archive in outgoing os.execute("zip -rj " .. obbs.path .. "/outgoing/" .. obbs.bbsid .. - ".qwk " .. dir) + ".qwk " .. target_dir) - fs.rmdir(dir) + fs.rmdir(target_dir) end -- Main -- 2.20.1