Index: trunk/Ohana/src/opihi/lib.shell/parse.c
===================================================================
--- trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 27491)
+++ trunk/Ohana/src/opihi/lib.shell/parse.c	(revision 30614)
@@ -1,13 +1,15 @@
 # include "opihi.h"
 
-char *parse (char *line) {
+char *parse (int *status, char *line) {
 
   double fval;
   float *fptr;
   char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p;
-  int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange;
+  int Nx, Ny, Nbytes, filestatus, size, NLINE, isBuffer, inRange;
   FILE *f;
   Vector *vec;
   Buffer *buf;
+
+  *status = TRUE; 
 
   Ny = 0;
@@ -49,4 +51,48 @@
     }
 
+    if (!strncmp (V1, "+=", 2)) {
+	V1 ++;
+	if (*V1 == 0) goto error;
+	V1 ++;
+	if (*V1 == 0) goto error;
+
+	val = get_variable (V0);
+	if (val == NULL) {
+	    fval = 0.0;
+	} else {
+	    fval = atof (val);
+	}
+
+	/* dvomath returns a new string, or NULL, with the result of the expression */
+	val = dvomath (1, &V1, &size, 0);
+	if (val == NULL) goto error;
+	fval += atof(val);
+	// save the result
+	set_variable (V0, fval);
+	goto escape;
+    }
+
+    if (!strncmp (V1, "-=", 2)) {
+	V1 ++;
+	if (*V1 == 0) goto error;
+	V1 ++;
+	if (*V1 == 0) goto error;
+
+	val = get_variable (V0);
+	if (val == NULL) {
+	    fval = 0.0;
+	} else {
+	    fval = atof (val);
+	}
+
+	/* dvomath returns a new string, or NULL, with the result of the expression */
+	val = dvomath (1, &V1, &size, 0);
+	if (val == NULL) goto error;
+	fval -= atof(val);
+	// save the result
+	set_variable (V0, fval);
+	goto escape;
+    }
+
     /* not an assignement, syntax error */
     if (*V1 != '=') goto error;
@@ -73,8 +119,8 @@
       Nbytes = fread (val, 1, 1023, f);
       val[Nbytes] = 0;
-      status = pclose (f);
+      filestatus = pclose (f);
       free (B);
 
-      if (status) gprint (GP_ERR, "warning: exit status of command %d\n", status);
+      if (filestatus) gprint (GP_ERR, "warning: exit status of command %d\n", filestatus);
 
       /* convert all but last return to ' '.  drop last return */
@@ -88,16 +134,17 @@
 	}
       }
+      // save the resulting value
+      set_str_variable (V0, val);
+      goto escape;  /* frees temp variables */
+    }
+
+    /* simple variable assignment */
+    /* dvomath returns a new string, or NULL, with the result of the expression */
+    val = dvomath (1, &V1, &size, 0);
+    if (val == NULL) { 
+      while (OHANA_WHITESPACE (*V1)) V1++;
+      val = strcreate (V1);
     } 
-
-    /* simple variable assignment */
-    if (*V1 != '`') {
-      /* dvomath returns a new string, or NULL, with the result of the expression */
-      val = dvomath (1, &V1, &size, 0);
-      if (val == NULL) { 
-	while (OHANA_WHITESPACE (*V1)) V1++;
-	val = strcreate (V1);
-      } 
-    }
-    /* both dvomath and command replacement create (char *) val */
+    // save the result
     set_str_variable (V0, val);
     goto escape;  /* frees temp variables */
@@ -172,5 +219,5 @@
       if (!inRange) {
 	gprint (GP_ERR, "no element %d,%d\n", Nx, Ny);
-	goto escape;
+	goto error;
       }
       if (Nx < 0) Nx += buf[0].header.Naxis[0];
@@ -188,5 +235,5 @@
       if (!inRange) {
 	gprint (GP_ERR, "no element %d\n", Nx);
-	goto escape;
+	goto error;
       }
       if (Nx < 0) Nx += vec[0].Nelements;
@@ -197,5 +244,4 @@
       }
     }
-
     goto escape;
   }
@@ -226,10 +272,10 @@
     if (c1 == NULL) {
       gprint (GP_ERR, "no close brackets!\n");
-      goto escape;
+      goto error;
     }
     c2 = strchr (L, '{');
     if ((c2 != NULL) && (c2 < c1)) {
       gprint (GP_ERR, "can't nest brackets!\n");
-      goto escape;
+      goto error;
     }
     *c1 = 0;
@@ -240,5 +286,5 @@
     if (val == NULL) {
       print_error ();
-      goto escape;
+      goto error;
     } 
 
@@ -257,13 +303,22 @@
   
   REALLOCATE (newline, char, strlen (newline) + 1);
+  *status = TRUE;
   return (newline); 
 
 error:
   gprint (GP_ERR, "syntax error\n");
-
-escape:
+  // assignment or increment operation: free line and return NULL
   if (line != (char *) NULL) free (line);
   if (val != (char *) NULL) free (val);
   if (V0 != (char *) NULL) free (V0);
+  *status = FALSE;
+  return NULL;
+
+escape:
+  // assignment or increment operation: free line and return NULL
+  if (line != (char *) NULL) free (line);
+  if (val != (char *) NULL) free (val);
+  if (V0 != (char *) NULL) free (V0);
+  *status = TRUE;
   return (NULL);
 }
