|
From: <cr...@us...> - 2009-04-26 14:28:12
|
Revision: 5350
http://jnode.svn.sourceforge.net/jnode/?rev=5350&view=rev
Author: crawley
Date: 2009-04-26 14:28:11 +0000 (Sun, 26 Apr 2009)
Log Message:
-----------
Fix bjorne so that builtins are only recognized if they first word
of a "simple command" matches a builtin command name BEFORE any expansion.
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java
trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-04-26 14:25:50 UTC (rev 5349)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-04-26 14:28:11 UTC (rev 5350)
@@ -983,7 +983,7 @@
throw new ShellFailureException("not implemented");
}
- int execute(CommandLine command, CommandIO[] streams) throws ShellException {
+ int execute(CommandLine command, CommandIO[] streams, boolean isBuiltin) throws ShellException {
if (isEchoExpansions()) {
StringBuilder sb = new StringBuilder();
sb.append(" + ").append(command.getCommandName());
@@ -993,7 +993,7 @@
resolvePrintStream(streams[Command.STD_ERR]).println(sb);
}
Map<String, String> env = buildEnvFromExports();
- lastReturnCode = interpreter.executeCommand(command, this, streams, null, env);
+ lastReturnCode = interpreter.executeCommand(command, this, streams, null, env, isBuiltin);
return lastReturnCode;
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2009-04-26 14:25:50 UTC (rev 5349)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneInterpreter.java 2009-04-26 14:28:11 UTC (rev 5350)
@@ -130,7 +130,7 @@
public static final int FLAG_PIPE = 0x0010;
public static final CommandNode EMPTY =
- new SimpleCommandNode(CMD_EMPTY, new BjorneToken[0]);
+ new SimpleCommandNode(CMD_EMPTY, new BjorneToken[0], false);
private static HashMap<String, BjorneBuiltin> BUILTINS =
new HashMap<String, BjorneBuiltin>();
@@ -327,14 +327,18 @@
this.shell = shell;
}
}
+
+ static boolean isBuiltin(String commandWord) {
+ return BUILTINS.containsKey(commandWord);
+ }
int executeCommand(CommandLine cmdLine, BjorneContext context, CommandIO[] streams,
- Properties sysProps, Map<String, String> env)
+ Properties sysProps, Map<String, String> env, boolean isBuiltin)
throws ShellException {
- BjorneBuiltin builtin = BUILTINS.get(cmdLine.getCommandName());
- if (builtin != null) {
+ if (isBuiltin) {
// FIXME ... built-in commands should use the Syntax mechanisms so
- // that completion, help, etc work as expected.
+ // that completion, help, etc will work as expected.
+ BjorneBuiltin builtin = BUILTINS.get(cmdLine.getCommandName());
return builtin.invoke(cmdLine, this, context);
} else {
cmdLine.setStreams(streams);
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java 2009-04-26 14:25:50 UTC (rev 5349)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneParser.java 2009-04-26 14:28:11 UTC (rev 5350)
@@ -276,6 +276,7 @@
List<BjorneToken> assignments = new LinkedList<BjorneToken>();
List<RedirectionNode> redirects = new LinkedList<RedirectionNode>();
List<BjorneToken> words = new LinkedList<BjorneToken>();
+ boolean builtin = false;
// Deal with cmd_prefix'es before the command name; i.e. assignments and
// redirections
@@ -334,12 +335,19 @@
break LOOP;
}
}
+ if (words.size() > 0) {
+ String commandWord = words.get(0).getText();
+ builtin = BjorneInterpreter.isBuiltin(commandWord);
+ // FIXME ... built-in commands should use the Syntax mechanisms so
+ // that completion, help, etc will work as expected.
+ }
} else {
// An empty command is legal, as are assignments and redirections
// w/o a command.
}
SimpleCommandNode res =
- new SimpleCommandNode(CMD_COMMAND, words.toArray(new BjorneToken[words.size()]));
+ new SimpleCommandNode(CMD_COMMAND,
+ words.toArray(new BjorneToken[words.size()]), builtin);
if (!redirects.isEmpty()) {
res.setRedirects(redirects.toArray(new RedirectionNode[redirects.size()]));
}
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java 2009-04-26 14:25:50 UTC (rev 5349)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/SimpleCommandNode.java 2009-04-26 14:28:11 UTC (rev 5350)
@@ -36,10 +36,13 @@
private BjorneToken[] assignments;
private final BjorneToken[] words;
+
+ private final boolean builtin;
- public SimpleCommandNode(int nodeType, BjorneToken[] words) {
+ public SimpleCommandNode(int nodeType, BjorneToken[] words, boolean builtin) {
super(nodeType);
this.words = words;
+ this.builtin = builtin;
}
public void setAssignments(BjorneToken[] assignments) {
@@ -54,6 +57,10 @@
return assignments;
}
+ public boolean isBuiltin() {
+ return builtin;
+ }
+
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("SimpleCommand{").append(super.toString());
@@ -61,6 +68,9 @@
sb.append(",assignments=");
appendArray(sb, assignments);
}
+ if (builtin) {
+ sb.append(",builtin=true");
+ }
if (words != null) {
sb.append(",words=");
appendArray(sb, words);
@@ -99,7 +109,7 @@
throw new ShellFailureException(
"asynchronous execution (&) not implemented yet");
} else {
- rc = childContext.execute(command, ios);
+ rc = childContext.execute(command, ios, builtin);
}
}
} finally {
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-04-26 14:25:50 UTC (rev 5349)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-builtin-tests.xml 2009-04-26 14:28:11 UTC (rev 5350)
@@ -74,4 +74,22 @@
<output>fred='ls'
</output>
</testSpec>
+ <testSpec title="builtins recognized early" command="test"
+ runMode="AS_SCRIPT" rc="0" trapException="org.jnode.shell.ShellException">
+ <script>#!bjorne
+ alias fred=ls
+ alias
+ unalias -a
+ echo done
+ UNALIAS=unalias
+ alias fred=dir
+ alias
+ $UNALIAS -a
+ echo done
+ </script>
+ <output>fred='ls'
+done
+fred='dir'
+</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.
|