diff options
Diffstat (limited to 'export_xml.c')
-rw-r--r-- | export_xml.c | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/export_xml.c b/export_xml.c deleted file mode 100644 index 91f5af0..0000000 --- a/export_xml.c +++ /dev/null @@ -1,137 +0,0 @@ -#include <libxml/xmlwriter.h> -#include <string.h> - -#include "export_xml.h" -#include "word.h" - -#if !defined(LIBXML_WRITER_ENABLED) -#error "libxml must be compiled with text writer support" -#endif - - -int export_xml(struct channel_t *channel, struct user_t *users) { - /* Create document and set root node. */ - xmlTextWriterPtr writer = xmlNewTextWriterFilename(channel->xmlpath, 0); - if(writer == NULL) { - fprintf(stderr, "Failed to create text writer for filename \"%s\"\n", channel->xmlpath); - return 0; - } - - xmlTextWriterStartDocument(writer, "1.0", "UTF-8", NULL); - xmlTextWriterStartElement(writer, (const xmlChar*)"channel"); - - /* Set the channel name. */ - xmlTextWriterStartElement(writer, (const xmlChar*)"name"); - xmlTextWriterWriteString(writer, (const xmlChar*)channel->name); - xmlTextWriterEndElement(writer); - - /* Add lines. */ - xmlTextWriterStartElement(writer, (const xmlChar*)"lines"); - for(int h = 0; h < 24; h++) { - xmlTextWriterStartElement(writer, (const xmlChar*)"hour"); - for(int q = 0; q < 4; q++) { - xmlTextWriterStartElement(writer, (const xmlChar*)"quarter"); - xmlTextWriterWriteFormatString(writer, "%lu", channel->hours[h*4 + q]); - xmlTextWriterEndElement(writer); - } - xmlTextWriterEndElement(writer); // hour - } - xmlTextWriterEndElement(writer); // lines - - /* Add users. */ - xmlTextWriterStartElement(writer, (const xmlChar*)"users"); - for(int u = 0; u < USERS_MAX; u++) { - struct user_t *user = &users[u]; - /* Iterate while we have a user (nick is non-NULL). */ - while(user && user->nick) { - /* Skip <NULL> (filtered nicks eg. bots). */ - if(strcmp(user->nick, "<NULL>") == 0) { - user = user->next; - continue; - } - xmlTextWriterStartElement(writer, (const xmlChar*)"user"); - - xmlTextWriterStartElement(writer, (const xmlChar*)"nick"); - xmlTextWriterWriteString(writer, (const xmlChar*)user->nick); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"words"); - xmlTextWriterWriteFormatString(writer, "%llu", user->words); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"characters"); - xmlTextWriterWriteFormatString(writer, "%llu", user->characters); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"kicks"); - xmlTextWriterWriteFormatString(writer, "%llu", user->kicks); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"kicked"); - xmlTextWriterWriteFormatString(writer, "%llu", user->kicked); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"monolog_lines"); - xmlTextWriterWriteFormatString(writer, "%llu", user->monolog_lines); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"monologs"); - xmlTextWriterWriteFormatString(writer, "%llu", user->monologs); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"seen_first"); - xmlTextWriterWriteFormatString(writer, "%lu", user->seen_first); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"seen_last"); - xmlTextWriterWriteFormatString(writer, "%lu", user->seen_last); - xmlTextWriterEndElement(writer); - - /* Add lines for this user. */ - xmlTextWriterStartElement(writer, (const xmlChar*)"lines"); - for(int h = 0; h < 24; h++) { - xmlTextWriterStartElement(writer, (const xmlChar*)"hour"); - for(int q = 0; q < 4; q++) { - xmlTextWriterStartElement(writer, (const xmlChar*)"quarter"); - xmlTextWriterWriteFormatString(writer, "%lu", user->lines[h*4 + q]); - xmlTextWriterEndElement(writer); - } - xmlTextWriterEndElement(writer); // hour - } - xmlTextWriterEndElement(writer); // lines - user = user->next; - - xmlTextWriterEndElement(writer); // user - } - } - xmlTextWriterEndElement(writer); // users - - /* Add words. */ - xmlTextWriterStartElement(writer, (const xmlChar*)"words"); - for(int w = 0; w < WORDS_MAX; w++) { - struct word_t *word = &words[w]; - while(word && word->name) { - xmlTextWriterStartElement(writer, (const xmlChar*)"word"); - - xmlTextWriterStartElement(writer, (const xmlChar*)"name"); - xmlTextWriterWriteString(writer, (const xmlChar*)word->name); - xmlTextWriterEndElement(writer); - - xmlTextWriterStartElement(writer, (const xmlChar*)"count"); - xmlTextWriterWriteFormatString(writer, "%llu", word->count); - xmlTextWriterEndElement(writer); - - word = word->next; - - xmlTextWriterEndElement(writer); // word - } - } - xmlTextWriterEndElement(writer); // words - - xmlTextWriterEndElement(writer); // channel - - xmlTextWriterEndDocument(writer); - xmlFreeTextWriter(writer); - - return 1; -} |