IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 27, 2006, 10:43:47 AM (20 years ago)
Author:
eugene
Message:

added last, next, return, fixed continue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.basic/run_if.c

    r10647 r10846  
    44int run_if (int argc, char **argv) {
    55
    6   int ThisList, depth, done, status, BreakOnTrue;
    7   int logic;
    8   char *input, *val;
     6  int ThisList, depth, done, status, InlineCommand;
     7  int i, length, logic;
     8  char *input, *val, *line;
    99  int nloop, size;
    1010
    11   BreakOnTrue = FALSE;
     11  InlineCommand = FALSE;
    1212
    13   if ((argc != 2) && (argc != 3)) {
    14     gprint (GP_ERR, "USAGE: if (conditional) [break], end with the word 'END'\n");
     13  if (argc < 2) {
     14    gprint (GP_ERR, "USAGE: if (conditional) : follow with commands, end with the word 'END'\n");
     15    gprint (GP_ERR, "   OR: if (conditional) command\n");
    1516    return (FALSE);
    1617  }
    17   if ((argc == 3) && strcmp (argv[2], "break")) {
    18     gprint (GP_ERR, "USAGE: if (conditional) [break], end with the word 'END'\n");
    19     return (FALSE);
     18  if (argc > 2) {
     19    InlineCommand = TRUE;
    2020  }
    21   if ((argc == 3) && !strcmp (argv[2], "break")) {
    22     BreakOnTrue = TRUE;
    23   }
    24 
    25   /* read in if-list */
    26   nloop = 0;
    27   depth = 0;
    28   ThisList = current_list_depth();
    2921
    3022  /* determine value of conditional expression */
     
    3426    return (FALSE);
    3527  }
    36   logic = atof (val); /* warning: round-off error is a danger */
     28  logic = atof (val); /* is round-off error a danger? */
    3729  free (val);
    3830
    39   if (BreakOnTrue) {
     31  if (InlineCommand) {
    4032    if (logic) {
    41       loop_break = TRUE;
    42       return (FALSE);
     33      /* re-build a command line from the remaining strings */
     34      length = 0;
     35      for (i = 2; i < argc; i++) {
     36        length += strlen(argv[i]) + 1;
     37      }
     38      length++;
     39      ALLOCATE (line, char, length);
     40      memset (line, 0, length);
     41      for (i = 2; i < argc; i++) {
     42        if (i == 2) {
     43          strcpy (line, argv[i]);
     44        } else {
     45          strcat (line, " ");
     46          strcat (line, argv[i]);
     47        }
     48      }
     49      status = multicommand (line);
     50      free (line);
     51      return (status);
    4352    } else {
    4453      return (TRUE);
    4554    }
    4655  }   
     56
     57  /* read in if-list */
     58  nloop = 0;
     59  depth = 0;
     60  ThisList = current_list_depth();
    4761
    4862  done = FALSE;
Note: See TracChangeset for help on using the changeset viewer.