summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2019-11-28 22:35:36 -0600
committer cracyc <cracyc@users.noreply.github.com>2019-11-28 22:35:36 -0600
commit8dbea98e20bf2d26810784b840174fcad8db7b7e (patch)
treeb74381757fd84abb2fa183112b47ff8a45c8e6e7 /plugins
parentb4bc924018e7120e495fb5a03af85bd9de7f978a (diff)
plugins/data: loading fixes (nw)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/data/data_command.lua2
-rw-r--r--plugins/data/data_marp.lua4
-rw-r--r--plugins/data/load_dat.lua90
3 files changed, 48 insertions, 48 deletions
diff --git a/plugins/data/data_command.lua b/plugins/data/data_command.lua
index e85533d152c..119374544b1 100644
--- a/plugins/data/data_command.lua
+++ b/plugins/data/data_command.lua
@@ -3,7 +3,7 @@ local info, ver
local datread = require("data/load_dat")
do
local convert = require("data/button_char")
- datread, ver = datread.open("command.dat", "# Command List%-.+hand", convert)
+ datread, ver = datread.open("command.dat", "# Version:", convert)
end
function dat.check(set, softlist)
diff --git a/plugins/data/data_marp.lua b/plugins/data/data_marp.lua
index ed077a8c5bd..40db2daf366 100644
--- a/plugins/data/data_marp.lua
+++ b/plugins/data/data_marp.lua
@@ -36,8 +36,6 @@ local function init()
romset VARCHAR NOT NULL,
data CLOB NOT NULL)]])
db.check("creating marp table")
- db.exec("CREATE INDEX \"romset_" .. file .. "\" ON \"" .. file .. "_idx\"(romset)")
- db.check("creating marp index")
end
for line in fh:lines() do
@@ -61,8 +59,6 @@ local function init()
if dbver then
db.exec("DELETE FROM \"" .. file .. "\"")
db.check("deleting marp")
- db.exec("DELETE FROM \"" .. file .. "_idx\"")
- db.check("deleting marp index")
stmt = db.prepare("UPDATE version SET version = ? WHERE datfile = ?")
db.check("updating marp version")
else
diff --git a/plugins/data/load_dat.lua b/plugins/data/load_dat.lua
index ce4ffed5c80..f71c260de9d 100644
--- a/plugins/data/load_dat.lua
+++ b/plugins/data/load_dat.lua
@@ -92,7 +92,6 @@ function datfile.open(file, vertag, fixupcb)
stmt:finalize()
do
- local inblock = false
fh:seek("set")
local buffer = fh:read("a")
db.exec("BEGIN TRANSACTION")
@@ -100,61 +99,66 @@ function datfile.open(file, vertag, fixupcb)
local function gmatchpos()
local pos = 1
local function iter()
- local tag1, tag2, data, start, inblock = false
+ local tags, data
while not data do
- local spos, epos, match = buffer:find("\n($[^\n\r]*)", pos)
+ local npos
+ local spos, epos = buffer:find("[\n\r]$[^=]*=[^\n\r]*", pos)
if not spos then
return nil
end
- if match ~= "$end" and not inblock then
- if not tag1 then
- tag1 = match
- else
- tag2 = match
- start = epos + 1
- inblock = true
- end
- elseif inblock == true then
- data = buffer:sub(start, spos)
- inblock = false
+ npos, epos = buffer:find("[\n\r]$[%w]*[\n\r]+", epos)
+ if not npos then
+ return nil
end
- pos = epos
+ tags = buffer:sub(spos, epos)
+ spos, npos = buffer:find("[\n\r]$end[\n\r]", epos)
+ if not spos then
+ return nil
+ end
+ data = buffer:sub(epos, spos)
+ pos = npos
end
- return tag1, tag2, data
+ return tags, data
end
return iter
end
- for info1, info2, data in gmatchpos() do
- local tag, set = info1:match("^%$([^%s=]+)=?([^%s]*)")
- if set and set ~= "" then
- local tags = {}
- local sets = {}
- tag:gsub("([^,]+)", function(s) tags[#tags + 1] = s end)
- set:gsub("([^,]+)", function(s) sets[#sets + 1] = s end)
- if #tags > 0 and #sets > 0 then
- local tag1 = info2:match("^$([^%s]*)")
- data = data:gsub("\r", "") -- strip crs
+ for info, data in gmatchpos() do
+ local tags = {}
+ local infotype
+ for s in info:gmatch("[\n\r]$([^\n\r]*)") do
+ if s:find("=", 1, true) then
+ local m1, m2 = s:match("([^=]*)=(.*)")
+ for tag in m1:gmatch("[^,]+") do
+ for set in m2:gmatch("[^,]+") do
+ tags[#tags + 1] = { tag = tag, set = set }
+ end
+ end
+ else
+ infotype = s
+ break
+ end
+ end
+
+ if #tags > 0 and infotype then
+ data = data:gsub("\r", "") -- strip crs
+ if fixupcb then
+ data = fixupcb(data)
+ end
+ stmt = db.prepare("INSERT INTO \"" .. file .. "\" VALUES (?)")
+ db.check("inserting values")
+ stmt:bind_values(data)
+ stmt:step()
+ local row = stmt:last_insert_rowid()
+ stmt:finalize()
+ for num, tag in pairs(tags) do
if fixupcb then
- data = fixupcb(data)
+ fixupcb(data)
end
- stmt = db.prepare("INSERT INTO \"" .. file .. "\" VALUES (?)")
- db.check("inserting values")
- stmt:bind_values(data)
+ stmt = db.prepare("INSERT INTO \"" .. file .. "_idx\" VALUES (?, ?, ?, ?)")
+ db.check("inserting into index")
+ stmt:bind_values(infotype, tag.tag, tag.set, row)
stmt:step()
- local row = stmt:last_insert_rowid()
stmt:finalize()
- for num1, tag2 in pairs(tags) do
- for num2, set in pairs(sets) do
- if fixupcb then
- fixupcb(data)
- end
- stmt = db.prepare("INSERT INTO \"" .. file .. "_idx\" VALUES (?, ?, ?, ?)")
- db.check("inserting into index")
- stmt:bind_values(tag1, tag2, set, row)
- stmt:step()
- stmt:finalize()
- end
- end
end
end
end