Richard Boegli's CnC_Generals_Zero_Hour Fork
WIP
This is documentation of Richard Boegil's Zero Hour Fork
Loading...
Searching...
No Matches
strtok_r.cpp
Go to the documentation of this file.
1
/*
2
** Command & Conquer Generals Zero Hour(tm)
3
** Copyright 2025 Electronic Arts Inc.
4
**
5
** This program is free software: you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation, either version 3 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program. If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
/***************************************************************************
20
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21
***************************************************************************
22
* *
23
* Project Name : G *
24
* *
25
* $Archive:: /G/wwlib/strtok_r.cpp $*
26
* *
27
* $Author:: Neal_k $*
28
* *
29
* $Modtime:: 4/03/00 11:43a $*
30
* *
31
* $Revision:: 1 $*
32
* *
33
*-------------------------------------------------------------------------*
34
* Functions: *
35
* strtok_r -- POSIX replacement for strtok (no internal static) *
36
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
#include "
strtok_r.h
"
39
#include <
string.h
>
40
#include <stdio.h>
41
42
//
43
// Replacement for strtok() that doesn't use a static to
44
// store the current position. The name comes from the
45
// POSIX threadsafe version of strtok (r = reentrant). The
46
// user provided var lasts is used in place of the static.
47
//
48
// Yes the Windows version of strtok is already threadsafe,
49
// but the fact that you can't call a function that uses strtok()
50
// during a series of strtok() calls is really annoying.
51
//
52
#ifndef _UNIX
53
char
*
strtok_r
(
char
*strptr,
const
char
*delimiters,
char
**lasts)
54
{
55
if
(strptr)
56
*lasts=strptr;
57
58
if
((*lasts)[0]==0)
// 0 length string?
59
return
(
NULL
);
60
61
//
62
// Note: strcspn & strspn are both called, they're opposites
63
//
64
int
dstart=strcspn(*lasts, delimiters);
// find first char of string in delimiters
65
66
if
(dstart == 0)
// string starts with a delimiter
67
{
68
int
dend=strspn(*lasts, delimiters);
// find last char of string NOT in delimiters
69
*lasts+=dend;
70
71
if
((*lasts)[0]==0)
// 0 length string?
72
return
(
NULL
);
73
74
dstart=strcspn(*lasts, delimiters);
75
}
76
char
*retval=*lasts;
77
78
if
((*lasts)[dstart]==0)
// is this the last token?
79
*lasts+=dstart;
80
else
// at least one more token to go...
81
{
82
(*lasts)[dstart]=0;
// null out the end
83
*lasts+=(dstart+1);
// advance pointer
84
}
85
return
(retval);
86
}
87
#endif
NULL
#define NULL
Definition
BaseType.h:92
string.h
strtok_r
char * strtok_r(char *strptr, const char *delimiters, char **lasts)
Definition
strtok_r.cpp:53
strtok_r.h
Code
Libraries
Source
WWVegas
WWLib
strtok_r.cpp
Generated by
1.13.2