void open_xml_file ( char* filename ) { xmlNodePtr cur; char *xmlfile; /* file name of knowledge base */ /* get a fully qualified, absolute path and filename for */ /* reading/writing the XML database file. */ /* What to do on a DOS system? Let's hope that libxml handles it!*/ xmlfile = G_strdup (filename); /* parse the XML structure; check that we have a valid file */ doc = xmlParseFile (xmlfile); if ( doc == NULL ) { xmlFreeDoc(doc); G_fatal_error ("Could not parse XML structure of knowledge base file.\n"); } cur = xmlDocGetRootElement(doc); if (cur == NULL) { xmlFreeDoc(doc); G_fatal_error ("Knowledge base is an empty file.\n"); } if (xmlStrcmp(cur->name, (const xmlChar *) "dst-kb")) { xmlFreeDoc(doc); G_fatal_error ("File is not a DST knowledge base.\n"); } N_SINGLETONS = atoi (xmlGetProp(cur, "N_SINGLETONS")); N_HYPOTHESES = atoi (xmlGetProp(cur, "N_HYPOTHESES")); }
static void _get_list(char ***list, int *count) { char **a; int n; char *buf; *list = NULL; *count = 0; buf = _get_text_2(); for (n = 0; *buf; n++) { if (n == 0) a = G_malloc(sizeof(char *)); else a = G_realloc(a, (n + 1) * sizeof(char *)); a[n] = G_strdup(buf); buf = _get_text_2(); } *list = a; *count = n; }