1 -- $Id: ConfigFile.lua,v 1.1 2004/11/28 03:52:05 cpressey Exp $
11 ConfigVars.new = function()
15 cv.get = function(cv, name)
19 cv.set = function(cv, name, value)
24 -- Populate this set of variables from a file.
26 -- This isn't perfect. It doesn't handle variables
27 -- with embedded newlines, for example. It also
28 -- has to execute the script, which is undesirable.
30 cv.read = function(cv, filename, filetype)
31 local cmds = CmdChain.new()
35 "set | ${root}${SORT} >${tmp}env.before",
37 cmdline = ". ${filename} && set | ${root}${SORT} >${tmp}env.after",
43 cmdline = "${root}${COMM} -1 -3 ${tmp}env.before ${tmp}env.after",
46 "${root}${RM} -f ${tmp}env.before ${tmp}env.after"
49 if not cmds:execute() then
53 diff = cmds:get_output("comm")
55 local found, ends, k, v
58 string.find(diff[i], "^([^=]+)='(.*)'$")
63 string.find(diff[i], "^([^=]+)=(.*)$")
73 -- Write this set of configuration variable settings to a file.
74 cv.write = function(cv, filename, filetype)
76 local file = io.open(filename, "a")
87 file:write("# -- BEGIN BSD Installer automatically generated configuration -- #\n")
88 file:write("# -- Written on " .. os.date() .. " -- #\n")
91 file:write(k .. "='" .. v.. "'\n")
95 file:write("# -- END of BSD Installer " ..
96 "automatically generated configuration -- #\n")