+ struct stat st;
+ if (stat(path, &st) < 0)
+ {
+ yaz_log(YLOG_FATAL|YLOG_ERRNO, "stat %s", path);
+ return -1;
+ }
+ else
+ {
+ if (S_ISREG(st.st_mode))
+ {
+ xmlDoc *doc = xmlParseFile(path);
+ yaz_log(YLOG_LOG, "processing include path=%s", path);
+ if (doc)
+ {
+ xmlNodePtr t = xmlDocGetRootElement(doc);
+ int ret = process_config_includes(config, t);
+ *sib = xmlAddNextSibling(*sib, xmlCopyNode(t, 1));
+ xmlFreeDoc(doc);
+ if (ret)
+ return -1;
+ }
+ else
+ {
+ yaz_log(YLOG_FATAL, "Could not parse %s", path);
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+static int config_include_src(struct conf_config *config, xmlNode **np,
+ const char *src)
+{
+ int ret = 0; /* return code. OK so far */
+ WRBUF w = wrbuf_alloc();
+ xmlNodePtr sib; /* our sibling that we append */
+ xmlNodePtr c; /* tmp node */
+
+ wrbuf_printf(w, " begin include src=\"%s\" ", src);
+
+ /* replace include element with a 'begin' comment */
+ sib = xmlNewComment((const xmlChar *) wrbuf_cstr(w));
+ xmlReplaceNode(*np, sib);
+
+ xmlFreeNode(*np);
+
+ wrbuf_rewind(w);
+ conf_dir_path(config, w, src);
+#if USE_POSIX_GLOB
+ {
+ size_t i;
+ glob_t glob_res;
+ glob(wrbuf_cstr(w), 0 /* flags */, 0 /* errfunc */, &glob_res);
+
+ for (i = 0; ret == 0 && i < glob_res.gl_pathc; i++)
+ {
+ const char *path = glob_res.gl_pathv[i];
+ ret = config_include_one(config, &sib, path);
+ }
+ globfree(&glob_res);
+ }
+#else
+ ret = config_include_one(config, &sib, wrbuf_cstr(w));
+#endif
+ wrbuf_rewind(w);
+ wrbuf_printf(w, " end include src=\"%s\" ", src);
+ c = xmlNewComment((const xmlChar *) wrbuf_cstr(w));
+ sib = xmlAddNextSibling(sib, c);
+
+ *np = sib;
+ wrbuf_destroy(w);
+ return ret;
+}