#include #include #include #include #include #include "todo.h" struct _F_todoxml_private{ xmlNodePtr node; bool modified; }; void _F_todoxml::setproject (const char *s) { priv->modified = true; xmlSetProp (priv->node,(const xmlChar*)K_PROJECT,(const xmlChar*)s); } void _F_todoxml::settype (const char *s) { priv->modified = true; xmlSetProp (priv->node,(const xmlChar*)K_TYPE,(const xmlChar*)s); } void _F_todoxml::setdate (const char *s) { priv->modified = true; xmlSetProp (priv->node,(const xmlChar*)K_DATE,(const xmlChar*)s); } void _F_todoxml::setremind (const char *s) { priv->modified = true; xmlSetProp (priv->node,(const xmlChar*)K_REMIND,(const xmlChar*)s); } void _F_todoxml::setevent (const char *s) { priv->modified = true; xmlSetProp (priv->node,(const xmlChar*)K_EVENT,(const xmlChar*)s); } void _F_todoxml::settext (const char *s) { SSTRING tmp; tmp.setfromf ("\n%s",s); priv->modified = true; xmlNodeSetContent(priv->node,(const xmlChar*)tmp.get()); } void todoxml (_F_todoxml &c, const char *fname) { glocal xmlParserCtxtPtr ctxt; _F_todoxml_private priv; c.priv = &priv; priv.modified = false; (fname,false); static const char *intro = "\n" "\n"; glocal.ctxt = xmlCreatePushParserCtxt(NULL, NULL, intro,strlen(intro), info.filename); xmlParseChunk(glocal.ctxt, "\n",12, 1); // char line[0]; // xmlParseChunk(glocal.ctxt, line, 0, 1); xmlParseChunk(glocal.ctxt, line, strlen(line), 0); return 0; xmlDocPtr doc = glocal.ctxt->myDoc; xmlFreeParserCtxt(glocal.ctxt); xmlNodePtr cur = xmlDocGetRootElement(doc); priv.node = cur->xmlChildrenNode; int no = 0; bool end = false; while (priv.node != NULL && !end){ TODOXML_INFO info; info.project = (char *)xmlGetProp(priv.node,(const xmlChar *)K_PROJECT); info.date = (char *)xmlGetProp(priv.node,(const xmlChar *)K_DATE); info.type = (char *)xmlGetProp(priv.node,(const xmlChar *)K_TYPE); info.remind = (char *)xmlGetProp(priv.node,(const xmlChar *)K_REMIND); if (info.remind == NULL) info.remind = ""; info.event = (char *)xmlGetProp(priv.node,(const xmlChar *)K_EVENT); if (info.event == NULL) info.event = ""; char *text = (char *)xmlNodeGetContent(priv.node); SSTRING s(str_skip(text)); free (text); s.strip_end (); info.text = s.get(); c.node (info,no++,end); priv.node = priv.node->next; } if (priv.modified){ glocal xmlChar *buf; int size; xmlDocDumpMemory (doc,&glocal.buf,&size); if (glocal.buf != NULL){ ("/tmp/toto.xml",false); // Skip the stuff added by libxml since our xml // file is just a bunch of nodes without document char *text = (char *)glocal.buf; char *pt = strchr(text,'\n'); if (pt != NULL) pt = strchr(pt+1,'\n'); if (pt != NULL) text = pt+1; pt = strstr (text,""); if (pt != NULL) *pt = '\0'; fputs (text,fout); return 0; free (glocal.buf); } } xmlFreeDoc(doc); }