IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 16, 2007, 2:27:00 PM (18 years ago)
Author:
eugene
Message:

fixed cases of hard-wired line length; some api cleanup in stack_math

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r15006 r15878  
    2222  if (*Nstack == 1) {
    2323    if (stack[0].type == 'S') {
    24       free (tmp_stack.name);
     24      clear_stack (&tmp_stack);
    2525      return (TRUE);
    2626    }
     
    3838    }
    3939    push_error ("syntax error: not a math expression");
    40     free (tmp_stack.name);
     40    clear_stack (&tmp_stack);
    4141    return (FALSE);
    4242  }     
     
    6363        sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name);
    6464        push_error (line);
    65         free (tmp_stack.name);
     65        clear_stack (&tmp_stack);
    6666        return (FALSE);
    6767      }
     
    8484        sprintf (line, "syntax error: invalid operand for binary operation: %s or %s\n", stack[i-1].name, stack[i-2].name);
    8585        push_error (line);
    86         free (tmp_stack.name);
     86        clear_stack (&tmp_stack);
    8787        return (FALSE);
    8888      }
     
    9090      delete_stack (&stack[i-1], 2);
    9191      for (j = i + 1; j < *Nstack; j++) {
    92         copy_stack (&stack[j - 2], &stack[j]);
     92        move_stack (&stack[j - 2], &stack[j]);
    9393      }
    9494      *Nstack -= 2;
     
    103103      if (i < 1) {  /* need one variable to operate on */
    104104        push_error ("syntax error: unary operator with no operand");
    105         free (tmp_stack.name);
    106         return (FALSE);
    107       }
    108      
     105        clear_stack (&tmp_stack);
     106        return (FALSE);
     107      }
     108
    109109      ONE_OP ("M", M_unary);
    110110      ONE_OP ("V", V_unary);
     
    114114      if (!strncasecmp (&stack[i - 1].type, "W", 1)) {
    115115        push_error ("syntax error: no valid string unary ops");
    116         free (tmp_stack.name);
     116        clear_stack (&tmp_stack);
    117117        return (FALSE);
    118118      }
     
    121121      delete_stack (&stack[i], 1);
    122122      for (j = i + 1; j < *Nstack; j++) {
    123         copy_stack (&stack[j - 1], &stack[j]);
     123        move_stack (&stack[j - 1], &stack[j]);
    124124      }
    125125      init_stack (&tmp_stack);
     
    129129    }
    130130  }
    131   free (tmp_stack.name);
     131  clear_stack (&tmp_stack);
    132132
    133133  if (*Nstack > 1) {
     
    153153/* replace data with new stack variable */
    154154void move_stack (StackVar *stack1, StackVar *stack2) {
    155   if (stack1[0].name != (char *) NULL)
    156     free (stack1[0].name);
     155  clear_stack (stack1);
    157156  copy_stack (stack1, stack2);
     157  stack2[0].name = NULL;
    158158}
    159159
     
    178178    }   
    179179    if (VERBOSE) gprint (GP_ERR, "free %s (name) (%d) (%lx)\n", stack[i].name, i, (long) stack[i].name);
    180     free (stack[i].name);
    181     stack[i].name = NULL;
     180    clear_stack (&stack[i]);
    182181  }
    183182
     
    188187  int i;
    189188  for (i = 0; i < Nstack; i++) {
    190     free (stack[i].name);
     189    clear_stack (&stack[i]);
    191190  }
    192191}
     
    195194  stack[0].buffer = NULL;
    196195  stack[0].vector = NULL;
    197   stack[0].name = strncreate ("tmp", NCHARS);
    198 }
     196  stack[0].name = NULL;
     197}
     198
     199void assign_stack (StackVar *stack, char *name, int type) {
     200  stack->name = strcreate (name);
     201  stack->type = type;
     202}
     203
     204void clear_stack (StackVar *stack) {
     205  if (stack->name == NULL) return;
     206  free (stack->name);
     207  stack->name = NULL;
     208  return;
     209}
Note: See TracChangeset for help on using the changeset viewer.