9 /* #include <stringops.h>
11 /* char *mystrtok(bufp, delimiters)
13 /* const char *delimiters;
15 /* mystrtok() splits a buffer on the specified \fIdelimiters\fR.
16 /* Tokens are delimited by runs of delimiters, so this routine
17 /* cannot return zero-length tokens.
19 /* The \fIbufp\fR argument specifies the start of the search; it
20 /* is updated with each call. The input is destroyed.
22 /* The result value is the next token, or a null pointer when the
23 /* end of the buffer was reached.
27 /* The Secure Mailer license must be distributed with this software.
30 /* IBM T.J. Watson Research
32 /* Yorktown Heights, NY 10598, USA
40 /* Utility library. */
42 #include "stringops.h"
44 /* mystrtok - safe tokenizer */
46 char *mystrtok(char **src
, const char *sep
)
52 * Skip over leading delimiters.
54 start
+= strspn(start
, sep
);
61 * Separate off one token.
63 end
= start
+ strcspn(start
, sep
);
73 * Test program: read lines from stdin, split on whitespace.
77 #include "vstring_vstream.h"
81 VSTRING
*vp
= vstring_alloc(100);
85 while (vstring_fgets(vp
, VSTREAM_IN
)) {
86 start
= vstring_str(vp
);
87 while ((str
= mystrtok(&start
, " \t\r\n")) != 0)
88 vstream_printf(">%s<\n", str
);
89 vstream_fflush(VSTREAM_OUT
);