+/*
+ * Search for the 'pattern' in 'text'.
+ * Returns 1 if 'text' matches the 'pattern' or else returns 0.
+ * When returning 1 and 'after' isn't NULL, the pointer to the
+ * first character after the pettern in 'text' is stored in 'after'.
+ * The characters '\n' and ' ' have a special mening in the search:
+ * * '\n': matches any space or tabs (including none) followed
+ * either by '\n' or '\0' (end of the string)
+ * * ' ': matches any space or tabs but at least one.
+ */
+static int matches(const char *pattern, char *text, char **after)
+{
+ char p, t;
+
+ t = *text;
+ p = *pattern;
+ while(p) {
+ switch(p) {
+ case '\n':
+ while (isblank(t))
+ t = *++text;
+ if (t) {
+ if (t != p)
+ return 0;
+ t = *++text;
+ }
+ break;
+ case ' ':
+ if (!isblank(t))
+ return 0;
+ do {
+ t = *++text;
+ } while(isblank(t));
+ break;
+ default:
+ if (t != p)
+ return 0;
+ t = *++text;
+ break;
+ }
+ p = *++pattern;
+ }
+ if (after)
+ *after = text;
+ return 1;
+}
+