struct res_entry *entries;
};
+static void add_entry(yaz_glob_res_t res, const char *str)
+{
+ struct res_entry *ent =
+ nmem_malloc(res->nmem, sizeof(*ent));
+ ent->file = nmem_strdup(res->nmem, str);
+ ent->next = 0;
+ *res->last_entry = ent;
+ res->last_entry = &ent->next;
+ res->number_of_entries++;
+}
+
static void glob_r(yaz_glob_res_t res, const char *pattern, size_t off,
char *prefix)
{
glob_r(res, pattern, i, prefix);
prefix[prefix_len] = '\0';
}
+ else if (!is_pattern && !pattern[i])
+ {
+ strcpy(prefix + prefix_len, pattern + off);
+ add_entry(res, prefix);
+ }
else
{
DIR * dir = opendir(*prefix ? prefix : "." );
}
else
{
- struct res_entry *ent =
- nmem_malloc(res->nmem, sizeof(*ent));
- ent->file = nmem_strdup(res->nmem, prefix);
- ent->next = 0;
- *res->last_entry = ent;
- res->last_entry = &ent->next;
- res->number_of_entries++;
+ add_entry(res, prefix);
}
prefix[prefix_len] = '\0';
}
#include <yaz/xml_include.h>
#include <yaz/test.h>
-static void tst_xml_include(void)
+static void tst_xml_include1(void)
{
#if YAZ_HAVE_XML2
const char *srcdir = getenv("srcdir");
#endif
}
+static void tst_xml_include2(void)
+{
+#if YAZ_HAVE_XML2
+ const char *srcdir = getenv("srcdir");
+ xmlDocPtr doc;
+ xmlNodePtr node;
+ const char *xml_in = "<x><include src=\"test_xml_no.xml\"/></x>";
+
+ if (srcdir == 0)
+ srcdir = ".";
+
+ doc = xmlParseMemory(xml_in, strlen(xml_in));
+ YAZ_CHECK(doc);
+ if (!doc)
+ return;
+ node = xmlDocGetRootElement(doc);
+ YAZ_CHECK(node);
+ if (node)
+ {
+ const char *expect =
+ "<?xml version=\"1.0\"?>\n"
+ "<x><!-- begin include src=\"test_xml_no.xml\" -->"
+ "<!-- end include src=\"test_xml_no.xml\" --></x>\n";
+
+ xmlChar *xml_out;
+ int len_out;
+ int ret = yaz_xml_include_simple(node, srcdir);
+ YAZ_CHECK(ret == -1);
+ }
+ xmlFreeDoc(doc);
+#endif
+}
+
+static void tst_xml_include3(void)
+{
+#if YAZ_HAVE_XML2
+ const char *srcdir = getenv("srcdir");
+ xmlDocPtr doc;
+ xmlNodePtr node;
+ const char *xml_in = "<x><include src=\"test_xml_no*.xml\"/></x>";
+
+ if (srcdir == 0)
+ srcdir = ".";
+
+ doc = xmlParseMemory(xml_in, strlen(xml_in));
+ YAZ_CHECK(doc);
+ if (!doc)
+ return;
+ node = xmlDocGetRootElement(doc);
+ YAZ_CHECK(node);
+ if (node)
+ {
+ const char *expect =
+ "<?xml version=\"1.0\"?>\n"
+ "<x><!-- begin include src=\"test_xml_no*.xml\" -->"
+ "<!-- end include src=\"test_xml_no*.xml\" --></x>\n";
+
+ xmlChar *xml_out;
+ int len_out;
+ int ret = yaz_xml_include_simple(node, srcdir);
+ YAZ_CHECK(ret == 0);
+ xmlDocDumpMemory(doc, &xml_out, &len_out);
+ YAZ_CHECK(xml_out && len_out > 0);
+ if (xml_out && len_out > 0)
+ {
+ YAZ_CHECK(strlen(expect) == len_out);
+ if (strlen(expect) == len_out)
+ {
+ YAZ_CHECK(memcmp(expect, xml_out, len_out) == 0);
+ }
+ else
+ {
+ fwrite(xml_out, 1, len_out, stdout);
+ fflush(stdout);
+ }
+ xmlFree(xml_out);
+ }
+ }
+ xmlFreeDoc(doc);
+#endif
+}
+
+
int main (int argc, char **argv)
{
YAZ_CHECK_INIT(argc, argv);
YAZ_CHECK_LOG();
- tst_xml_include();
+ tst_xml_include1();
+ tst_xml_include2();
+ tst_xml_include3();
YAZ_CHECK_TERM;
}