|
From: <cr...@us...> - 2009-02-24 15:28:40
|
Revision: 5063
http://jnode.svn.sourceforge.net/jnode/?rev=5063&view=rev
Author: crawley
Date: 2009-02-24 15:28:36 +0000 (Tue, 24 Feb 2009)
Log Message:
-----------
Implement '( <cmd> ; ... ) > file '
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
trunk/shell/src/shell/org/jnode/shell/bjorne/ListCommandNode.java
trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-02-24 13:33:41 UTC (rev 5062)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-02-24 15:28:36 UTC (rev 5063)
@@ -942,6 +942,12 @@
holders[index].setStream(stream, mine);
}
}
+
+ void closeStreams() {
+ for (StreamHolder holder : holders) {
+ holder.close();
+ }
+ }
void performAssignments(BjorneToken[] assignments) throws ShellException {
if (assignments != null) {
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/ListCommandNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/ListCommandNode.java 2009-02-24 13:33:41 UTC (rev 5062)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/ListCommandNode.java 2009-02-24 15:28:36 UTC (rev 5063)
@@ -71,44 +71,55 @@
@Override
public int execute(BjorneContext context) throws ShellException {
+ int listFlags = getFlags();
int rc = 0;
- if (getNodeType() == BjorneInterpreter.CMD_SUBSHELL) {
- // This simulates creating a 'subshell'.
- context = new BjorneContext(context);
- }
- int listFlags = getFlags();
- if ((listFlags & BjorneInterpreter.FLAG_PIPE) != 0) {
- PipelineStage[] stages = assemblePipeline(context);
- boolean done = false;
- try {
- rc = runPipeline(stages);
- done = true;
- } finally {
- if (!done) {
- // If we are propagating an exception, all streams that
- // were opened by 'assemblePipeline' must be closed.
- for (PipelineStage stage : stages) {
- for (StreamHolder holder : stage.holders) {
- holder.close();
- }
- }
+ try {
+ if (getNodeType() == BjorneInterpreter.CMD_SUBSHELL) {
+ // This simulates creating a 'subshell'.
+ context = new BjorneContext(context);
+ StreamHolder[] holders = context.evaluateRedirections(getRedirects());
+ for (int i = 0; i < holders.length; i++) {
+ CommandIO stream = holders[i].getStream();
+ context.setStream(i, stream, holders[i].isMine());
}
}
- } else {
- for (CommandNode command : commands) {
- int commandFlags = command.getFlags();
- if ((commandFlags & BjorneInterpreter.FLAG_AND_IF) != 0) {
- if (context.getLastReturnCode() != 0) {
- break;
+ if ((listFlags & BjorneInterpreter.FLAG_PIPE) != 0) {
+ PipelineStage[] stages = assemblePipeline(context);
+ boolean done = false;
+ try {
+ rc = runPipeline(stages);
+ done = true;
+ } finally {
+ if (!done) {
+ // If we are propagating an exception, all streams that
+ // were opened by 'assemblePipeline' must be closed.
+ for (PipelineStage stage : stages) {
+ for (StreamHolder holder : stage.holders) {
+ holder.close();
+ }
+ }
}
}
- if ((commandFlags & BjorneInterpreter.FLAG_OR_IF) != 0) {
- if (context.getLastReturnCode() == 0) {
- break;
+ } else {
+ for (CommandNode command : commands) {
+ int commandFlags = command.getFlags();
+ if ((commandFlags & BjorneInterpreter.FLAG_AND_IF) != 0) {
+ if (context.getLastReturnCode() != 0) {
+ break;
+ }
}
+ if ((commandFlags & BjorneInterpreter.FLAG_OR_IF) != 0) {
+ if (context.getLastReturnCode() == 0) {
+ break;
+ }
+ }
+ rc = command.execute(context);
}
- rc = command.execute(context);
}
+ } finally {
+ if (getNodeType() == BjorneInterpreter.CMD_SUBSHELL) {
+ context.closeStreams();
+ }
}
if ((listFlags & BjorneInterpreter.FLAG_BANG) != 0) {
rc = (rc == 0) ? -1 : 0;
Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml
===================================================================
--- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-02-24 13:33:41 UTC (rev 5062)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-02-24 15:28:36 UTC (rev 5063)
@@ -629,4 +629,45 @@
<error>Hello mother again
</error>
</testSpec>
+ <testSpec title="pipeline" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ echo > @TEMP_DIR@/1 Hi mum
+ echo > @TEMP_DIR@/2 Hi mum again
+ cat @TEMP_DIR@/1 @TEMP_DIR@/2 @TEMP_DIR@/1 @TEMP_DIR@/2 | cat
+ cat @TEMP_DIR@/1 @TEMP_DIR@/2 @TEMP_DIR@/1 @TEMP_DIR@/2 | cat > @TEMP_DIR@/3
+ </script>
+ <file name="1" input="false">Hi mum
+</file>
+ <file name="2" input="false">Hi mum again
+</file>
+ <file name="3" input="false">Hi mum
+Hi mum again
+Hi mum
+Hi mum again
+</file>
+ <output>Hi mum
+Hi mum again
+Hi mum
+Hi mum again
+</output>
+ </testSpec>
+ <testSpec title="subshell" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ echo > @TEMP_DIR@/1 Hi mum
+ echo > @TEMP_DIR@/2 Hi mum again
+ ( cat @TEMP_DIR@/1 ; cat @TEMP_DIR@/2 )
+ ( cat @TEMP_DIR@/1 ; cat @TEMP_DIR@/2 ) > @TEMP_DIR@/3
+ </script>
+ <file name="1" input="false">Hi mum
+</file>
+ <file name="2" input="false">Hi mum again
+</file>
+ <file name="3" input="false">Hi mum
+Hi mum again
+</file>
+ <output>Hi mum
+Hi mum again
+</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.
|