IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15878


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

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

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/include/dvomath.h

    r11084 r15878  
    4949void          clean_stack           PROTO((StackVar *stack, int Nstack));
    5050void          delete_stack          PROTO((StackVar *stack, int Nstack));
     51void          clear_stack           PROTO((StackVar *stack));
     52void          assign_stack          PROTO((StackVar *stack, char *name, int type));
     53
    5154int           VV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
    5255int           SV_binary             PROTO((StackVar *OUT, StackVar *V1, StackVar *V2, char *op));
  • trunk/Ohana/src/opihi/include/shell.h

    r15791 r15878  
    132132char         *thiscomm                  PROTO((char *));
    133133char         *nextcomm                  PROTO((char *));
     134char         *opihi_append              PROTO((char *output, int *Noutput, char *start, char *stop));
     135void          interpolate_slash         PROTO((char *line));
    134136
    135137/* macro functions (mapped to commands) */
  • trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c

    r7917 r15878  
    9797        /* pop previous, higher operators from OP stack to stack */
    9898        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type > type); j--) {
    99           strcpy (stack[Nstack].name, op_stack[j].name);
    100           stack[Nstack].type = op_stack[j].type;
     99          move_stack (&stack[Nstack], &op_stack[j]);
    101100          Nstack ++;
    102101          Nop_stack --;
    103102        }
    104103        /* push operator on OP stack */
    105         strcpy (op_stack[Nop_stack].name, argv[i]);
    106         op_stack[Nop_stack].type = type;
     104        assign_stack (&op_stack[Nop_stack], argv[i], type);
    107105        Nop_stack ++;
    108106        break;
     
    115113        /* pop previous, higher or equal operators from OP stack to stack */
    116114        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type >= type); j--) {
    117           strcpy (stack[Nstack].name, op_stack[j].name);
    118           stack[Nstack].type = op_stack[j].type;
     115          move_stack (&stack[Nstack], &op_stack[j]);
    119116          Nstack ++;
    120117          Nop_stack --;
    121118        }
    122119        /* push operator on OP stack */
    123         strcpy (op_stack[Nop_stack].name, argv[i]);
    124         op_stack[Nop_stack].type = type;
     120        assign_stack (&op_stack[Nop_stack], argv[i], type);
    125121        Nop_stack ++;
    126122        break;
    127123      case 2: 
    128124        /* push operator on OP stack */
    129         strcpy (op_stack[Nop_stack].name, argv[i]);
    130         op_stack[Nop_stack].type = type;
     125        assign_stack (&op_stack[Nop_stack], argv[i], type);
    131126        Nop_stack ++;
    132127        break;
     
    134129        /* pop rest of operators from OP stack to stack, looking for '(' */
    135130        for (j = Nop_stack - 1; (j >= 0) && (op_stack[j].type != 2); j--) {
    136           strcpy (stack[Nstack].name, op_stack[j].name);
    137           stack[Nstack].type = op_stack[j].type;
     131          move_stack (&stack[Nstack], &op_stack[j]);
    138132          Nstack ++;
    139133          Nop_stack --;
     
    149143        /* place the value (number or vector/matrix name) on stack */
    150144        /* value of 'X' is used as sentinel until we sort out values */
    151         strcpy (stack[Nstack].name, argv[i]);
    152         stack[Nstack].type = 'X';
     145        assign_stack (&stack[Nstack], argv[i], 'X');
    153146        Nstack ++;
    154147        break;
     
    163156      goto cleanup;
    164157    }
    165     strcpy (stack[Nstack].name, op_stack[j].name);
    166     stack[Nstack].type = op_stack[j].type;
     158    move_stack (&stack[Nstack],  &op_stack[j]);
    167159    Nstack ++;
    168160  }
     
    170162cleanup:
    171163  /*** free up unused stack space ***/
    172   clean_stack (op_stack, NSTACK);
     164
     165  // XXX there should not be any un-freed op_stacks at this point
     166  // clean_stack (op_stack, NSTACK);
    173167  free (op_stack);
    174   clean_stack (&stack[Nstack], NSTACK - Nstack);
     168
     169  // XXX there should not be any data on higher stack entries
     170  // clean_stack (&stack[Nstack], NSTACK - Nstack);
    175171  REALLOCATE (stack, StackVar, MAX (Nstack, 1));
    176172  *nstack = Nstack;
  • 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}
  • trunk/Ohana/src/opihi/lib.shell/expand_vars.c

    r10646 r15878  
    44
    55  char *L, *N, *V0, *V1, *Val, *newline, *c, found;
    6   int done, MacroDepth;
     6  int done, MacroDepth, NLINE, Noff;
    77
    88  if (line == NULL) return (NULL);
     
    1010
    1111  found = FALSE;
    12   ALLOCATE (newline, char, 1024);  /* WARNING: this limits the length of the input line */
     12  NLINE = MAX (128, strlen(line));
     13  ALLOCATE (newline, char, NLINE);  /* WARNING: this limits the length of the input line */
    1314
    1415  V0 = thiscomm (line);
     
    3435         L++;
    3536         N++;
     37         if (N - newline >= NLINE - 5) {
     38           Noff = N - newline;
     39           NLINE += 128;
     40           REALLOCATE (newline, char, NLINE);
     41           N = newline + Noff;
     42         }
    3643      }
    3744    }
     
    4653    if (V0 == NULL) {
    4754      *N = *L;
     55      if (N - newline >= NLINE - 5) {
     56        Noff = N - newline;
     57        NLINE += 128;
     58        REALLOCATE (newline, char, NLINE);
     59        N = newline + Noff;
     60      }
    4861      continue;
    4962    }
     
    5467        *N = *L;
    5568        free (V0);
     69        if (N - newline >= NLINE - 5) {
     70          Noff = N - newline;
     71          NLINE += 128;
     72          REALLOCATE (newline, char, NLINE);
     73          N = newline + Noff;
     74        }
    5675        continue;
    5776      }
     
    6584        goto error;
    6685      } else { /* if we are executing a macro, attach the list depth to the front, pass on down the line */
     86        // XXX this is limiting!!!
    6787        ALLOCATE (c, char, 1024);
    6888        sprintf (c, "%d.%s", MacroDepth, V0);
     
    7999    for (; *Val != 0; N++, Val++)  {
    80100      *N = *Val; /* place the value of the variable in the newline */
     101      if (N - newline >= NLINE - 5) {
     102        Noff = N - newline;
     103        NLINE += 128;
     104        REALLOCATE (newline, char, NLINE);
     105        N = newline + Noff;
     106      }
    81107    }
    82108    N--; /* we overshoot on last loop */
  • trunk/Ohana/src/opihi/lib.shell/expand_vectors.c

    r10073 r15878  
    33char *expand_vectors (char *line) {
    44
    5   char *newline, *tmpline, *val;
     5  char *newline, *tmpline, strValue[128], *val;
    66  char *L, *N, *p, *q, *w;
    7   int n, I, size;
     7  int n, I, size, showLength, NLINE, Noff;
    88  double f1;
    99  Vector *vec;
     
    1111  if (line == NULL) return (NULL);
    1212
    13   ALLOCATE (newline, char, 1024);  /* WARNING: this limits the length of the input line */
    14   ALLOCATE (tmpline, char, 1024);  /* WARNING: this limits the length of the input line */
     13  NLINE = MAX (128, strlen(line));
     14  ALLOCATE (newline, char, NLINE);
    1515
    1616  /* look for form fred[stuff] */
     
    1919  if (L == NULL) {
    2020    free (newline);
    21     free (tmpline);
    2221    return (line);
    2322  }
     
    3534    if (p > q) goto dumpline; /* odd state: unmatched pair: ][ */
    3635    n = (int) (q - p - 1);
     36    val = NULL;
     37    showLength = FALSE;
    3738    if (n == 0) {
    38       ALLOCATE (val, char, 64);
    39       sprintf (val, "-1");
    40       /* this choice of sentinel prevents us from using
    41          x[-1], x[-2], and is not really needed */
     39      showLength = TRUE;
    4240    } else {
    43       strncpy (tmpline, p+1, n);
    44       tmpline[n] = 0;
     41      tmpline = strncreate (p+1, n);
    4542      val = dvomath (1, &tmpline, &size, 0);
     43      free (tmpline);
    4644      if (val == NULL) goto dumpline; /* not a valid vector subscript */
    4745    }
    48     I = atoi (val);
    49     free (val);
     46    I = 0;
     47    if (val != NULL) {
     48      I = atoi (val);
     49      free (val);
     50    }     
    5051
    5152    /* find vector name */
     
    5354    w ++;
    5455    n = (int)(p - w);
    55     strncpy (tmpline, w, n);
    56     tmpline[n] = 0;
     56    tmpline = strncreate (w, n);
    5757    if ((vec = SelectVector (tmpline, OLDVECTOR, TRUE)) == NULL) goto dumpline;
     58    free (tmpline);
    5859
    5960    /* find vector element */
    60     if (I >= vec[0].Nelements) {
     61    if ((I >= vec[0].Nelements) || (I < -1*vec[0].Nelements)) {
    6162      gprint (GP_ERR, "vector subscript out of range\n");
    6263      goto escape;
    6364    }
    64     if (I < 0) {
     65    if (showLength) {
    6566      f1 = vec[0].Nelements;
    6667    } else {
    67       f1 = vec[0].elements[I];
     68      if (I < 0) {
     69        f1 = vec[0].elements[vec[0].Nelements+I];
     70      } else {
     71        f1 = vec[0].elements[I];
     72      }
    6873    }
    6974    if ((int)f1 == f1)
    70       sprintf (tmpline, "%.0f", f1);
     75      snprintf (strValue, 128, "%.0f", f1);
    7176    else
    72       sprintf (tmpline, "%.9g", f1);
    73     /* interpolate vector element */
     77      snprintf (strValue, 128, "%.9g", f1);
     78
     79    /* interpolate vector element into newline (being accumulated) */
     80    size = (N - newline) + (w - L) + strlen(strValue);
     81    if (size >= NLINE) {
     82      Noff = N - newline;
     83      NLINE += 128 + strlen(strValue) + (w - L);
     84      REALLOCATE (newline, char, NLINE);
     85      N = newline + Noff;
     86    }
     87
    7488    n = (int) (w - L);
    7589    strncpy (N, L, n);
    7690    N += n;
    77     n = strlen (tmpline);
    78     strncpy (N, tmpline, n);
     91    n = strlen (strValue);
     92    strncpy (N, strValue, n);
    7993    N += n;
    8094    L = q + 1;
     
    8296
    8397dumpline:
     98  size = (N - newline) + strlen(L);
     99  if (size >= NLINE) {
     100    Noff = N - newline;
     101    NLINE += 128 + strlen(L);
     102    REALLOCATE (newline, char, NLINE);
     103    N = newline + Noff;
     104  }
     105
    84106  n = strlen (L);
    85107  strncpy (N, L, n);
    86108  N[n] = 0;
    87109  free (line);
    88   free (tmpline);
    89110  return (newline);
    90111 
     
    92113  free (line);
    93114  free (newline);
    94   free (tmpline);
    95115  return (NULL);
    96116}
  • trunk/Ohana/src/opihi/lib.shell/isolate_elements.c

    r10073 r15878  
    88
    99/* local private static variables */
    10 int Nchar, Nout, NOUT;
    11 char **out;
     10int NCHAR, Nchar, Nout, NOUT;
     11char **myOutput;
    1212
    1313char **isolate_elements (int Nin, char **in, int *nout) {
     
    1717  NOUT = Nin;
    1818  Nchar = Nout = 0;
    19   ALLOCATE (out, char *, NOUT);
    20   ALLOCATE (out[Nout], char, NCHARS);
     19  NCHAR = 256;
     20  ALLOCATE (myOutput, char *, NOUT);
     21  ALLOCATE (myOutput[Nout], char, NCHAR);
    2122
    2223  for (i = 0; i < Nin; i++) {
     
    3536        /* check previous entry on line */
    3637        if (Nchar) {
    37           OpStat = IsAnOp (out[Nout]);
    38           if (out[Nout][0] == ')') OpStat = FALSE;
     38          OpStat = IsAnOp (myOutput[Nout]);
     39          if (myOutput[Nout][0] == ')') OpStat = FALSE;
    3940        } else {
    40           OpStat = IsAnOp (out[Nout-1]);
    41           if (out[Nout-1][0] == ')') OpStat = FALSE;
     41          OpStat = IsAnOp (myOutput[Nout-1]);
     42          if (myOutput[Nout-1][0] == ')') OpStat = FALSE;
    4243        }
    4344        /* if - follows an operator, must be negator */
     
    6768        /* check previous entry on line */
    6869        if (Nchar) {
    69           OpStat = IsAnOp (out[Nout]);
    70           if (out[Nout][0] == ')') OpStat = FALSE;
     70          OpStat = IsAnOp (myOutput[Nout]);
     71          if (myOutput[Nout][0] == ')') OpStat = FALSE;
    7172        } else {
    72           OpStat = IsAnOp (out[Nout-1]);
    73           if (out[Nout-1][0] == ')') OpStat = FALSE;
     73          OpStat = IsAnOp (myOutput[Nout-1]);
     74          if (myOutput[Nout-1][0] == ')') OpStat = FALSE;
    7475        }
    7576        /* if + follows an operator, must be posator */
     
    9192        if (posate) continue;
    9293        EndOfString ();
    93         /* copy operator to out[Nout] */
     94        /* copy operator to myOutput[Nout] */
    9495        InsertValue (in[i][j]);
    9596        if (negate) InsertValue ('-');
     
    131132
    132133  /* one extra entry is allocated, free here */
    133   free (out[Nout]);
     134  free (myOutput[Nout]);
    134135  *nout = Nout;
    135   return (out);
     136  return (myOutput);
    136137
    137138}
    138139
    139140void InsertValue (char c) {
    140   out[Nout][Nchar] = c;
     141  myOutput[Nout][Nchar] = c;
    141142  Nchar ++;
    142   out[Nout][Nchar] = 0;
     143  if (Nchar >= NCHAR - 2) {
     144    NCHAR += 256;
     145    REALLOCATE (myOutput[Nout], char, NCHAR);
     146  }
     147  myOutput[Nout][Nchar] = 0;
    143148}
    144149
    145150void EndOfString () {
    146151  if (Nchar > 0) {
    147     out[Nout][Nchar] = 0;
     152    myOutput[Nout][Nchar] = 0;
    148153    Nout ++;
    149154    Nchar = 0;
     
    151156    if (Nout >= NOUT - 1) {
    152157      NOUT += 10;
    153       REALLOCATE (out, char *, NOUT);
     158      REALLOCATE (myOutput, char *, NOUT);
    154159    }
    155     ALLOCATE (out[Nout], char, NCHARS);
     160    NCHAR = 256;
     161    ALLOCATE (myOutput[Nout], char, NCHAR);
    156162  }
    157163}
  • trunk/Ohana/src/opihi/lib.shell/parse.c

    r10073 r15878  
    11# include "opihi.h"
    22
    3 void interpolate_slash (char *line);
    4 
    53char *parse (char *line) {
    64
    75  double fval;
    8   char *newline, *N, *L, *val, *B, *V, *V0, *V1, *end, *c1, *c2;
    9   int Nval, Nbytes, status, size;
     6  char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p;
     7  int Nval, Nbytes, status, size, NLINE;
    108  FILE *f;
    119  Vector *vec;
     
    6462
    6563      /* val will hold the result */
     64      // XXX this is limiting!!!
    6665      ALLOCATE (val, char, 1024);
    6766
     
    153152
    154153  /* case 3: {expression} */
    155   ALLOCATE (newline, char, 1024);
    156   for (L = line, N = newline; *L != 0; L++, N++) {
    157 
    158     /* copy elements from L (line) to N (newline) until we hit a '{' */
    159     for (; (*L != '{') && (*L != 0); L++, N++) *N = *L;
    160     if (*L == 0) break;
    161 
    162     if ((L != line) && (*(L-1) == 0x5c)) {
    163       N--;
    164       *N = *L;
     154  NLINE = MAX (128, strlen (line));
     155  ALLOCATE (newline, char, NLINE);
     156  memset (newline, 0, NLINE);
     157  for (L = line; *L != 0; ) {
     158
     159    // copy elements from L (line) to newline up to first '{'
     160    p = strchr (L, '{');
     161    newline = opihi_append (newline, &NLINE, L, p);
     162    if (p == NULL) break;
     163    L = p + 1;
     164
     165    // check for \{ at this point, replace \ in newline with {
     166    if ((p > line) && (*(p - 1) == 0x5c)) {
     167      N = newline + strlen(newline) - 1;
     168      *N = '{'; // replace \ with {
    165169      continue;
    166170    }
    167171
    168172    /* check on the syntax of the line */
    169     L++;
     173    L = p + 1;
    170174    c1 = strchr (L, '}');
    171175    if (c1 == NULL) {
     
    178182      goto escape;
    179183    }
    180     end = c1;
    181184    *c1 = 0;
    182185
     
    188191      goto escape;
    189192    }
     193
     194    /* interpolate vector element into newline (being accumulated) */
     195    newline = opihi_append (newline, &NLINE, val, NULL);
     196
    190197    /* copy val to outline */
    191     for (V = val; *V != 0; V++,N++) *N = *V;
    192     L = end;
    193     N--;
     198    L = c1 + 1;
    194199    free (val); val = (char *) NULL;
    195200  }
    196  
    197   *N = 0;
     201
    198202  free (line); line = (char *) NULL;
    199203
     
    204208  return (newline);
    205209
    206   error:
     210error:
    207211  gprint (GP_ERR, "syntax error\n");
    208212
    209   escape:
     213escape:
    210214  if (line != (char *) NULL) free (line);
    211215  if (val != (char *) NULL) free (val);
     
    214218}
    215219
    216 /* replace all instances of \A with A in line */
    217 void interpolate_slash (char *line) {
    218 
    219   char *in, *out;
    220 
    221   for (in = out = line; *in != 0; in++, out++) {
    222     if (*in == 0x5c) in++;
    223     *out = *in;
    224     if (*in == 0) return;
    225   }
    226   *out = *in;
    227 }
    228 
    229   /* this routine looks for math and/or logic expressions that
    230      need to be evaluated and passes them on to "parenthesis",
    231      which evaluates the expression */
    232 
    233   /* There are two situations now which define an expression to
    234      be evaluated:
    235      1) $var = expression   -- everything after the = must be a math expression or a string
    236      2) {expression}        -- everything within the {} must be a math expression
    237    */
    238 
    239   /* case 1: $var = expression.  test that
    240      a) there is a $ as the first character
    241      b) the variable defined by that $ is not null
    242      c) there is an = sign following the variable
    243      d) there is something following the = sign
    244      */
     220/* this routine looks for math and/or logic expressions that
     221   need to be evaluated and passes them on to "parenthesis",
     222   which evaluates the expression */
     223
     224/* There are two situations now which define an expression to
     225   be evaluated:
     226   1) $var = expression   -- everything after the = must be a math expression or a string
     227   2) {expression}        -- everything within the {} must be a math expression
     228*/
     229
     230/* case 1: $var = expression.  test that
     231   a) there is a $ as the first character
     232   b) the variable defined by that $ is not null
     233   c) there is an = sign following the variable
     234   d) there is something following the = sign
     235*/
    245236 
    246   /* case 2: vect[N] = expression. check syntax:
    247      a) last char must be ]
    248      b) word must contain [
    249      c) between [ & ] must be an integer
    250      d) vector must exist
    251      e) there is an = sign following the first word
    252      f) there is something following the = sign
    253   */
     237/* case 2: vect[N] = expression. check syntax:
     238   a) last char must be ]
     239   b) word must contain [
     240   c) between [ & ] must be an integer
     241   d) vector must exist
     242   e) there is an = sign following the first word
     243   f) there is something following the = sign
     244*/
    254245     
    255246
    256   /* case 3: we hunt for '{', and then the first '}' and pass everything
    257      inbetween.  no nested {{}}s are allowed! */
     247/* case 3: we hunt for '{', and then the first '}' and pass everything
     248   inbetween.  no nested {{}}s are allowed! */
    258249 
    259250/* thisword ALLOCATES
  • trunk/Ohana/src/opihi/lib.shell/parse_commands.c

    r2598 r15878  
    44char **parse_commands (char *line, int *argc) {
    55
    6   int i, j, NARG;
     6  int i, NARG;
    77  char *c;
    88  char **argv;
     
    2121  for (i = 1; c != (char *) NULL; i++) {
    2222    argv[i] = thisword (c);
    23     if (argv[i] == (char *) NULL) {
    24       for (j = 0; j < i; j++)
    25         free (argv[i]);
    26       free (argv);
    27       *argc = 0;
    28       return (argv);
    29     }
     23
     24    /* if one of the words does not parse (eg, ""), skip it */
     25    if (argv[i] == NULL) i--;
     26
    3027    c = nextword (c);
    3128    if (i == NARG - 1) {
     
    4946
    5047
     48
     49/* old code:
     50      for (j = 0; j < i; j++)
     51        free (argv[i]);
     52      free (argv);
     53      *argc = 0;
     54      return (argv);
     55    }
     56*/
  • trunk/Ohana/src/opihi/lib.shell/stack_math.c

    r14517 r15878  
    3030  }
    3131  OUT[0].type = 'v'; /*** <<--- says this is a temporary matrix ***/
    32   strcpy (OUT[0].name, "tmp");
     32
    3333  M1  = V1[0].ptr;
    3434  M2  = V2[0].ptr;
     
    128128    free (V2[0].vector);
    129129  }
    130 
    131130  /* at the end, V1 and V2 are deleted only if they were temporary */
     131
     132  clear_stack (V1);
     133  clear_stack (V2);
    132134  return (TRUE);
    133135
     
    150152  }
    151153  OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
    152   strcpy (OUT[0].name, "tmp");
     154
    153155  M1  = V1[0].ptr;
    154156  M2  = V2[0].ptr;
     
    243245    free (V2[0].vector);
    244246  }
     247
     248  clear_stack (V1);
     249  clear_stack (V2);
    245250
    246251  /* at the end, V1 and V2 are deleted only if they were temporary */
     
    265270  }
    266271  OUT[0].type = 'v';   /*** <<--- says this is a temporary matrix ***/
    267   strcpy (OUT[0].name, "tmp");
     272
    268273  M1  = V1[0].ptr;
    269274  M2  = V2[0].ptr;
     
    359364    free (V1[0].vector);
    360365  }
     366
     367  clear_stack (V1);
     368  clear_stack (V2);
     369
    361370  /* at the end, V1 and V2 are deleted only if they were temporary */
    362371  return (TRUE);
     
    387396  }
    388397  OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
    389   strcpy (OUT[0].name, "tmp");
     398
    390399  M1  = V1[0].ptr;
    391400  M2  = V2[0].ptr;
     
    524533    free (V2[0].vector);
    525534  }
     535
     536  clear_stack (V1);
     537  clear_stack (V2);
     538
    526539  /* at the end, V1 and V2 are deleted only if they were temporary */
    527540  return (TRUE);
     
    551564  }
    552565  OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
    553   strcpy (OUT[0].name, "tmp");
     566
    554567  M1  = V1[0].ptr;
    555568  M2  = V2[0].ptr;
     
    707720    free (V2[0].buffer);
    708721  }
     722
     723  clear_stack (V1);
     724  clear_stack (V2);
     725
    709726  /* at the end, V1 and V2 are deleted only if they were temporary */
    710727  return (TRUE);
     
    734751  }
    735752  OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
    736   strcpy (OUT[0].name, "tmp");
     753
    737754  M1  = V1[0].ptr;
    738755  M2  = V2[0].ptr;
     
    834851    free (V2[0].buffer);
    835852  }
     853
     854  clear_stack (V1);
     855  clear_stack (V2);
     856
    836857  /* at the end, V1 and V2 are deleted only if they were temporary */
    837858  return (TRUE);
     
    858879  }
    859880  OUT[0].type = 'm';      /*** <<--- says this is a temporary matrix ***/
    860   strcpy (OUT[0].name, "tmp");
     881
    861882  M1  = V1[0].ptr;
    862883  M2  = V2[0].ptr;
     
    951972    free (V1[0].buffer);
    952973  }
     974  clear_stack (V1);
     975  clear_stack (V2);
     976
    953977  return (TRUE);
    954978
     
    973997  }
    974998  OUT[0].type = 'm'; /*** <<--- says this is a temporary matrix ***/
    975   strcpy (OUT[0].name, "tmp");
     999
    9761000  M1  = V1[0].ptr;
    9771001  M2  = V2[0].ptr;
     
    10661090    free (V2[0].buffer);
    10671091  }
     1092  clear_stack (V1);
     1093  clear_stack (V2);
     1094
    10681095  return (TRUE);
    10691096
     
    10801107  OUT[0].ptr = V1[0].ptr;
    10811108  out = OUT[0].ptr;
    1082   strcpy (OUT[0].name, "tmp");
     1109
    10831110
    10841111  switch (op[0]) {
     
    11471174  OUT[0].Float = *(OUT[0].ptr);
    11481175  OUT[0].type = 'S';
     1176
     1177  clear_stack (V1);
     1178  clear_stack (V2);
     1179
    11491180  return (TRUE);
    11501181
     
    11921223
    11931224escape:
    1194   strcpy (OUT[0].name, "tmp");
    11951225  OUT[0].Float = value;
    11961226  OUT[0].type = 'S';
    11971227  OUT[0].ptr = &OUT[0].Float;
     1228
     1229  clear_stack (V1);
     1230  clear_stack (V2);
    11981231  return (TRUE);
    11991232
     
    12441277  OUT[0].Float = *out;
    12451278  OUT[0].type = 'S';
     1279
     1280  clear_stack (V1);
    12461281  return (TRUE);
    12471282
     
    13091344    free (V1[0].vector[0].elements);
    13101345    free (V1[0].vector);
     1346    V1[0].vector = NULL;
    13111347  } 
     1348
     1349  clear_stack (V1);
    13121350  return (TRUE);
    13131351
     
    13901428    free (V1[0].buffer);
    13911429  }
     1430
     1431  clear_stack (V1);
    13921432  return (TRUE);
    13931433
  • trunk/Ohana/src/opihi/lib.shell/string.c

    r10732 r15878  
    249249  return (c);
    250250}
     251
     252// append string defined by range start - stop to the end of output, which
     253// currently has an allocated size of Noutput.  if this operation would overshoot Noutput,
     254// output is reallocated to a sufficiently large size
     255char *opihi_append (char *output, int *Noutput, char *start, char *stop) {
     256
     257  int N1, N2, outlen;
     258
     259  // a NULL end pointer means 'go to end of line'
     260  if (stop == NULL) {
     261    stop = start + strlen(start);
     262  }
     263
     264  // enough space?
     265  N1 = strlen(output);
     266  N2 = stop - start;
     267  outlen = N1 + N2;
     268  if (outlen >= *Noutput) {
     269    *Noutput = outlen + 128;
     270    REALLOCATE (output, char, *Noutput);
     271    memset (&output[N1], 0, N2 + 128);
     272  }
     273
     274  strncat (output, start, stop - start);
     275  return output;
     276}
     277
     278/* replace all instances of \A with A in line */
     279void interpolate_slash (char *line) {
     280
     281  char *in, *out;
     282
     283  for (in = out = line; *in != 0; in++, out++) {
     284    if (*in == 0x5c) in++;
     285    *out = *in;
     286    if (*in == 0) return;
     287  }
     288  *out = *in;
     289}
Note: See TracChangeset for help on using the changeset viewer.