2 ** brkstring.c -- (destructively) split a string into
3 ** -- an array of substrings
5 ** This code is Copyright (c) 2002, by the authors of nmh. See the
6 ** COPYRIGHT file in the root directory of the nmh distribution for
7 ** complete copyright information.
13 /* allocate this number of pointers at a time */
16 static char **broken = NULL; /* array of substring start addresses */
17 static int len = 0; /* current size of "broken" */
21 ** returns pointer to static memory
24 brkstring(char *str, char *brksep, char *brkterm)
29 /* allocate initial space for pointers on first call */
32 broken = (char **)mh_xmalloc((size_t)(len * sizeof(*broken)));
36 ** scan string, replacing separators with zeroes
37 ** and enter start addresses in "broken".
41 /* enlarge pointer array, if necessary */
44 broken = mh_xrealloc(broken,
45 (size_t)(len * sizeof(*broken)));
48 /* handle separators */
49 while ((c=*s) && brksep && strchr(brksep, c)) {
54 ** we are either at the end of the string, or the
55 ** terminator found has been found, so finish up.
57 if (!c || (brkterm && strchr(brkterm, c))) {
63 /* set next start addr and walk over word */
66 if (brksep && strchr(brksep, c)) {
69 if (brkterm && strchr(brkterm, c)) {
74 adios("brkstring()", "reached unreachable point");