sscani = {}
sscani.config = {}
sscani.config.show_splash = true
sscani.config.splash = string.format([[
@@@ sscani v%s - Interactive REPL for sscan
@@@ Authors: %s (%s)
@@@ License: %s
@@@
@@@ Enter any valid Lua, terminated by ';'.
@@@ Use help(); for help, exit(); to exit.
]],about.version, about.authors, about.repository, about.license_spdx)
sscani.config.prompt = 'sscan> '
sscani.config.prompt_continue = ' ... '
function sscani.prompt()
io.write(sscani.config.prompt)
io.flush()
end
function sscani.prompt_continue()
io.write(sscani.config.prompt_continue)
io.flush()
end
function sscani.splash()
io.write(sscani.config.splash)
io.flush()
end
function exit()
os.exit(0)
end
function sscani.try_get_home()
local home = os.getenv('HOME')
if home ~= nil then return home end
home = os.getenv('USERPROFILE')
return home
end
function sscani.check_for_rcfile()
local home = sscani.try_get_home()
if home == nil then return end
local test_paths = {
home .. '/.sscanirc',
home .. '/.sscanirc.lua',
home .. '/.sscani.rc.lua',
home .. '/.config/sscanirc',
home .. '/.config/sscanirc.lua',
home .. '/.config/sscani.rc.lua'
}
for _, path in ipairs(test_paths)
do
test = io.open(path, 'r')
if test ~= nil then
test:close()
dofile(path)
return
end
end
end
function sscani.mkrcfile()
local home = sscani.try_get_home()
if home == nil then
io.write('Could not generate rcfile: failed to find $HOME or $USERPROFILE.\n')
io.flush()
return
end
local rcfile = io.open(home .. '/.sscani.rc.lua', 'w')
if rcfile == nil then
io.write('Could not generate rcfile: access denied for ~/.sscani.rc.lua.\n')
io.flush()
return
end
rcfile:write(sscani.rc_default)
rcfile:close()
io.write('Wrote default rcfile to ~/.sscani.rc.lua\n')
io.write("See help('rcfile') for help on configuration.\n\n")
io.flush()
end
sscani.check_for_rcfile()
if sscani.config.show_splash then sscani.splash() end