-
-/*
- * brkstring.c -- (destructively) split a string into
+/* brkstring.c -- (destructively) split a string into
* -- an array of substrings
*
- * $Id$
- *
* This code is Copyright (c) 2002, by the authors of nmh. See the
* COPYRIGHT file in the root directory of the nmh distribution for
* complete copyright information.
*/
-#include <h/mh.h>
-#include <h/utils.h>
+#include "h/mh.h"
+#include "brkstring.h"
+#include "h/utils.h"
/* allocate this number of pointers at a time */
#define NUMBROKEN 256
/* allocate initial space for pointers on first call */
if (!broken) {
len = NUMBROKEN;
- broken = (char **) mh_xmalloc ((size_t) (len * sizeof(*broken)));
+ broken = mh_xmalloc ((size_t) (len * sizeof(*broken)));
}
/*
/* enlarge pointer array, if necessary */
if (i >= len) {
len += NUMBROKEN;
- if (!(broken = realloc (broken, (size_t) (len * sizeof(*broken)))))
- adios (NULL, "unable to realloc array in brkstring");
+ broken = mh_xrealloc (broken, (size_t) (len * sizeof(*broken)));
}
while (brkany (c = *s, brksep))
if (!c || brkany (c, brkterm)) {
*s = '\0';
broken[i] = NULL;
- return broken;
+ break;
}
/* set next start addr */
; /* empty body */
}
- return broken; /* NOT REACHED */
+ return broken;
}
static int
brkany (char c, char *str)
{
- char *s;
-
- if (str) {
- for (s = str; *s; s++)
- if (c == *s)
- return 1;
- }
- return 0;
+ return str && c && strchr(str, c);
}