From: Mikko Rasa Date: Wed, 24 Mar 2010 06:17:40 +0000 (+0000) Subject: Support command aliases X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=64592975a49e2bd26a561f36425071427f37d5fb;p=gldbg.git Support command aliases Add quit command as an alias for exit --- diff --git a/source/commandinterpreter.cpp b/source/commandinterpreter.cpp index c684979..d02a0b4 100644 --- a/source/commandinterpreter.cpp +++ b/source/commandinterpreter.cpp @@ -31,6 +31,7 @@ CommandInterpreter::CommandInterpreter(GlDbg &d): " Gives detailed information on a command\n"); commands["exit"] = Command(&CommandInterpreter::cmd_exit, "Ends the debugging session"); + commands["quit"] = Command(&commands["exit"]); commands["run"] = Command(&CommandInterpreter::cmd_run, "Starts the program"); @@ -49,7 +50,7 @@ CommandInterpreter::CommandInterpreter(GlDbg &d): commands["trace"] = Command(&CommandInterpreter::cmd_trace, "Traces GL function calls", "trace\n" - " Send trace output to stdout.\n" + " Send trace output to stdout.\n\n" "trace FILE\n" " Send trace output to FILE (- for stdout).\n\n" "trace {off|on}\n" @@ -110,16 +111,22 @@ void CommandInterpreter::cmd_help(const string &args) if(args.empty()) { for(map::const_iterator i=commands.begin(); i!=commands.end(); ++i) - IO::print("%-10s : %s\n", i->first, i->second.description); + if(!i->second.alias_for) + IO::print("%-10s : %s\n", i->first, i->second.description); } else { map::const_iterator i = commands.find(args); if(i==commands.end()) throw KeyError("Unknown command", args); - IO::print("%s : %s\n", i->first, i->second.description); + + const Command *cmd = &i->second; + while(cmd->alias_for) + cmd = cmd->alias_for; + + IO::print("%s : %s\n", i->first, cmd->description); if(!i->second.help.empty()) - IO::print("\n%s", i->second.help); + IO::print("\n%s", cmd->help); } } @@ -309,16 +316,24 @@ void CommandInterpreter::cmd_buffer(const string &args) CommandInterpreter::Command::Command(): - func(0) + func(0), + alias_for(0) +{ } + +CommandInterpreter::Command::Command(Command *cmd): + func(cmd->func), + alias_for(cmd) { } CommandInterpreter::Command::Command(Func f, const string &d): func(f), - description(d) + description(d), + alias_for(0) { } CommandInterpreter::Command::Command(Func f, const string &d, const string &h): func(f), description(d), - help(h) + help(h), + alias_for(0) { } diff --git a/source/commandinterpreter.h b/source/commandinterpreter.h index 852ba65..537245f 100644 --- a/source/commandinterpreter.h +++ b/source/commandinterpreter.h @@ -23,8 +23,10 @@ private: Func func; std::string description; std::string help; + Command *alias_for; Command(); + Command(Command *); Command(Func, const std::string &); Command(Func, const std::string &, const std::string &); };