summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-05-20 20:56:05 +0000
committerTed Trask <ttrask01@yahoo.com>2008-05-20 20:56:05 +0000
commit9396b4a55193e8d95261d438b399c57213dafd4a (patch)
treee23b81c2e9a780720da62a2647cea1416c56eeba
parentb99d78fdfcda5ebdc8a19876c910cc44f62c7a81 (diff)
downloadacf-core-9396b4a55193e8d95261d438b399c57213dafd4a.tar.bz2
acf-core-9396b4a55193e8d95261d438b399c57213dafd4a.tar.xz
Continuing to work on openssl. Not done yet.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1127 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--lib/getopts.lua25
1 files changed, 20 insertions, 5 deletions
diff --git a/lib/getopts.lua b/lib/getopts.lua
index ee6a3c8..874d70d 100644
--- a/lib/getopts.lua
+++ b/lib/getopts.lua
@@ -77,10 +77,17 @@ end
-- If the search_name is not found, we'll add it at the end of the section
function setoptsinfile (file, search_section, search_name, value, to_table, optionvalue)
if not file or file == "" or not search_name or search_name == "" or (to_table == true and not value) then
- return false, nil, "Invalid input for getopts.setoptsinfile()"
+ return false, nil, "Invalid input for getopts.setoptsinfile()", file
end
search_section = search_section or ""
- local conf_file = fs.read_file_as_array ( file )
+ local conf_file = {}
+ if (fs.is_file(file)) then
+ conf_file = fs.read_file_as_array ( file )
+ else
+ for line in string.gmatch(file, "([^\n]*)\n") do
+ conf_file[#conf_file + 1] = line
+ end
+ end
local new_conf_file = {}
local section = ""
local done = false
@@ -130,8 +137,13 @@ function setoptsinfile (file, search_section, search_name, value, to_table, opti
new_conf_file[#new_conf_file + 1] = create_entry(search_name, value, to_table, optionvalue, nil)
end
- fs.write_file(file, table.concat(new_conf_file, '\n'))
- return true, "File '" .. file .. "' has been modified!", nil
+ if (fs.is_file(file)) then
+ fs.write_file(file, table.concat(new_conf_file, '\n'))
+ else
+ file = table.concat(new_conf_file, '\n')
+ end
+
+ return true, "File has been modified!", nil, file
end
-- Parse file for name=value pairs, returned in a table
@@ -140,12 +152,15 @@ end
-- If to_table is true, attempt to convert value string to array of options
-- If filter is defined (and table is true), only list option matching filter
function getoptsfromfile (file, search_section, search_name, to_table, filter)
+ if not file or file == "" then
+ return nil
+ end
local opts = nil
local conf_file = {}
if (fs.is_file(file)) then
conf_file = fs.read_file_as_array ( file )
else
- for line in string.gmatch(file, "(.*)\n") do
+ for line in string.gmatch(file, "([^\n]*)\n") do
conf_file[#conf_file + 1] = line
end
end