IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 29, 2009, 10:16:52 AM (17 years ago)
Author:
eugene
Message:

adding an inthash function which accepts non-numeric words (and treats them as zero)

File:
1 edited

Legend:

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

    r16427 r25965  
    3434    sprintf (line, "%s:n", argv[1]);
    3535    set_int_variable (line, i);
     36
     37    return (TRUE);
     38  }
     39
     40  // return an error if -add is given with no other args
     41  if ((argc > 2) && (!strcmp (argv[2], "-splitbychar"))) {
     42    if (argc < 4) {
     43      gprint (GP_ERR, "USAGE: list (root) -splitbychar (char) (word) [(word)...]\n");
     44      return (FALSE);
     45    }
     46   
     47    int j, nWords;
     48    char splitter;
     49    char *new, *word, *ptr;
     50
     51    nWords = 0;
     52    splitter = argv[3][0];
     53
     54    for (i = 0; i < argc - 3; i++) {
     55      new = strcreate (argv[i+3]);
     56      for (j = 0; new[j]; j++) {
     57        if (new[j] == splitter) new[j] = ' ';
     58      }
     59
     60      ptr = new;
     61      while (ptr) {
     62        word = thisword (ptr);
     63        if (!word) break;
     64       
     65        sprintf (line, "%s:%d", argv[1], nWords);
     66        set_str_variable (line, word);
     67        FREE (word);
     68        ptr = nextword (ptr);
     69        nWords ++;
     70      }
     71      FREE (new);
     72    }
     73    sprintf (line, "%s:n", argv[1]);
     74    set_int_variable (line, nWords);
    3675
    3776    return (TRUE);
Note: See TracChangeset for help on using the changeset viewer.