Allow variable arguments to command functions
This commit is contained in:
parent
a396b9c39f
commit
000d45b9eb
10 changed files with 143 additions and 173 deletions
|
@ -103,7 +103,7 @@ namespace
|
|||
|
||||
avi_avsnoop* vid_dumper;
|
||||
|
||||
function_ptr_command avi_dump("dump-avi", "Start AVI capture",
|
||||
function_ptr_command<const std::string&> avi_dump("dump-avi", "Start AVI capture",
|
||||
"Syntax: dump-avi <level> <prefix>\nStart AVI capture to <prefix> using compression\n"
|
||||
"level <level> (0-18).\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
|
@ -141,11 +141,9 @@ namespace
|
|||
messages << "Dumping to " << prefix << " at level " << level2 << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command end_avi("end-avi", "End AVI capture",
|
||||
function_ptr_command<> end_avi("end-avi", "End AVI capture",
|
||||
"Syntax: end-avi\nEnd a AVI capture.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
if(!vid_dumper)
|
||||
throw std::runtime_error("No video dump in progress");
|
||||
try {
|
||||
|
|
52
command.cpp
52
command.cpp
|
@ -10,15 +10,13 @@ namespace
|
|||
std::set<std::string> command_stack;
|
||||
std::map<std::string, std::list<std::string>> aliases;
|
||||
|
||||
function_ptr_command run_script("run-script", "run file as a script",
|
||||
function_ptr_command<arg_filename> run_script("run-script", "run file as a script",
|
||||
"Syntax: run-script <file>\nRuns file <file> just as it would have been entered in the command line\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename needed");
|
||||
[](arg_filename filename) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::istream* o = NULL;
|
||||
try {
|
||||
o = &open_file_relative(args, "");
|
||||
messages << "Running '" << args << "'" << std::endl;
|
||||
o = &open_file_relative(filename, "");
|
||||
messages << "Running '" << std::string(filename) << "'" << std::endl;
|
||||
std::string line;
|
||||
while(std::getline(*o, line))
|
||||
command::invokeC(line);
|
||||
|
@ -30,17 +28,15 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
function_ptr_command show_aliases("show-aliases", "show aliases",
|
||||
function_ptr_command<> show_aliases("show-aliases", "show aliases",
|
||||
"Syntax: show-aliases\nShow expansions of all aliases\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
for(auto i = aliases.begin(); i != aliases.end(); i++)
|
||||
for(auto j = i->second.begin(); j != i->second.end(); j++)
|
||||
messages << "alias " << i->first << " " << *j << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command unalias_command("unalias-command", "unalias a command",
|
||||
function_ptr_command<const std::string&> unalias_command("unalias-command", "unalias a command",
|
||||
"Syntax: unalias-command <aliasname>\nClear expansion of alias <aliasname>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
tokensplitter t(args);
|
||||
|
@ -53,7 +49,7 @@ namespace
|
|||
messages << "Command '" << aliasname << "' unaliased" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command alias_command("alias-command", "alias a command",
|
||||
function_ptr_command<const std::string&> alias_command("alias-command", "alias a command",
|
||||
"Syntax: alias-command <aliasname> <command>\nAppend <command> to expansion of alias <aliasname>\n"
|
||||
"Valid alias names can't be empty nor start with '*' or '?'\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
|
@ -222,30 +218,26 @@ std::string tokensplitter::tail() throw(std::bad_alloc)
|
|||
return line.substr(position);
|
||||
}
|
||||
|
||||
function_ptr_command::function_ptr_command(const std::string& name, const std::string& _description,
|
||||
const std::string& _help, void (*_fn)(const std::string& arguments)) throw(std::bad_alloc)
|
||||
: command(name)
|
||||
{
|
||||
description = _description;
|
||||
help = _help;
|
||||
fn = _fn;
|
||||
}
|
||||
|
||||
void function_ptr_command::invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error)
|
||||
template<>
|
||||
void invoke_command_fn(void (*fn)(const std::string& args), const std::string& args)
|
||||
{
|
||||
fn(args);
|
||||
}
|
||||
|
||||
std::string function_ptr_command::get_short_help() throw(std::bad_alloc)
|
||||
template<>
|
||||
void invoke_command_fn(void (*fn)(), const std::string& args)
|
||||
{
|
||||
return description;
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
fn();
|
||||
}
|
||||
|
||||
std::string function_ptr_command::get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return help;
|
||||
}
|
||||
|
||||
function_ptr_command::~function_ptr_command() throw()
|
||||
template<>
|
||||
void invoke_command_fn(void (*fn)(struct arg_filename a), const std::string& args)
|
||||
{
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
arg_filename b;
|
||||
b.v = args;
|
||||
fn(b);
|
||||
}
|
||||
|
|
49
command.hpp
49
command.hpp
|
@ -94,9 +94,25 @@ private:
|
|||
size_t position;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mandatory filename
|
||||
*/
|
||||
struct arg_filename
|
||||
{
|
||||
std::string v;
|
||||
operator std::string() { return v; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Run command function.
|
||||
*/
|
||||
template<typename... args>
|
||||
void invoke_command_fn(void (*fn)(args... arguments), const std::string& a);
|
||||
|
||||
/**
|
||||
* Warp function pointer as command.
|
||||
*/
|
||||
template<typename... args>
|
||||
class function_ptr_command : public command
|
||||
{
|
||||
public:
|
||||
|
@ -108,34 +124,51 @@ public:
|
|||
* parameter help: Help for the command.
|
||||
* parameter fn: Function to call on command.
|
||||
*/
|
||||
function_ptr_command(const std::string& name, const std::string& description, const std::string& help,
|
||||
void (*fn)(const std::string& arguments)) throw(std::bad_alloc);
|
||||
function_ptr_command(const std::string& name, const std::string& _description, const std::string& _help,
|
||||
void (*_fn)(args... arguments)) throw(std::bad_alloc)
|
||||
: command(name)
|
||||
{
|
||||
description = _description;
|
||||
help = _help;
|
||||
fn = _fn;
|
||||
}
|
||||
/**
|
||||
* Destroy a commnad.
|
||||
*/
|
||||
~function_ptr_command() throw();
|
||||
~function_ptr_command() throw()
|
||||
{
|
||||
}
|
||||
/**
|
||||
* Invoke a command.
|
||||
*
|
||||
* parameter args: Arguments to function.
|
||||
* parameter a: Arguments to function.
|
||||
*/
|
||||
void invoke(const std::string& args) throw(std::bad_alloc, std::runtime_error);
|
||||
void invoke(const std::string& a) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
invoke_command_fn(fn, a);
|
||||
}
|
||||
/**
|
||||
* Get short description.
|
||||
*
|
||||
* returns: Description.
|
||||
* throw std::bad_alloc: Not enough memory.
|
||||
*/
|
||||
std::string get_short_help() throw(std::bad_alloc);
|
||||
std::string get_short_help() throw(std::bad_alloc)
|
||||
{
|
||||
return description;
|
||||
}
|
||||
/**
|
||||
* Get long help.
|
||||
*
|
||||
* returns: help.
|
||||
* throw std::bad_alloc: Not enough memory.
|
||||
*/
|
||||
std::string get_long_help() throw(std::bad_alloc);
|
||||
std::string get_long_help() throw(std::bad_alloc)
|
||||
{
|
||||
return help;
|
||||
}
|
||||
private:
|
||||
void (*fn)(const std::string& arguments);
|
||||
void (*fn)(args... arguments);
|
||||
std::string description;
|
||||
std::string help;
|
||||
};
|
||||
|
|
|
@ -92,12 +92,10 @@ namespace
|
|||
draw_special_screen(target, rl_corrupt);
|
||||
}
|
||||
|
||||
function_ptr_command take_screenshot("take-screenshot", "Takes a screenshot",
|
||||
function_ptr_command<arg_filename> take_screenshot("take-screenshot", "Takes a screenshot",
|
||||
"Syntax: take-screenshot <file>\nSaves screenshot to PNG file <file>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
framebuffer.save_png(args);
|
||||
[](arg_filename file) throw(std::bad_alloc, std::runtime_error) {
|
||||
framebuffer.save_png(file);
|
||||
messages << "Saved PNG screenshot" << std::endl;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_command bind_key("bind-key", "Bind a (pseudo-)key",
|
||||
function_ptr_command<const std::string&> bind_key("bind-key", "Bind a (pseudo-)key",
|
||||
"Syntax: bind-key [<mod>/<modmask>] <key> <command>\nBind command to specified key (with specified "
|
||||
" modifiers)\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
|
@ -34,7 +34,7 @@ namespace
|
|||
window::bind(mod, modmask, keyname, command);
|
||||
});
|
||||
|
||||
function_ptr_command unbind_key("unbind-key", "Unbind a (pseudo-)key",
|
||||
function_ptr_command<const std::string&> unbind_key("unbind-key", "Unbind a (pseudo-)key",
|
||||
"Syntax: unbind-key [<mod>/<modmask>] <key>\nUnbind specified key (with specified modifiers)\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::string mod, modmask, keyname, command;
|
||||
|
@ -56,11 +56,9 @@ namespace
|
|||
window::unbind(mod, modmask, keyname);
|
||||
});
|
||||
|
||||
function_ptr_command show_bindings("show-bindings", "Show active bindings",
|
||||
function_ptr_command<> show_bindings("show-bindings", "Show active bindings",
|
||||
"Syntax: show-bindings\nShow bindings that are currently active.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
window::dumpbindings();
|
||||
});
|
||||
}
|
||||
|
|
8
lua.cpp
8
lua.cpp
|
@ -366,7 +366,7 @@ void lua_callback_snoop_input(uint32_t port, uint32_t controller, uint32_t index
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_command evaluate_lua("evaluate-lua", "Evaluate expression in Lua VM",
|
||||
function_ptr_command<const std::string&> evaluate_lua("evaluate-lua", "Evaluate expression in Lua VM",
|
||||
"Syntax: evaluate-lua <expression>\nEvaluates <expression> in Lua VM.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
|
@ -374,12 +374,10 @@ namespace
|
|||
do_eval_lua(args);
|
||||
});
|
||||
|
||||
function_ptr_command run_lua("run-lua", "Run Lua script in Lua VM",
|
||||
function_ptr_command<arg_filename> run_lua("run-lua", "Run Lua script in Lua VM",
|
||||
"Syntax: run-lua <file>\nRuns <file> in Lua VM.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error)
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(args == "")
|
||||
throw std::runtime_error("Expected script to run");
|
||||
do_run_lua(args);
|
||||
});
|
||||
}
|
||||
|
|
111
mainloop.cpp
111
mainloop.cpp
|
@ -486,7 +486,7 @@ class my_interface : public SNES::Interface
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_command quit_emulator("quit-emulator", "Quit the emulator",
|
||||
function_ptr_command<const std::string&> quit_emulator("quit-emulator", "Quit the emulator",
|
||||
"Syntax: quit-emulator [/y]\nQuits emulator (/y => don't ask for confirmation).\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "/y" || window::modal_message("Really quit?", true)) {
|
||||
|
@ -496,11 +496,9 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
function_ptr_command pause_emulator("pause-emulator", "(Un)pause the emulator",
|
||||
function_ptr_command<> pause_emulator("pause-emulator", "(Un)pause the emulator",
|
||||
"Syntax: pause-emulator\n(Un)pauses the emulator.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
if(amode != ADVANCE_AUTO) {
|
||||
amode = ADVANCE_AUTO;
|
||||
window::paused(false);
|
||||
|
@ -514,11 +512,9 @@ namespace
|
|||
}
|
||||
});
|
||||
|
||||
function_ptr_command padvance_frame("+advance-frame", "Advance one frame",
|
||||
function_ptr_command<> padvance_frame("+advance-frame", "Advance one frame",
|
||||
"Syntax: +advance-frame\nAdvances the emulation by one frame.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
amode = ADVANCE_FRAME;
|
||||
cancel_advance = false;
|
||||
advanced_once = false;
|
||||
|
@ -526,21 +522,17 @@ namespace
|
|||
window::paused(false);
|
||||
});
|
||||
|
||||
function_ptr_command nadvance_frame("-advance-frame", "Advance one frame",
|
||||
function_ptr_command<> nadvance_frame("-advance-frame", "Advance one frame",
|
||||
"No help available\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
cancel_advance = true;
|
||||
window::cancel_wait();
|
||||
window::paused(false);
|
||||
});
|
||||
|
||||
function_ptr_command padvance_poll("+advance-poll", "Advance one subframe",
|
||||
function_ptr_command<> padvance_poll("+advance-poll", "Advance one subframe",
|
||||
"Syntax: +advance-poll\nAdvances the emulation by one subframe.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
amode = ADVANCE_SUBFRAME;
|
||||
cancel_advance = false;
|
||||
advanced_once = false;
|
||||
|
@ -548,103 +540,81 @@ namespace
|
|||
window::paused(false);
|
||||
});
|
||||
|
||||
function_ptr_command nadvance_poll("-advance-poll", "Advance one subframe",
|
||||
function_ptr_command<> nadvance_poll("-advance-poll", "Advance one subframe",
|
||||
"No help available\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
cancel_advance = true;
|
||||
window::cancel_wait();
|
||||
window::paused(false);
|
||||
});
|
||||
|
||||
function_ptr_command advance_skiplag("advance-skiplag", "Skip to next poll",
|
||||
function_ptr_command<> advance_skiplag("advance-skiplag", "Skip to next poll",
|
||||
"Syntax: advance-skiplag\nAdvances the emulation to the next poll.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
amode = ADVANCE_SKIPLAG;
|
||||
window::cancel_wait();
|
||||
window::paused(false);
|
||||
});
|
||||
|
||||
function_ptr_command reset_c("reset", "Reset the SNES",
|
||||
function_ptr_command<> reset_c("reset", "Reset the SNES",
|
||||
"Syntax: reset\nResets the SNES in beginning of the next frame.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
pending_reset_cycles = 0;
|
||||
});
|
||||
|
||||
function_ptr_command load_state_c("load-state", "Load savestate (R/W)",
|
||||
function_ptr_command<arg_filename> load_state_c("load-state", "Load savestate (R/W)",
|
||||
"Syntax: load-state <file>\nLoads SNES state from <file> in Read/Write mode\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error) {
|
||||
mark_pending_load(args, LOAD_STATE_RW);
|
||||
});
|
||||
|
||||
function_ptr_command load_readonly("load-readonly", "Load savestate (RO)",
|
||||
function_ptr_command<arg_filename> load_readonly("load-readonly", "Load savestate (RO)",
|
||||
"Syntax: load-readonly <file>\nLoads SNES state from <file> in read-only mode\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error) {
|
||||
mark_pending_load(args, LOAD_STATE_RO);
|
||||
});
|
||||
|
||||
function_ptr_command load_preserve("load-preserve", "Load savestate (preserve input)",
|
||||
function_ptr_command<arg_filename> load_preserve("load-preserve", "Load savestate (preserve input)",
|
||||
"Syntax: load-preserve <file>\nLoads SNES state from <file> preserving input\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error) {
|
||||
mark_pending_load(args, LOAD_STATE_PRESERVE);
|
||||
});
|
||||
|
||||
function_ptr_command load_movie_c("load-movie", "Load movie",
|
||||
function_ptr_command<arg_filename> load_movie_c("load-movie", "Load movie",
|
||||
"Syntax: load-movie <file>\nLoads SNES movie from <file>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error) {
|
||||
mark_pending_load(args, LOAD_STATE_MOVIE);
|
||||
});
|
||||
|
||||
|
||||
function_ptr_command save_state("save-state", "Save state",
|
||||
function_ptr_command<arg_filename> save_state("save-state", "Save state",
|
||||
"Syntax: save-state <file>\nSaves SNES state to <file>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error) {
|
||||
mark_pending_save(args, SAVE_STATE);
|
||||
});
|
||||
|
||||
function_ptr_command save_movie("save-movie", "Save movie",
|
||||
function_ptr_command<arg_filename> save_movie("save-movie", "Save movie",
|
||||
"Syntax: save-movie <file>\nSaves SNES movie to <file>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args == "")
|
||||
throw std::runtime_error("Filename required");
|
||||
[](arg_filename args) throw(std::bad_alloc, std::runtime_error) {
|
||||
mark_pending_save(args, SAVE_MOVIE);
|
||||
});
|
||||
|
||||
function_ptr_command set_rwmode("set-rwmode", "Switch to read/write mode",
|
||||
function_ptr_command<> set_rwmode("set-rwmode", "Switch to read/write mode",
|
||||
"Syntax: set-rwmode\nSwitches to read/write mode\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
movb.get_movie().readonly_mode(false);
|
||||
lua_callback_do_readwrite();
|
||||
update_movie_state();
|
||||
window::notify_screen_update();
|
||||
});
|
||||
|
||||
function_ptr_command repaint("repaint", "Redraw the screen",
|
||||
function_ptr_command<> repaint("repaint", "Redraw the screen",
|
||||
"Syntax: repaint\nRedraws the screen\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
redraw_framebuffer();
|
||||
});
|
||||
|
||||
function_ptr_command add_watch("add-watch", "Add a memory watch",
|
||||
function_ptr_command<const std::string&> add_watch("add-watch", "Add a memory watch",
|
||||
"Syntax: add-watch <name> <expression>\nAdds a new memory watch\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
tokensplitter t(args);
|
||||
|
@ -656,7 +626,7 @@ namespace
|
|||
update_movie_state();
|
||||
});
|
||||
|
||||
function_ptr_command remove_watch("remove-watch", "Remove a memory watch",
|
||||
function_ptr_command<const std::string&> remove_watch("remove-watch", "Remove a memory watch",
|
||||
"Syntax: remove-watch <name>\nRemoves a memory watch\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
tokensplitter t(args);
|
||||
|
@ -672,24 +642,25 @@ namespace
|
|||
update_movie_state();
|
||||
});
|
||||
|
||||
function_ptr_command test1("test-1", "no description available", "No help available\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
function_ptr_command<> test1("test-1", "no description available", "No help available\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
framebuffer = screen_nosignal;
|
||||
redraw_framebuffer();
|
||||
});
|
||||
|
||||
function_ptr_command test2("test-2", "no description available", "No help available\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
function_ptr_command<> test2("test-2", "no description available", "No help available\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
framebuffer = screen_corrupt;
|
||||
redraw_framebuffer();
|
||||
});
|
||||
|
||||
function_ptr_command test3("test-3", "no description available", "No help available\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
function_ptr_command<> test3("test-3", "no description available", "No help available\n",
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
while(1);
|
||||
});
|
||||
|
||||
function_ptr_command mouse_button_handler("mouse_button", "no description available", "No help available\n",
|
||||
function_ptr_command<const std::string&> mouse_button_handler("mouse_button", "no description available",
|
||||
"No help available\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
tokensplitter t(args);
|
||||
std::string x = t;
|
||||
|
|
|
@ -32,27 +32,23 @@ namespace
|
|||
numeric_setting savecompression("savecompression", 0, 9, 7);
|
||||
|
||||
|
||||
function_ptr_command get_gamename("get-gamename", "Get the game name",
|
||||
function_ptr_command<> get_gamename("get-gamename", "Get the game name",
|
||||
"Syntax: get-gamename\nPrints the game name\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
messages << "Game name is '" << our_movie.gamename << "'" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command set_gamename("set-gamename", "Set the game name",
|
||||
function_ptr_command<const std::string&> set_gamename("set-gamename", "Set the game name",
|
||||
"Syntax: set-gamename <name>\nSets the game name to <name>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
our_movie.gamename = args;
|
||||
messages << "Game name changed to '" << our_movie.gamename << "'" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command show_authors("show-authors", "Show the run authors",
|
||||
function_ptr_command<> show_authors("show-authors", "Show the run authors",
|
||||
"Syntax: show-authors\nShows the run authors\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error)
|
||||
[]() throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take parameters");
|
||||
size_t idx = 0;
|
||||
for(auto i = our_movie.authors.begin(); i != our_movie.authors.end(); i++) {
|
||||
messages << (idx++) << ": " << i->first << "|" << i->second << std::endl;
|
||||
|
@ -60,7 +56,7 @@ namespace
|
|||
messages << "End of authors list" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command add_author("add-author", "Add an author",
|
||||
function_ptr_command<const std::string&> add_author("add-author", "Add an author",
|
||||
"Syntax: add-author <fullname>\nSyntax: add-author |<nickname>\n"
|
||||
"Syntax: add-author <fullname>|<nickname>\nAdds a new author\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
|
@ -70,7 +66,7 @@ namespace
|
|||
messages << (our_movie.authors.size() - 1) << ": " << g.first << "|" << g.second << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command remove_author("remove-author", "Remove an author",
|
||||
function_ptr_command<const std::string&> remove_author("remove-author", "Remove an author",
|
||||
"Syntax: remove-author <id>\nRemoves author with ID <id>\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
tokensplitter t(args);
|
||||
|
@ -80,7 +76,7 @@ namespace
|
|||
our_movie.authors.erase(our_movie.authors.begin() + index);
|
||||
});
|
||||
|
||||
function_ptr_command edit_author("edit-author", "Edit an author",
|
||||
function_ptr_command<const std::string&> edit_author("edit-author", "Edit an author",
|
||||
"Syntax: edit-author <authorid> <fullname>\nSyntax: edit-author <authorid> |<nickname>\n"
|
||||
"Syntax: edit-author <authorid> <fullname>|<nickname>\nEdits author name\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
|
|
12
settings.cpp
12
settings.cpp
|
@ -10,7 +10,7 @@ namespace
|
|||
{
|
||||
std::map<std::string, setting*>* settings;
|
||||
|
||||
function_ptr_command set_setting("set-setting", "set a setting",
|
||||
function_ptr_command<const std::string&> set_setting("set-setting", "set a setting",
|
||||
"Syntax: set-setting <setting> [<value>]\nSet setting to a new value. Omit <value> to set to ''\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::string syntax = "Syntax: set-setting <setting> [<value>]";
|
||||
|
@ -24,7 +24,7 @@ namespace
|
|||
<< std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command unset_setting("unset-setting", "unset a setting",
|
||||
function_ptr_command<const std::string&> unset_setting("unset-setting", "unset a setting",
|
||||
"Syntax: unset-setting <setting>\nTry to unset a setting. Note that not all settings can be unset\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::string syntax = "Syntax: unset-setting <setting>";
|
||||
|
@ -36,7 +36,7 @@ namespace
|
|||
messages << "Setting '" << settingname << "' unset" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command get_command("get-setting", "get value of a setting",
|
||||
function_ptr_command<const std::string&> get_command("get-setting", "get value of a setting",
|
||||
"Syntax: get-setting <setting>\nShow value of setting\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
tokensplitter t(args);
|
||||
|
@ -50,11 +50,9 @@ namespace
|
|||
messages << "Setting '" << settingname << "' unset" << std::endl;
|
||||
});
|
||||
|
||||
function_ptr_command show_settings("show-settings", "Show values of all settings",
|
||||
function_ptr_command<> show_settings("show-settings", "Show values of all settings",
|
||||
"Syntax: show-settings\nShow value of all settings\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
setting::print_all();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1805,7 +1805,7 @@ void window::sound_enable(bool enable) throw()
|
|||
|
||||
namespace
|
||||
{
|
||||
function_ptr_command enable_sound("enable-sound", "Enable/Disable sound",
|
||||
function_ptr_command<const std::string&> enable_sound("enable-sound", "Enable/Disable sound",
|
||||
"Syntax: enable-sound <on/off>\nEnable or disable sound.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
std::string s = args;
|
||||
|
@ -1817,19 +1817,15 @@ namespace
|
|||
throw std::runtime_error("Bad sound setting");
|
||||
});
|
||||
|
||||
function_ptr_command identify_key("identify-key", "Identify a key",
|
||||
function_ptr_command<> identify_key("identify-key", "Identify a key",
|
||||
"Syntax: identify-key\nIdentifies a (pseudo-)key.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
identify();
|
||||
});
|
||||
|
||||
function_ptr_command scroll_up("scroll-up", "Scroll messages a page up",
|
||||
function_ptr_command<> scroll_up("scroll-up", "Scroll messages a page up",
|
||||
"Syntax: scroll-up\nScrolls message console backward one page.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
if(messagebuffer_first_show > maxmessages)
|
||||
messagebuffer_first_show -= maxmessages;
|
||||
else
|
||||
|
@ -1839,20 +1835,16 @@ namespace
|
|||
window::notify_screen_update();
|
||||
});
|
||||
|
||||
function_ptr_command scroll_fullup("scroll-fullup", "Scroll messages to beginning",
|
||||
function_ptr_command<> scroll_fullup("scroll-fullup", "Scroll messages to beginning",
|
||||
"Syntax: scroll-fullup\nScrolls message console to its beginning.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
messagebuffer_first_show = messagebuffer_first_seq;
|
||||
window::notify_screen_update();
|
||||
});
|
||||
|
||||
function_ptr_command scroll_fulldown("scroll-fulldown", "Scroll messages to end",
|
||||
function_ptr_command<> scroll_fulldown("scroll-fulldown", "Scroll messages to end",
|
||||
"Syntax: scroll-fulldown\nScrolls message console to its end.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
if(messagebuffer_next_seq < maxmessages)
|
||||
messagebuffer_first_show = 0;
|
||||
else
|
||||
|
@ -1860,11 +1852,9 @@ namespace
|
|||
window::notify_screen_update();
|
||||
});
|
||||
|
||||
function_ptr_command scrolldown("scroll-down", "Scroll messages a page down",
|
||||
function_ptr_command<> scrolldown("scroll-down", "Scroll messages a page down",
|
||||
"Syntax: scroll-up\nScrolls message console forward one page.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
messagebuffer_first_show += maxmessages;
|
||||
if(messagebuffer_next_seq < maxmessages)
|
||||
messagebuffer_first_show = 0;
|
||||
|
@ -1873,11 +1863,9 @@ namespace
|
|||
window::notify_screen_update();
|
||||
});
|
||||
|
||||
function_ptr_command toggle_console("toggle-console", "Toggle console between small and full window",
|
||||
function_ptr_command<> toggle_console("toggle-console", "Toggle console between small and full window",
|
||||
"Syntax: toggle-console\nToggles console between small and large.\n",
|
||||
[](const std::string& args) throw(std::bad_alloc, std::runtime_error) {
|
||||
if(args != "")
|
||||
throw std::runtime_error("This command does not take arguments");
|
||||
[]() throw(std::bad_alloc, std::runtime_error) {
|
||||
console_mode = !console_mode;
|
||||
if(console_mode)
|
||||
maxmessages = hwsurf ? (hwsurf->h - 38) / 16 : 36;
|
||||
|
|
Loading…
Add table
Reference in a new issue