mirror of
https://github.com/holub/mame
synced 2025-07-05 09:57:47 +03:00
plugins/data: small cleanups (nw)
This commit is contained in:
parent
35a1da30f1
commit
b32f90e5a9
@ -236,9 +236,9 @@ local convert_text =
|
|||||||
}
|
}
|
||||||
|
|
||||||
local function convert_char(str)
|
local function convert_char(str)
|
||||||
str = str:gsub("@([a-zA-Z%-]+)", function(s) if convert_text[s] then return utf8.char(convert_text[s] + 0xe000) end return s end)
|
str = str:gsub("@(%g+)", function(s) if convert_text[s] then return utf8.char(convert_text[s] + 0xe000) end return s end)
|
||||||
str = str:gsub("_(.)", function(s) if default_text[s] then return utf8.char(default_text[s] + 0xe000) end return s end)
|
str = str:gsub("_(%g)", function(s) if default_text[s] then return utf8.char(default_text[s] + 0xe000) end return s end)
|
||||||
str = str:gsub("%^(.)", function(s) if expand_text[s] then return utf8.char(expand_text[s] + 0xe000) end return s end)
|
str = str:gsub("%^(%g)", function(s) if expand_text[s] then return utf8.char(expand_text[s] + 0xe000) end return s end)
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2,7 +2,11 @@ local dat = {}
|
|||||||
local info, ver
|
local info, ver
|
||||||
local datread = require("data/load_dat")
|
local datread = require("data/load_dat")
|
||||||
do
|
do
|
||||||
local convert = require("data/button_char")
|
local buttonchar
|
||||||
|
local function convert(str)
|
||||||
|
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", "# Version:", convert)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
local datfile = {}
|
local datfile = {}
|
||||||
local db = require("data/database")
|
local db = require("data/database")
|
||||||
|
|
||||||
function datfile.open(file, vertag, fixupcb)
|
local function readret(file)
|
||||||
if not db then
|
|
||||||
return nil
|
|
||||||
end
|
|
||||||
local function read(tag1, tag2, set)
|
local function read(tag1, tag2, set)
|
||||||
local data
|
local data
|
||||||
local stmt = db.prepare("SELECT f.data FROM \"" .. file .. "_idx\" AS fi, \"" .. file .. [["
|
local stmt = db.prepare("SELECT f.data FROM \"" .. file .. "_idx\" AS fi, \"" .. file .. [["
|
||||||
AS f WHERE fi.type = ? AND fi.val = ? AND fi.romset = ? AND f.rowid = fi.data]])
|
AS f WHERE fi.type = ? AND fi.val = ? AND fi.romset = ? AND f.rowid = fi.data]])
|
||||||
db.check("reading " .. tag1 .. " - " .. tag2 .. " - " .. set)
|
db.check("reading " .. tag1 .. " - " .. tag2 .. " - " .. set)
|
||||||
stmt:bind_values(tag1, tag2, set)
|
stmt:bind_values(tag1, tag2, set)
|
||||||
if stmt:step() == db.ROW then
|
if stmt:step() == db.ROW then
|
||||||
@ -17,7 +14,14 @@ function datfile.open(file, vertag, fixupcb)
|
|||||||
stmt:finalize()
|
stmt:finalize()
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
return read
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function datfile.open(file, vertag, fixupcb)
|
||||||
|
if not db then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
local ver, dbver
|
local ver, dbver
|
||||||
local filepath
|
local filepath
|
||||||
local fh
|
local fh
|
||||||
@ -60,7 +64,7 @@ function datfile.open(file, vertag, fixupcb)
|
|||||||
|
|
||||||
if vertag then
|
if vertag then
|
||||||
for line in fh:lines() do
|
for line in fh:lines() do
|
||||||
local match = line:match(vertag .. "%s*([^%s]+)")
|
local match = line:match(vertag .. "%s*(%S+)")
|
||||||
if match then
|
if match then
|
||||||
ver = match
|
ver = match
|
||||||
break
|
break
|
||||||
@ -106,7 +110,7 @@ function datfile.open(file, vertag, fixupcb)
|
|||||||
if not spos then
|
if not spos then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
npos, epos = buffer:find("[\n\r]$[%w]*[\n\r]+", epos)
|
npos, epos = buffer:find("[\n\r]$%w*[\n\r]+", epos)
|
||||||
if not npos then
|
if not npos then
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -164,7 +168,7 @@ function datfile.open(file, vertag, fixupcb)
|
|||||||
end
|
end
|
||||||
fh:close()
|
fh:close()
|
||||||
|
|
||||||
return read, ver
|
return readret(file), ver
|
||||||
end
|
end
|
||||||
|
|
||||||
return datfile
|
return datfile
|
||||||
|
Loading…
Reference in New Issue
Block a user