public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM] frysk system monitor/debugger branch, master, updated. 767f3b3a74eeac703deb3c972e485ae0e5f6fee2
Date: Thu, 08 Nov 2007 04:17:00 -0000	[thread overview]
Message-ID: <20071108041710.19095.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  767f3b3a74eeac703deb3c972e485ae0e5f6fee2 (commit)
      from  935a05a3cc0421e015b6170a5e09042fe933c4fb (commit)

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

- Log -----------------------------------------------------------------
commit 767f3b3a74eeac703deb3c972e485ae0e5f6fee2
Author: Andrew Cagney <cagney@redhat.com>
Date:   Wed Nov 7 23:15:13 2007 -0500

    Add ParameterizedCommand handling command options / parameters.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-07  Andrew Cagney  <cagney@redhat.com>
    
    	* TestParameterizedCommand.java: New.
    	* CommandOption.java: New.
    	* ParameterizedCommand.java: New.
    	* ExamineCommand.java: Extend ParameterizedCommand.
    	* PeekCommand.java: Ditto.
    	* CoreCommand.java: Ditto.
    	* LoadCommand.java: Ditto.
    	* DisassembleCommand.java: Ditto.
    	* OptionParser.java: Delete.
    	* Command.java (parser): Delete.
    	* TestOptionParser.java: Delete.

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

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog                     |   12 ++
 frysk-core/frysk/hpd/Command.java                  |    3 -
 .../{isa/ISAMap.java => hpd/CommandOption.java}    |   64 ++++----
 frysk-core/frysk/hpd/CoreCommand.java              |   21 +--
 frysk-core/frysk/hpd/DisassembleCommand.java       |   65 ++-----
 frysk-core/frysk/hpd/ExamineCommand.java           |   10 +-
 frysk-core/frysk/hpd/LoadCommand.java              |   12 +-
 frysk-core/frysk/hpd/OptionParser.java             |  190 --------------------
 frysk-core/frysk/hpd/ParameterizedCommand.java     |  170 +++++++++++++++++
 frysk-core/frysk/hpd/PeekCommand.java              |   13 +-
 ...onParser.java => TestParameterizedCommand.java} |   56 ++++---
 11 files changed, 284 insertions(+), 332 deletions(-)
 copy frysk-core/frysk/{isa/ISAMap.java => hpd/CommandOption.java} (65%)
 delete mode 100644 frysk-core/frysk/hpd/OptionParser.java
 create mode 100644 frysk-core/frysk/hpd/ParameterizedCommand.java
 rename frysk-core/frysk/hpd/{TestOptionParser.java => TestParameterizedCommand.java} (79%)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index 9ee65ef..990c128 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,5 +1,17 @@
 2007-11-07  Andrew Cagney  <cagney@redhat.com>
 
+	* TestParameterizedCommand.java: New.
+	* CommandOption.java: New.
+	* ParameterizedCommand.java: New.
+	* ExamineCommand.java: Extend ParameterizedCommand.
+	* PeekCommand.java: Ditto.
+	* CoreCommand.java: Ditto.
+	* LoadCommand.java: Ditto.
+	* DisassembleCommand.java: Ditto.
+	* OptionParser.java: Delete.
+	* Command.java (parser): Delete.
+	* TestOptionParser.java: Delete.
+
 	* CLI.java (CLI): Do not add HelpCommand using addHandler.
 	* MultiLevelCommand.java (lookup(String)): New.
 	(help(CLI,Input)): New.
