IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11119


Ignore:
Timestamp:
Jan 17, 2007, 3:39:12 PM (19 years ago)
Author:
eugene
Message:

fixed problem with list in macro

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

Legend:

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

    r10647 r11119  
    55int list (int argc, char **argv) {
    66
    7   int ThisList, depth, i, done;
     7  int ThisList, depth, i, done, found;
    88  char *input, line[1024];
    99  int N, Nbytes, NBYTES, Nread, status;
     
    3737  }
    3838
     39  if ((argc > 2) && (!strcmp (argv[2], "-add"))) {
     40    if (argc == 3) {
     41      gprint (GP_ERR, "USAGE: list (root) -add (word) (word) ...\n");
     42      return (FALSE);
     43    }
     44   
     45    sprintf (line, "%s:n", argv[1]);
     46    N = get_int_variable (line, &found);
     47    for (i = 0; i < argc - 3; i++) {
     48      sprintf (line, "%s:%d", argv[1], N + i);
     49      set_str_variable (line, argv[i+3]);
     50    }
     51    sprintf (line, "%s:n", argv[1]);
     52    set_int_variable (line, N + i);
     53
     54    return (TRUE);
     55  }
     56
    3957  if (argc != 2) {
    40     gprint (GP_ERR, "USAGE: list (root) -- terminate with 'END'\n");
     58    gprint (GP_ERR, "USAGE: list (root)                : supply list data, terminate with 'END'\n");
     59    gprint (GP_ERR, "USAGE: list (root) -x (command)   : create list from shell output\n");
     60    gprint (GP_ERR, "USAGE: list (root) -split (words) : create list from words\n");
     61    gprint (GP_ERR, "USAGE: list (root) -add (words)   : extend a list\n");
    4162    return (FALSE);
    4263  }
  • trunk/Ohana/src/opihi/lib.shell/ListOps.c

    r11007 r11119  
    157157}
    158158
     159// list (word) : nested list
     160// list (word) -x : not nested list
     161// list (word) -split : not nested list
     162int is_list_data (char *line) {
     163
     164  char *comm, *temp;
     165
     166  temp = thisword (nextword (nextword (line)));
     167  comm = thisword (line);
     168
     169  if (comm == NULL) goto escape;
     170
     171  if (strcmp (comm, "list")) goto escape;
     172
     173  /* if (cond) (command) does not define a complete block */
     174  if (temp != NULL) {
     175      if (!strcmp (temp, "-x")) goto escape;
     176      if (!strcmp (temp, "-split")) goto escape;
     177      if (!strcmp (temp, "-add")) goto escape;
     178  }
     179
     180  if (temp != NULL) free (temp);
     181  if (comm != NULL) free (comm);
     182  return (TRUE);
     183
     184escape:
     185  if (comm != NULL) free (comm);
     186  if (temp != NULL) free (temp);
     187  return (FALSE);
     188}
     189
    159190int is_loop (char *line) {
    160191
     
    216247  status |= is_macro_create (line);
    217248  status |= is_for_loop (line);
     249  status |= is_list_data (line);
    218250  status |= is_loop (line);
    219251  status |= is_task (line);
Note: See TracChangeset for help on using the changeset viewer.