plugin/data: handle multiple blocks in dat

This commit is contained in:
cracyc 2021-10-24 20:46:57 -05:00 committed by Vas Crabb
parent fc87679998
commit f16565a556
2 changed files with 12 additions and 7 deletions

View file

@ -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

View file

@ -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