IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 8, 2022, 5:01:57 PM (4 years ago)
Author:
eugene
Message:

fix string-vector assignment; fix while loop logic involving vector or matrix sizes

Location:
branches/eam_branches/ipp-20220316/Ohana/src/opihi
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/cmd.basic/run_while.c

    r31667 r42165  
    7272  // test the logic once before running the loop
    7373  logic_line = strcreate (argv[1]);
    74   logic_line = expand_vars (logic_line);
     74  logic_line = expand_vars (logic_line); // recalculates scalar elements
     75  logic_line = expand_vectors (logic_line); // recalculates vector/matrix elements (e.g., vec[])
    7576  val = dvomath (1, &logic_line, &size, 0);
    7677  free (logic_line);
     
    9091
    9192    logic_line = strcreate (argv[1]);
    92     logic_line = expand_vars (logic_line);
     93    logic_line = expand_vars (logic_line); // recalculates scalar elements
     94    logic_line = expand_vectors (logic_line); // recalculates vector/matrix elements (e.g., vec[])
    9395    val = dvomath (1, &logic_line, &size, 0);
    9496    free (logic_line);
  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/include/dvomath.h

    r42083 r42165  
    125125int           M_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
    126126int           W_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
     127int           L_unary               PROTO((StackVar *OUT, StackVar *V1, char *op));
    127128
    128129/* variable handling */
  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/lib.shell/evaluate_stack.c

    r42080 r42165  
    6767    if (stack[0].type == ST_VECTOR) {
    6868      /* need to make a copy so we set output value? */
    69       V_unary (&tmp_stack, &stack[0], "=");
     69      if (stack->vector->type == OPIHI_STR) {
     70        L_unary (&tmp_stack, &stack[0], "=");
     71      } else {
     72        V_unary (&tmp_stack, &stack[0], "=");
     73      }
    7074      move_stack (&stack[0], &tmp_stack);
    7175      return (TRUE);
  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/lib.shell/expand_vectors.c

    r42080 r42165  
    2828  ALLOCATE (newline, char, NLINE);
    2929
     30  // special case: don't expand vectors in while () statement
     31  char *V0 = thiscomm (line);
     32  if (V0 && !strncmp ("while", V0, strlen(V0))) {
     33      strcpy (newline, line);
     34      free (line);
     35      return (newline);
     36  }
     37  free (V0);
     38
    3039  /* look for form fred[stuff] */
    31   /* skip first word (command) */
    32   L = nextword (line);
     40  if (*line == '(') {
     41    // if line is "(stuff)" then do not skip first word
     42      L = line;
     43  } else {
     44    /* skip first word (command) */
     45    L = nextword (line);
     46  }
    3347  if (L == NULL) {
    3448    free (newline);
  • branches/eam_branches/ipp-20220316/Ohana/src/opihi/lib.shell/stack_math.c

    r42080 r42165  
    17061706  char line[512]; // this is only used to report an error
    17071707  snprintf (line, 512, "error: op %s not defined as unary vector op!", op);
     1708  push_error (line);
     1709  return (FALSE);
     1710
     1711escape:
     1712
     1713  if (V1[0].type == ST_VECTOR_TMP) {
     1714    free (V1[0].vector[0].elements.Ptr);
     1715    free (V1[0].vector);
     1716    V1[0].vector = NULL;
     1717  } 
     1718
     1719  clear_stack (V1);
     1720  return (TRUE);
     1721
     1722}
     1723
     1724// vector string operations
     1725int L_unary (StackVar *OUT, StackVar *V1, char *op) {
     1726
     1727  int Nx = V1[0].vector[0].Nelements;
     1728
     1729  OUT[0].vector = InitVector ();
     1730  OUT[0].type = ST_VECTOR_TMP; /*** <<--- says this is a temporary matrix ***/
     1731
     1732  ResetVector (OUT[0].vector, OPIHI_STR, V1[0].vector[0].Nelements);
     1733  char **Iv =  V1[0].vector[0].elements.Str;
     1734  char **Ov = OUT[0].vector[0].elements.Str;
     1735  if (!strcmp (op, "=")) {
     1736    for (int i = 0; i < Nx; i++) {                     
     1737      Ov[i] = strcreate (Iv[i]);
     1738    }                                                                   
     1739    goto escape;                                                       
     1740  }
     1741
     1742  // free the temp vector if needed
     1743  if (V1[0].type == ST_VECTOR_TMP) {
     1744    // XXX this probably does not free the strings
     1745    free (V1[0].vector[0].elements.Ptr);
     1746    free (V1[0].vector);
     1747    V1[0].vector = NULL;
     1748  } 
     1749
     1750  clear_stack (V1);
     1751
     1752  char line[512]; // this is only used to report an error
     1753  snprintf (line, 512, "error: op %s not defined as unary string vector op!", op);
    17081754  push_error (line);
    17091755  return (FALSE);
Note: See TracChangeset for help on using the changeset viewer.