|
From: <cr...@us...> - 2009-03-29 07:24:25
|
Revision: 5175
http://jnode.svn.sourceforge.net/jnode/?rev=5175&view=rev
Author: crawley
Date: 2009-03-29 07:24:21 +0000 (Sun, 29 Mar 2009)
Log Message:
-----------
Added 'unalias' and fixed bugs in 'alias'.
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml
Added Paths:
-----------
trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java 2009-03-29 04:20:40 UTC (rev 5174)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/AliasBuiltin.java 2009-03-29 07:24:21 UTC (rev 5175)
@@ -40,10 +40,11 @@
BjorneContext context) throws ShellException {
Iterator<String> args = command.iterator();
context = context.getParent();
- PrintStream ps = context.resolvePrintStream(context.getIO(Command.STD_ERR));
+ PrintStream out = context.resolvePrintStream(context.getIO(Command.STD_OUT));
+ PrintStream err = context.resolvePrintStream(context.getIO(Command.STD_ERR));
int rc = 0;
if (!args.hasNext()) {
- printAliases(ps, context.getAliases());
+ printAliases(out, context.getAliases());
} else {
while (args.hasNext()) {
String arg = args.next();
@@ -60,14 +61,14 @@
if (alias == null) {
alias = context.getAlias(aliasName);
if (alias == null) {
- error("alias: " + aliasName + " not found", context);
+ err.println("alias: " + aliasName + " not found");
rc = 1;
} else {
- printAlias(ps, aliasName, alias);
+ printAlias(out, aliasName, alias);
}
} else {
if (!BjorneToken.isName(aliasName)) {
- error("alias: " + aliasName + ": not a valid alias name", context);
+ err.println("alias: " + aliasName + ": not a valid alias name");
}
context.defineAlias(aliasName, alias);
}
@@ -83,7 +84,7 @@
}
private void printAlias(PrintStream ps, String aliasName, String alias) {
- ps.println(aliasName + "=" + alias);
+ ps.println(aliasName + "='" + alias + "'");
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2009-03-29 04:20:40 UTC (rev 5174)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2009-03-29 07:24:21 UTC (rev 5175)
@@ -148,8 +148,9 @@
BUILTINS.put("return", new ReturnBuiltin());
BUILTINS.put("set", new SetBuiltin());
BUILTINS.put("shift", new ShiftBuiltin());
+ BUILTINS.put("source", new SourceBuiltin());
+ BUILTINS.put("unalias", new UnaliasBuiltin());
BUILTINS.put(".", new SourceBuiltin());
- BUILTINS.put("source", new SourceBuiltin());
BUILTINS.put(":", new ColonBuiltin());
}
Added: trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/UnaliasBuiltin.java 2009-03-29 07:24:21 UTC (rev 5175)
@@ -0,0 +1,60 @@
+/*
+ * $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.bjorne;
+
+import java.io.PrintStream;
+import java.util.Iterator;
+
+import org.jnode.shell.Command;
+import org.jnode.shell.CommandLine;
+import org.jnode.shell.ShellException;
+
+/**
+ * This class implements the 'unalias' built-in.
+ *
+ * @author cr...@jn...
+ */
+final class UnaliasBuiltin extends BjorneBuiltin {
+ @SuppressWarnings("deprecation")
+ public int invoke(CommandLine command, BjorneInterpreter interpreter,
+ BjorneContext context) throws ShellException {
+ Iterator<String> args = command.iterator();
+ context = context.getParent();
+ PrintStream err = context.resolvePrintStream(context.getIO(Command.STD_ERR));
+ int rc = 0;
+ while (args.hasNext()) {
+ String arg = args.next();
+ if (arg.equals("-a")) {
+ context.getAliases().clear();
+ break;
+ } else {
+ String alias = context.getAlias(arg);
+ if (alias == null) {
+ err.println("alias: " + arg + " not found");
+ rc = 1;
+ } else {
+ context.undefineAlias(arg);
+ }
+ }
+ }
+ return rc;
+ }
+}
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml 2009-03-29 04:20:40 UTC (rev 5174)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml 2009-03-29 07:24:21 UTC (rev 5175)
@@ -24,4 +24,30 @@
<error>alias: fred not found
</error>
</testSpec>
+ <testSpec title="alias 3" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ alias fred=ls
+ alias fred
+ alias jim="echo hi"
+ alias jim
+ alias
+ </script>
+ <output>fred='ls'
+jim='echo hi'
+fred='ls'
+jim='echo hi'
+</output>
+ </testSpec>
+ <testSpec title="unalias" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ alias fred=ls
+ alias jim="echo hi"
+ unalias jim
+ alias
+ unalias -a
+ alias
+ </script>
+ <output>fred='ls'
+</output>
+ </testSpec>
</testSet>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|