From: <cr...@us...> - 2009-06-01 14:32:55
|
Revision: 5537 http://jnode.svn.sourceforge.net/jnode/?rev=5537&view=rev Author: crawley Date: 2009-06-01 14:32:48 +0000 (Mon, 01 Jun 2009) Log Message: ----------- Fix code that outputs the usage information following a command syntax exception. Modified Paths: -------------- trunk/cli/src/commands/org/jnode/command/common/UnixTestCommand.java trunk/cli/src/commands/org/jnode/command/system/LoadkeysCommand.java trunk/shell/src/shell/org/jnode/shell/CommandRunner.java trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java Removed Paths: ------------- trunk/shell/src/shell/org/jnode/shell/help/SyntaxErrorException.java Modified: trunk/cli/src/commands/org/jnode/command/common/UnixTestCommand.java =================================================================== --- trunk/cli/src/commands/org/jnode/command/common/UnixTestCommand.java 2009-06-01 10:49:03 UTC (rev 5536) +++ trunk/cli/src/commands/org/jnode/command/common/UnixTestCommand.java 2009-06-01 14:32:48 UTC (rev 5537) @@ -27,7 +27,7 @@ import org.jnode.shell.AbstractCommand; import org.jnode.shell.CommandLine; -import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.shell.syntax.CommandSyntaxException; /** @@ -123,7 +123,7 @@ args = commandLine.getArguments(); try { if (bracketted && args.length == 0) { - throw new SyntaxErrorException("missing ']'"); + throw new CommandSyntaxException("missing ']'"); } else if (bracketted && !args[args.length - 1].equals("]")) { processAsOptions(args); res = true; @@ -135,7 +135,7 @@ Object obj = evaluate(); if (pos <= lastArg) { if (args[pos].equals(")")) { - throw new SyntaxErrorException("unmatched ')'"); + throw new CommandSyntaxException("unmatched ')'"); } else { throw new AssertionError("I'm confused! pos = " + pos + ", lastArg = " + lastArg + ", next arg is " + args[pos]); @@ -153,13 +153,13 @@ if (!res) { exit(1); } - } catch (SyntaxErrorException ex) { + } catch (CommandSyntaxException ex) { getError().getPrintWriter().println(ex.getMessage()); exit(2); } } - private Object evaluate() throws SyntaxErrorException { + private Object evaluate() throws CommandSyntaxException { evaluateExpression(false); while (!operatorStack.isEmpty()) { reduce(); @@ -170,27 +170,27 @@ return operandStack.pop(); } - private void evaluateExpression(boolean nested) throws SyntaxErrorException { + private void evaluateExpression(boolean nested) throws CommandSyntaxException { evaluatePrimary(nested); while (pos <= lastArg) { String tok = next(); Operator op = OPERATOR_MAP.get(tok); if (op == null) { - throw new SyntaxErrorException("expected an operator"); + throw new CommandSyntaxException("expected an operator"); } switch(op.kind) { case OP_UNARY: - throw new SyntaxErrorException("misplaced unary operator"); + throw new CommandSyntaxException("misplaced unary operator"); case OP_BINARY: evaluatePrimary(nested); reduceAndPush(op, popOperand()); break; case OP_SPECIAL: if (op.opNo == OP_LPAREN) { - throw new SyntaxErrorException("misplaced '('"); + throw new CommandSyntaxException("misplaced '('"); } else if (op.opNo == OP_RPAREN) { if (!nested) { - throw new SyntaxErrorException("misplaced ')'"); + throw new CommandSyntaxException("misplaced ')'"); } back(); return; @@ -199,7 +199,7 @@ } } - private void evaluatePrimary(boolean nested) throws SyntaxErrorException { + private void evaluatePrimary(boolean nested) throws CommandSyntaxException { String tok = next(); Operator op = OPERATOR_MAP.get(tok); if (op == null) { @@ -211,13 +211,13 @@ operandStack.push(next()); break; case OP_BINARY: - throw new SyntaxErrorException("misplaced binary operator"); + throw new CommandSyntaxException("misplaced binary operator"); case OP_SPECIAL: if (op.opNo == OP_LPAREN) { operatorStack.push(op); // ... as a marker. evaluateExpression(true); if (!next().equals(")")) { - throw new SyntaxErrorException("missing ')'"); + throw new CommandSyntaxException("missing ')'"); } while (operatorStack.peek() != op) { reduce(); @@ -226,13 +226,13 @@ throw new AssertionError("cannot find my marker!"); } } else { - throw new SyntaxErrorException("unmatched ')'"); + throw new CommandSyntaxException("unmatched ')'"); } } } } - private void reduceAndPush(Operator operator, Object operand) throws SyntaxErrorException { + private void reduceAndPush(Operator operator, Object operand) throws CommandSyntaxException { while (!operatorStack.isEmpty() && operator.priority <= operatorStack.peek().priority) { reduce(); } @@ -240,7 +240,7 @@ operandStack.push(operand); } - private void reduce() throws SyntaxErrorException { + private void reduce() throws CommandSyntaxException { Operator operator = operatorStack.pop(); Object operand = null, operand2 = null; if (operator.kind == OP_UNARY) { @@ -321,7 +321,7 @@ } } - private void processAsOptions(String[] args) throws SyntaxErrorException { + private void processAsOptions(String[] args) throws CommandSyntaxException { PrintWriter err = getError().getPrintWriter(); for (String option : args) { if (option.equals("--help")) { @@ -329,7 +329,7 @@ } else if (option.equals("--version")) { err.println("JNode test 0.0"); } else { - throw new SyntaxErrorException("unknown option '" + option + "'"); + throw new CommandSyntaxException("unknown option '" + option + "'"); } } } @@ -346,51 +346,51 @@ operandStack.push(new Long(value)); } - private Object popOperand() throws SyntaxErrorException { + private Object popOperand() throws CommandSyntaxException { if (operandStack.isEmpty()) { - throw new SyntaxErrorException("missing LHS for operator"); + throw new CommandSyntaxException("missing LHS for operator"); } return operandStack.pop(); } - private long toNumber(Object obj) throws SyntaxErrorException { + private long toNumber(Object obj) throws CommandSyntaxException { if (obj instanceof Long) { return ((Long) obj).longValue(); } else if (obj instanceof String) { try { return Long.parseLong((String) obj); } catch (NumberFormatException ex) { - throw new SyntaxErrorException( + throw new CommandSyntaxException( "operand is not a number: '" + obj.toString() + "'"); } } else { - throw new SyntaxErrorException("subexpression is not an INTEGER"); + throw new CommandSyntaxException("subexpression is not an INTEGER"); } } - private boolean toBoolean(Object obj) throws SyntaxErrorException { + private boolean toBoolean(Object obj) throws CommandSyntaxException { if (obj instanceof Boolean) { return obj == Boolean.TRUE; } else if (obj instanceof String) { return ((String) obj).length() > 0; } else { - throw new SyntaxErrorException("operand is an INTEGER"); + throw new CommandSyntaxException("operand is an INTEGER"); } } - private String toString(Object obj) throws SyntaxErrorException { + private String toString(Object obj) throws CommandSyntaxException { if (obj instanceof String) { return (String) obj; } else { - throw new SyntaxErrorException("operand is not a STRING"); + throw new CommandSyntaxException("operand is not a STRING"); } } - private File toFile(Object obj) throws SyntaxErrorException { + private File toFile(Object obj) throws CommandSyntaxException { if (obj instanceof String) { return new File((String) obj); } else { - throw new SyntaxErrorException("operand is not a FILENAME"); + throw new CommandSyntaxException("operand is not a FILENAME"); } } @@ -401,7 +401,7 @@ return args[pos++]; } - private void back() throws SyntaxErrorException { + private void back() throws CommandSyntaxException { pos--; } Modified: trunk/cli/src/commands/org/jnode/command/system/LoadkeysCommand.java =================================================================== --- trunk/cli/src/commands/org/jnode/command/system/LoadkeysCommand.java 2009-06-01 10:49:03 UTC (rev 5536) +++ trunk/cli/src/commands/org/jnode/command/system/LoadkeysCommand.java 2009-06-01 14:32:48 UTC (rev 5537) @@ -31,9 +31,9 @@ import org.jnode.driver.input.KeyboardLayoutManager; import org.jnode.naming.InitialNaming; import org.jnode.shell.AbstractCommand; -import org.jnode.shell.help.SyntaxErrorException; import org.jnode.shell.syntax.Argument; import org.jnode.shell.syntax.ClassNameArgument; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.syntax.CountryArgument; import org.jnode.shell.syntax.FlagArgument; import org.jnode.shell.syntax.KeyboardLayoutArgument; @@ -109,7 +109,7 @@ if (argAdd.isSet()) { String layoutID = getLayoutID(mgr); if (!argClass.isSet()) { - throw new SyntaxErrorException(ex_syntax_class); + throw new CommandSyntaxException(ex_syntax_class); } String className = argClass.getValue(); mgr.add(layoutID, className); @@ -141,16 +141,16 @@ } } - private String getLayoutID(KeyboardLayoutManager mgr) throws SyntaxErrorException { + private String getLayoutID(KeyboardLayoutManager mgr) throws CommandSyntaxException { if (!argTriple.isSet()) { if (argLayout.isSet()) { return argLayout.getValue(); } else { - throw new SyntaxErrorException(ex_syntax_layout); + throw new CommandSyntaxException(ex_syntax_layout); } } else { if (!argCountry.isSet()) { - throw new SyntaxErrorException(ex_syntax_country); + throw new CommandSyntaxException(ex_syntax_country); } String country = argCountry.getValue(); String language = argLanguage.isSet() ? argLanguage.getValue() : ""; Modified: trunk/shell/src/shell/org/jnode/shell/CommandRunner.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/CommandRunner.java 2009-06-01 10:49:03 UTC (rev 5536) +++ trunk/shell/src/shell/org/jnode/shell/CommandRunner.java 2009-06-01 14:32:48 UTC (rev 5537) @@ -36,9 +36,9 @@ import org.jnode.shell.help.HelpException; import org.jnode.shell.help.HelpFactory; -import org.jnode.shell.help.SyntaxErrorException; import org.jnode.shell.io.CommandIO; import org.jnode.shell.io.CommandOutput; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.vm.VmExit; /** @@ -90,7 +90,7 @@ try { prepare(); execute(); - } catch (SyntaxErrorException ex) { + } catch (CommandSyntaxException ex) { try { HelpFactory.getHelpFactory().getHelp(commandLine.getCommandName(), commandLine.getCommandInfo()).usage(shellErr); shellErr.println(ex.getMessage()); Modified: trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java 2009-06-01 10:49:03 UTC (rev 5536) +++ trunk/shell/src/shell/org/jnode/shell/DefaultCommandInvoker.java 2009-06-01 14:32:48 UTC (rev 5537) @@ -31,7 +31,7 @@ import java.security.PrivilegedActionException; import org.jnode.shell.help.HelpFactory; -import org.jnode.shell.help.SyntaxErrorException; +import org.jnode.shell.syntax.CommandSyntaxException; import org.jnode.shell.io.CommandIO; import org.jnode.vm.VmExit; @@ -127,7 +127,7 @@ throw ex2; } } - } catch (SyntaxErrorException ex) { + } catch (CommandSyntaxException ex) { HelpFactory.getHelpFactory().getHelp(cmdName, cmdInfo).usage(err); err.println(ex.getMessage()); } catch (VmExit ex) { Deleted: trunk/shell/src/shell/org/jnode/shell/help/SyntaxErrorException.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/SyntaxErrorException.java 2009-06-01 10:49:03 UTC (rev 5536) +++ trunk/shell/src/shell/org/jnode/shell/help/SyntaxErrorException.java 2009-06-01 14:32:48 UTC (rev 5537) @@ -1,33 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003-2009 JNode.org - * - * This library is free software; you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published - * by the Free Software Foundation; either version 2.1 of the License, or - * (at your option) any later version. - * - * This library 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 Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package org.jnode.shell.help; - -/** - * @author qades - */ -public class SyntaxErrorException extends HelpException { - - private static final long serialVersionUID = 1L; - - public SyntaxErrorException(String message) { - super(message); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |