]> mj.ucw.cz Git - libucw.git/commitdiff
added sepsplit() in wordsplit.c
authorRobert Spalek <robert@ucw.cz>
Sat, 21 Aug 2004 16:29:06 +0000 (16:29 +0000)
committerRobert Spalek <robert@ucw.cz>
Sat, 21 Aug 2004 16:29:06 +0000 (16:29 +0000)
lib/lib.h
lib/wordsplit.c

index 2a106e7ff50d234d65ea46c7b76114d53c64f9cc..de5b4b8cac65b2935543a57add7e70aa4b1ed909 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -128,6 +128,7 @@ int fls(u32);
 
 /* wordsplit.c */
 
 
 /* wordsplit.c */
 
+int sepsplit(byte *str, byte sep, byte **rec, uns max);
 int wordsplit(byte *, byte **, uns);
 
 /* pat(i)match.c: Matching of shell patterns */
 int wordsplit(byte *, byte **, uns);
 
 /* pat(i)match.c: Matching of shell patterns */
index 6e2e792edd71b9ed62989c6cb7c7aefe4613f661..1a488f2e68d305e88424626eba549c753788ab61 100644 (file)
@@ -2,6 +2,7 @@
  *     Sherlock Library -- Word Splitting
  *
  *     (c) 1997 Martin Mares <mj@ucw.cz>
  *     Sherlock Library -- Word Splitting
  *
  *     (c) 1997 Martin Mares <mj@ucw.cz>
+ *     (c) 2004 Robert Spalek <robert@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
 #include "lib/lib.h"
 #include "lib/chartype.h"
 
 #include "lib/lib.h"
 #include "lib/chartype.h"
 
+#include <string.h>
+
+int
+sepsplit(byte *str, byte sep, byte **rec, uns max)
+{
+  uns cnt = 0;
+  while (1)
+  {
+    rec[cnt++] = str;
+    str = strchr(str, sep);
+    if (!str)
+      return cnt;
+    if (cnt >= max)
+      return -1;
+    *str++ = 0;
+  }
+}
+
 int
 wordsplit(byte *src, byte **dst, uns max)
 {
 int
 wordsplit(byte *src, byte **dst, uns max)
 {