summaryrefslogtreecommitdiffstats
path: root/lib/format.lua
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2009-07-02 15:04:52 +0000
committerTed Trask <ttrask01@yahoo.com>2009-07-02 15:04:52 +0000
commitd03e958cfe2632296b04f1af7b0eaaa85a5385de (patch)
treed4cbac2623371c2774f19c89c5aafaeeb93f854a /lib/format.lua
parentb53f2922633b0fc3999ac7639156ef9dac738fa8 (diff)
downloadacf-core-d03e958cfe2632296b04f1af7b0eaaa85a5385de.tar.bz2
acf-core-d03e958cfe2632296b04f1af7b0eaaa85a5385de.tar.xz
Added format.get_ini_entry to evaluate ini file entry value.
Diffstat (limited to 'lib/format.lua')
-rw-r--r--lib/format.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/format.lua b/lib/format.lua
index 63b8fec..0076fdf 100644
--- a/lib/format.lua
+++ b/lib/format.lua
@@ -483,3 +483,30 @@ function set_ini_section (file, search_section, section_content)
return file, true
end
+
+-- Find the value of an entry allowing for parent section and $variables
+-- the file parameter can be a string or structure returned by parse_ini_file
+-- beginning and ending quotes are removed
+-- returns value or "" if not found
+function get_ini_entry (file, section, value)
+ local opts = file
+ if not file or not value then
+ return nil
+ elseif type(file) == "string" then
+ opts = parse_ini_file(file)
+ end
+ section = section or ""
+ local result = opts[section][value]
+ if not result then
+ section = ""
+ result = opts[section][value] or ""
+ end
+ while string.find(result, "%$[%w_]+") do
+ local sub = string.match(result, "%$[%w_]+")
+ result = string.gsub(result, escapemagiccharacters(sub), get_ini_entry(opts, section, sub))
+ end
+ if string.find(result, '^"') and string.find(result, '"$') then
+ result = string.sub(result, 2, -2)
+ end
+ return result
+end