|
From: <cr...@us...> - 2009-03-21 01:13:55
|
Revision: 5134
http://jnode.svn.sourceforge.net/jnode/?rev=5134&view=rev
Author: crawley
Date: 2009-03-21 01:13:41 +0000 (Sat, 21 Mar 2009)
Log Message:
-----------
Implemented expansion of HERE documents.
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java
trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java
trunk/shell/src/shell/org/jnode/shell/bjorne/RedirectionNode.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-03-20 20:42:48 UTC (rev 5133)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-03-21 01:13:41 UTC (rev 5134)
@@ -1056,8 +1056,11 @@
switch (redir.getRedirectionType()) {
case REDIR_DLESS:
case REDIR_DLESSDASH:
- // FIXME do expansion
- in = new CommandInput(new StringReader(redir.getHereDocument()));
+ String here = redir.getHereDocument();
+ if (redir.isHereDocumentExpandable()) {
+ here = expand(here).toString();
+ }
+ in = new CommandInput(new StringReader(here));
stream = new CommandIOHolder(in, true);
break;
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java 2009-03-20 20:42:48 UTC (rev 5133)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneTokenizer.java 2009-03-21 01:13:41 UTC (rev 5134)
@@ -252,6 +252,14 @@
throw new UnsupportedOperationException("remove not supported");
}
+ /**
+ * This method bypasses normal tokenization and reads a raw line of
+ * text up to the next NL (or the end of stream).
+ *
+ * @param trimTabs if {@code true}, trim any leading TABs from the line
+ * @return the line read without the terminating NL. If we got an
+ * end of stream immediately, return {@code null}.
+ */
public String readHereLine(boolean trimTabs) {
StringBuilder sb = new StringBuilder(40);
while (true) {
Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/RedirectionNode.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/bjorne/RedirectionNode.java 2009-03-20 20:42:48 UTC (rev 5133)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/RedirectionNode.java 2009-03-21 01:13:41 UTC (rev 5134)
@@ -26,8 +26,10 @@
private final BjorneToken io;
private final BjorneToken arg;
+
+ private String hereDocument;
- private String hereDocument;
+ private boolean expandable = true;
public RedirectionNode(final int redirectionType, BjorneToken io,
BjorneToken arg) {
@@ -50,6 +52,8 @@
}
public void setHereDocument(String hereDocument) {
+ // FIXME ... should analyze the document and set 'expandable'
+ // if there anything that requires expansion.
this.hereDocument = hereDocument;
}
@@ -70,4 +74,8 @@
sb.append("}");
return sb.toString();
}
+
+ public boolean isHereDocumentExpandable() {
+ return expandable;
+ }
}
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-03-20 20:42:48 UTC (rev 5133)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-03-21 01:13:41 UTC (rev 5134)
@@ -639,6 +639,32 @@
Hi mum again
</file>
</testSpec>
+ <testSpec title="here 2" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ for i in 1 2 3 4 5 ; do cat <<EOF ; done
+Hi mum $i
+EOF
+ </script>
+ <output>Hi mum 1
+Hi mum 2
+Hi mum 3
+Hi mum 4
+Hi mum 5
+</output>
+ </testSpec>
+ <testSpec title="here 3" command="test" runMode="AS_SCRIPT" rc="0">
+ <script>#!bjorne
+ for i in 1 2 3 4 5 ; do cat <<EOF ; done
+Hi mum `echo $i`
+EOF
+ </script>
+ <output>Hi mum 1
+Hi mum 2
+Hi mum 3
+Hi mum 4
+Hi mum 5
+</output>
+ </testSpec>
<testSpec title="pipeline" command="test" runMode="AS_SCRIPT" rc="0">
<script>#!bjorne
echo > @TEMP_DIR@/1 Hi mum
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|