]> git.tdb.fi Git - gldbg.git/commitdiff
Support command aliases
authorMikko Rasa <tdb@tdb.fi>
Wed, 24 Mar 2010 06:17:40 +0000 (06:17 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 24 Mar 2010 06:17:40 +0000 (06:17 +0000)
Add quit command as an alias for exit

source/commandinterpreter.cpp
source/commandinterpreter.h

index c684979bae2061b49f9fddd06a8cead8c381e9d6..d02a0b49901d55ac396175958b53bc796ecf0013 100644 (file)
@@ -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<string, Command>::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<string, Command>::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)
 { }
index 852ba65781241a3e12847ec4dc70b37ec067da2d..537245fb53c1a0f38bea5b0a652f490e97fa64cf 100644 (file)
@@ -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 &);
        };