trawick 01/05/23 07:15:55
Modified: . CHANGES libapr.dsp apr.dsp
include apr_strings.h
strings Makefile.in
test .cvsignore Makefile.in
Added: strings apr_strtok.c
test teststr.c
Log:
Add apr_strtok(), a thread-safe flavor of strtok() which has the
same interface as strtok_r().
Revision Changes Path
1.107 +4 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- CHANGES 2001/05/17 12:19:45 1.106
+++ CHANGES 2001/05/23 14:15:27 1.107
@@ -1,4 +1,8 @@
Changes with APR b1
+
+ *) Add apr_strtok(), a thread-safe flavor of strtok() which has the
+ same interface as strtok_r(). [Jeff Trawick]
+
*) Add other child support to Win32 [Bill Stoddard]
*) Other-child registrations are automatically removed when the
1.30 +4 -0 apr/libapr.dsp
Index: libapr.dsp
===================================================================
RCS file: /home/cvs/apr/libapr.dsp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- libapr.dsp 2001/05/17 12:19:49 1.29
+++ libapr.dsp 2001/05/23 14:15:29 1.30
@@ -133,6 +133,10 @@
SOURCE=.\strings\apr_strnatcmp.c
# End Source File
+# Begin Source File
+
+SOURCE=.\strings\apr_strtok.c
+# End Source File
# End Group
# Begin Group "passwd"
1.71 +4 -0 apr/apr.dsp
Index: apr.dsp
===================================================================
RCS file: /home/cvs/apr/apr.dsp,v
retrieving revision 1.70
retrieving revision 1.71
diff -u -r1.70 -r1.71
--- apr.dsp 2001/05/17 12:19:47 1.70
+++ apr.dsp 2001/05/23 14:15:31 1.71
@@ -127,6 +127,10 @@
SOURCE=.\strings\apr_strnatcmp.c
# End Source File
+# Begin Source File
+
+SOURCE=.\strings\apr_strtok.c
+# End Source File
# End Group
# Begin Group "passwd"
1.17 +14 -0 apr/include/apr_strings.h
Index: apr_strings.h
===================================================================
RCS file: /home/cvs/apr/include/apr_strings.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- apr_strings.h 2001/05/22 11:23:47 1.16
+++ apr_strings.h 2001/05/23 14:15:39 1.17
@@ -220,6 +220,20 @@
char ***argv_out,
apr_pool_t *token_context);
+/**
+ * Split a string into separate '\0'-terminated tokens. The tokens are
+ * delimited in the string by one or more characters from the sep
+ * argument.
+ * @param str The string to separate; this should be specified on the
+ * first call to apr_strtok() for a given string, and NULL
+ * on subsequent calls.
+ * @param sep The set of delimiters
+ * @param last Internal state saved by apr_strtok() between calls.
+ * @return The next token from the string
+ * @deffunc char *apr_strtok(char *str, const char *sep, char **last)
+ */
+APR_DECLARE(char *) apr_strtok(char *str, const char *sep, char **last);
+
/*
* These are snprintf implementations based on apr_vformatter().
*
1.9 +2 -1 apr/strings/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr/strings/Makefile.in,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Makefile.in 2001/01/09 11:06:17 1.8
+++ Makefile.in 2001/05/23 14:15:43 1.9
@@ -4,7 +4,8 @@
apr_snprintf.lo \
apr_strnatcmp.lo \
apr_strings.lo \
- apr_fnmatch.lo
+ apr_fnmatch.lo \
+ apr_strtok.lo
# bring in rules.mk for standard functionality
@INCLUDE_RULES@
1.1 apr/strings/apr_strtok.c
Index: apr_strtok.c
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#ifdef HAVE_STDDEF_H
#include <stddef.h> /* for NULL */
#endif
#include "apr.h"
#include "apr_strings.h"
#define APR_WANT_STRFUNC /* for strchr() */
#include "apr_want.h"
APR_DECLARE(char *) apr_strtok(char *str, const char *sep, char **last)
{
char *token;
if (!str) /* subsequent call */
str = *last; /* start where we left off */
/* skip characters in sep (will terminate at '\0') */
while (*str && strchr(sep, *str))
++str;
if (!*str) /* no more tokens */
return NULL;
token = str;
/* skip valid token characters to terminate token and
* prepare for the next call (will terminate at '\0)
*/
*last = token + 1;
while (**last && !strchr(sep, **last))
++*last;
if (**last) {
**last = '\0';
++*last;
}
return token;
}
1.22 +1 -0 apr/test/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/apr/test/.cvsignore,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- .cvsignore 2001/05/09 18:25:58 1.21
+++ .cvsignore 2001/05/23 14:15:49 1.22
@@ -13,6 +13,7 @@
testpipe
testpoll
testshmem
+teststr
testtime
testthread
client
1.55 +5 -1 apr/test/Makefile.in
Index: Makefile.in
===================================================================
RCS file: /home/cvs/apr/test/Makefile.in,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- Makefile.in 2001/05/13 13:06:10 1.54
+++ Makefile.in 2001/05/23 14:15:50 1.55
@@ -22,7 +22,8 @@
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
[EMAIL PROTECTED]@ \
- [EMAIL PROTECTED]@
+ [EMAIL PROTECTED]@ \
+ [EMAIL PROTECTED]@
TARGETS = $(PROGRAMS)
@@ -113,5 +114,8 @@
[EMAIL PROTECTED]@: testmem.lo $(LOCAL_LIBS)
$(LINK) testmem.lo $(LOCAL_LIBS) $(ALL_LIBS)
+
[EMAIL PROTECTED]@: teststr.lo $(LOCAL_LIBS)
+ $(LINK) teststr.lo $(LOCAL_LIBS) $(ALL_LIBS)
# DO NOT REMOVE
1.1 apr/test/teststr.c
Index: teststr.c
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "apr_general.h"
#include "apr_strings.h"
static void closeapr(void)
{
apr_terminate();
}
static void test_strtok(apr_pool_t *p)
{
struct {
char *input;
char *sep;
}
tc[] = {
{
"",
"Z"
},
{
" asdf jkl; 77889909 \r\n\1\2\3Z",
" \r\n\3\2\1"
},
{
NULL, /* but who cares if apr_strtok() segfaults? */
" \t"
},
#if 0 /* don't do this... you deserve to segfault */
{
"a b c ",
NULL
},
#endif
{
" a b c ",
""
},
{
"a b c ",
" "
}
};
int curtc;
for (curtc = 0; curtc < sizeof tc / sizeof tc[0]; curtc++) {
char *retval1, *retval2;
char *str1, *str2;
char *state;
str1 = apr_pstrdup(p, tc[curtc].input);
str2 = apr_pstrdup(p, tc[curtc].input);
do {
retval1 = apr_strtok(str1, tc[curtc].sep, &state);
retval2 = strtok(str2, tc[curtc].sep);
if (!retval1)
assert(!retval2);
else {
assert(retval2);
assert(!strcmp(retval1, retval2));
}
str1 = str2 = NULL; /* make sure we pass NULL on subsequent calls
*/
} while (retval1);
}
}
int main(int argc, const char * const argv[])
{
apr_pool_t *p;
apr_initialize();
atexit(closeapr);
apr_pool_create(&p, NULL);
test_strtok(p);
return 0;
}