/* Use to walk the output generated by nacom (from the linuxconf-tool package) */ #include #include #include #include "tledit.h" #include #include "component.h" #include "tledit.m" static const unsigned char K_SECTION[]="section"; static const unsigned char K_NAME[]="name"; static const unsigned char K_SPEC[]="spec"; static const unsigned char K_SRCFILE[]="srcfile"; static const unsigned char K_LINE[]="line"; static const unsigned char K_KEY[]="key"; static const unsigned char K_SOURCE[]="source"; static char *spec_getcontent( xmlNodePtr cur, const unsigned char *key) { char *ret = NULL; xmlNodePtr sub = cur->xmlChildrenNode; while (sub != NULL){ if (xmlStrcmp(sub->name,key)==0){ ret = (char *)xmlNodeGetContent(sub); break; } sub = sub->next; } return ret; } static void spec_walk (_F_spec_walk &c, xmlNodePtr cur, const char *section) { bool end = false; while (!end && cur != NULL){ if (xmlStrcmp(cur->name,K_SECTION)==0){ char *name = (char *)xmlGetProp(cur,K_NAME); xmlNodePtr sub = cur->xmlChildrenNode; spec_walk (c,sub,name); free (name); }else if (xmlStrcmp(cur->name,K_SPEC)==0){ char *key = (char *)xmlGetProp(cur,K_KEY); char *line = (char *)xmlGetProp(cur,K_LINE); char *src = (char *)xmlGetProp(cur,K_SRCFILE); char *text = spec_getcontent (cur,K_SOURCE); c.onespec (key,src,text,atoi(line),section,end); free (key); free (line); free (src); free (text); } cur = cur->next; } } int spec_walk (_F_spec_walk &c, const char *fname) { int ret = -1; c.priv = NULL; xmlDocPtr doc = xmlParseFile(fname); if (doc != NULL){ ret = 0; xmlNodePtr cur = xmlDocGetRootElement(doc); spec_walk (c,cur,""); xmlFreeDoc(doc); } return ret; }