Revision: 5658
          http://jnode.svn.sourceforge.net/jnode/?rev=5658&view=rev
Author:   crawley
Date:     2009-08-21 13:24:37 +0000 (Fri, 21 Aug 2009)

Log Message:
-----------
Arithmetic Expression evaluation using $((...)) now works ... modulo
that the POSIX spec is so unclear that it is difficult to figure
out exactly what is correct in edge-cases.

Modified Paths:
--------------
    trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.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-08-20 15:31:54 UTC (rev 5657)
+++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java     
2009-08-21 13:24:37 UTC (rev 5658)
@@ -1029,10 +1029,6 @@
     }
     
     private CharSequence dollarParenParenExpand(CharIterator ci) throws 
ShellException {
-        // Different shells handle $(( ... )) differently, but dash seems to 
do what 
-        // the POSIX spec seems to say.  In the first phase, we look for the 
matching '))'
-        // keeping track of nested parentheses and performing any $ 
expansions.  Double
-        // quotes should be treated as literal.
         StringBuilder sb = new StringBuilder();
         int nesting = 0;
         boolean done = false;
@@ -1054,16 +1050,15 @@
                         sb.append(')');
                     }
                     break;
-                case '$':
-                    sb.append(dollarExpand(ci, '\000'));
-                    break;
                 case -1:
                     throw new ShellSyntaxException("Unmatched \"((\" (double 
left parenthesis)");
                 default:
                     sb.append((char) ch);
             }
+            ci.nextCh();
         } while (!done);
-        return new BjorneArithmeticEvaluator(this).evaluateExpression(sb);
+        CharSequence tmp = dollarBacktickExpand(new CharIterator(sb), '\000');
+        return new BjorneArithmeticEvaluator(this).evaluateExpression(tmp);
     }
 
     int execute(CommandLine command, CommandIO[] streams, boolean isBuiltin) 
throws ShellException {

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-08-20 15:31:54 UTC (rev 5657)
+++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml     
2009-08-21 13:24:37 UTC (rev 5658)
@@ -98,6 +98,20 @@
 1 1
 </output>
     </testSpec>
+    <testSpec title="$((...))" command="test" runMode="AS_SCRIPT" rc="0">
+        <script>#!bjorne
+A=1
+echo $A
+B="$((A + 1))"
+echo $B
+C="$(($B + 1))"
+echo $C
+</script>
+        <output>1
+2
+3
+</output>
+    </testSpec>
     <testSpec title="if ... then ... fi" command="test" runMode="AS_SCRIPT" 
rc="0">
         <script>#!bjorne
 if true ; then echo HI ; fi


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to