IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 13, 2011, 11:28:01 AM (15 years ago)
Author:
eugene
Message:

add += and -= to opihi; allow 0 length vectors; fix mem leak in some binary math operations; check and handle some error cases in command.c

File:
1 edited

Legend:

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

    r27790 r30614  
    1010  Command *cmd;
    1111
    12   // rawline = NULL;
    13   rawline = strcreate (line);
     12  // the input line is never NULL
     13  if (!line) { fprintf (stderr, "programming error\n"); abort(); }
     14
     15  rawline = strcreate (line);  // used for error messages which should echo the unparsed line
    1416
    1517  /* force a space between ! and first word: !ls becomes ! ls */
     
    2224  /* expand anything of the form $fred or $fred$sam, etc */
    2325  line = expand_vars (line);     /* line is freed here, new one allocated */
     26  if (!line) goto escape;
     27
    2428  /* expand anything of the form fred[N] */
    2529  line = expand_vectors (line);  /* line is freed here, new one allocated */
     30  if (!line) goto escape;
    2631
    2732  // print the line with the variables and vectors expanded, but before evaluating
     
    2934  if (VERBOSE_SHELL == OPIHI_VERBOSE_ON) gprint (GP_ERR, "opihi: %s\n", line);
    3035
    31   /* solve math expresions, assign variable, if needed */
    32   line = parse (line);        /* line is freed here, new one allocated */
    33   /* 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;
    3440
    3541  /* we may have reallocated line, return new pointer */
     
    3945  if (argc == 0) {
    4046      FREE (rawline);
     47      set_int_variable ("STATUS", TRUE);
    4148      return (TRUE);  /* empty command or assignment */
    4249  }
     
    7481  FREE (rawline);
    7582  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
     93  if (VERBOSE_SHELL != OPIHI_VERBOSE_OFF) gprint (GP_ERR, "error on line: %s\n", rawline);
     94
     95  // return the current value of line, in case it was modified
     96  *outline = line;
     97  return FALSE;
    7698}
    7799
Note: See TracChangeset for help on using the changeset viewer.