This is the mail archive of the frysk-cvs@sources.redhat.com mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[SCM] frysk system monitor/debugger branch, master, updated. 935a05a3cc0421e015b6170a5e09042fe933c4fb


The branch, master has been updated
       via  935a05a3cc0421e015b6170a5e09042fe933c4fb (commit)
      from  74e3e2ffac29c082dc752233408ef8efb73a0aad (commit)

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

- Log -----------------------------------------------------------------
commit 935a05a3cc0421e015b6170a5e09042fe933c4fb
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Nov 7 16:20:18 2007 -0500

    Add Command.help(CLI,Input); and use/test.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-07  Andrew Cagney  <cagney@redhat.com>
    
    	* CLI.java (CLI): Do not add HelpCommand using addHandler.
    	* MultiLevelCommand.java (lookup(String)): New.
    	(help(CLI,Input)): New.
    	(interpret(CLI,Input)): Use lookup(String).
    	* TopLevelCommand.java (Help): New.
    	(TopLevelCommand(DbgVariables)): Use Help to implement "help".
    	* Command.java (help(CLI,Input)): New.
    	* TestHelp.java: New file.
    	* HelpCommand.java: Delete.

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

Summary of changes:
 frysk-core/frysk/hpd/CLI.java                      |    1 -
 frysk-core/frysk/hpd/ChangeLog                     |   12 +++
 frysk-core/frysk/hpd/Command.java                  |   19 +++++
 frysk-core/frysk/hpd/HelpCommand.java              |   72 -------------------
 frysk-core/frysk/hpd/MultiLevelCommand.java        |   75 ++++++++++++--------
 .../hpd/{TestPtypeCommand.java => TestHelp.java}   |   33 ++++++---
 frysk-core/frysk/hpd/TopLevelCommand.java          |   27 +++++++-
 7 files changed, 126 insertions(+), 113 deletions(-)
 delete mode 100644 frysk-core/frysk/hpd/HelpCommand.java
 copy frysk-core/frysk/hpd/{TestPtypeCommand.java => TestHelp.java} (78%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/CLI.java b/frysk-core/frysk/hpd/CLI.java
index ed30e4a..f72545e 100644
--- a/frysk-core/frysk/hpd/CLI.java
+++ b/frysk-core/frysk/hpd/CLI.java
@@ -248,7 +248,6 @@ public class CLI {
         addHandler(new FocusCommand());
         addHandler(new GoCommand());
         addHandler(new HaltCommand());
-        addHandler(new HelpCommand());
         addHandler(new ListCommand());
         addHandler(new StepNextCommand());
         addHandler(new StepNextiCommand());
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 0b0b2cb..9ee65ef 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,3 +1,15 @@
+2007-11-07  Andrew Cagney  <cagney@redhat.com>
+
+	* CLI.java (CLI): Do not add HelpCommand using addHandler.
+	* MultiLevelCommand.java (lookup(String)): New.
+	(help(CLI,Input)): New.
+	(interpret(CLI,Input)): Use lookup(String).
+	* TopLevelCommand.java (Help): New.
+	(TopLevelCommand(DbgVariables)): Use Help to implement "help".
+	* Command.java (help(CLI,Input)): New.
+	* TestHelp.java: New file.
+	* HelpCommand.java: Delete.
+
 2007-11-07  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* CoreCommand.java (interpret): Check for runtime exceptions
diff --git a/frysk-core/frysk/hpd/Command.java b/frysk-core/frysk/hpd/Command.java
index c181163..c95715e 100644
--- a/frysk-core/frysk/hpd/Command.java
+++ b/frysk-core/frysk/hpd/Command.java
@@ -77,4 +77,23 @@ public abstract class Command {
     int complete(CLI cli, Input buffer, int cursor, List candidates) {
 	return -1;
     }
+
+    /**
+     * Print a full "help" message (syntax and then details) for this
+     * command.
+     */
+    void help(CLI cli, Input buffer) {
+	cli.outWriter.print("Usage: ");
+	cli.outWriter.print(help.getSyntax());
+	cli.outWriter.println();
+	cli.outWriter.print(help.getFull());
+	cli.outWriter.println();
+    }
+
+    /**
+     * Return a brief (one line) description of the command.
+     */
+    String description() {
+	return help.getDescription();
+    }
 }
diff --git a/frysk-core/frysk/hpd/HelpCommand.java b/frysk-core/frysk/hpd/HelpCommand.java
deleted file mode 100644
index 64dedf7..0000000
--- a/frysk-core/frysk/hpd/HelpCommand.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;
-
-import java.util.Iterator;
-
-class HelpCommand extends Command {
-    HelpCommand() {
-	super("help", "Display this help message.", "help [command]",
-	      "Display help (possibly for a command.)");
-    }
-
-    public void interpret(CLI cli, Input cmd) {
-	String output = "";
-	String temp = "";
-	if (cmd.size() == 0) {
-	    for (Iterator iter = cli.userhelp.getCmdList().iterator(); iter
-		    .hasNext();) {
-		temp = (String) iter.next();
-		output += temp + " - " + cli.userhelp.getCmdDescription(temp)
-			+ "\n";
-	    }
-	} else {
-	    for (Iterator iter = cli.userhelp.getCmdList().iterator(); iter
-		    .hasNext();) {
-		temp = (String) iter.next();
-		if (temp.compareTo(cmd.parameter(0)) == 0) {
-		    output += cli.userhelp.getCmdSyntax(temp) + "\n";
-		    output += cli.userhelp.getCmdFullDescr(temp);
-		}
-	    }
-	}
-	cli.addMessage(output, Message.TYPE_NORMAL);
-    }
-}
diff --git a/frysk-core/frysk/hpd/MultiLevelCommand.java b/frysk-core/frysk/hpd/MultiLevelCommand.java
index 3dffede..cd13717 100644
--- a/frysk-core/frysk/hpd/MultiLevelCommand.java
+++ b/frysk-core/frysk/hpd/MultiLevelCommand.java
@@ -39,6 +39,7 @@
 
 package frysk.hpd;
 
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Iterator;
@@ -55,6 +56,7 @@ public abstract class MultiLevelCommand extends Command {
 		      String full) {
 	super(name, description, syntax, full);
     }
+
     /**
      * Add the specified command.
      */
@@ -63,43 +65,58 @@ public abstract class MultiLevelCommand extends Command {
 	return this;
     }
 
-    private void help(CLI cli) {
-	for (Iterator i = subCommands.values().iterator(); i.hasNext(); ) {
-	    Command c = (Command)(i.next());
-	    cli.outWriter.print(c.getName());
-	    cli.outWriter.print(": ");
-	    cli.outWriter.print(c.getHelp().getDescription());
+    private Command lookup(String subAction) {
+	// If there's an exact match return; even when the command is
+	// ambiguous (e.x. "step" vs "step" "stepi").
+	Command command = (Command)subCommands.get(subAction);
+	if (command != null)
+	    return command;
+	// Look for something starting, but if multiple matches bail.
+	Map.Entry subEntry = null;
+	for (Iterator i = subCommands.entrySet().iterator(); i.hasNext(); ) {
+	    Map.Entry entry = (Map.Entry)(i.next());
+	    String key = (String)entry.getKey();
+	    if (key.startsWith(subAction)) {
+		if (subEntry == null) {
+		    subEntry = entry;
+		} else {
+		    throw new InvalidCommandException("Ambigious command: "
+						      + subAction);
+		}
+	    }
+	}
+	if (subEntry == null)
+	    throw new InvalidCommandException("Unknown command: " + subAction);
+	return (Command)subEntry.getValue();
+    }
+
+    /**
+     * Pass the help request down to the next level (if there is one)
+     * or just print the list of commands at this level.
+     */
+    void help(CLI cli, Input input) {
+	if (input.size() == 0) {
+	    for (Iterator i = subCommands.entrySet().iterator();
+		 i.hasNext(); ) {
+		Map.Entry entry = (Map.Entry)(i.next());
+		String name = (String)entry.getKey();
+		Command command = (Command)entry.getValue();
+		cli.outWriter.print(name);
+		cli.outWriter.print(" - ");
+		cli.outWriter.println(command.description());
+	    }
+	} else {
+	    lookup(input.parameter(0)).help(cli, input.accept());
 	}
     }
 
     public void interpret(CLI cli, Input input) {
 	String subAction = input.parameter(0);
 	if (subAction == null) {
-	    help(cli);
+	    help(cli, input);
 	    return;
 	}
-	Command subCommand = (Command)(subCommands.get(subAction));
-	if (subCommand == null) {
-	    String subName = null;
-	    for (Iterator i = subCommands.keySet().iterator(); i.hasNext(); ) {
-		String key = (String)(i.next());
-		if (key.startsWith(subAction)) {
-		    if (subName == null) {
-			subName = key;
-		    } else {
-			throw new InvalidCommandException("Ambigious command: "
-							  + subAction);
-		    }
-		}
-	    }
-	    if (subCommand == null) {
-		throw new InvalidCommandException("Unknown command: "
-						  + subAction);
-	    }
-	    // This must work!
-	    subCommand = (Command)(subCommands.get(subName));
-	}
-	subCommand.interpret(cli, input.accept());
+	lookup(subAction).interpret(cli, input.accept());
     }
 
     int complete(CLI cli, Input input, int cursor, List candidates) {
diff --git a/frysk-core/frysk/hpd/TestPtypeCommand.java b/frysk-core/frysk/hpd/TestHelp.java
similarity index 78%
copy from frysk-core/frysk/hpd/TestPtypeCommand.java
copy to frysk-core/frysk/hpd/TestHelp.java
index 54a8a81..e2c7b6d 100644
--- a/frysk-core/frysk/hpd/TestPtypeCommand.java
+++ b/frysk-core/frysk/hpd/TestHelp.java
@@ -40,23 +40,36 @@
 package frysk.hpd;
 
 /**
- * Test the functionality of the ptype command.
- *
- * The intent here is not to test underlying code such as the type
- * parser; that is the responsibility of underlying tests.
+ * Test the help command, and -help option.
  */
 
-public class TestPtypeCommand
+public class TestHelp
     extends TestLib
 {
-    public void testPtype() {
+    public void testHelp() {
 	e = new HpdTestbed();
-	e.sendCommandExpectPrompt("ptype 2+2", "long\r\n");
+	e.send("help\n");
+	e.expect("actionpoints - ");
+	e.expect("core - ");
+	e.expect("finish - ");
+	e.expect("list - ");
+	e.expect("peek - ");
+	e.expect("regs - ");
+	e.expect("step - ");
+	e.expect("up - ");
+	e.expectPrompt("whichsets.*");
     }
 
-    public void testPtypeFails() {
+    public void testHelpCompletion() {
 	e = new HpdTestbed();
-	e.sendCommandExpectPrompt("ptype bogus", "Error: Symbol \"bogus\" is not found " +
-				  "in the current context.\r\n");
+	e.send("help u\t");
+	e.expect("unalias\r\nundefset\r\nunset\r\nup\r\n"
+		 + prompt + "help u");
+    }
+
+    public void testHelpHelp() {
+	e = new HpdTestbed();
+	e.sendCommandExpectPrompt("help help",
+				  "Display help.*");
     }
 }
diff --git a/frysk-core/frysk/hpd/TopLevelCommand.java b/frysk-core/frysk/hpd/TopLevelCommand.java
index f2140df..82c1447 100644
--- a/frysk-core/frysk/hpd/TopLevelCommand.java
+++ b/frysk-core/frysk/hpd/TopLevelCommand.java
@@ -39,11 +39,36 @@
 
 package frysk.hpd;
 
+import java.util.List;
+
 /**
  * A handler class for the CLI that supplies its own help messages.
  */
 
 public class TopLevelCommand extends MultiLevelCommand {
+    /**
+     * Implement top-level help.
+     */
+    private class Help extends Command {
+	Help() {
+	    super("help", "Display this help message.", "help [command]",
+		  "Display help (possibly for a command.)");
+	}
+	
+	public void interpret(CLI cli, Input cmd) {
+	    TopLevelCommand.this.help(cli, cmd);
+	}
+	
+	/**
+	 * Complete the line, throw problem back at the top level
+	 * command.
+	 */
+	int complete(CLI cli, Input buffer, int cursor, List candidates) {
+	    return TopLevelCommand.this.complete(cli, buffer, cursor,
+						 candidates);
+	}
+    }
+
     TopLevelCommand(DbgVariables dbgvars) {
 	super("<top-level", "top level command",
 	      "<command> <parameter> ...",
@@ -64,7 +89,7 @@ public class TopLevelCommand extends MultiLevelCommand {
         add(new FocusCommand());
         add(new GoCommand());
         add(new HaltCommand());
-        add(new HelpCommand());
+        add(new Help());
         add(new ListCommand());
         add(new StepNextCommand());
         add(new StepNextiCommand());


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]