2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) INRIA - Cong WU
4 * Copyright (C) INRIA - 2008 - Allan CORNET
5 * Copyright (C) Digiteo - 2011 - Cedric DELAMARRE
7 * This file must be used under the terms of the CeCILL.
8 * This source file is licensed as described in the file COPYING, which
9 * you should have received as part of this distribution. The terms
10 * are also available at
11 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
15 /*------------------------------------------------------------------------*/
18 #include "sci_malloc.h"
20 #include "os_string.h"
21 #include "os_wcstok.h"
24 /*------------------------------------------------------------------------*/
25 char** stringTokens(const char* str, const char* delim, int* sizeoutputs)
27 char **outputs = NULL;
34 char *pstToken = NULL;
35 char *pstWork = os_strdup(str);
36 char *pstState = NULL;
38 //compute size of outputs array
39 for (pstToken = os_strtok(pstWork, delim, &pstState);
41 pstToken = os_strtok(NULL, delim, &pstState), (*sizeoutputs)++)
46 if (*sizeoutputs == 0)
53 outputs = (char**)MALLOC(sizeof(char*) * *sizeoutputs);
56 pstWork = os_strdup(str);
57 for (pstToken = os_strtok(pstWork, delim, &pstState);
59 pstToken = os_strtok(NULL, delim, &pstState), i++)
61 outputs[i] = os_strdup(pstToken);
69 /*--------------------------------------------------------------------------*/