public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Alias commands extend ParameterizedCommand; test.
@ 2007-11-08 18:21 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2007-11-08 18:21 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  b5953ea2cdffa37921ca9f21e01c3c5c0e712261 (commit)
      from  c5892213ca4bee5d89b7c02ce0ba9ab19d3bb8ed (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit b5953ea2cdffa37921ca9f21e01c3c5c0e712261
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Nov 8 13:20:11 2007 -0500

    Alias commands extend ParameterizedCommand; test.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-08  Andrew Cagney  <cagney@redhat.com>
    
    	* AliasCommands.java: New.
    	* AliasCommand.java: Delete.
    	* UnaliasCommand.java: Delete.
    	* ParameterizedCommand.java: Fix off-by-one error.
    	* AliasCommand.java: Extend ParameterizedCommand.
    	* CLI.java: Update.
    	* TopLevelCommand.java: Update.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/hpd/AliasCommand.java         |   82 ------------
 frysk-core/frysk/hpd/AliasCommands.java        |  158 ++++++++++++++++++++++++
 frysk-core/frysk/hpd/CLI.java                  |    4 +-
 frysk-core/frysk/hpd/ChangeLog                 |   10 ++
 frysk-core/frysk/hpd/ParameterizedCommand.java |    2 +-
 frysk-core/frysk/hpd/TopLevelCommand.java      |    4 +-
 frysk-core/frysk/hpd/UnaliasCommand.java       |   72 -----------
 7 files changed, 173 insertions(+), 159 deletions(-)
 delete mode 100644 frysk-core/frysk/hpd/AliasCommand.java
 create mode 100644 frysk-core/frysk/hpd/AliasCommands.java
 delete mode 100644 frysk-core/frysk/hpd/UnaliasCommand.java

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/AliasCommand.java b/frysk-core/frysk/hpd/AliasCommand.java
deleted file mode 100644
index 43b0ddf..0000000
--- a/frysk-core/frysk/hpd/AliasCommand.java
+++ /dev/null
@@ -1,82 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2005, 2006, 2007 Red Hat Inc.
-//
-// FRYSK is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// FRYSK is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with FRYSK; if not, write to the Free Software Foundation,
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-// 
-// In addition, as a special exception, Red Hat, Inc. gives You the
-// additional right to link the code of FRYSK with code not covered
-// under the GNU General Public License ("Non-GPL Code") and to
-// distribute linked combinations including the two, subject to the
-// limitations in this paragraph. Non-GPL Code permitted under this
-// exception must only link to the code of FRYSK through those well
-// defined interfaces identified in the file named EXCEPTION found in
-// the source code files (the "Approved Interfaces"). The files of
-// Non-GPL Code may instantiate templates or use macros or inline
-// functions from the Approved Interfaces without causing the
-// resulting work to be covered by the GNU General Public
-// License. Only Red Hat, Inc. may make changes or additions to the
-// list of Approved Interfaces. You must obey the GNU General Public
-// License in all respects for all of the FRYSK code and other code
-// used in conjunction with FRYSK except the Non-GPL Code covered by
-// this exception. If you modify this file, you may extend this
-// exception to your version of the file, but you are not obligated to
-// do so. If you do not wish to provide this exception without
-// modification, you must delete this exception statement from your
-// version and license this file solely under the GPL without
-// exception.
-
-package frysk.hpd;
-
-class AliasCommand extends Command {
-
-    private static final String full = "The alias command associates a "
-	    + "user-defined name with a list of one or\n"
-	    + "more debugger commands. After definition, the user-defined "
-	    + "command can\n"
-	    + "be used in the same way as a debugger-defined command, "
-	    + "including as part\n"
-	    + "of the definition of new user-defined commands. ";
-
-    AliasCommand() {
-	super("alias", "Create or view user-defined commands",
-	      "alias command-name command body\nalias [command-name]", full);
-    }
-
-    public void interpret(CLI cli, Input cmd) {
-	if (cmd.size() == 1 && cmd.parameter(0).equals("-help")) {
-	    cli.printUsage(cmd);
-	    return;
-	}
-	if (cmd.size() <= 2) {
-	    if (cmd.size() == 2) {
-		cli.aliases.put((String) cmd.parameter(0),
-				(String) cmd.parameter(1));
-	    } else if (cmd.size() == 1) {
-		String temp = (String) cmd.parameter(0);
-		if (cli.aliases.containsKey(temp)) {
-		    cli.addMessage(temp + " = "
-			    + (String) (cli.aliases).get(temp),
-			    Message.TYPE_NORMAL);
-		} else
-		    cli.addMessage("Alias \"" + temp + "\" not defined.",
-			    Message.TYPE_ERROR);
-	    } else {
-		cli.addMessage(cli.aliases.toString(), Message.TYPE_NORMAL);
-	    }
-	} else {
-	    cli.printUsage(cmd);
-	}
-    }
-}
diff --git a/frysk-core/frysk/hpd/AliasCommands.java b/frysk-core/frysk/hpd/AliasCommands.java
new file mode 100644
index 0000000..aba2b26
--- /dev/null
+++ b/frysk-core/frysk/hpd/AliasCommands.java
@@ -0,0 +1,158 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2005, 2006, 2007 Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+package frysk.hpd;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Iterator;
+
+abstract class AliasCommands extends ParameterizedCommand {
+
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List completions) {
+	for (Iterator i = cli.aliases.keySet().iterator(); i.hasNext(); ) {
+	    String key = (String)i.next();
+	    if (key.startsWith(incomplete))
+		completions.add(key);
+	}
+	CompletionFactory.padSingleCandidate(completions);
+	return 0;
+    }
+
+    AliasCommands(String name, String description, String syntax,
+		  String full) {
+	super(name, description, syntax, full);
+    }
+
+    static class Alias extends AliasCommands {
+	Alias() {
+	    super("alias", "create or view user-defined commands",
+		  ("alias <command-name> <command-body> -- define an alias\n"
+		   + "alias [ <command-name> ] -- view an alias"),
+		  ("The alias command associates a "
+		   + "user-defined name with a list of one or more debugger"
+		   + " commands. After definition, the user-defined command"
+		   + " can be used in the same way as a debugger-defined"
+		   + " command, including as part of the definition of new"
+		   + " user-defined commands."));
+	}
+
+	void interpret(CLI cli, Input cmd, Object options) {
+	    switch (cmd.size()) {
+	    default:
+		throw new InvalidCommandException("Too many parameters");
+	    case 2:
+		cli.aliases.put(cmd.parameter(0), cmd.parameter(1));
+		break;
+	    case 1:
+		String temp = cmd.parameter(0);
+		if (!cli.aliases.containsKey(temp))
+		    throw new InvalidCommandException("Alias \"" + temp
+						      + "\" not defined.");
+		cli.outWriter.print(temp);
+		cli.outWriter.print(" = ");
+		cli.outWriter.print(cli.aliases.get(temp));
+		cli.outWriter.println();
+		break;
+	    case 0:
+		if (cli.aliases.size() == 0) {
+		    cli.outWriter.println("No aliases.");
+		} else {
+		    for (Iterator i = cli.aliases.entrySet().iterator();
+			 i.hasNext(); ) {
+			Map.Entry entry = (Map.Entry)i.next();
+			cli.outWriter.print(entry.getKey());
+			cli.outWriter.print(" = ");
+			cli.outWriter.print(entry.getValue());
+			cli.outWriter.println();
+		    }
+		}
+		break;
+	    }
+	}
+    }
+
+    static class Unalias extends AliasCommands {
+	private static class Options {
+	    boolean deleteAll;
+	}
+	Object options() {
+	    return new Options();
+	}
+	Unalias() {
+	    super("unalias", "Create or view user-define commands.",
+		  "unalias [ command-name | -all -",
+		  ("The unalias command removes the alias that was"
+		   + " previously established for the specified"
+		   + " user-defined command name."));
+	    add(new CommandOption("all", "delete all use-defined aliases") {
+		    void parse(String argument, Object options) {
+			((Options)options).deleteAll = true;
+		    }
+		});
+	}
+
+	public void interpret(CLI cli, Input input, Object o) {
+	    Options options = (Options)o;
+	    if (options.deleteAll) {
+		if (input.size() != 0)
+		    throw new InvalidCommandException("Extra parameters");
+		cli.outWriter.println("Removing all aliases.");
+		cli.aliases.clear();
+	    } else {
+		if (input.size() == 0)
+		    throw new InvalidCommandException("Missing alias");
+		for (int i = 0; i < input.size(); i++) {
+		    String temp = input.parameter(i);
+		    if (cli.aliases.containsKey(temp)) {
+			cli.outWriter.print("Removed alias \"");
+			cli.outWriter.print(temp);
+			cli.outWriter.println("\"");
+			cli.aliases.remove(temp);
+		    } else {
+			cli.outWriter.print("Alias \"");
+			cli.outWriter.print(temp);
+			cli.outWriter.println("\" not defined.");
+		    }
+		}
+	    }
+	}
+    }
+}
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index f72545e..70871e3 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -233,7 +233,8 @@ public class CLI {
         //otherwise build system will discard those classes. Therefore
         //CLI cannot be made to be a singleton.
         addHandler(new ActionsCommand());
-        addHandler(new AliasCommand());
+        addHandler(new AliasCommands.Alias());
+        addHandler(new AliasCommands.Unalias());
         addHandler(new AssignCommand());
         addHandler(new AttachCommand());
         addHandler(new BreakpointCommand());
@@ -259,7 +260,6 @@ public class CLI {
         addHandler(new SetCommand(dbgvars));
         addHandler(new StepCommand());
         addHandler(new StepInstructionCommand());
-        addHandler(new UnaliasCommand());
         addHandler(new UndefsetCommand());
         addHandler(new UnsetCommand(dbgvars));
         addHandler(new FrameCommands("up"));
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 2d36832..797684f 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,13 @@
+2007-11-08  Andrew Cagney  <cagney@redhat.com>
+
+	* AliasCommands.java: New.
+	* AliasCommand.java: Delete.
+	* UnaliasCommand.java: Delete.
+	* ParameterizedCommand.java: Fix off-by-one error.
+	* AliasCommand.java: Extend ParameterizedCommand.
+	* CLI.java: Update.
+	* TopLevelCommand.java: Update.
+
 2007-11-08  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* CoreCommand.java (interpret): Remove try{} for host building.
diff --git a/frysk-core/frysk/hpd/ParameterizedCommand.java b/frysk-core/frysk/hpd/ParameterizedCommand.java
index eb9db6f..be08aa0 100644
--- a/frysk-core/frysk/hpd/ParameterizedCommand.java
+++ b/frysk-core/frysk/hpd/ParameterizedCommand.java
@@ -177,7 +177,7 @@ abstract class ParameterizedCommand extends Command {
 	int start = input.token(0).start;
 	int pos = complete(cli, cli.getCommandPTSet(input),
 			   input.stringValue(), cursor - start, candidates);
-	if (pos > 0) {
+	if (pos >= 0) {
 	    return pos + start;
 	} else {
 	    return -1;
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index 82c1447..89c43e9 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -74,7 +74,8 @@ public class TopLevelCommand extends MultiLevelCommand {
 	      "<command> <parameter> ...",
 	      "a top level command");
         add(new ActionsCommand());
-        add(new AliasCommand());
+        add(new AliasCommands.Alias());
+        add(new AliasCommands.Unalias());
         add(new AssignCommand());
         add(new AttachCommand());
         add(new BreakpointCommand());
@@ -101,7 +102,6 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new SetCommand(dbgvars));
         add(new StepCommand());
         add(new StepInstructionCommand());
-        add(new UnaliasCommand());
         add(new UndefsetCommand());
         add(new UnsetCommand(dbgvars));
         add(new FrameCommands("up"));
diff --git a/frysk-core/frysk/hpd/UnaliasCommand.java b/frysk-core/frysk/hpd/UnaliasCommand.java
deleted file mode 100644
index a76783d..0000000
--- a/frysk-core/frysk/hpd/UnaliasCommand.java
+++ /dev/null
@@ -1,72 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2005, 2006, 2007 Red Hat Inc.
-//
-// FRYSK is free software; you can redistribute it and/or modify it
-// under the terms of the GNU General Public License as published by
-// the Free Software Foundation; version 2 of the License.
-//
-// FRYSK is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with FRYSK; if not, write to the Free Software Foundation,
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-// 
-// In addition, as a special exception, Red Hat, Inc. gives You the
-// additional right to link the code of FRYSK with code not covered
-// under the GNU General Public License ("Non-GPL Code") and to
-// distribute linked combinations including the two, subject to the
-// limitations in this paragraph. Non-GPL Code permitted under this
-// exception must only link to the code of FRYSK through those well
-// defined interfaces identified in the file named EXCEPTION found in
-// the source code files (the "Approved Interfaces"). The files of
-// Non-GPL Code may instantiate templates or use macros or inline
-// functions from the Approved Interfaces without causing the
-// resulting work to be covered by the GNU General Public
-// License. Only Red Hat, Inc. may make changes or additions to the
-// list of Approved Interfaces. You must obey the GNU General Public
-// License in all respects for all of the FRYSK code and other code
-// used in conjunction with FRYSK except the Non-GPL Code covered by
-// this exception. If you modify this file, you may extend this
-// exception to your version of the file, but you are not obligated to
-// do so. If you do not wish to provide this exception without
-// modification, you must delete this exception statement from your
-// version and license this file solely under the GPL without
-// exception.
-
-package frysk.hpd;
-
-class UnaliasCommand extends Command {
-    private static final String full = "The unalias command removes the alias "
-	    + "that was previously established\n"
-	    + "for the specified user-defined command name. Use of the "
-	    + "argument -all\n" + "deletes all user-defined commands at once.";
-
-    UnaliasCommand() {
-	super("unalias", "Create or view user-define commands.",
-	      "unalias { command-name | -all }", full);
-    }
-
-    public void interpret(CLI cli, Input cmd) {
-	if (cmd.size() == 1) {
-	    if ((cmd.parameter(0)).equals("-all")) {
-		cli.aliases.clear();
-		cli.addMessage("Removing all aliases.", Message.TYPE_VERBOSE);
-	    } else {
-		String temp = cmd.parameter(0);
-		if (cli.aliases.containsKey(temp)) {
-		    cli.aliases.remove(temp);
-		    cli.addMessage("Removed alias \"" + temp + "\"",
-			    Message.TYPE_VERBOSE);
-		} else
-		    cli.addMessage("Alias \"" + temp + "\" not defined.",
-			    Message.TYPE_ERROR);
-	    }
-	} else {
-	    cli.printUsage(cmd);
-	}
-    }
-}


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2007-11-08 18:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-08 18:21 [SCM] master: Alias commands extend ParameterizedCommand; test cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).