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.
14 /* allocate this number of pointers at a time */
17 static char **broken = NULL; /* array of substring start addresses */
18 static int len = 0; /* current size of "broken" */
22 ** returns pointer to static memory
25 brkstring(char *str, char *brksep, char *brkterm)
30 /* allocate initial space for pointers on first call */
33 broken = mh_xcalloc(len, sizeof(*broken));
37 ** scan string, replacing separators with zeroes
38 ** and enter start addresses in "broken".
42 /* enlarge pointer array, if necessary */
45 broken = mh_xrealloc(broken, 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(EX_SOFTWARE, "brkstring()", "reached unreachable point");