IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30300


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

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

Location:
branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell
Files:
3 edited

Legend:

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

    r15878 r30300  
    6464    /* variable assignment (skip these variables) */
    6565    if ((L == line) && (V1 != NULL)) {
    66       if ((*V1 == '=') || !strcmp (V1, "++") || !strcmp (V1, "--")) {
     66      int isAssignment;
     67
     68      isAssignment = FALSE;
     69      isAssignment |= (V1[0] == '=');
     70      isAssignment |= (V1[0] == '+') && (V1[1] == '=');
     71      isAssignment |= (V1[0] == '-') && (V1[1] == '=');
     72      isAssignment |= (V1[0] == '+') && (V1[1] == '+');
     73      isAssignment |= (V1[0] == '-') && (V1[1] == '-');
     74
     75      if (isAssignment) {
    6776        *N = *L;
    6877        free (V0);
  • 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 */
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell/stack_math.c

    r27435 r30300  
    972972        *out = OP;                                              \
    973973      }                                                         \
    974       clear_stack (V1);                                         \
    975       return (TRUE);                                            \
     974      goto escape;                                              \
    976975    }                                                           \
    977976    if ((V1->vector->type == OPIHI_INT) && (FTYPE == 'S')) {    \
     
    982981        *out = OP;                                              \
    983982      }                                                         \
    984       clear_stack (V1);                                         \
    985       return (TRUE);                                            \
     983      goto escape;                                              \
    986984    }                                                           \
    987985    if ((V1->vector->type == OPIHI_INT) && (FTYPE == 's')) {    \
     
    992990        *out = OP;                                              \
    993991      }                                                         \
    994       clear_stack (V1);                                         \
    995       return (TRUE);                                            \
     992      goto escape;                                              \
    996993    } }                                                 
    997994
     
    10351032# undef V_FUNC
    10361033
     1034escape:
     1035
    10371036  if (V1[0].type == 'v') {
    10381037    free (V1[0].vector[0].elements.Ptr);
Note: See TracChangeset for help on using the changeset viewer.