Index: trunk/Ohana/src/opihi/lib.shell/parse.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 10073)
+++ trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 15878)
@@ -1,11 +1,9 @@
 # include "opihi.h"
 
-void interpolate_slash (char *line);
-
 char *parse (char *line) {
 
   double fval;
-  char *newline, *N, *L, *val, *B, *V, *V0, *V1, *end, *c1, *c2;
-  int Nval, Nbytes, status, size;
+  char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p;
+  int Nval, Nbytes, status, size, NLINE;
   FILE *f;
   Vector *vec;
@@ -64,4 +62,5 @@
 
       /* val will hold the result */
+      // XXX this is limiting!!!
       ALLOCATE (val, char, 1024);
 
@@ -153,19 +152,24 @@
 
   /* case 3: {expression} */
-  ALLOCATE (newline, char, 1024);
-  for (L = line, N = newline; *L != 0; L++, N++) { 
-
-    /* copy elements from L (line) to N (newline) until we hit a '{' */
-    for (; (*L != '{') && (*L != 0); L++, N++) *N = *L;
-    if (*L == 0) break;
-
-    if ((L != line) && (*(L-1) == 0x5c)) {
-      N--;
-      *N = *L;
+  NLINE = MAX (128, strlen (line));
+  ALLOCATE (newline, char, NLINE);
+  memset (newline, 0, NLINE);
+  for (L = line; *L != 0; ) { 
+
+    // copy elements from L (line) to newline up to first '{'
+    p = strchr (L, '{');
+    newline = opihi_append (newline, &NLINE, L, p);
+    if (p == NULL) break;
+    L = p + 1;
+
+    // check for \{ at this point, replace \ in newline with {
+    if ((p > line) && (*(p - 1) == 0x5c)) {
+      N = newline + strlen(newline) - 1;
+      *N = '{'; // replace \ with {
       continue;
     }
 
     /* check on the syntax of the line */
-    L++;
+    L = p + 1;
     c1 = strchr (L, '}');
     if (c1 == NULL) {
@@ -178,5 +182,4 @@
       goto escape;
     }
-    end = c1;
     *c1 = 0;
 
@@ -188,12 +191,13 @@
       goto escape;
     } 
+
+    /* interpolate vector element into newline (being accumulated) */
+    newline = opihi_append (newline, &NLINE, val, NULL);
+
     /* copy val to outline */
-    for (V = val; *V != 0; V++,N++) *N = *V;
-    L = end;
-    N--;
+    L = c1 + 1;
     free (val); val = (char *) NULL;
   }
-  
-  *N = 0;
+
   free (line); line = (char *) NULL;
 
@@ -204,8 +208,8 @@
   return (newline); 
 
-  error:
+error:
   gprint (GP_ERR, "syntax error\n");
 
-  escape:
+escape:
   if (line != (char *) NULL) free (line);
   if (val != (char *) NULL) free (val);
@@ -214,46 +218,33 @@
 }
 
-/* replace all instances of \A with A in line */
-void interpolate_slash (char *line) {
-
-  char *in, *out;
-
-  for (in = out = line; *in != 0; in++, out++) {
-    if (*in == 0x5c) in++;
-    *out = *in;
-    if (*in == 0) return;
-  }
-  *out = *in;
-}
-
-  /* this routine looks for math and/or logic expressions that 
-     need to be evaluated and passes them on to "parenthesis",
-     which evaluates the expression */
-
-  /* There are two situations now which define an expression to 
-     be evaluated:
-     1) $var = expression   -- everything after the = must be a math expression or a string
-     2) {expression}        -- everything within the {} must be a math expression
-   */
-
-  /* case 1: $var = expression.  test that
-     a) there is a $ as the first character
-     b) the variable defined by that $ is not null
-     c) there is an = sign following the variable
-     d) there is something following the = sign
-     */
+/* this routine looks for math and/or logic expressions that 
+   need to be evaluated and passes them on to "parenthesis",
+   which evaluates the expression */
+
+/* There are two situations now which define an expression to 
+   be evaluated:
+   1) $var = expression   -- everything after the = must be a math expression or a string
+   2) {expression}        -- everything within the {} must be a math expression
+*/
+
+/* case 1: $var = expression.  test that
+   a) there is a $ as the first character
+   b) the variable defined by that $ is not null
+   c) there is an = sign following the variable
+   d) there is something following the = sign
+*/
   
-  /* case 2: vect[N] = expression. check syntax:
-     a) last char must be ]
-     b) word must contain [
-     c) between [ & ] must be an integer
-     d) vector must exist
-     e) there is an = sign following the first word
-     f) there is something following the = sign
-  */
+/* case 2: vect[N] = expression. check syntax:
+   a) last char must be ]
+   b) word must contain [
+   c) between [ & ] must be an integer
+   d) vector must exist
+   e) there is an = sign following the first word
+   f) there is something following the = sign
+*/
      
 
-  /* case 3: we hunt for '{', and then the first '}' and pass everything
-     inbetween.  no nested {{}}s are allowed! */
+/* case 3: we hunt for '{', and then the first '}' and pass everything
+   inbetween.  no nested {{}}s are allowed! */
   
 /* thisword ALLOCATES
