]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add PL_strtok_r
authorMichael Jerris <mike@jerris.com>
Tue, 18 Dec 2012 03:50:34 +0000 (22:50 -0500)
committerMichael Jerris <mike@jerris.com>
Tue, 18 Dec 2012 03:50:49 +0000 (22:50 -0500)
libs/sipcc/Makefile.am
libs/sipcc/core/gsm/gsm_sdp.c
libs/sipcc/core/sdp/sdp_attr.c
libs/sipcc/core/sipstack/ccsip_messaging.c
libs/sipcc/core/sipstack/ccsip_pmh.c
libs/sipcc/core/sipstack/ccsip_spi_utils.c
libs/sipcc/cpr/common/strtok.c [new file with mode: 0644]
libs/sipcc/cpr/include/plstr.h [new file with mode: 0644]

index 74a1784d6419c4dfd737bd7d2ed2db32970baecc..a09220a6df8736deea5e5339941c3e2d461a8230 100644 (file)
@@ -125,7 +125,7 @@ core/src-common/util_ios_queue.c \
 core/src-common/util_parse.c \
 core/src-common/util_string.c
 
-CPR_COMMON_SRC = cpr/common/cpr_string.c
+CPR_COMMON_SRC = cpr/common/cpr_string.c cpr/common/strtok.c
 
 CPR_DARWIN_SRC = \
 cpr/darwin/cpr_darwin_errno.c \
@@ -342,6 +342,7 @@ cpr/darwin/cpr_darwin_timers.h \
 cpr/darwin/cpr_darwin_tst.h \
 cpr/darwin/cpr_darwin_types.h \
 cpr/include/cpr.h \
+cpr/include/plstr.h \
 cpr/include/cpr_assert.h \
 cpr/include/cpr_debug.h \
 cpr/include/cpr_errno.h \
index 6a795200fd1eeb0a889202795575ff652aed622b..e349a347ae2a73df2d9f6905bcb26f50864f7172 100644 (file)
@@ -22,7 +22,7 @@
 #include "platform_api.h"
 #include "vcm.h"
 //#include "prlog.h"
-//#include "plstr.h"
+#include "plstr.h"
 #include "sdp_private.h"
 
 //TODO Need to place this in a portable location
index fadaceede8e880b687d502adcb440cf5372e0fae..b0105ee59d8b955970c90fc9b67f73c5df3d2fec 100644 (file)
@@ -5,7 +5,7 @@
 #include <errno.h>
 #include <limits.h>
 
-//#include "plstr.h"
+#include "plstr.h"
 #include "sdp_os_defs.h"
 #include "sdp.h"
 #include "sdp_private.h"
index 515d0a90bc00652e19b71fb08896c495201e7cea..d9a79651e953c4fcc756ebbfc2b5a6443e9fe23a 100644 (file)
@@ -2,7 +2,7 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-//#include "plstr.h"
+#include "plstr.h"
 #include "cpr_types.h"
 #include "cpr_time.h"
 #include "cpr_stdio.h"
index 9717058a3a667c8fc34ae90cf89daa860b322945..e298993c0975d688fdd0abf417a5560a8b73d315 100644 (file)
@@ -15,7 +15,7 @@
 #include <errno.h>
 #include <limits.h>
 
-//#include "plstr.h"
+#include "plstr.h"
 #include "cpr_types.h"
 #include "cpr_stdio.h"
 #include "cpr_stdlib.h"
index 781bee2d4353de3ce2c4f3505419cf46cefa5e73..97ce502d31c9a0b2333e5202140cdee16fe526eb 100755 (executable)
@@ -9,7 +9,7 @@
  * CCAPI callids, conversion from CCAPI to SIP cause codes and the
  * like.
  */
-//#include "plstr.h"
+#include "plstr.h"
 #include "cpr_types.h"
 #include "cpr_stdlib.h"
 #include "cpr_string.h"
diff --git a/libs/sipcc/cpr/common/strtok.c b/libs/sipcc/cpr/common/strtok.c
new file mode 100644 (file)
index 0000000..0818229
--- /dev/null
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "plstr.h"
+
+char * PL_strtok_r(char *s1, const char *s2, char **lasts)
+{
+    const char *sepp;
+    int         c, sc;
+    char       *tok;
+
+    if( s1 == NULL )
+    {
+        if( *lasts == NULL )
+            return NULL;
+
+        s1 = *lasts;
+    }
+  
+    for( ; (c = *s1) != 0; s1++ )
+    {
+        for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
+        {
+            if( c == sc )
+                break;
+        }
+        if( sc == 0 )
+            break; 
+    }
+
+    if( c == 0 )
+    {
+        *lasts = NULL;
+        return NULL;
+    }
+  
+    tok = s1++;
+
+    for( ; (c = *s1) != 0; s1++ )
+    {
+        for( sepp = s2; (sc = *sepp) != 0; sepp++ )
+        {
+            if( c == sc )
+            {
+                *s1++ = '\0';
+                *lasts = s1;
+                return tok;
+            }
+        }
+    }
+    *lasts = NULL;
+    return tok;
+}
diff --git a/libs/sipcc/cpr/include/plstr.h b/libs/sipcc/cpr/include/plstr.h
new file mode 100644 (file)
index 0000000..46f101a
--- /dev/null
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef _plstr_h
+#define _plstr_h
+
+#include "cpr_types.h"
+
+__BEGIN_DECLS
+
+/*
+ * PL_strtok_r
+ *
+ * Splits the string s1 into tokens, separated by one or more characters
+ * from the separator string s2.  The argument lasts points to a
+ * user-supplied char * pointer in which PL_strtok_r stores information
+ * for it to continue scanning the same string.
+ *
+ * In the first call to PL_strtok_r, s1 points to a string and the value
+ * of *lasts is ignored.  PL_strtok_r returns a pointer to the first
+ * token, writes '\0' into the character following the first token, and
+ * updates *lasts.
+ *
+ * In subsequent calls, s1 is null and lasts must stay unchanged from the
+ * previous call.  The separator string s2 may be different from call to
+ * call.  PL_strtok_r returns a pointer to the next token in s1.  When no
+ * token remains in s1, PL_strtok_r returns null.
+ */
+
+char * PL_strtok_r(char *s1, const char *s2, char **lasts);
+
+/*
+ * Things not (yet?) included: strspn/strcspn, strsep.
+ * memchr, memcmp, memcpy, memccpy, index, rindex, bcmp, bcopy, bzero.
+ * Any and all i18n/l10n stuff.
+ */
+
+__END_DECLS
+
+#endif /* _plstr_h */