+ * Returns the first space-delimited token of the string starting at position *len.
+ * On return *len contains the length of the token. Spaces inside brackets are ignored, so that
+ * eg. '${foo bar}' is treated as a single token. Sets *len to zero and *str points to the end of
+ * the string when there are no more tokens.
+ */
+static const char* tokenize(const char *str, size_t *len)
+{
+ str += *len;
+ *len = 0;
+ while(str && isspace(*str))
+ ++str;
+
+ size_t level = 0;
+ while(str[*len] && (level > 0 || !isspace(str[*len]))) {
+ switch(str[*len]) {
+ case '{': ++level; break;
+ case '}': --level; break;
+ }
+ ++*len;
+ }
+
+ if(!str[*len] && level > 0)
+ NORM_ERR("tokenize: improperly nested token: %s", str);
+
+ return str;
+}
+
+/*