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] master: Fix typo in changelog.


The branch, master has been updated
       via  fdb837f1918543acf84ece7806c0900798fd27d2 (commit)
       via  167c2efe1c4c8a23f92698d544fd1a142d02e3fb (commit)
      from  1e79ab9a46d499104cc07e265842e5b075a90a3b (commit)

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

- Log -----------------------------------------------------------------
commit fdb837f1918543acf84ece7806c0900798fd27d2
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Nov 9 13:18:33 2007 -0500

    Fix typo in changelog.

commit 167c2efe1c4c8a23f92698d544fd1a142d02e3fb
Author: Andrew Cagney <cagney@redhat.com>
Date:   Fri Nov 9 13:01:13 2007 -0500

    PrintCommand extends ParameterizedCommand.
    
    frysk-core/frysk/hpd/ChangeLog
    2007-11-09  Andrew Cagney  <cagney@redhat.com>
    
    	* TestParameterizedCommand.java (check(...)): Add check for
    	input.stringValue().
    	* PrintCommand.java: Extend ParameterizedCommand.
    	* CommandOption.java (parseFormat(String)): New.

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

Summary of changes:
 frysk-core/frysk/hpd/ChangeLog                     |    5 +
 frysk-core/frysk/hpd/CommandOption.java            |   27 ++++
 frysk-core/frysk/hpd/PrintCommand.java             |  146 ++++++++------------
 frysk-core/frysk/hpd/TestParameterizedCommand.java |   25 ++--
 4 files changed, 105 insertions(+), 98 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/hpd/ChangeLog b/frysk-core/frysk/hpd/ChangeLog
index d03ce52..f46f0fa 100644
--- a/frysk-core/frysk/hpd/ChangeLog
+++ b/frysk-core/frysk/hpd/ChangeLog
@@ -1,5 +1,10 @@
 2007-11-09  Andrew Cagney  <cagney@redhat.com>
 
+	* TestParameterizedCommand.java (check(...)): Add check for
+	input.stringValue().
+	* PrintCommand.java: Extend ParameterizedCommand.
+	* CommandOption.java (FormatOption): New.
+
 	* MultiLevelCommand.java: Handle null tokens.
 	* ParameterizedCommand.java: Ditto.
 	
diff --git a/frysk-core/frysk/hpd/CommandOption.java b/frysk-core/frysk/hpd/CommandOption.java
index a830779..5f795a1 100644
--- a/frysk-core/frysk/hpd/CommandOption.java
+++ b/frysk-core/frysk/hpd/CommandOption.java
@@ -39,6 +39,8 @@
 
 package frysk.hpd;
 
+import frysk.value.Format;
+
 /**
  * A command option; optionally parameterized.
  */
@@ -82,5 +84,30 @@ abstract class CommandOption {
 		("option -" + longName + " requires yes or no parameter");
     }
 
+    /**
+     * Template option; parse a format.
+     */
+    static abstract class FormatOption extends CommandOption {
+	FormatOption() {
+	    super("format", "print format", "d|o|x|t");
+	}
+	void parse(String argument, Object options) {
+	    Format format;
+	    if (argument.compareTo("d") == 0) 
+		format = Format.DECIMAL;
+	    else if (argument.compareTo("o") == 0)
+		format = Format.OCTAL;
+	    else if (argument.compareTo("x") == 0) 
+		format = Format.HEXADECIMAL;
+	    else if (argument.compareTo("t") == 0)
+		format = Format.BINARY;
+	    else
+		throw new InvalidCommandException("unrecognized format: "
+						  + argument);
+	    set(options, format);
+	}
+	abstract void set(Object options, Format format);
+    }
+
     abstract void parse(String argument, Object options);
 }
diff --git a/frysk-core/frysk/hpd/PrintCommand.java b/frysk-core/frysk/hpd/PrintCommand.java
index 71a1d47..e7b62ed 100644
--- a/frysk-core/frysk/hpd/PrintCommand.java
+++ b/frysk-core/frysk/hpd/PrintCommand.java
@@ -47,16 +47,35 @@ import frysk.value.PointerType;
 import frysk.value.Type;
 import java.util.List;
 
