IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30115


Ignore:
Timestamp:
Dec 20, 2010, 8:36:52 AM (15 years ago)
Author:
eugene
Message:

handle syntax errors in ohana scripts as errors

Location:
branches/eam_branches/ipp-20101205/Ohana/src/opihi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/include/shell.h

    r27790 r30115  
    7676char         *expand_vars               PROTO((char *line));
    7777char         *expand_vectors            PROTO((char *line));
    78 char         *parse                     PROTO((char *line));
     78char         *parse                     PROTO((int *status, char *line));
    7979char        **parse_commands            PROTO((char *, int *));
    8080void          welcome                   PROTO((void));
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell/command.c

    r30081 r30115  
    1010  Command *cmd;
    1111
    12   // rawline = NULL;
     12  // the input line is never NULL
     13  if (!line) { fprintf (stderr, "programming error\n"); abort(); }
     14
    1315  rawline = strcreate (line);
    1416
     
    2022  }
    2123
    22  XXX: check for NULL return from expand_* and raise error
    23 
    2424  /* expand anything of the form $fred or $fred$sam, etc */
    2525  line = expand_vars (line);     /* line is freed here, new one allocated */
     26  if (!line) goto escape;
     27
    2628  /* expand anything of the form fred[N] */
    2729  line = expand_vectors (line);  /* line is freed here, new one allocated */
     30  if (!line) goto escape;
    2831
    2932  // print the line with the variables and vectors expanded, but before evaluating
     
    3134  if (VERBOSE_SHELL == OPIHI_VERBOSE_ON) gprint (GP_ERR, "opihi: %s\n", line);
    3235
    33   /* solve math expresions, assign variable, if needed */
    34   line = parse (line);        /* line is freed here, new one allocated */
    35   /* any entry in line of the form {foo} returns value or tmp vector / buffer */
     36  /* solve math expresions, assign variable, if needed.  any entry in line of the form {foo}
     37   * returns value or tmp vector / buffer */
     38  line = parse (&status, line);        /* line is freed here, new one allocated */
     39  if (!status) goto escape;
    3640
    3741  /* we may have reallocated line, return new pointer */
     
    4145  if (argc == 0) {
    4246      FREE (rawline);
     47      set_int_variable ("STATUS", TRUE);
    4348      return (TRUE);  /* empty command or assignment */
    4449  }
     
    7681  FREE (rawline);
    7782  return (status);
     83
     84 escape:
     85  set_int_variable ("STATUS", FALSE);
     86
     87  # if (DEBUG)
     88  gprint (GP_ERR, "command: %s, status: %d\n", line, FALSE);
     89  # endif
     90
     91  FREE (rawline);
     92  return FALSE;
    7893}
    7994
  • branches/eam_branches/ipp-20101205/Ohana/src/opihi/lib.shell/parse.c

    r27491 r30115  
    11# include "opihi.h"
    22
    3 char *parse (char *line) {
     3char *parse (int *status, char *line) {
    44
    55  double fval;
    66  float *fptr;
    77  char *newline, *N, *L, *val, *B, *V, *V0, *V1, *c1, *c2, *p;
    8   int Nx, Ny, Nbytes, status, size, NLINE, isBuffer, inRange;
     8  int Nx, Ny, Nbytes, filestatus, size, NLINE, isBuffer, inRange;
    99  FILE *f;
    1010  Vector *vec;
    1111  Buffer *buf;
     12
     13  *status = TRUE;
    1214
    1315  Ny = 0;
     
    7375      Nbytes = fread (val, 1, 1023, f);
    7476      val[Nbytes] = 0;
    75       status = pclose (f);
     77      filestatus = pclose (f);
    7678      free (B);
    7779
    78       if (status) gprint (GP_ERR, "warning: exit status of command %d\n", status);
     80      if (filestatus) gprint (GP_ERR, "warning: exit status of command %d\n", filestatus);
    7981
    8082      /* convert all but last return to ' '.  drop last return */
     
    9193
    9294    /* simple variable assignment */
    93     if (*V1 != '`') {
    94       /* dvomath returns a new string, or NULL, with the result of the expression */
    95       val = dvomath (1, &V1, &size, 0);
    96       if (val == NULL) {
    97         while (OHANA_WHITESPACE (*V1)) V1++;
    98         val = strcreate (V1);
    99       }
    100     }
     95    /* dvomath returns a new string, or NULL, with the result of the expression */
     96    val = dvomath (1, &V1, &size, 0);
     97    if (val == NULL) {
     98      while (OHANA_WHITESPACE (*V1)) V1++;
     99      val = strcreate (V1);
     100    }
    101101    /* both dvomath and command replacement create (char *) val */
    102102    set_str_variable (V0, val);
     
    172172      if (!inRange) {
    173173        gprint (GP_ERR, "no element %d,%d\n", Nx, Ny);
    174         goto escape;
     174        goto error;
    175175      }
    176176      if (Nx < 0) Nx += buf[0].header.Naxis[0];
     
    188188      if (!inRange) {
    189189        gprint (GP_ERR, "no element %d\n", Nx);
    190         goto escape;
     190        goto error;
    191191      }
    192192      if (Nx < 0) Nx += vec[0].Nelements;
     
    197197      }
    198198    }
    199 
    200199    goto escape;
    201200  }
     
    226225    if (c1 == NULL) {
    227226      gprint (GP_ERR, "no close brackets!\n");
    228       goto escape;
     227      goto error;
    229228    }
    230229    c2 = strchr (L, '{');
    231230    if ((c2 != NULL) && (c2 < c1)) {
    232231      gprint (GP_ERR, "can't nest brackets!\n");
    233       goto escape;
     232      goto error;
    234233    }
    235234    *c1 = 0;
     
    240239    if (val == NULL) {
    241240      print_error ();
    242       goto escape;
     241      goto error;
    243242    }
    244243
     
    257256 
    258257  REALLOCATE (newline, char, strlen (newline) + 1);
     258  *status = TRUE;
    259259  return (newline);
    260260
    261261error:
    262262  gprint (GP_ERR, "syntax error\n");
    263 
    264 escape:
     263  // assignment or increment operation: free line and return NULL
    265264  if (line != (char *) NULL) free (line);
    266265  if (val != (char *) NULL) free (val);
    267266  if (V0 != (char *) NULL) free (V0);
     267  *status = FALSE;
     268  return NULL;
     269
     270escape:
     271  // assignment or increment operation: free line and return NULL
     272  if (line != (char *) NULL) free (line);
     273  if (val != (char *) NULL) free (val);
     274  if (V0 != (char *) NULL) free (V0);
     275  *status = TRUE;
    268276  return (NULL);
    269277}
Note: See TracChangeset for help on using the changeset viewer.