summaryrefslogtreecommitdiffstatshomepage
path: root/plugins
diff options
context:
space:
mode:
author cracyc <cracyc@users.noreply.github.com>2018-01-08 22:03:54 -0600
committer cracyc <cracyc@users.noreply.github.com>2018-01-08 22:03:54 -0600
commitc5ee1d8a45088a34853d9883bc0b54e66e2041ac (patch)
tree03eb35f3467516511a71575a043519d7822a4c2d /plugins
parentdbaa54425107baa28982c978bc267aaae00acfe6 (diff)
plugins/portname: add #import and #set tags (nw)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/portname/init.lua74
1 files changed, 53 insertions, 21 deletions
diff --git a/plugins/portname/init.lua b/plugins/portname/init.lua
index bcd38e43809..3fef9045d4f 100644
--- a/plugins/portname/init.lua
+++ b/plugins/portname/init.lua
@@ -2,6 +2,8 @@
-- copyright-holders:Carl
-- use plugin options to save the input port list to a gettext formatted file
-- the file is saved in the ctrlrpath dir
+-- use #import <filename.po> to load names from a different file
+-- use #set <set1>,<set2>,... to override names for a child set, common names should be listed at the top before any #set tags
local exports = {}
exports.name = "portname"
exports.version = "0.0.1"
@@ -18,39 +20,69 @@ function portname.startplugin()
if emu.softname() ~= "" and not nosoft then
filename = emu.romname() .. "_" .. emu.softname() .. ".po"
else
- filename = emu.romname() .. ".po"
+ filename = emu.romname() .. ".po"
end
return filename
end
emu.register_start(function()
+ local reclevel = 0
+ local function parse_names(names)
+ local orig, rep
+ local setfound = true
+ reclevel = reclevel + 1
+ if reclevel == 3 then
+ emu.print_verbose("portname: too many import levels\n")
+ return
+ end
+ names:gsub("[^\n\r]*", function (line)
+ if line:find("^#import") then
+ local impfile = emu.file(ctrlrpath .. "/portname", "r")
+ local ret = impfile:open(line:match("^#import (.*)"))
+ if ret then
+ emu.print_verbose("portname: import file not found\n")
+ else
+ parse_names(impfile:read(impfile:size()))
+ end
+ elseif line:find("^#set") then
+ local sets = line:match("^#set (.*)")
+ setfound = false
+ for s in sets:gmatch("[^,]*") do
+ if s == emu.romname() then
+ setfound = true
+ break
+ end
+ end
+ elseif line:find("^msgid") then
+ orig = line:match("^msgid \"(.+)\"")
+ elseif line:find("^msgstr") then
+ rep = line:match("^msgstr \"(.+)\"")
+ if rep and rep ~= "" and setfound then
+ rep = rep:gsub("\\(.)", "%1")
+ orig = orig:gsub("\\(.)", "%1")
+ for pname, port in pairs(manager:machine():ioport().ports) do
+ if port.fields[orig] then
+ port.fields[orig].live.name = rep
+ end
+ end
+ end
+ end
+ return line
+ end)
+ reclevel = reclevel - 1
+ end
local file = emu.file(ctrlrpath .. "/portname", "r")
local ret = file:open(get_filename())
if ret then
ret = file:open(get_filename(true))
if ret then
- return
- end
- end
- local names = file:read(file:size())
- local orig, rep
- names:gsub("[^\n\r]*", function (line)
- if line:find("^msgid") then
- orig = line:match("^msgid \"(.+)\"")
- elseif line:find("^msgstr") then
- rep = line:match("^msgstr \"(.+)\"")
- if rep and rep ~= "" then
- rep = rep:gsub("\\(.)", "%1")
- orig = orig:gsub("\\(.)", "%1")
- for pname, port in pairs(manager:machine():ioport().ports) do
- if port.fields[orig] then
- port.fields[orig].live.name = rep
- end
- end
+ ret = file:open(manager:machine():system().parent .. ".po")
+ if ret then
+ return
end
end
- return line
- end)
+ end
+ parse_names(file:read(file:size()))
end)
local function menu_populate()