IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 19, 2011, 3:19:06 PM (16 years ago)
Author:
eugene
Message:

plug a leak in vector math; fix the assign-from-command operator; add += and -=

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell/parse.c

    r30115 r30300  
    5151    }
    5252
     53    if (!strncmp (V1, "+=", 2)) {
     54        V1 ++;
     55        if (*V1 == 0) goto error;
     56        V1 ++;
     57        if (*V1 == 0) goto error;
     58
     59        val = get_variable (V0);
     60        if (val == NULL) {
     61            fval = 0.0;
     62        } else {
     63            fval = atof (val);
     64        }
     65
     66        /* dvomath returns a new string, or NULL, with the result of the expression */
     67        val = dvomath (1, &V1, &size, 0);
     68        if (val == NULL) goto error;
     69        fval += atof(val);
     70        // save the result
     71        set_variable (V0, fval);
     72        goto escape;
     73    }
     74
     75    if (!strncmp (V1, "-=", 2)) {
     76        V1 ++;
     77        if (*V1 == 0) goto error;
     78        V1 ++;
     79        if (*V1 == 0) goto error;
     80
     81        val = get_variable (V0);
     82        if (val == NULL) {
     83            fval = 0.0;
     84        } else {
     85            fval = atof (val);
     86        }
     87
     88        /* dvomath returns a new string, or NULL, with the result of the expression */
     89        val = dvomath (1, &V1, &size, 0);
     90        if (val == NULL) goto error;
     91        fval -= atof(val);
     92        // save the result
     93        set_variable (V0, fval);
     94        goto escape;
     95    }
     96
    5397    /* not an assignement, syntax error */
    5498    if (*V1 != '=') goto error;
     
    90134        }
    91135      }
    92     }
     136      // save the resulting value
     137      set_str_variable (V0, val);
     138      goto escape;  /* frees temp variables */
     139    }
    93140
    94141    /* simple variable assignment */
     
    99146      val = strcreate (V1);
    100147    }
    101     /* both dvomath and command replacement create (char *) val */
     148    // save the result
    102149    set_str_variable (V0, val);
    103150    goto escape;  /* frees temp variables */
Note: See TracChangeset for help on using the changeset viewer.