From e7f3ce58a95b7b538483462d866cacdbd11a77c6 Mon Sep 17 00:00:00 2001 From: cracyc Date: Sun, 24 Oct 2021 20:46:57 -0500 Subject: plugin/data: handle multiple blocks in dat --- plugins/data/data_command.lua | 3 +-- plugins/data/load_dat.lua | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/data/data_command.lua b/plugins/data/data_command.lua index f32544c5063..de2483bcdc9 100644 --- a/plugins/data/data_command.lua +++ b/plugins/data/data_command.lua @@ -7,7 +7,7 @@ do if not buttonchar then buttonchar = require("data/button_char") end return buttonchar(str) end - datread, ver = datread.open("command.dat", "# Version:", convert) + datread, ver = datread.open("command.dat", "#[^V]*Ver[^.:]*[.:]", convert) end function dat.check(set, softlist) @@ -19,7 +19,6 @@ function dat.check(set, softlist) if not status or not info then return nil end - info = "#jf\n" .. info return _("Command") end diff --git a/plugins/data/load_dat.lua b/plugins/data/load_dat.lua index ed13fbefdcc..1b067aef1eb 100644 --- a/plugins/data/load_dat.lua +++ b/plugins/data/load_dat.lua @@ -106,21 +106,21 @@ function datfile.open(file, vertag, fixupcb) local tags, data while not data do local npos - local spos, epos = buffer:find("[\n\r]$[^=]*=[^\n\r]*", pos) + local spos, epos = buffer:find("[\n\r]$[^=\n\r]*=[^\n\r]*", pos) if not spos then return nil end - npos, epos = buffer:find("[\n\r]$%w*[\n\r]+", epos) + npos, epos = buffer:find("[\n\r]$%w+%s*[\n\r]+", epos) if not npos then return nil end tags = buffer:sub(spos, epos) - spos, npos = buffer:find("[\n\r]$end[\n\r]", epos) + spos, npos = buffer:find("[\n\r]$[^=\n\r]*=[^\n\r]*", epos) if not spos then return nil end data = buffer:sub(epos, spos) - pos = npos + pos = spos end return tags, data end @@ -129,6 +129,8 @@ function datfile.open(file, vertag, fixupcb) for info, data in gmatchpos() do local tags = {} local infotype + info = info:gsub(utf8.char(0xfeff), "") --remove boms + data = data:gsub(utf8.char(0xfeff), "") for s in info:gmatch("[\n\r]$([^\n\r]*)") do if s:find("=", 1, true) then local m1, m2 = s:match("([^=]*)=(.*)") @@ -142,7 +144,11 @@ function datfile.open(file, vertag, fixupcb) break end end - + + data = data:gsub("[\n\r]$end%s*[\n\r]$%w+%s*[\n\r]", "\n") + data = data:gsub("[\n\r]$end%s*[\n\r].-[\n\r]$%w+%s*[\n\r]", "\n") + data = data:gsub("[\n\r]$end%s*[\n\r].*", "") + if #tags > 0 and infotype then data = data:gsub("\r", "") -- strip crs if fixupcb then -- cgit v1.2.3