Changeset d275eb2 for util.c


Ignore:
Timestamp:
Jan 2, 2011, 3:31:58 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
2bc6ad35
Parents:
f640876
git-author:
David Benjamin <davidben@mit.edu> (12/15/10 13:18:34)
git-committer:
David Benjamin <davidben@mit.edu> (01/02/11 15:31:58)
Message:
Replace atokenize with glib's g_strsplit_set

Glib's had g_strsplit_set since forever, and it does exactly the same
thing as atokenize, modulo needing a pesky NULL check. We may as well
use it.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • util.c

    rfa90c34 rd275eb2  
    1111#include <glib/gstdio.h>
    1212#include <glib-object.h>
    13 
    14 char **atokenize(const char *buffer, const char *sep, int *i)
    15 {
    16   /* each element of return must be freed by user */
    17   char **args;
    18   char *workbuff, *foo;
    19   int done=0, first=1, count=0;
    20 
    21   workbuff = owl_strdup(buffer);
    22 
    23   args=NULL;
    24   while (!done) {
    25     if (first) {
    26       first=0;
    27       foo=strtok(workbuff, sep);
    28     } else {
    29       foo=strtok(NULL, sep);
    30     }
    31     if (foo==NULL) {
    32       done=1;
    33     } else {
    34       args=owl_realloc(args, sizeof(char *) * (count+1));
    35       args[count] = owl_strdup(foo);
    36       count++;
    37     }
    38   }
    39   *i=count;
    40   owl_free(workbuff);
    41   return(args);
    42 }
    4313
    4414const char *skiptokens(const char *buff, int n) {
     
    12797}
    12898
    129 void atokenize_delete(char **tok, int nels)
    130 {
    131   int i;
    132   for (i=0; i<nels; i++) {
    133     owl_free(tok[i]);
    134   }
    135   owl_free(tok);
    136 }
    137 
    138 
    13999void owl_parse_delete(char **argv, int argc)
    140100{
Note: See TracChangeset for help on using the changeset viewer.