+static int name_cmp(const void *n1, const void *n2)
+{
+ return strcmp(*(char * const *)n1, *(char * const *)n2);
+}
+
+static int include_config(char *include, int manage_globals)
+{
+ item_list conf_list;
+ struct dirent *di;
+ char buf[MAXPATHLEN], **bpp;
+ int ret = 1;
+ size_t j;
+ DIR *d;
+
+ memset(&conf_list, 0, sizeof conf_list);
+
+ if ((d = opendir(include)) != NULL) {
+ while ((di = readdir(d)) != NULL) {
+ char *dname = d_name(di);
+ if (!wildmatch("*.conf", dname))
+ continue;
+ bpp = EXPAND_ITEM_LIST(&conf_list, char *, 32);
+ pathjoin(buf, sizeof buf, include, dname);
+ *bpp = strdup(buf);
+ }
+ closedir(d);
+ } else {
+ STRUCT_STAT sb;
+ if (stat(include, &sb) < 0)
+ return 0;
+ bpp = EXPAND_ITEM_LIST(&conf_list, char *, 1);
+ *bpp = strdup(include);
+ }
+
+ if (conf_list.count > 1)
+ qsort(conf_list.items, conf_list.count, sizeof (char *), name_cmp);
+
+ bpp = conf_list.items;
+ for (j = 0; j < conf_list.count; j++) {
+ if (manage_globals && the_sfunc)
+ the_sfunc(j == 0 ? "]push" : "]reset");
+ if ((ret = pm_process(bpp[j], the_sfunc, the_pfunc)) != 1)
+ break;
+ }
+
+ if (manage_globals && the_sfunc && conf_list.count)
+ the_sfunc("]pop");
+
+ for (j = 0; j < conf_list.count; j++)
+ free(bpp[j]);
+
+ return ret;
+}
+
+static int parse_directives(char *name, char *val)
+{
+ if (strcasecmp(name, "include") == 0)
+ return include_config(val, 1);
+ if (strcasecmp(name, "merge") == 0)
+ return include_config(val, 0);
+ rprintf(FLOG, "Unknown directive: &%s.\n", name);
+ return 0;
+}
+
+static int Parse( FILE *InFile,