-class PrintCommand
-    extends Command
-{
+class PrintCommand extends ParameterizedCommand {
+    private class Options {
+	Format format = Format.NATURAL;
+	boolean dumpTree = false;
+    }
+    Object options() {
+	return new Options();
+    }
+
     PrintCommand() {
-	this("print", "Evaluate and display the value of a program variable or expression.",
-	     "print expression [-name] [-index] [-format d|o|x|t]", "The print command evaluates and displays an expression. The debugger\n" +
-	     "interprets the expression by looking up the value(s) associated with\n" +
-	     "each symbol and applying the operators.  The result of an expression may\n" +
-	     "be a scalar value or an aggregate (array, array slice, record, or\n" +
-	     "structure.");
+	this("print",
+	     "Evaluate and display the value of an expression.",
+	     "print expression [-format d|o|x|t]",
+	     ("The print command evaluates and displays an expression. The"
+	     + " debugger interprets the expression by looking up the"
+	      + " value(s) associated with each symbol and applying the"
+	      + " operators.  The result of an expression may be a scalar"
+	      + " value or an aggregate (array, array slice, record, or"
+	      + " structure."));
+	add(new CommandOption.FormatOption() {
+		void set(Object options, Format format) {
+		    ((Options)options).format = format;
+		}
+	    });
+	add(new CommandOption("dump-tree", "dump the expression AST") {
+		void parse(String arg, Object options) {
+		    ((Options)options).dumpTree = true;
+		}
+	    });
     }
     
     PrintCommand (String name, String description, String syntax, 
@@ -64,106 +83,57 @@ class PrintCommand
 	super (name, description, syntax, full);
     }
 
-    public void interpret(CLI cli, Input cmd) {
-        PTSet ptset = cli.getCommandPTSet(cmd);
-	boolean dumpTree = false;
-	if (cmd.size() == 1 && cmd.parameter(0).equals("-help")) {
-	    cli.printUsage(cmd);
-	    return;
-        }
-	if (cmd.size() == 0
-	    || ((cmd.parameter(0)).equals("-help"))) {
-	    cli.printUsage(cmd);
-	    return;
-        }
-        // Skip set specification, if any.  XXX: Should do this after
-        // parameter parsing.
-	String sInput = cmd.stringValue();
-
-	Format format = null;
-	for (int i = 0; i < cmd.size(); i++) {
-	    if ((cmd.parameter(i)).equals("-format")) {
-		i += 1;
-		String arg = cmd.parameter(i);
-		if (arg.compareTo("d") == 0) 
-		    format = Format.DECIMAL;
-		else if (arg.compareTo("o") == 0)
-		    format = Format.OCTAL;
-		else if (arg.compareTo("x") == 0) 
-		    format = Format.HEXADECIMAL;
-		else if (arg.compareTo("t") == 0)
-		    format = Format.BINARY;
-		else
-		    throw new InvalidCommandException
-			("unrecognized format: " + arg);
-	    }
-	    else if ((cmd.parameter(i)).equals("-dump-tree")) 
-		dumpTree = true;
-	}
-	if (format != null)
-	    sInput = sInput.substring(0,sInput.indexOf("-format"));
-	else
-	    format = Format.NATURAL;
-	if (dumpTree == true)
-	    sInput = sInput.substring(0,sInput.indexOf("-dump-tree"));
+    public void interpret(CLI cli, Input input, Object o) {
+	if (input.size() == 0)
+	    throw new InvalidCommandException("missing expression");
+	Options options = (Options)o;
+        PTSet ptset = cli.getCommandPTSet(input);
 
-	if (sInput.length() == 0) {
-	    cli.printUsage(cmd);
-	    return;
-	}
-
-	if (cmd.getAction().compareTo("assign") == 0) {
+	String sInput = input.stringValue();
+	if (input.getAction().compareTo("assign") == 0) {
 	    int i = sInput.indexOf(' ');
 	    if (i == -1) {
-		cli.printUsage(cmd);          
-		return;
+		throw new InvalidCommandException("bad expression XXX");
 	    }
 	    sInput = sInput.substring(0, i) + "=" + sInput.substring(i);
 	}        
 
 	Value result = null;
         Iterator taskDataIter = ptset.getTaskData();
-        boolean doWithoutTask = !taskDataIter.hasNext();
-        while (doWithoutTask || taskDataIter.hasNext()) {
-            TaskData td = null;
+	do {
             Task task = null;
-            if (!doWithoutTask) {
-                td = (TaskData)taskDataIter.next();
+            if (taskDataIter.hasNext()) {
+		TaskData td = (TaskData)taskDataIter.next();
                 task = td.getTask();
-                cli.outWriter.println("[" + td.getParentID() + "." + td.getID()
-                                      + "]\n");
+                cli.outWriter.print("[");
+		cli.outWriter.print(td.getParentID());
+		cli.outWriter.print(".");
+		cli.outWriter.print(td.getID());
+		cli.outWriter.println("]");
             }
-            doWithoutTask = false;
             try {
-                result = cli.parseValue(task, sInput, dumpTree);	  
+                result = cli.parseValue(task, sInput, options.dumpTree);
             } catch (RuntimeException nnfe) {
 		cli.addMessage(nnfe.getMessage(), Message.TYPE_ERROR);
                 continue;
             }
 
-	    // XXX: Would it be better to just always have some sort
-	    // of fake task?
-	    if (task == null)
-		result.toPrint(cli.outWriter, null, format);
-	    else {
-		Type t = result.getType();
-		if (t instanceof PointerType) {
-		    cli.outWriter.print("(");
-		    t.toPrint(cli.outWriter);
-		    cli.outWriter.print(") ");
-		}
-		result.toPrint(cli.outWriter, task.getMemory(), format);
+	    Type t = result.getType();
+	    if (t instanceof PointerType) {
+		cli.outWriter.print("(");
+		t.toPrint(cli.outWriter);
+		cli.outWriter.print(") ");
 	    }	
+	    result.toPrint(cli.outWriter,
+			   task == null ? null : task.getMemory(),
+			   options.format);
 	    cli.outWriter.println();
-        }
-        if (result == null) {
-            cli.addMessage("Symbol \"" + sInput + "\" is not found in the current context.",
-                           Message.TYPE_ERROR);
-        }
+        } while (taskDataIter.hasNext());
     }
 
-    int complete(CLI cli, Input input, int cursor, List candidates) {
-	return CompletionFactory.completeFocusedExpression(cli, input, cursor,
-							   candidates);
+    int complete(CLI cli, PTSet ptset, String incomplete, int base,
+		 List candidates) {
+	return CompletionFactory.completeExpression(cli, ptset, incomplete,
+						    base, candidates);
     }
 }
diff --git a/frysk-core/frysk/hpd/TestParameterizedCommand.java b/frysk-core/frysk/hpd/TestParameterizedCommand.java
index 00edef9..f625adb 100644
--- a/frysk-core/frysk/hpd/TestParameterizedCommand.java
+++ b/frysk-core/frysk/hpd/TestParameterizedCommand.java
@@ -97,10 +97,12 @@ public class TestParameterizedCommand extends TestLib {
 	command.interpret(null, input);
     }
 
-    private void check(String string, String[] parameters,
+    private void check(String string, String stringValue,
+		       String[] parameters,
 		       boolean parsedOption, String argument) {
 	parse(string);
 	assertEquals("input size", parameters.length, input.size());
+	assertEquals("stringValue", stringValue, input.stringValue());
 	assertEquals("parsedOption", this.parsedOption, parsedOption);
 	assertEquals("argument", this.argument, argument);
 	for (int i = 0; i < parameters.length; i++) {
@@ -111,39 +113,42 @@ public class TestParameterizedCommand extends TestLib {
     }
 
     public void testDashDash() {
-	check("parser --", new String[0], false, null);
+	check("parser --", "", new String[0], false, null);
     }
 
     public void testRegular() {
-	check("parser argument", new String[] { "argument" }, false, null);
+	check("parser argument", "argument",
+	      new String[] { "argument" }, false, null);
     }
 
     public void testRegularDashDash() {
-	check("parser argument --", new String[] { "argument" }, false, null);
+	check("parser argument --", "argument",
+	      new String[] { "argument" }, false, null);
     }
 
     public void testOption() {
-	check("parser -opt", new String[0], true, null);
+	check("parser -opt", "", new String[0], true, null);
     }
 
     public void testOptionAfterDashDash() {
-	check("parser -- -opt", new String[0], true, null);
+	check("parser -- -opt", "", new String[0], true, null);
     }
 
     public void testOptionBeforeDashDash() {
-	check("parser -opt --", new String[] { "-opt" }, false, null);
+	check("parser -opt --", "-opt", new String[] { "-opt" }, false, null);
     }
 
     public void testOptionWithArg() {
-	check("parser -arg argument", new String[0], true, "argument");
+	check("parser -arg argument", "", new String[0], true, "argument");
     }
 
     public void testOptionWithArgAfterDashDash() {
-	check("parser -- -arg argument", new String[0], true, "argument");
+	check("parser -- -arg argument", "", new String[0], true, "argument");
     }
 
     public void testOptionWithArgBeforeDashDash() {
-	check("parser -arg argument --", new String[] { "-arg", "argument" },
+	check("parser -arg argument --", "-arg argument",
+	      new String[] { "-arg", "argument" },
 	      false, null);
     }
 


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]