Changeset 4462
- Timestamp:
- Jul 6, 2005, 10:29:08 AM (21 years ago)
- Location:
- trunk/Ohana/src/opihi
- Files:
-
- 10 edited
-
cmd.basic/run_if.c (modified) (1 diff)
-
include/shell.h (modified) (1 diff)
-
lib.shell/command.c (modified) (2 diffs)
-
lib.shell/convert_to_RPN.c (modified) (1 diff)
-
lib.shell/exec_loop.c (modified) (2 diffs)
-
lib.shell/multicommand.c (modified) (1 diff)
-
lib.shell/opihi.c (modified) (2 diffs)
-
lib.shell/stack_math.c (modified) (9 diffs)
-
pcontrol/GetJobOutput.c (modified) (3 diffs)
-
scripts/sched.pro (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.basic/run_if.c
r3922 r4462 94 94 if (logic) { 95 95 if (*input) { 96 status = multicommand (input); 96 97 if (ThisList == 0) add_history (input); 97 status = command (input, &outline); 98 if (outline != (char *) NULL) free (outline); 99 if (!status) return (FALSE); 98 if (auto_break && !status) return (FALSE); 100 99 } 101 } else { 102 free (input); 103 } 100 } 101 free (input); 104 102 } 105 103 return (TRUE); -
trunk/Ohana/src/opihi/include/shell.h
r2843 r4462 40 40 void initialize PROTO((int argc, char **argv)); 41 41 void startup PROTO((int argc, char **argv)); 42 char **multicommand PROTO((char *line, int *nlist));42 int multicommand PROTO((char *line)); 43 43 int command PROTO((char *, char **)); 44 44 char *expand_vars PROTO((char *line)); -
trunk/Ohana/src/opihi/lib.shell/command.c
r4448 r4462 2 2 # define VERBOSE 0 3 3 4 static int Ncalls = 0;5 6 4 int command (char *line, char **outline) { 7 5 8 int i, status, argc , targc;9 char **argv , **targv;6 int i, status, argc; 7 char **argv; 10 8 Command *cmd; 11 12 Ncalls ++;13 9 14 10 /* force a space between ! and first word: !ls becomes ! ls */ … … 26 22 line = parse (line); /* line is freed here, new one allocated */ 27 23 /* any entry in line of the form {foo} returns value or tmp vector / buffer */ 24 25 /* we may have reallocated line, return new pointer */ 26 *outline = line; 28 27 29 targv = parse_commands (line, &targc); 30 if (targc == 0) { 31 /* empty command or assignment */ 32 if (line != (char *) NULL) free (line); 33 *outline = (char *) NULL; 34 return (TRUE); 28 argv = parse_commands (line, &argc); 29 if (argc == 0) return (TRUE); /* empty command or assignment */ 30 31 cmd = MatchCommand (argv[0], TRUE, FALSE); 32 if (cmd == NULL) { 33 status = FALSE; 34 } else { 35 free (argv[0]); 36 argv[0] = strcreate (cmd[0].name); 37 status = (*cmd[0].func) (argc, argv); 38 } 39 for (i = 0; i < argc; i++) free (argv[i]); 40 free (argv); 41 42 if (!status) { 43 char *msg; 44 msg = get_variable_ptr ("ERRORMSG"); 45 if (msg != (char *) NULL) fprintf (stderr, "%s\n", msg); 35 46 } 36 47 37 /* this needs some work to use multicommand correctly */38 /* allocate extra space to have null terminated list */39 ALLOCATE (argv, char *, targc + 1);40 argc = 0;41 status = TRUE;42 for (i = 0; status && (i < targc); i++) {43 if (targv[i][0] != ';') {44 argv[argc] = targv[i];45 argc ++;46 }47 if ((targv[i][0] == ';') || (i == targc - 1)) {48 49 if (argc == 0) continue;50 argv[argc] = 0;51 52 /* i +> argc + 1, argv[argc-1] = targv[i]53 * argv[n] = argv[argc - 1 - argc + 1 + n] = targv[i - argc + 1 + n]54 */55 56 cmd = MatchCommand (argv[0], TRUE, FALSE);57 if (cmd != NULL) {58 REALLOCATE (argv[0], char, strlen(cmd[0].name) + 1);59 targv[i-argc+1] = argv[0]; /* need to keep ptr in sync */60 strcpy (argv[0], cmd[0].name);61 status &= (*cmd[0].func) (argc, argv);62 if (auto_break && !status) break;63 }64 argc = 0;65 }66 }67 for (i = 0; i < targc; i++) free (targv[i]);68 free (argv);69 free (targv);70 *outline = line;71 if (!status) {72 char *msg;73 msg = get_variable ("ERRORMSG");74 if (msg != (char *) NULL) {75 fprintf (stderr, "%s\n", msg);76 free (msg);77 }78 }79 48 set_int_variable ("STATUS", status); 80 49 if (VERBOSE) fprintf (stderr, "command: %s, status: %d\n", line, status); 81 50 return (status); 82 83 51 } 84 85 void print_ncalls () {86 fprintf (stderr, "Ncalls to command(): %d\n", Ncalls);87 }88 -
trunk/Ohana/src/opihi/lib.shell/convert_to_RPN.c
r4306 r4462 68 68 if (!strcmp (argv[i], "/")) { type = 7; goto gotit; } 69 69 if (!strcmp (argv[i], "*")) { type = 7; goto gotit; } 70 if (!strcmp (argv[i], "%")) { type = 7; goto gotit; } 70 71 71 72 if (!strcmp (argv[i], "+")) { type = 6; goto gotit; } -
trunk/Ohana/src/opihi/lib.shell/exec_loop.c
r2843 r4462 5 5 void *Signal; 6 6 int n, Nlines, j, status, ThisList; 7 char * outline;7 char *line; 8 8 9 9 /* increase the shell level (Nlists) by one */ … … 29 29 for (n = 0; (n < Nlines) && !interrupt; n++) { 30 30 lists[ThisList].n = n; 31 status = command (lists[ThisList].line[n], &outline); 31 line = lists[ThisList].line[n]; 32 status = multicommand (line); 33 if (line != NULL) free (line); 32 34 n = lists[ThisList].n; 33 35 Nlines = lists[ThisList].Nlines; 34 if (outline != NULL) free (outline);35 36 if (auto_break && !status) loop_break = TRUE; 36 37 if (loop_break || loop_continue) break; -
trunk/Ohana/src/opihi/lib.shell/multicommand.c
r2598 r4462 1 1 # include "opihi.h" 2 2 3 char **multicommand (char *line, int *nlist) { 3 /* take input line and split into multiple lines 4 at the semi-colons. send these to 'command' */ 4 5 5 char **list; 6 int Nlist, NLIST; 6 int multicommand (char *line) { 7 8 int done, status; 9 char *p, *q, *tmpline, *outline; 7 10 8 Nlist = 0; 9 NLIST = 10; 10 ALLOCATE (list, char *, NLIST); 11 12 list[0] = strcreate (line); 13 *nlist = 1; 14 return (list); 11 p = line; 12 done = FALSE; 13 while (!done) { 14 q = strchr (p, ';'); 15 if (q == NULL) { 16 q = p + strlen(p); 17 done = TRUE; 18 } 19 tmpline = strncreate (p, q - p); 20 stripwhite (tmpline); 21 if (*tmpline) { 22 status = command (tmpline, &outline); 23 if (outline != NULL) free (outline); 24 if (!status && auto_break) done = TRUE; 25 } 26 p = q + 1; 27 } 28 return (status); 15 29 } 16 30 31 /* should skip ; surrounded by "" */ -
trunk/Ohana/src/opihi/lib.shell/opihi.c
r3907 r4462 36 36 stripwhite (line); 37 37 if (*line) { 38 list = multicommand (line, &Nlist); 39 for (i = 0; i < Nlist; i++) { 40 status = command (list[i], &outline); 41 if (outline != NULL) free (outline); 42 } 38 status = multicommand (line); 43 39 add_history (line); 44 40 append_history (1, history); 45 free (list);46 41 } 47 42 free (line); … … 49 44 } 50 45 } 51 52 /* this needs some work to use multicommand correctly53 multicommand is currently a do-nothing function.54 if we want multicommand to interact with the list/macro style commands,55 we need a command to push all the elements of the line onto the command stack.56 */ -
trunk/Ohana/src/opihi/lib.shell/stack_math.c
r4305 r4462 52 52 *out = *M1 / *M2; 53 53 break; 54 case '%': 55 for (i = 0; i < Nx; i++, out++, M1++, M2++) 56 *out = (int) *M1 % (int) *M2; 57 break; 54 58 case 0x5e: 55 59 for (i = 0; i < Nx; i++, out++, M1++, M2++) … … 168 172 *out = *M1 / *M2; 169 173 break; 174 case '%': 175 for (i = 0; i < Nx; i++, out++, M2++) 176 *out = (int) *M1 % (int) *M2; 177 break; 170 178 case 0x5e: 171 179 for (i = 0; i < Nx; i++, out++, M2++) … … 278 286 for (i = 0; i < Nx; i++, out++, M1++) 279 287 *out = *M1 / *M2; 288 break; 289 case '%': 290 for (i = 0; i < Nx; i++, out++, M1++) 291 *out = (int) *M1 % (int) *M2; 280 292 break; 281 293 case 0x5e: … … 405 417 } 406 418 break; 419 case '%': 420 for (i = 0; i < Ny; i++, M2++) { 421 for (j = 0; j < Nx; j++, out++, M1++) 422 *out = (int) *M1 % (int) *M2; 423 } 424 break; 407 425 case 0x5e: 408 426 for (i = 0; i < Ny; i++, M2++) { … … 565 583 for (j = 0; j < Nx; j++, out++, M1++, M2++) 566 584 *out = *M1 / *M2; 585 } 586 break; 587 case '%': 588 for (i = 0; i < Ny; i++) { 589 M1 = V1[0].ptr; 590 for (j = 0; j < Nx; j++, out++, M1++, M2++) 591 *out = (int) *M1 % (int) *M2; 567 592 } 568 593 break; … … 731 756 *out = *M1 / *M2; 732 757 break; 758 case '%': 759 for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++) 760 *out = (int) *M1 % (int) *M2; 761 break; 733 762 case 0x5e: 734 763 for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++) … … 851 880 *out = *M1 / *M2; 852 881 break; 882 case '%': 883 for (i = 0; i < Nx*Ny; i++, out++, M1++) 884 *out = (int) *M1 % (int) *M2; 885 break; 853 886 case 0x5e: 854 887 for (i = 0; i < Nx*Ny; i++, out++, M1++) … … 961 994 for (i = 0; i < Nx*Ny; i++, out++, M2++) 962 995 *out = *M1 / *M2; 996 break; 997 case '%': 998 for (i = 0; i < Nx*Ny; i++, out++, M2++) 999 *out = (int) *M1 % (int) *M2; 963 1000 break; 964 1001 case 0x5e: … … 1057 1094 case '/': 1058 1095 *out = *M1 / *M2; 1096 break; 1097 case '%': 1098 *out = (int) *M1 % (int) *M2; 1059 1099 break; 1060 1100 case 0x5e: -
trunk/Ohana/src/opihi/pcontrol/GetJobOutput.c
r4450 r4462 3 3 4 4 /* we read Nbytes from the host, then watch for the prompt */ 5 int GetJobOutput (char *c ommand, Host *host, IOBuffer *buffer, int Nbytes) {5 int GetJobOutput (char *cmd, Host *host, IOBuffer *buffer, int Nbytes) { 6 6 7 7 int i, status, Nstart; … … 13 13 Nstart = buffer[0].Nbuffer; 14 14 15 /* send c ommand (stdout / stderr) */16 ALLOCATE (line, char, MAX (1, strlen(c ommand) + 1));17 sprintf (line, "%s\n", c ommand);15 /* send cmd (stdout / stderr) */ 16 ALLOCATE (line, char, MAX (1, strlen(cmd) + 1)); 17 sprintf (line, "%s\n", cmd); 18 18 status = write (host[0].stdin, line, strlen(line)); 19 19 free (line); … … 46 46 47 47 default: 48 fprintf (stderr, "message received (GetJobOutput : %s)\n", c ommand);48 fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd); 49 49 /* drop extra bytes from pclient (not pclient:job) */ 50 50 buffer[0].Nbuffer = Nstart + Nbytes; -
trunk/Ohana/src/opihi/scripts/sched.pro
r4452 r4462 1 1 2 controller host localhost2 # controller host localhost 3 3 4 4 task test … … 6 6 periods -poll 1.0 7 7 periods -exec 2.0 8 periods -timeout 2.08 periods -timeout 8.0 9 9 # host local 10 10 host localhost … … 16 16 17 17 task.exit 0 18 echo stdout: $stdout 19 echo stderr: $stderr 20 exec echo "foo bar" >> failure.log 21 output test.log 18 # note that $stdout/$stderr may contain return characters 19 # which will interfere with 'exec' 20 output success.log 22 21 echo $stdout 23 22 output stdout 24 echo "successful job"25 23 end 26 24 27 25 task.exit 1 28 echo stdout: $stdout29 echo stderr: $stderr30 echo "failed job"26 output failure.log 27 echo $stdout 28 output stdout 31 29 end 32 30 … … 36 34 37 35 task.exit timeout 38 echo "job timed out" 36 output timeout.log 37 echo $stdout 38 output stdout 39 39 end 40 40 end
Note:
See TracChangeset
for help on using the changeset viewer.
