IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 4462


Ignore:
Timestamp:
Jul 6, 2005, 10:29:08 AM (21 years ago)
Author:
eugene
Message:

fixed multicommand to parse subcommands sequentially, added modulus operator

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

Legend:

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

    r3922 r4462  
    9494    if (logic) {
    9595      if (*input) {
     96        status = multicommand (input);
    9697        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);
    10099      }
    101     } else {
    102       free (input);
    103     }
     100    }
     101    free (input);
    104102  }
    105103  return (TRUE);
  • trunk/Ohana/src/opihi/include/shell.h

    r2843 r4462  
    4040void          initialize                PROTO((int argc, char **argv));
    4141void          startup                   PROTO((int argc, char **argv));
    42 char        **multicommand              PROTO((char *line, int *nlist));
     42int           multicommand              PROTO((char *line));
    4343int           command                   PROTO((char *, char **));
    4444char         *expand_vars               PROTO((char *line));
  • trunk/Ohana/src/opihi/lib.shell/command.c

    r4448 r4462  
    22# define VERBOSE 0
    33
    4 static int Ncalls = 0;
    5 
    64int command (char *line, char **outline) {
    75
    8   int i, status, argc, targc;
    9   char **argv, **targv;
     6  int i, status, argc;
     7  char **argv;
    108  Command *cmd;
    11 
    12   Ncalls ++;
    139
    1410  /* force a space between ! and first word: !ls becomes ! ls */
     
    2622  line = parse (line);        /* line is freed here, new one allocated */
    2723  /* 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;
    2827 
    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);
    3546  }
    3647
    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   }
    7948  set_int_variable ("STATUS", status);
    8049  if (VERBOSE) fprintf (stderr, "command: %s, status: %d\n", line, status);
    8150  return (status);
    82 
    8351}
    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  
    6868    if (!strcmp (argv[i], "/"))      { type = 7; goto gotit; }
    6969    if (!strcmp (argv[i], "*"))      { type = 7; goto gotit; }
     70    if (!strcmp (argv[i], "%"))      { type = 7; goto gotit; }
    7071
    7172    if (!strcmp (argv[i], "+"))      { type = 6; goto gotit; }
  • trunk/Ohana/src/opihi/lib.shell/exec_loop.c

    r2843 r4462  
    55  void *Signal;
    66  int n, Nlines, j, status, ThisList;
    7   char *outline;
     7  char *line;
    88 
    99  /* increase the shell level (Nlists) by one */
     
    2929  for (n = 0; (n < Nlines) && !interrupt; n++) {
    3030    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);
    3234    n = lists[ThisList].n;
    3335    Nlines = lists[ThisList].Nlines;
    34     if (outline != NULL) free (outline);
    3536    if (auto_break && !status) loop_break = TRUE;
    3637    if (loop_break || loop_continue) break;
  • trunk/Ohana/src/opihi/lib.shell/multicommand.c

    r2598 r4462  
    11# include "opihi.h"
    22
    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' */
    45
    5   char **list;
    6   int Nlist, NLIST;
     6int multicommand (char *line) {
     7 
     8  int done, status;
     9  char *p, *q, *tmpline, *outline;
    710
    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);
    1529}
    1630
     31/* should skip ; surrounded by "" */
  • trunk/Ohana/src/opihi/lib.shell/opihi.c

    r3907 r4462  
    3636    stripwhite (line);
    3737    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);
    4339      add_history (line);
    4440      append_history (1, history);
    45       free (list);
    4641    }
    4742    free (line);
     
    4944  }
    5045}
    51 
    52   /* this needs some work to use multicommand correctly
    53      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  
    5252      *out = *M1 / *M2;
    5353    break;
     54  case '%':
     55    for (i = 0; i < Nx; i++, out++, M1++, M2++)
     56      *out = (int) *M1 % (int) *M2;
     57    break;
    5458  case 0x5e:
    5559    for (i = 0; i < Nx; i++, out++, M1++, M2++)
     
    168172      *out = *M1 / *M2;
    169173    break;
     174  case '%':
     175    for (i = 0; i < Nx; i++, out++, M2++)
     176      *out = (int) *M1 % (int) *M2;
     177    break;
    170178  case 0x5e:
    171179    for (i = 0; i < Nx; i++, out++, M2++)
     
    278286    for (i = 0; i < Nx; i++, out++, M1++)
    279287      *out = *M1 / *M2;
     288    break;
     289  case '%':
     290    for (i = 0; i < Nx; i++, out++, M1++)
     291      *out = (int) *M1 % (int) *M2;
    280292    break;
    281293  case 0x5e:
     
    405417    }
    406418    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;
    407425  case 0x5e:
    408426    for (i = 0; i < Ny; i++, M2++) {
     
    565583      for (j = 0; j < Nx; j++, out++, M1++, M2++)
    566584        *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;
    567592    }
    568593    break;
     
    731756      *out = *M1 / *M2;
    732757    break;
     758  case '%':
     759    for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++)
     760      *out = (int) *M1 % (int) *M2;
     761    break;
    733762  case 0x5e:
    734763    for (i = 0; i < Nx*Ny; i++, out++, M1++, M2++)
     
    851880      *out = *M1 / *M2;
    852881    break;
     882  case '%':
     883    for (i = 0; i < Nx*Ny; i++, out++, M1++)
     884      *out = (int) *M1 % (int) *M2;
     885    break;
    853886  case 0x5e:
    854887    for (i = 0; i < Nx*Ny; i++, out++, M1++)
     
    961994    for (i = 0; i < Nx*Ny; i++, out++, M2++)
    962995      *out = *M1 / *M2;
     996    break;
     997  case '%':
     998    for (i = 0; i < Nx*Ny; i++, out++, M2++)
     999      *out = (int) *M1 % (int) *M2;
    9631000    break;
    9641001  case 0x5e:
     
    10571094  case '/':
    10581095    *out = *M1 / *M2;
     1096    break;
     1097  case '%':
     1098    *out = (int) *M1 % (int) *M2;
    10591099    break;
    10601100  case 0x5e:
  • trunk/Ohana/src/opihi/pcontrol/GetJobOutput.c

    r4450 r4462  
    33
    44/* we read Nbytes from the host, then watch for the prompt */
    5 int GetJobOutput (char *command, Host *host, IOBuffer *buffer, int Nbytes) {
     5int GetJobOutput (char *cmd, Host *host, IOBuffer *buffer, int Nbytes) {
    66 
    77  int i, status, Nstart;
     
    1313  Nstart = buffer[0].Nbuffer;
    1414
    15   /* send command (stdout / stderr) */
    16   ALLOCATE (line, char, MAX (1, strlen(command) + 1));
    17   sprintf (line, "%s\n", command);
     15  /* send cmd (stdout / stderr) */
     16  ALLOCATE (line, char, MAX (1, strlen(cmd) + 1));
     17  sprintf (line, "%s\n", cmd);
    1818  status = write (host[0].stdin, line, strlen(line));
    1919  free (line);
     
    4646
    4747    default:
    48       fprintf (stderr, "message received (GetJobOutput : %s)\n", command); 
     48      fprintf (stderr, "message received (GetJobOutput : %s)\n", cmd); 
    4949      /* drop extra bytes from pclient (not pclient:job) */
    5050      buffer[0].Nbuffer = Nstart + Nbytes;
  • trunk/Ohana/src/opihi/scripts/sched.pro

    r4452 r4462  
    11
    2 controller host localhost
     2# controller host localhost
    33
    44task test
     
    66  periods -poll 1.0
    77  periods -exec 2.0
    8   periods -timeout 2.0
     8  periods -timeout 8.0
    99  # host local
    1010  host localhost
     
    1616
    1717  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
    2221    echo $stdout
    2322    output stdout
    24     echo "successful job"
    2523  end
    2624
    2725  task.exit 1
    28     echo stdout: $stdout
    29     echo stderr: $stderr
    30     echo "failed job"
     26    output failure.log
     27    echo $stdout
     28    output stdout
    3129  end
    3230
     
    3634
    3735  task.exit timeout
    38     echo "job timed out"
     36    output timeout.log
     37    echo $stdout
     38    output stdout
    3939  end
    4040end
Note: See TracChangeset for help on using the changeset viewer.