2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
32 /**********************************************************
34 * OS Testing - Silicon Graphics, Inc.
36 * FUNCTION NAME : string_to_tokens
38 * FUNCTION TITLE : Break a string into its tokens
42 * int string_to_tokens(arg_string, arg_array, array_size, separator)
48 * AUTHOR : Richard Logan
52 * INITIAL RELEASE : UNICOS 7.0
55 * This function parses the string 'arg_string', placing pointers to
56 * the 'separator' separated tokens into the elements of 'arg_array'.
57 * The array is terminated with a null pointer.
58 * 'arg_array' must contains at least 'array_size' elements.
59 * Only the first 'array_size' minus one tokens will be placed into
60 * 'arg_array'. If there are more than 'array_size'-1 tokens, the rest are
61 * ignored by this routine.
64 * This function returns the number of 'separator' separated tokens that
65 * were found in 'arg_string'.
66 * If 'arg_array' or 'separator' is NULL or 'array_size' is less than 2, -1 is returned.
69 * This function uses strtok() to parse 'arg_string', and thus
70 * physically alters 'arg_string' by placing null characters where the
71 * separators originally were.
74 *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
76 #include <string.h> /* for string functions */
77 #include "string_to_tokens.h"
80 string_to_tokens(char *arg_string, char *arg_array[], int array_size, char *separator)
82 int num_toks = 0; /* number of tokens found */
85 if ( arg_array == NULL || array_size <= 1 || separator == NULL )
89 * Use strtok() to parse 'arg_string', placing pointers to the
90 * individual tokens into the elements of 'arg_array'.
92 if ( (arg_array[num_toks] = strtok(arg_string, separator)) == NULL ) {
96 for (num_toks=1;num_toks<array_size; num_toks++) {
97 if ( (arg_array[num_toks] = strtok(NULL, separator)) == NULL )
101 if ( num_toks == array_size )
102 arg_array[num_toks] = NULL;
105 * Return the number of tokens that were found in 'arg_string'.
109 } /* end of string_to_tokens */