add a missing section header table index conversion
[tangerine.git] / compiler / clib / strtok.c
blobe8b62293be95b6ab2abebaf614fdc774d1ab58aa
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function strtok().
6 */
8 #include <stdio.h>
10 /*****************************************************************************
12 NAME */
13 #include <string.h>
15 char * strtok (
17 /* SYNOPSIS */
18 char * str,
19 const char * sep)
21 /* FUNCTION
22 Separates a string by the characters in sep.
24 INPUTS
25 str - The string to check or NULL if the next word in
26 the last string is to be searched.
27 sep - Characters which separate "words" in str.
29 RESULT
30 The first word in str or the next one if str is NULL.
32 NOTES
33 The function changes str !
35 EXAMPLE
36 char buffer[64];
38 strcpy (buffer, "Hello, this is a test.");
40 // Init. Returns "Hello"
41 strtok (str, " \t,.");
43 // Next word. Returns "this"
44 strtok (NULL, " \t,.");
46 // Next word. Returns "is"
47 strtok (NULL, " \t");
49 // Next word. Returns "a"
50 strtok (NULL, " \t");
52 // Next word. Returns "test."
53 strtok (NULL, " \t");
55 // Next word. Returns NULL.
56 strtok (NULL, " \t");
58 BUGS
60 SEE ALSO
62 INTERNALS
64 ******************************************************************************/
66 static char * t;
68 if (str != NULL)
69 t = str;
70 else
71 str = t;
73 str += strspn (str, sep);
75 if (*str == '\0')
76 return NULL;
78 t = str;
80 t += strcspn (str, sep);
82 if (*t != '\0')
83 *t ++ = '\0';
85 return str;
86 } /* strtok */