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/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
Note: See TracChangeset for help on using the changeset viewer.