Changeset 10846
- Timestamp:
- Dec 27, 2006, 10:43:47 AM (20 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 9 edited
-
cmd.basic/continue.c (modified) (1 diff)
-
cmd.basic/init.c (modified) (2 diffs)
-
cmd.basic/run_for.c (modified) (4 diffs)
-
cmd.basic/run_if.c (modified) (2 diffs)
-
cmd.basic/run_while.c (modified) (3 diffs)
-
include/shell.h (modified) (2 diffs)
-
lib.shell/ListOps.c (modified) (1 diff)
-
lib.shell/exec_loop.c (modified) (3 diffs)
-
lib.shell/macro_exec.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.basic/continue.c
r2598 r10846 1 1 # include "basic.h" 2 2 3 int exec_ continue(int argc, char **argv) {4 loop_ continue= TRUE;3 int exec_next (int argc, char **argv) { 4 loop_next = TRUE; 5 5 return (TRUE); 6 6 } 7 7 8 int 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 7 7 int date PROTO((int, char **)); 8 8 int echo PROTO((int, char **)); 9 int exec_last PROTO((int, char **)); 10 int exec_next PROTO((int, char **)); 9 11 int exec_break PROTO((int, char **)); 10 int exec_continue PROTO((int, char **));11 12 int file PROTO((int, char **)); 12 13 int getchr_func PROTO((int, char **)); … … 44 45 {"echo", echo, "type this line *"}, 45 46 {"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"}, 47 51 {"file", file, "test file existence"}, 48 52 {"getchr", getchr_func, "find character in string"}, -
trunk/Ohana/src/opihi/cmd.basic/run_for.c
r10647 r10846 79 79 80 80 status = TRUE; 81 interrupt = loop_break =FALSE;81 interrupt = FALSE; 82 82 for (value = start; (sign*value < sign*end) && !interrupt; value += delta) { 83 loop_continue = loop_break = FALSE;84 83 if ((int)value == value) 85 84 set_int_variable (argv[1], (int) value); … … 88 87 status = exec_loop (&loop); 89 88 value = get_double_variable (argv[1]); 89 if (loop_next) continue; 90 if (loop_last) break; 90 91 if (loop_break) break; 91 if (loop_continue) continue;92 92 } 93 loop_continue = loop_break = FALSE; 93 loop_last = loop_next = FALSE; 94 /* 'last' and 'next' should only affect one loop */ 94 95 if (auto_break && !status) loop_break = TRUE; 95 96 … … 99 100 } 100 101 free (loop.line); 102 101 103 if (loop_break) return (FALSE); 102 104 return (TRUE); … … 109 111 */ 110 112 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 4 4 int run_if (int argc, char **argv) { 5 5 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; 9 9 int nloop, size; 10 10 11 BreakOnTrue= FALSE;11 InlineCommand = FALSE; 12 12 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"); 15 16 return (FALSE); 16 17 } 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; 20 20 } 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();29 21 30 22 /* determine value of conditional expression */ … … 34 26 return (FALSE); 35 27 } 36 logic = atof (val); /* warning: round-off error is a danger*/28 logic = atof (val); /* is round-off error a danger? */ 37 29 free (val); 38 30 39 if ( BreakOnTrue) {31 if (InlineCommand) { 40 32 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); 43 52 } else { 44 53 return (TRUE); 45 54 } 46 55 } 56 57 /* read in if-list */ 58 nloop = 0; 59 depth = 0; 60 ThisList = current_list_depth(); 47 61 48 62 done = FALSE; -
trunk/Ohana/src/opihi/cmd.basic/run_while.c
r10647 r10846 78 78 /* execute for loop */ 79 79 do { 80 loop_continue = loop_break = FALSE;81 80 status = exec_loop (&loop); 81 if (loop_next) continue; 82 if (loop_last) break; 82 83 if (loop_break) break; 83 if (loop_continue) continue;84 84 85 85 logic_line = strcreate (argv[1]); … … 92 92 free (val); 93 93 } while (logic && !interrupt); 94 loop_continue = loop_break = FALSE; 94 loop_last = loop_next = FALSE; 95 /* 'last' and 'next' should only affect one loop */ 95 96 if (auto_break && !status) loop_break = TRUE; 96 97 … … 100 101 } 101 102 free (loop.line); 103 102 104 if (loop_break) return (FALSE); 103 105 return (TRUE); -
trunk/Ohana/src/opihi/include/shell.h
r10647 r10846 53 53 int interrupt; /* true if C-C has been pressed */ 54 54 int auto_break; /* if true, zero exit status forces macros to escape */ 55 int loop_next; /* set to true when next (or continue) is called */ 56 int loop_last; /* set to true when last (or return) is called */ 55 57 int loop_break; /* set to true when break is called */ 56 int loop_continue; /* set to true when continue is called */57 58 int is_script; /* being run within a shell script */ 58 59 … … 150 151 void gprintSetFile PROTO((gpDest dest, char *filename)); 151 152 FILE *gprintGetFile PROTO((gpDest dest)); 153 char *gprintGetName PROTO((gpDest dest)); 152 154 int gprint PROTO((gpDest dest, char *format, ...)); 153 155 int gwrite PROTO((char *buffer, int size, int N, gpDest dest)); -
trunk/Ohana/src/opihi/lib.shell/ListOps.c
r10647 r10846 150 150 if (strcmp (comm, "if")) goto escape; 151 151 152 /* if (cond) breakdoes 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; 154 154 155 155 if (temp != NULL) free (temp); -
trunk/Ohana/src/opihi/lib.shell/exec_loop.c
r10647 r10846 21 21 22 22 /* process the list */ 23 loop_ continue = loop_break= FALSE;23 loop_next = loop_break = loop_last = FALSE; 24 24 status = TRUE; 25 25 … … 30 30 free (line); 31 31 if (auto_break && !status) loop_break = TRUE; 32 if (loop_break || loop_ continue) break;32 if (loop_break || loop_last || loop_next) break; 33 33 } 34 34 signal (SIGINT, Signal); … … 43 43 44 44 /** note that the list number runs from 1 - Nlists+1 **/ 45 /** XXX this is kind of silly: I should simply define a function46 to pop next line off the specified list. review this... **/ -
trunk/Ohana/src/opihi/lib.shell/macro_exec.c
r7917 r10846 32 32 /* process this list */ 33 33 status = exec_loop (¯o[0]); 34 loop_last = loop_next = FALSE; 35 /* 'last' and 'next' should only affect one loop */ 34 36 35 37 /* clear out the command line variables */
Note:
See TracChangeset
for help on using the changeset viewer.
