Changeset 10846 for trunk/Ohana/src/opihi/cmd.basic/run_if.c
- Timestamp:
- Dec 27, 2006, 10:43:47 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.basic/run_if.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.
