From 14e35e4d1f2f8927685b0c55bdc1f5d6bd5a2e9f Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Mon, 15 Nov 2010 18:46:40 +0100 Subject: Removed XML export. --- SConstruct | 3 +- channel.c | 4 +- channel.h | 3 +- config.c | 10 +---- export_xml.c | 137 ----------------------------------------------------------- export_xml.h | 9 ---- main.c | 1 - parsing.c | 2 - 8 files changed, 5 insertions(+), 164 deletions(-) delete mode 100644 export_xml.c delete mode 100644 export_xml.h diff --git a/SConstruct b/SConstruct index cbc8521..97e885a 100644 --- a/SConstruct +++ b/SConstruct @@ -3,7 +3,7 @@ AddOption('--release', action = 'store_true') env = Environment() conf = Configure(env) -for lib in ('config', 'pcre', 'xml2'): +for lib in ('config', 'pcre'): if not conf.CheckLib(lib): print 'Could not find %s' % lib Exit(1) @@ -18,7 +18,6 @@ else: env.ParseConfig('pkg-config --cflags --libs libconfig') env.ParseConfig('pcre-config --cflags --libs') -env.ParseConfig('xml2-config --cflags --libs') env.Program('ircstats', Glob('*.c')) diff --git a/channel.c b/channel.c index 8c32a96..559f3c6 100644 --- a/channel.c +++ b/channel.c @@ -13,7 +13,7 @@ void channel_init() { channel_count = 0; } -struct channel_t *channel_add(const char *name, const char *xmlpath) { +struct channel_t *channel_add(const char *name) { channels = realloc(channels, ++channel_count * sizeof(struct channel_t)); if(!channels) { char *error = strerror(errno); @@ -22,7 +22,6 @@ struct channel_t *channel_add(const char *name, const char *xmlpath) { } struct channel_t *channel = &channels[channel_count-1]; channel->name = strdup(name); - channel->xmlpath = strdup(xmlpath); channel->files = NULL; memset(channel->hours, 0, 24*4 * sizeof(unsigned long)); return channel; @@ -55,7 +54,6 @@ struct channel_t *channel_get(int index) { void channel_free() { for(int i = 0; i < channel_count; i++) { free(channels[i].name); - free(channels[i].xmlpath); struct channel_file_t *file = channels[i].files; while(file) { struct channel_file_t *next = file->next; diff --git a/channel.h b/channel.h index 3f4e4cd..0335782 100644 --- a/channel.h +++ b/channel.h @@ -11,14 +11,13 @@ struct channel_file_t { struct channel_t { char *name; - char *xmlpath; struct channel_file_t *files; unsigned long hours[24*4]; }; void channel_init(); -struct channel_t *channel_add(const char *name, const char *xmlpath); +struct channel_t *channel_add(const char *name); struct channel_file_t *channel_file_add(struct channel_t *channel, const char *path, int rs_index); int channel_get_count(); struct channel_t *channel_get(int index); diff --git a/config.c b/config.c index 84bcf39..9d465bd 100644 --- a/config.c +++ b/config.c @@ -87,21 +87,15 @@ int cfg_init() { int channel_count = config_setting_length(channels_setting); for(int i = 0; i < channel_count; i++) { config_setting_t *channel_setting = config_setting_get_elem(channels_setting, i); - const char *name, *xmlpath; + const char *name; if(!config_setting_lookup_string(channel_setting, "name", &name)) { char *sname; sname = malloc(sizeof(char) * 16); snprintf(sname, 16, "channel #%d", i+1); name = sname; } - if(!config_setting_lookup_string(channel_setting, "xmlpath", &xmlpath)) { - /* Index-based filename if xmlpath isn't set. */ - char temp[0xf]; - snprintf(temp, 0xf, "%d.xml", i); - xmlpath = strdup(temp); - } struct channel_t *channel; - if(!(channel = channel_add(name, xmlpath))) { + if(!(channel = channel_add(name))) { return 0; } config_setting_t *files = config_setting_get_member(channel_setting, "files"); 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 -#include - -#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 (filtered nicks eg. bots). */ - if(strcmp(user->nick, "") == 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; -} diff --git a/export_xml.h b/export_xml.h deleted file mode 100644 index f16379a..0000000 --- a/export_xml.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _EXPORT_XML_H_ -#define _EXPORT_XML_H_ - -#include "channel.h" -#include "user.h" - -int export_xml(struct channel_t *channel, struct user_t *users); - -#endif diff --git a/main.c b/main.c index b6fb6ca..5c34642 100644 --- a/main.c +++ b/main.c @@ -5,7 +5,6 @@ #include "channel.h" #include "user.h" #include "word.h" -#include "export_xml.h" #include "nick.h" #include "parsing.h" diff --git a/parsing.c b/parsing.c index 2447363..aeec3e6 100644 --- a/parsing.c +++ b/parsing.c @@ -8,7 +8,6 @@ #include "channel.h" #include "user.h" #include "word.h" -#include "export_xml.h" #include "config.h" #define NICK_BUFFER_SIZE 0x100 @@ -349,7 +348,6 @@ void process() { file = file->next; } - export_xml(channel, users); user_free(); word_free(); } -- cgit v1.2.3