IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2792 for trunk/Ohana/src/opihi


Ignore:
Timestamp:
Dec 22, 2004, 1:23:23 PM (22 years ago)
Author:
eugene
Message:

fixing dvomath for strings

Location:
trunk/Ohana/src/opihi
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.basic/run_if.c

    r2598 r2792  
    3030  /* determine value of conditional expression */
    3131  val = dvomath (1, &argv[1], &size, 0);
    32   if (val == NULL) { /* try expression as string op string */
    33     char **stack;
    34     int Nstack;
     32  if (val == NULL) return (FALSE);
     33  logic = atof (val); /* warning: round-off error is a danger */
    3534
    36     stack = isolate_elements (1, &argv[1], &Nstack);
    37     if (Nstack != 5) goto syntax;
    38     if (strcmp (stack[0], "(")) goto syntax;
    39     if (strcmp (stack[4], ")")) goto syntax;
    40     equals = -1;
    41     if (!strcmp (stack[2], "==")) equals = TRUE;
    42     if (!strcmp (stack[2], "!=")) equals = TRUE;
    43     if (equals == -1) goto syntax;
    44     logic = FALSE;
    45     if (equals && !strcmp (stack[1], stack[3])) logic = TRUE;
    46     if (!equals && strcmp (stack[1], stack[3])) logic = TRUE;
    47   } else {
    48     logic = atof (val); /* warning: round-off error is a danger */
    49   }
    5035  if (BreakOnTrue) {
    5136    if (logic) {
  • trunk/Ohana/src/opihi/include/dvomath.h

    r2598 r2792  
    5050char        **isolate_elements      PROTO((int argc, char **argv, int *nstack));
    5151StackVar     *convert_to_RPN        PROTO((int argc, char **argv, int *nstack));
    52 int           check_stack           PROTO((StackVar *stack, int Nstack));
     52int           check_stack           PROTO((StackVar *stack, int Nstack, int validsize));
    5353int           evaluate_stack        PROTO((StackVar *stack, int *Nstack));
    5454void          init_stack            PROTO((StackVar *stack));
  • trunk/Ohana/src/opihi/lib.shell/check_stack.c

    r2598 r2792  
    11# include "opihi.h"
    22
    3 int check_stack (StackVar *stack, int Nstack) {
     3int check_stack (StackVar *stack, int Nstack, int validsize) {
    44
    5   int i, Nx, Ny, Nv;
     5  int i, Nx, Ny, Nv, size;
    66  char *c, line[128];
    77
     
    1010  for (i = 0; i < Nstack; i++) {
    1111    if (stack[i].type == 'X') {
     12
    1213      /** if this is a number, put it on the list of scalers and move on **/
    1314      stack[i].Float = strtod (stack[i].name, &c);
     
    1718        continue;
    1819      }
     20
     21      /** if we demand a scalar, interpret strings as strings */
     22      if (validsize == 0) {
     23        stack[i].type  = 'W';
     24        continue;
     25      }
     26       
    1927      /** if this is a matrix, find the dimensions and check with existing values **/
    2028      if (IsBuffer (stack[i].name)) {
     
    3846        continue;
    3947      }
     48
    4049      /** if this is a vector, find the dimensions and check with existing values **/
    4150      if (IsVector (stack[i].name)) {
     
    6372  }
    6473
    65   /* we return a value which is 1 greater than the object dimension */
    66   if (Nx != -1) return (2);
    67   if (Nv != -1) return (1);
    68   return (0);
     74  /* return object dimensions */
     75  size = 0;
     76  if (Nv != -1) size = 1;
     77  if (Nx != -1) size = 2;
     78  if (validsize == -1)   return (size);
     79  if (validsize != size) return (-1);
     80  return (size);
    6981}
  • trunk/Ohana/src/opihi/lib.shell/dvomath.c

    r2598 r2792  
    2222
    2323  /* distinguish scalar, vector, matrix, check dimensions */
    24   *size = check_stack (stack, Nstack);
    25   if ((validsize != -1) && (validsize != *size)) goto error;
     24  *size = check_stack (stack, Nstack, validsize);
    2625  if (*size < 0) goto error;
    2726
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r2598 r2792  
    2626      return (TRUE);
    2727    }
    28     fprintf (stderr, "syntax error!\n");
     28    push_error ("syntax error!");
    2929    free (tmp_stack.name);
    3030    return (FALSE);
     
    5454        return (FALSE);
    5555      }
     56
     57      /* this could be macro generated... */
     58      # define TWO_OP(A,B,FUNC) \
     59      if (!strncasecmp (&stack[i - 2].type, A, 1) && !strncasecmp (&stack[i - 1].type, B, 1)) \
     60        status = FUNC (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
     61
     62      TWO_OP ("M","M",MM_binary);
     63      TWO_OP ("M","V",MV_binary);
     64      TWO_OP ("M","S",MS_binary);
     65      TWO_OP ("V","M",VM_binary);
     66      TWO_OP ("V","V",VV_binary);
     67      TWO_OP ("V","S",VS_binary);
     68      TWO_OP ("S","M",SM_binary);
     69      TWO_OP ("S","V",SV_binary);
     70      TWO_OP ("S","S",SS_binary);     
     71      TWO_OP ("W","W",WW_binary);     
     72     
     73      /*
    5674      if (!strncasecmp (&stack[i - 2].type, "V", 1) && !strncasecmp (&stack[i - 1].type, "V", 1))
    5775        status = VV_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
     
    7290      if (!strncasecmp (&stack[i - 2].type, "S", 1) && !strncasecmp (&stack[i - 1].type, "S", 1))
    7391        status = SS_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
     92      if (!strncasecmp (&stack[i - 2].type, "X", 1) && !strncasecmp (&stack[i - 1].type, "X", 1))
     93        status = XX_binary (&tmp_stack, &stack[i - 2], &stack[i - 1], stack[i].name);
     94      */
     95
     96      /* string op number is not valid */
     97      if (!strncasecmp (&stack[i - 2].type, "W", 1) && strncasecmp (&stack[i - 1].type, "W", 1)) {
     98        free (tmp_stack.name);
     99        return (FALSE);
     100      }
     101      if (strncasecmp (&stack[i - 2].type, "W", 1) && !strncasecmp (&stack[i - 1].type, "W", 1)) {
     102        free (tmp_stack.name);
     103        return (FALSE);
     104      }
     105
    74106      if (!status) {
    75107        free (tmp_stack.name);
     
    102134      if (!strncasecmp (&stack[i - 1].type, "S", 1))
    103135        S_unary (&tmp_stack, &stack[i - 1], stack[i].name);
     136
     137      /* there are no valid unary string operators */
     138      if (!strncasecmp (&stack[i - 1].type, "W", 1)) {
     139        fprintf (stderr, "syntax error\n");
     140        free (tmp_stack.name);
     141        return (FALSE);
     142      }
    104143
    105144      move_stack (&stack[i-1], &tmp_stack);
  • trunk/Ohana/src/opihi/lib.shell/expand_vectors.c

    r2598 r2792  
    3737      ALLOCATE (val, char, 64);
    3838      sprintf (val, "-1");
     39      /* this choice of sentinel prevents us from using
     40         x[-1], x[-2], and is not really needed */
    3941    } else {
    4042      strncpy (tmpline, p+1, n);
    4143      tmpline[n] = 0;
    4244      val = dvomath (1, &tmpline, &size, 0);
    43       if (val == NULL) goto dumpline; /* not really a vector */
     45      if (val == NULL) goto dumpline; /* not a valid vector subscript */
    4446    }
    4547    /* find vector name */
  • trunk/Ohana/src/opihi/lib.shell/parse.c

    r2598 r2792  
    5656    if (*V1 == 0) goto error;
    5757
    58     /* command replacement.  execute the line, place answer in val. */
    5958    if (*V1 == '`') {
     59      /* command replacement.  execute the line, place answer in val. */
    6060
    6161      /* look for end of line, must be ` */
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r2598 r2792  
    10431043
    10441044}
     1045
     1046int WW_binary (StackVar *OUT, StackVar *V1, StackVar *V2, char *op) {
     1047
     1048  int value;
     1049 
     1050  switch (op[0]) {
     1051  case 'E':
     1052    value = strcmp (V1[0].name, V2[0].name) ? 0 : 1;
     1053    break;
     1054  case 'N':
     1055    value = strcmp (V1[0].name, V2[0].name) ? 1 : 0;
     1056    break;
     1057  default:
     1058    fprintf (stderr, "error: op %c not valid\n", op[0]);
     1059  }
     1060
     1061  strcpy (OUT[0].name, "tmp");
     1062  OUT[0].Float = value;
     1063  OUT[0].type = 'S';
     1064  OUT[0].ptr = &OUT[0].Float;
     1065  return (TRUE);
     1066
     1067}
     1068
    10451069
    10461070int S_unary (StackVar *OUT, StackVar *V1, char *op) {
Note: See TracChangeset for help on using the changeset viewer.