diff --git a/frysk-core/frysk/hpd/Command.java b/frysk-core/frysk/hpd/Command.java
index c95715e..943a1a7 100644
--- a/frysk-core/frysk/hpd/Command.java
+++ b/frysk-core/frysk/hpd/Command.java
@@ -49,8 +49,6 @@ public abstract class Command {
     private final CommandHelp help;
     private final String name;  
 
-    protected OptionParser parser;
-  
     public CommandHelp getHelp() {
 	return help;
     }
@@ -62,7 +60,6 @@ public abstract class Command {
     Command (String name, String description, String syntax, String full) {
 	this.name = name;
 	this.help = new CommandHelp(name, description, syntax, full);
-	parser = new OptionParser(name, syntax, full + "\n");
     }
   
     public abstract void interpret(CLI cli, Input cmd);
diff --git a/frysk-core/frysk/isa/ISAMap.java b/frysk-core/frysk/hpd/CommandOption.java
similarity index 65%
copy from frysk-core/frysk/isa/ISAMap.java
copy to frysk-core/frysk/hpd/CommandOption.java
index 25fa072..a830779 100644
--- a/frysk-core/frysk/isa/ISAMap.java
+++ b/frysk-core/frysk/hpd/CommandOption.java
@@ -37,50 +37,50 @@
 // version and license this file solely under the GPL without
 // exception.
 
-package frysk.isa;
-
-import java.util.LinkedHashMap;
+package frysk.hpd;
 
 /**
- * Searchable, insertion ordered table indexed by ISA.
+ * A command option; optionally parameterized.
  */
 
-public class ISAMap {
-
-    private final LinkedHashMap map = new LinkedHashMap();
-    private final String what;
-    public ISAMap(String what) {
-	this.what = what;
+abstract class CommandOption {
+    final String longName;
+    final char shortName;
+    final String description;
+    final String parameter;
+    CommandOption(String longName, char shortName, String description,
+		  String parameter) {
+	this.longName = longName;
+	this.shortName = shortName;
+	this.description = description;
+	this.parameter = parameter;
     }
-
-    /**
-     * Add the ISA to the table; this allows cascaded calls vis:
-     * .put(IA32, O1).put(X8664, O2).
-     */
-    public ISAMap put(ISA isa, Object o) {
-	map.put(isa, o);
-	return this;
+    CommandOption(String name, String description, String parameter) {
+	this(name, '\0', description, parameter);
     }
-
     /**
-     * Find the ISA object, throw an exception if it isn't found.
+     * An option that doesn't have an argument.
      */
-    public Object get(ISA isa) {
-	Object o = map.get(isa);
-	if (o == null)
-	    throw new RuntimeException("The " + isa + " is not supported"
-				       + " (required by " + what + ")");
-	return o;
+    CommandOption(String name, String description) {
+	this(name, '\0', description, null);
     }
 
     /**
-     * Return true iff the map contains ISA.
+     * Utility, parse a boolean parameter.
      */
-    public boolean containsKey(ISA isa) {
-	return map.containsKey(isa);
+    boolean parseBoolean(String argument) {
+	argument = argument.toLowerCase();
+	if (argument.equals("yes")
+	    || argument.equals("y"))
+	    return true;
+	else if (argument.equals("no")
+		 || argument.equals("n"))
+	    return false;
+	
+	else
+	    throw new InvalidCommandException
+		("option -" + longName + " requires yes or no parameter");
     }
 
-    public String toString() {
-	return map.toString();
-    }
+    abstract void parse(String argument, Object options);
 }
diff --git a/frysk-core/frysk/hpd/CoreCommand.java b/frysk-core/frysk/hpd/CoreCommand.java
index 3485353..cdda025 100644
--- a/frysk-core/frysk/hpd/CoreCommand.java
+++ b/frysk-core/frysk/hpd/CoreCommand.java
@@ -50,26 +50,19 @@ import frysk.proc.Manager;
 import frysk.proc.Proc;
 import frysk.proc.Task;
 
-public class CoreCommand extends Command {
-
-    private static String desc = "open a core file";
+public class CoreCommand extends ParameterizedCommand {
 
     CoreCommand() {
-	super("core", desc, "core core.file [executable]", desc);
+	super("core", "core <core-file> [ <executable> ]",
+	      "open a core file");
     }
 
-    public void interpret(CLI cli, Input cmd) {
+    void interpret(CLI cli, Input cmd, Object options) {
     	
-    Proc coreProc;
-    File exeFile = null;
-    LinuxHost coreHost = null;
+	Proc coreProc;
+	File exeFile = null;
+	LinuxHost coreHost = null;
     
-    // If parse fails, print help
-	if (!parser.parse(cmd)) {
-	    parser.printHelp(cli.outWriter);
-	    return;
-	}
-
 	// If > 2 parameter, then too many parameters.
 	if (cmd.size() > 2) {
 	    throw new InvalidCommandException("Too many parameters");
diff --git a/frysk-core/frysk/hpd/DisassembleCommand.java b/frysk-core/frysk/hpd/DisassembleCommand.java
index c6e18a1..c075948 100644
--- a/frysk-core/frysk/hpd/DisassembleCommand.java
+++ b/frysk-core/frysk/hpd/DisassembleCommand.java
@@ -45,12 +45,10 @@ import frysk.debuginfo.DebugInfoFrame;
 import frysk.proc.Task;
 import frysk.symtab.Symbol;
 import frysk.symtab.SymbolFactory;
-import gnu.classpath.tools.getopt.Option;
-import gnu.classpath.tools.getopt.OptionException;
 import lib.opcodes.Disassembler;
 import lib.opcodes.Instruction;
 
-public class DisassembleCommand extends Command {
+public class DisassembleCommand extends ParameterizedCommand {
 
     public DisassembleCommand() {
 	super("disassemble", "disassemble a section of memory",
@@ -60,45 +58,26 @@ public class DisassembleCommand extends Command {
 	      "disassemble the function surrounding the current pc, "
 	      + "the function surrounding a given address, "
 	      + "or a range of functions.");
-	parser.add(new Option("all-instructions", 'a',
+	add(new CommandOption("all-instructions", 'a',
 		"only print the instruction portion not the parameters",
 		"<Yes|no>") {
-
-	    public void parsed(String argument) throws OptionException {
-		allInstructions = parseBoolean(argument);
-	    }
-
-	});
-
-	parser.add(new Option("full-function", 'f',
-		"disassemble the entire function", "<yes/No>") {
-
-	    public void parsed(String argument) throws OptionException {
-		full = parseBoolean(argument);
-	    }
-
-	});
-
-	parser.add(new Option("symbol", 's', "print the symbol name",
-		"<Yes|no>") {
-
-	    public void parsed(String argument) throws OptionException {
-
-		symbol = parseBoolean(argument);
-	    }
-	});
-    }
-
-    private boolean parseBoolean(String argument) throws OptionException {
-	if (argument.toLowerCase().equals("yes")
-		|| argument.toLowerCase().equals("y"))
-	    return true;
-	else if (argument.toLowerCase().equals("no")
-		|| argument.toLowerCase().equals("n"))
-	    return false;
-
-	else
-	    throw new OptionException("argument should be one of yes or no");
+		void parse(String argument, Object options) {
+		    allInstructions = parseBoolean(argument);
+		}
+	    });
+	add(new CommandOption("full-function", 'f',
+			      "disassemble the entire function",
+			      "<yes/No>") {
+		void parse(String argument, Object options) {
+		    full = parseBoolean(argument);
+		}
+	    });
+	add(new CommandOption("symbol", 's', "print the symbol name",
+			      "<Yes|no>") {
+		void parse(String argument, Object options) {
+		    symbol = parseBoolean(argument);
+		}
+	    });
     }
 
     private boolean allInstructions = true;
@@ -113,14 +92,10 @@ public class DisassembleCommand extends Command {
 	symbol = true;
     }
 
-    public void interpret(CLI cli, Input cmd) {
+    public void interpret(CLI cli, Input cmd, Object options) {
 	reset();
 	PTSet ptset = cli.getCommandPTSet(cmd);
 	Iterator taskDataIter = ptset.getTaskData();
-	if (!parser.parse(cmd)) {
-	    parser.printHelp(cli.outWriter);
-	    return;
-	}
 	if (cmd.size() > 2)
 	    throw new InvalidCommandException
 		("too many arguments to disassemble");
diff --git a/frysk-core/frysk/hpd/ExamineCommand.java b/frysk-core/frysk/hpd/ExamineCommand.java
index 1bd6618..bf794d7 100644
--- a/frysk-core/frysk/hpd/ExamineCommand.java
+++ b/frysk-core/frysk/hpd/ExamineCommand.java
@@ -42,19 +42,15 @@ package frysk.hpd;
 import java.util.Iterator;
 import frysk.value.Value;
 
-public class ExamineCommand extends Command {
+public class ExamineCommand extends ParameterizedCommand {
 
     public ExamineCommand() {
-	super("examine", "examine a value", "examine VALUE\n",
+	super("examine", "examine <value>",
 	      "Examine a value in more detail.");
     }
 
-    public void interpret(CLI cli, Input cmd) {
+    void interpret(CLI cli, Input cmd, Object options) {
 	PTSet ptset = cli.getCommandPTSet(cmd);
-	if (!parser.parse(cmd)) {
-	    parser.printHelp(cli.outWriter);
-	    return;
-	}
 	if (cmd.size() == 0) {
 	    throw new InvalidCommandException("No value to examine");
 	}
diff --git a/frysk-core/frysk/hpd/LoadCommand.java b/frysk-core/frysk/hpd/LoadCommand.java
index 2c2f9e0..4ed5292 100644
--- a/frysk-core/frysk/hpd/LoadCommand.java
+++ b/frysk-core/frysk/hpd/LoadCommand.java
@@ -57,19 +57,13 @@ import java.util.List;
  *
  */
 
-public class LoadCommand extends Command {
-
-    private static String desc = "load an executable file";
+public class LoadCommand extends ParameterizedCommand {
 
     LoadCommand() {
-	super("load", desc, "load path-to-executable", desc);
+	super("load", "load path-to-executable", "load an executable file");
     }
 
-    public void interpret(CLI cli, Input cmd) {
-	if (!parser.parse(cmd)) {
-	    parser.printHelp(cli.outWriter);
-	    return;
-	}
+    public void interpret(CLI cli, Input cmd, Object options) {
 	if (cmd.size() > 2) {
 	    throw new InvalidCommandException("Too many parameters");
 	}
diff --git a/frysk-core/frysk/hpd/OptionParser.java b/frysk-core/frysk/hpd/OptionParser.java
deleted file mode 100644
index 7d06c81..0000000
--- a/frysk-core/frysk/hpd/OptionParser.java
+++ /dev/null
@@ -1,190 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 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 gnu.classpath.tools.getopt.Option;
-import gnu.classpath.tools.getopt.OptionException;
-import gnu.classpath.tools.getopt.OptionGroup;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.LinkedList;
-import java.util.Iterator;
-import java.util.List;
-import java.io.PrintWriter;
-
-class OptionParser {
-
-    private final List options = new LinkedList();
-    private final OptionGroup defaultGroup;
-    private final OptionGroup finalGroup;
-    private final String header;
-    private final String footer;
-    private final String programName;
-
-    OptionParser(String programName, String header, String footer) {
-	this.programName = programName;
-	this.header = header;
-	this.footer = footer;
-	defaultGroup = new OptionGroup(programName + " Options");
-	finalGroup = new OptionGroup("Standard Options");
-	Option help = new Help();
-	finalGroup.add(help);
-	options.add(help);
-    }
-
-    void add(Option option) {	
-	defaultGroup.add(option);
-	options.add(option);
-    }
-
-    private static class HelpException extends RuntimeException {
-	static final long serialVersionUID = 1;
-    }
-
-    private class Help extends Option {
-	Help() {
-	    super("help", "print this help");
-	}
-	public void parsed(String argument) throws OptionException {
-	    throw new HelpException();
-	}
-    }
-
-    void printHelp(PrintWriter out) {
-	ByteArrayOutputStream scratchStream = new ByteArrayOutputStream();
-	PrintStream writer = new PrintStream(scratchStream);
-	if (header != null) {
-	    writer.println(header);
-	}
-	if (defaultGroup != null) {
-	    defaultGroup.printHelp(writer, true);
-	    writer.println();
-	}
-	finalGroup.printHelp(writer, true);
-	if (footer != null) {
-	    writer.println(footer);
-	}
-	out.print(scratchStream.toString());
-    }
-
-    /**
-     * Given a list of arguments, parse and remove options as they are
-     * found.
-     */
-    boolean parse(Input input) {
-	try {
-	    for (int currentIndex = input.size() - 1;
-		 currentIndex > -1;
-		 --currentIndex) {
-		String string = input.parameter(currentIndex);
-		if (string.equals("--")) {
-		    input.remove(currentIndex);
-		    break;
-		}
-		if (string.charAt(0) != '-')
-		    continue;
-		handleLongOption(input, string, currentIndex + 1);
-		input.remove(currentIndex);
-	    }
-	    // See if something went wrong.
-	    validate();
-	} catch (HelpException h) {
-	    return false;
-	} catch (OptionException err) {
-	    throw new InvalidCommandException
-		(programName + ": " + err.getMessage() + "\n"
-		 + programName + ": Try '" + programName
-		 + " -help for more information");
-	}
-	return true;
-    }
-
-    private void handleLongOption(Input input, String real, int index)
-	throws OptionException {
-	String option = real.substring(real.lastIndexOf('-') + 1);
-	String justName = option;
-	int eq = option.indexOf('=');
-	if (eq != -1)
-	    justName = option.substring(0, eq);
-	boolean isPlainShort = justName.length() == 1;
-	char shortName = justName.charAt(0);
-	Option found = null;
-	for (Iterator i = options.iterator(); i.hasNext(); ) {
-	    Option opt = (Option)(i.next());
-	    if (justName.equals(opt.getLongName())) {
-		found = opt;
-		break;
-	    }
-	    if ((isPlainShort || opt.isJoined())
-		&& opt.getShortName() == shortName) {
-		if (!isPlainShort) {
-		    // The rest of the option string is the argument.
-		    eq = 0;
-		}
-		found = opt;
-		break;
-	    }
-	}
-
-	if (found == null) {
-	    String msg = "unrecognized option '" + real + "'";
-	    throw new OptionException(msg);
-	}
-	String argument = null;
-	if (found.getTakesArgument()) {


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


                 reply	other threads:[~2007-11-08  4:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071108041710.19095.qmail@sourceware.org \
    --to=cagney@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).