From: plugd Date: Wed, 7 Aug 2024 23:44:45 +0000 (+0200) Subject: REP parsing tentatively working. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=cd992b9a299a64518389cb2353456c5ca55281ec;p=qwikboard.git REP parsing tentatively working. --- diff --git a/obbs b/obbs index b61219a..74734c9 100755 --- a/obbs +++ b/obbs @@ -100,11 +100,45 @@ end --- Message database parsing --- -local msgs = {} function Message(msg) msgs[msg.number] = msg end +local function get_next_msg_number(obbs, conf_num) + local msgnum_filename = obbs.path .. "/conferences/" .. + obbs.conferences[conf_num+1] .. ".next" + local mnf = assert(io.open(msgnum_filename, "r")) + local next_num = tonumber(mnf:read("*all")) + mnf:close() + return next_num +end + +local function set_next_msg_number(obbs, conf_num, next_num) + local msgnum_filename = obbs.path .. "/conferences/" .. + obbs.conferences[conf_num+1] .. ".next" + local mnf = assert(io.open(msgnum_filename, "w")) + mnf:write(next_num) + mnf:close() +end + +local function append_new_msg(obbs, conf_num, msg) + local cf = assert(io.open(obbs.path .. "/conferences/" .. + obbs.conferences[conf_num+1] .. ".msgs", "a+")) + cf:write("\n") + cf:write("Message{\n") + cf:write("\tnumber=" .. msg.number .. ",\n") + cf:write("\tto=" .. string.format("%q", msg.to) .. ",\n") + cf:write("\tfrom=" .. string.format("%q", msg.from) .. ",\n") + cf:write("\tsubject=" .. string.format("%q", msg.subject) .. ",\n") + cf:write("\treplyto=" .. msg.replyto .. ",\n") + cf:write("\tdate=" .. string.format("%q", msg.date) .. ",\n") + cf:write("\ttime=" .. string.format("%q", msg.time) .. ",\n") + cf:write("\ttext=" .. string.format("%q",msg.text) .. "\n") + cf:write("}\n") + cf:close() +end + + --- QWK formatting --- local qwk = {} @@ -187,7 +221,7 @@ function qwk.write_message_text(mf, obbs, msg) mf:write(string.rep("\0",padding)) end -function qwk.read_message(archive_dir, obbs, user_name) +function qwk.process_replies(archive_dir, obbs, user_name) local msg_filename = archive_dir .. "/" .. obbs.bbsid .. ".MSG" @@ -205,11 +239,11 @@ function qwk.read_message(archive_dir, obbs, user_name) end while mf:read(0) do - qwk.read_message_header(mf, obbs) + qwk.process_reply(mf, obbs) end end -function qwk.read_message_header(mf, obbs) +function qwk.process_reply(mf, obbs) local msg = {} mf:read(1) -- Message status (ignore for now) @@ -235,11 +269,18 @@ function qwk.read_message_header(mf, obbs) end msg.text = string.gsub(msg.text, "\xe3", "\n") - print("Message{") - for k,v in pairs(msg) do - print("\t" .. k .. "=\'" .. v .. "',") - end - print("}") + msg.number = get_next_msg_number(obbs, conf_num) + set_next_msg_number(obbs, conf_num, msg.number+1) + + append_new_msg(obbs, conf_num, msg) + + print("Processed message for conference " .. obbs.conferences[conf_num+1] .. ".") + + -- print("Message{") + -- for k,v in pairs(msg) do + -- print("\t" .. k .. "=\'" .. v .. "',") + -- end + -- print("}") end --- Commands --- @@ -359,7 +400,7 @@ function cmd.repin() fs.copy(rep_filename, work_dir .. "/repfile.rep") os.execute("unzip " .. work_dir .. "/repfile.rep -d " .. work_dir) - qwk.read_message(work_dir, obbs, user_name) + qwk.process_replies(work_dir, obbs, user_name) fs.rmdir(work_dir, true)