Patch:    ivtools-131114-scott-004
For:      ivtools-1.2.11
Author:   scott@wavesemi.com
Subject:  fix problem with command arguments that are expressions that start with left paren

This is an intermediate patch to ivtools-1.2.11.  To apply, cd to the
top-level directory of the ivtools source tree (the directory with src
and config subdirs), and apply like this:

	patch -p0 <ThisFile

Then rebuild with "make;make install"


Index: src/ComTerp/ctrlfunc.c
===================================================================
--- src/ComTerp/ctrlfunc.c	(revision 8263)
+++ src/ComTerp/ctrlfunc.c	(revision 8287)
@@ -418,7 +418,7 @@
         FuncObj* tokbuf = (FuncObj*)argv.obj_val();
         val = new ComValue(comterpserv()->run(tokbuf->toks(), tokbuf->ntoks()));
       }
-      if (val->is_nil() && symretv.is_true()) {
+      if (!val || val->is_nil() && symretv.is_true()) {
 	delete val;
 	val = new ComValue(argv.symbol_val(), AttributeValue::SymbolType);
       }
Index: src/ComUtil/_parser.c
===================================================================
--- src/ComUtil/_parser.c	(revision 8263)
+++ src/ComUtil/_parser.c	(revision 8287)
@@ -1097,11 +1097,27 @@
 
 	 }
 
-      /* If left paren was encountered without a proceeding identifier   */
-      /* it is not to be associated with a command.  Push it on the      */
-      /* paren stack with a -1 indicator for the command id to show such.*/
-      /* Push the negated value of the token type onto the operator      */
-      /* stack, in order to distinguish it from the other operators.     */
+      /* If left paren was encountered without a proceeding identifier */
+      /* it is not to be associated with a command.  First pop any     */
+      /* previous expression off the stack.  Then push it on the paren */
+      /* stack with a -1 indicator for the command id to show such.    */
+      /* Push the negated value of the token type onto the operator    */
+      /* stack, in order to distinguish it from the other operators.   */
+	 while ( (OperStack[TopOfOperStack].oper_type != LEFTPAREN) &&
+                 (TopOfOperStack >= 0 ))
+         {
+             if (OperStack[TopOfOperStack].oper_type == OPERATOR)
+             {
+                 OPERSTK_POP( temp_id );
+                 PFOUT( TOK_COMMAND, opr_tbl_commid( temp_id ),
+                      (opr_tbl_optype( temp_id ) == OPTYPE_BINARY ? 2 : 1), 0, 1 );
+             }
+             else
+             {
+                 OPERSTK_POP( temp_id );
+                 PFOUT( TOK_KEYWORD, temp_id, 1, 0, 0);
+             }
+	 }
 	 PARENSTK_PUSH( toktype, -1, 1 );
 	 OPERSTK_PUSH( -toktype, LEFTPAREN );
 
