IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2801


Ignore:
Timestamp:
Dec 23, 2004, 7:36:01 AM (22 years ago)
Author:
eugene
Message:

fixed dvomath for strings

Location:
trunk/Ohana/src/opihi/lib.shell
Files:
5 edited

Legend:

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

    r2792 r2801  
    1919      }
    2020
    21       /** if we demand a scalar, interpret strings as strings */
    22       if (validsize == 0) {
    23         stack[i].type  = 'W';
    24         continue;
    25       }
    26        
    2721      /** if this is a matrix, find the dimensions and check with existing values **/
    2822      if (IsBuffer (stack[i].name)) {
     
    6660        continue;
    6761      }
     62
     63      /* this is not a scalar, vector, or matrix.  must be string */
     64      stack[i].type  = 'W';
     65       
     66      /* let's not consider this an error
    6867      sprintf (line, "unknown object %s", stack[i].name);
    6968      push_error (line);
    70       return (-1);
     69      return (-1);
     70      */
    7171    }
    7272  }
     
    8080  return (size);
    8181}
     82
     83/* check stack identifies the data elements as scalar, vector, matrix, or word.
     84   operators have already been identified. 
     85   check stack returns the total stack dimensionality (0,1,2)
     86   on error, check stack returns -1
     87   possible errors:
     88     - mismatch with requested dimensionality
     89     - mismatch in data dimensions
     90*/
  • trunk/Ohana/src/opihi/lib.shell/dvomath.c

    r2792 r2801  
    11# include "opihi.h"
    22
    3 /* return value on success is temp vector/buffer name or scalar value
    4    return value on error is NULL, all internals freed? */
    5 
     3/* return value on success is temp vector/buffer name or scalar value return value on error is NULL, all
     4   internals freed.  errors are sent to error stack.  may be printed by calling function */
     5   
    66char *dvomath (int argc, char **argv, int *size, int validsize) {
    77 
  • trunk/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r2792 r2801  
    55 
    66  int i, j, Nvar, Nout, status;
     7  char line[512];
    78  StackVar tmp_stack;
    89  Nout = Nvar = 0;
     
    2627      return (TRUE);
    2728    }
    28     push_error ("syntax error!");
     29    push_error ("syntax error: not a math expression");
    2930    free (tmp_stack.name);
    3031    return (FALSE);
     
    5051
    5152      if (i < 2) {  /* need two variables to operate on */
    52         fprintf (stderr, "syntax error\n");
     53        sprintf (line, "syntax error: binary operator with one operand: %s\n", stack[i].name);
     54        push_error (line);
    5355        free (tmp_stack.name);
    5456        return (FALSE);
     
    123125
    124126      if (i < 1) {  /* need one variable to operate on */
    125         fprintf (stderr, "syntax error\n");
     127        push_error ("syntax error: unary operator with no operand");
    126128        free (tmp_stack.name);
    127129        return (FALSE);
     
    137139      /* there are no valid unary string operators */
    138140      if (!strncasecmp (&stack[i - 1].type, "W", 1)) {
    139         fprintf (stderr, "syntax error\n");
     141        push_error ("syntax error: no valid string unary ops");
    140142        free (tmp_stack.name);
    141143        return (FALSE);
     
    156158
    157159  if (*Nstack > 1) {
    158     fprintf (stderr, "syntax error\n");
     160    push_error ("syntax error in evaluation");
    159161    return (FALSE);
    160162  }
  • trunk/Ohana/src/opihi/lib.shell/parse.c

    r2792 r2801  
    5656    if (*V1 == 0) goto error;
    5757
     58    /* command replacement.  execute the line, place answer in val. */
    5859    if (*V1 == '`') {
    59       /* command replacement.  execute the line, place answer in val. */
    6060
    6161      /* look for end of line, must be ` */
     
    7979        if (*B == '\n') *B = ' ';
    8080      }
    81     } else {
     81    }
     82
     83    /* simple variable assignment */
     84    if (*V1 != '`') {
    8285      /* dvomath returns a new string, or NULL, with the result of the expression */
    8386      val = dvomath (1, &V1, &size, 0);
     
    107110    V = strncreate (N+1, L - N - 1);
    108111
    109     /* expand value in parenthesis */
     112    /* expand value in brackets */
    110113    val = dvomath (1, &V, &size, 0);
    111114    if (val == NULL) {
     
    172175    *c1 = 0;
    173176
    174     /* value in brackets must be an expression of some sort */
     177    /* value in brackets must be a math expression of some sort.
     178       isolated words are not valid here */
    175179    val = dvomath (1, &L, &size, -1);
    176180    if (val == NULL) {
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r2792 r2801  
    1010  int i, Nx;
    1111  float *out, *M1, *M2;
     12  char line[512];
    1213 
    1314  Nx = V1[0].vector[0].Nelements;
     
    104105    break;
    105106  default:
    106     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     107    sprintf (line, "error: op %c not defined!", op[0]);
     108    push_error (line);
     109    return (FALSE);
    107110  }
    108111
     
    127130  int i, Nx;
    128131  float *out, *M1, *M2;
     132  char line[512];
    129133 
    130134  Nx = V2[0].vector[0].Nelements;
     
    213217    break;
    214218  default:
    215     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     219    sprintf (line, "error: op %c not defined!", op[0]);
     220    push_error (line);
     221    return (FALSE);
    216222  }
    217223
     
    231237  int i, Nx;
    232238  float *out, *M1, *M2;
     239  char line[512];
    233240 
    234241  Nx = V1[0].vector[0].Nelements;
     
    317324    break;
    318325  default:
    319     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     326    sprintf (line, "error: op %c not defined!", op[0]);
     327    push_error (line);
     328    return (FALSE);
    320329  }
    321330
     
    335344  int i, j, Nx, Ny;
    336345  float *out, *M1, *M2;
    337  
     346  char line[512];
     347 
    338348  Nx = V1[0].buffer[0].matrix.Naxis[0];
    339349  Ny = V1[0].buffer[0].matrix.Naxis[1];
    340350  if (Ny != V2[0].vector[0].Nelements) {
    341     fprintf (stderr, "dimension mismatch\n");
     351    push_error ("dimension mismatch");
    342352    return (FALSE);
    343353  }
     
    462472    break;
    463473  default:
    464     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     474    sprintf (line, "error: op %c not defined!", op[0]);
     475    push_error (line);
     476    return (FALSE);
    465477  }
    466478
     
    486498  int i, j, Nx, Ny;
    487499  float *out, *M1, *M2;
     500  char line[512];
    488501 
    489502  Nx = V2[0].buffer[0].matrix.Naxis[0];
     
    628641    break;
    629642  default:
    630     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     643    sprintf (line, "error: op %c not defined!", op[0]);
     644    push_error (line);
     645    return (FALSE);
    631646  }
    632647
     
    651666  int i, Nx, Ny;
    652667  float *out, *M1, *M2;
     668  char line[512];
    653669 
    654670  Nx = V1[0].buffer[0].matrix.Naxis[0];
     
    743759    break;
    744760  default:
    745     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     761    sprintf (line, "error: op %c not defined!", op[0]);
     762    push_error (line);
     763    return (FALSE);
    746764  }
    747765
     
    768786  int i, Nx, Ny;
    769787  float *out, *M1, *M2;
     788  char line[512];
    770789 
    771790  Nx = V1[0].buffer[0].matrix.Naxis[0];
     
    856875    break;
    857876  default:
    858     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     877    sprintf (line, "error: op %c not defined!", op[0]);
     878    push_error (line);
     879    return (FALSE);
    859880  }
    860881
     
    873894  int i, Nx, Ny;
    874895  float *out, *M1, *M2;
     896  char line[512];
    875897 
    876898  Nx = V2[0].buffer[0].matrix.Naxis[0];
     
    960982    break;
    961983  default:
    962     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     984    sprintf (line, "error: op %c not defined!", op[0]);
     985    push_error (line);
     986    return (FALSE);
    963987  }
    964988
     
    9761000
    9771001  float *M1, *M2, *out;
    978  
     1002  char line[512];
     1003
    9791004  M1  = V1[0].ptr;
    9801005  M2  = V2[0].ptr;
     
    10361061    break;
    10371062  default:
    1038     fprintf (stderr, "error: op %c not defined!\n", op[0]);
     1063    sprintf (line, "error: op %c not defined!", op[0]);
     1064    push_error (line);
     1065    return (FALSE);
    10391066  }
    10401067  OUT[0].Float = *(OUT[0].ptr);
     
    10471074
    10481075  int value;
    1049  
     1076  char line[512];
     1077
    10501078  switch (op[0]) {
    10511079  case 'E':
     
    10561084    break;
    10571085  default:
    1058     fprintf (stderr, "error: op %c not valid\n", op[0]);
     1086    sprintf (line, "error: op %c not defined!", op[0]);
     1087    push_error (line);
     1088    return (FALSE);
    10591089  }
    10601090
Note: See TracChangeset for help on using the changeset viewer.