IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 10846


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

added last, next, return, fixed continue

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

Legend:

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

    r2598 r10846  
    11# include "basic.h"
    22
    3 int exec_continue (int argc, char **argv) {
    4   loop_continue = TRUE;
     3int exec_next (int argc, char **argv) {
     4  loop_next = TRUE;
    55  return (TRUE);
    66}
    77
     8int exec_last (int argc, char **argv) {
     9  loop_last = TRUE;
     10  return (TRUE);
     11}
     12
  • trunk/Ohana/src/opihi/cmd.basic/init.c

    r9040 r10846  
    77int date            PROTO((int, char **));
    88int echo            PROTO((int, char **));
     9int exec_last       PROTO((int, char **));
     10int exec_next       PROTO((int, char **));
    911int exec_break      PROTO((int, char **));
    10 int exec_continue   PROTO((int, char **));
    1112int file            PROTO((int, char **));
    1213int getchr_func     PROTO((int, char **));
     
    4445  {"echo",          echo,               "type this line *"},
    4546  {"break",         exec_break,         "escape from function *"},
    46   {"continue",      exec_continue,      "next loop iteration"},
     47  {"continue",      exec_next,          "next loop iteration"},
     48  {"next",          exec_next,          "next loop iteration"},
     49  {"last",          exec_last,          "last loop iteration"},
     50  {"return",        exec_last,          "exit from macro"},
    4751  {"file",          file,               "test file existence"},
    4852  {"getchr",        getchr_func,        "find character in string"},
  • trunk/Ohana/src/opihi/cmd.basic/run_for.c

    r10647 r10846  
    7979
    8080  status = TRUE;
    81   interrupt = loop_break = FALSE;
     81  interrupt = FALSE;
    8282  for (value = start; (sign*value < sign*end) && !interrupt; value += delta) {
    83     loop_continue = loop_break = FALSE;
    8483    if ((int)value == value)
    8584      set_int_variable (argv[1], (int) value);
     
    8887    status = exec_loop (&loop);
    8988    value = get_double_variable (argv[1]);
     89    if (loop_next) continue;
     90    if (loop_last) break;
    9091    if (loop_break) break;
    91     if (loop_continue) continue;
    9292  }
    93   loop_continue = loop_break = FALSE;
     93  loop_last = loop_next = FALSE;
     94  /* 'last' and 'next' should only affect one loop */
    9495  if (auto_break && !status) loop_break = TRUE;
    9596
     
    99100  }
    100101  free (loop.line);
     102
    101103  if (loop_break) return (FALSE);
    102104  return (TRUE);
     
    109111*/
    110112     
     113/* while processing the loop, the loop status variables may be set
     114   by the loop commands, or the loop may quite on a failed command,
     115   setting the exec_loop return status to false. the loop status variables
     116   are:
     117   loop_next : stop this loop, but try another loop
     118   loop_last : stop loop processing, but return true so external loop may continue
     119   loop_break : stop loop processing, and return false so external loop will break
     120   interrupt : external interrupt signal
     121*/
     122
  • 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;
  • trunk/Ohana/src/opihi/cmd.basic/run_while.c

    r10647 r10846  
    7878  /* execute for loop */
    7979  do {
    80     loop_continue = loop_break = FALSE;
    8180    status = exec_loop (&loop);
     81    if (loop_next) continue;
     82    if (loop_last) break;
    8283    if (loop_break) break;
    83     if (loop_continue) continue;
    8484
    8585    logic_line = strcreate (argv[1]);
     
    9292    free (val);
    9393  } while (logic && !interrupt);
    94   loop_continue = loop_break = FALSE;
     94  loop_last = loop_next = FALSE;
     95  /* 'last' and 'next' should only affect one loop */
    9596  if (auto_break && !status) loop_break = TRUE;
    9697
     
    100101  }
    101102  free (loop.line);
     103
    102104  if (loop_break) return (FALSE);
    103105  return (TRUE);
  • trunk/Ohana/src/opihi/include/shell.h

    r10647 r10846  
    5353int          interrupt;                 /* true if C-C has been pressed */
    5454int          auto_break;                /* if true, zero exit status forces macros to escape */
     55int          loop_next;                 /* set to true when next (or continue) is called */
     56int          loop_last;                 /* set to true when last (or return) is called */
    5557int          loop_break;                /* set to true when break is called */
    56 int          loop_continue;             /* set to true when continue is called */
    5758int          is_script;                 /* being run within a shell script */
    5859
     
    150151void          gprintSetFile             PROTO((gpDest dest, char *filename));
    151152FILE         *gprintGetFile             PROTO((gpDest dest));
     153char         *gprintGetName             PROTO((gpDest dest));
    152154int           gprint                    PROTO((gpDest dest, char *format, ...));
    153155int           gwrite                    PROTO((char *buffer, int size, int N, gpDest dest));
  • trunk/Ohana/src/opihi/lib.shell/ListOps.c

    r10647 r10846  
    150150  if (strcmp (comm, "if")) goto escape;
    151151
    152   /* if (cond) break does not define a complete block */
    153   if ((temp != NULL) && !strcmp (temp, "break")) goto escape;
     152  /* if (cond) (command) does not define a complete block */
     153  if (temp != NULL) goto escape;
    154154
    155155  if (temp != NULL) free (temp);
  • trunk/Ohana/src/opihi/lib.shell/exec_loop.c

    r10647 r10846  
    2121
    2222  /* process the list */
    23   loop_continue = loop_break = FALSE;
     23  loop_next = loop_break = loop_last = FALSE;
    2424  status = TRUE;
    2525
     
    3030    free (line);
    3131    if (auto_break && !status) loop_break = TRUE;
    32     if (loop_break || loop_continue) break;
     32    if (loop_break || loop_last || loop_next) break;
    3333  }
    3434  signal (SIGINT, Signal);
     
    4343
    4444/** note that the list number runs from 1 - Nlists+1 **/
    45 /** XXX this is kind of silly: I should simply define a function
    46     to pop next line off the specified list.  review this... **/
  • trunk/Ohana/src/opihi/lib.shell/macro_exec.c

    r7917 r10846  
    3232  /* process this list */
    3333  status = exec_loop (&macro[0]);
     34  loop_last = loop_next = FALSE;
     35  /* 'last' and 'next' should only affect one loop */
    3436
    3537  /* clear out the command line variables */
Note: See TracChangeset for help on using the changeset viewer.