/*! \file tokenizer.c \brief String tokenization routines This file contains various routines for splitting an input string into tokens and returning them in form of a list. The goal is to mimic perl's split function. \date Started 11/23/04 \author George \version\verbatim $Id: tokenizer.c 10711 2011-08-31 22:23:04Z karypis $ \endverbatim */ #include /************************************************************************ * This function tokenizes a string based on the user-supplied delimiters * list. The resulting tokens are returned into an array of strings. *************************************************************************/ void gk_strtokenize(char *str, char *delim, gk_Tokens_t *tokens) { int i, ntoks, slen; tokens->strbuf = gk_strdup(str); slen = strlen(str); str = tokens->strbuf; /* Scan once to determine the number of tokens */ for (ntoks=0, i=0; intoks = ntoks; tokens->list = (char **)gk_malloc(ntoks*sizeof(char *), "strtokenize: tokens->list"); /* Scan a second time to mark and link the tokens */ for (ntoks=0, i=0; ilist[ntoks++] = str+i; /* Consume all the consecutive characters from the token */ while (ilist, &tokens->strbuf, LTERM); }