|
|
@ -318,6 +318,7 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
-- scan for scripts and add their help to the db
|
|
|
|
-- scan for scripts and add their help to the db
|
|
|
|
local function scan_scripts(old_db, db)
|
|
|
|
local function scan_scripts(old_db, db)
|
|
|
|
|
|
|
|
local entry_types = {[ENTRY_TYPES.COMMAND]=true}
|
|
|
|
for _,script_path in ipairs(dfhack.internal.getScriptPaths()) do
|
|
|
|
for _,script_path in ipairs(dfhack.internal.getScriptPaths()) do
|
|
|
|
local files = dfhack.filesystem.listdir_recursive(
|
|
|
|
local files = dfhack.filesystem.listdir_recursive(
|
|
|
|
script_path, nil, false)
|
|
|
|
script_path, nil, false)
|
|
|
@ -330,12 +331,13 @@ local function scan_scripts(old_db, db)
|
|
|
|
goto continue
|
|
|
|
goto continue
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local dot_index = f.path:find('%.[^.]*$')
|
|
|
|
local dot_index = f.path:find('%.[^.]*$')
|
|
|
|
|
|
|
|
local entry_name = f.path:sub(1, dot_index - 1)
|
|
|
|
local script_source = script_path .. '/' .. f.path
|
|
|
|
local script_source = script_path .. '/' .. f.path
|
|
|
|
update_db(old_db, db,
|
|
|
|
update_db(old_db, db,
|
|
|
|
has_rendered_help(f.path) and
|
|
|
|
has_rendered_help(entry_name) and
|
|
|
|
HELP_SOURCES.RENDERED or HELP_SOURCES.SCRIPT,
|
|
|
|
HELP_SOURCES.RENDERED or HELP_SOURCES.SCRIPT,
|
|
|
|
f.path:sub(1, dot_index - 1),
|
|
|
|
entry_name,
|
|
|
|
{script_source=script_source})
|
|
|
|
{entry_types=entry_types, script_source=script_source})
|
|
|
|
::continue::
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
end
|
|
|
|
::skip_path::
|
|
|
|
::skip_path::
|
|
|
@ -388,6 +390,33 @@ end
|
|
|
|
-- get API
|
|
|
|
-- get API
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- converts strings into single-element lists containing that string
|
|
|
|
|
|
|
|
local function normalize_string_list(l)
|
|
|
|
|
|
|
|
if not l or #l == 0 then return nil end
|
|
|
|
|
|
|
|
if type(l) == 'string' then
|
|
|
|
|
|
|
|
return {l}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return l
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function has_keys(str, dict)
|
|
|
|
|
|
|
|
if not str or #str == 0 then
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
ensure_db()
|
|
|
|
|
|
|
|
for _,s in ipairs(normalize_string_list(str)) do
|
|
|
|
|
|
|
|
if not dict[s] then
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- returns whether the given string (or list of strings) is an entry in the db
|
|
|
|
|
|
|
|
function is_entry(str)
|
|
|
|
|
|
|
|
return has_keys(str, db)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function get_db_property(entry_name, property)
|
|
|
|
local function get_db_property(entry_name, property)
|
|
|
|
ensure_db()
|
|
|
|
ensure_db()
|
|
|
|
if not db[entry_name] then
|
|
|
|
if not db[entry_name] then
|
|
|
@ -420,19 +449,9 @@ function get_entry_tags(entry)
|
|
|
|
return set_to_sorted_list(get_db_property(entry, 'tags'))
|
|
|
|
return set_to_sorted_list(get_db_property(entry, 'tags'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- returns whether the given string matches a tag name
|
|
|
|
-- returns whether the given string (or list of strings) matches a tag name
|
|
|
|
function is_tag(str)
|
|
|
|
function is_tag(str)
|
|
|
|
if not str or #str == 0 then
|
|
|
|
return has_keys(str, tag_index)
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
ensure_db()
|
|
|
|
|
|
|
|
if type(str) == "string" then str = {str} end
|
|
|
|
|
|
|
|
for _,s in ipairs(str) do
|
|
|
|
|
|
|
|
if not tag_index[s] then
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- returns the defined tags in alphabetical order
|
|
|
|
-- returns the defined tags in alphabetical order
|
|
|
@ -524,15 +543,6 @@ local function matches(entry_name, filter)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
-- converts strings into single-element lists containing that string
|
|
|
|
|
|
|
|
local function normalize_string_list(l)
|
|
|
|
|
|
|
|
if not l or #l == 0 then return nil end
|
|
|
|
|
|
|
|
if type(l) == 'string' then
|
|
|
|
|
|
|
|
return {l}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
return l
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- normalizes the lists in the filter and returns nil if no filter elements are
|
|
|
|
-- normalizes the lists in the filter and returns nil if no filter elements are
|
|
|
|
-- populated
|
|
|
|
-- populated
|
|
|
|
local function normalize_filter(f)
|
|
|
|
local function normalize_filter(f)
|
|
|
|