2014-06-22 18:44:35 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#ifdef HAVE_NCURSESW_NCURSES_H
|
|
|
|
#include <ncursesw/ncurses.h>
|
|
|
|
#elif HAVE_NCURSES_H
|
|
|
|
#include <ncurses.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ui/window.h"
|
|
|
|
#include "ui/buffer.h"
|
|
|
|
|
2014-07-20 16:53:50 -04:00
|
|
|
#define BUFF_SIZE 1200
|
|
|
|
|
2014-07-18 18:07:08 -04:00
|
|
|
struct prof_buff_t {
|
|
|
|
GSList *entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void _free_entry(ProfBuffEntry *entry);
|
|
|
|
|
|
|
|
ProfBuff
|
2014-07-16 17:31:25 -04:00
|
|
|
buffer_create()
|
|
|
|
{
|
2014-07-18 18:07:08 -04:00
|
|
|
ProfBuff new_buff = malloc(sizeof(struct prof_buff_t));
|
|
|
|
new_buff->entries = NULL;
|
2014-07-16 17:31:25 -04:00
|
|
|
return new_buff;
|
2014-06-22 18:44:35 -04:00
|
|
|
}
|
|
|
|
|
2014-07-16 17:31:25 -04:00
|
|
|
int
|
2014-07-18 18:07:08 -04:00
|
|
|
buffer_size(ProfBuff buffer)
|
2014-07-16 17:31:25 -04:00
|
|
|
{
|
2014-07-18 18:07:08 -04:00
|
|
|
return g_slist_length(buffer->entries);
|
2014-06-29 09:04:23 -04:00
|
|
|
}
|
|
|
|
|
2014-06-22 18:44:35 -04:00
|
|
|
void
|
2014-07-18 18:07:08 -04:00
|
|
|
buffer_free(ProfBuff buffer)
|
2014-07-16 17:31:25 -04:00
|
|
|
{
|
2014-07-18 18:07:08 -04:00
|
|
|
g_slist_free_full(buffer->entries, (GDestroyNotify)_free_entry);
|
2014-07-16 17:31:25 -04:00
|
|
|
free(buffer);
|
2014-07-18 18:07:08 -04:00
|
|
|
buffer = NULL;
|
2014-06-22 18:44:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-07-18 18:07:08 -04:00
|
|
|
buffer_push(ProfBuff buffer, const char show_char, const char * const date_fmt,
|
2014-07-16 17:31:25 -04:00
|
|
|
int flags, int attrs, const char * const from, const char * const message)
|
|
|
|
{
|
2014-07-18 18:07:08 -04:00
|
|
|
ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t));
|
2014-07-16 17:31:25 -04:00
|
|
|
e->show_char = show_char;
|
|
|
|
e->flags = flags;
|
|
|
|
e->attrs = attrs;
|
|
|
|
|
|
|
|
e->date_fmt = malloc(strlen(date_fmt)+1);
|
|
|
|
strcpy(e->date_fmt, date_fmt);
|
|
|
|
|
|
|
|
e->from = malloc(strlen(from)+1);
|
|
|
|
strcpy(e->from, from);
|
|
|
|
|
|
|
|
e->message = malloc(strlen(message)+1);
|
|
|
|
strcpy(e->message, message);
|
|
|
|
|
2014-07-20 16:53:50 -04:00
|
|
|
if (g_slist_length(buffer->entries) == BUFF_SIZE) {
|
2014-07-18 18:07:08 -04:00
|
|
|
_free_entry(buffer->entries->data);
|
|
|
|
buffer->entries = g_slist_delete_link(buffer->entries, buffer->entries);
|
2014-07-16 17:31:25 -04:00
|
|
|
}
|
2014-07-18 18:07:08 -04:00
|
|
|
|
|
|
|
buffer->entries = g_slist_append(buffer->entries, e);
|
2014-06-22 18:44:35 -04:00
|
|
|
}
|
|
|
|
|
2014-07-19 12:14:04 -04:00
|
|
|
ProfBuffEntry*
|
2014-07-18 18:07:08 -04:00
|
|
|
buffer_yield_entry(ProfBuff buffer, int entry)
|
|
|
|
{
|
|
|
|
GSList *node = g_slist_nth(buffer->entries, entry);
|
2014-07-19 12:14:04 -04:00
|
|
|
return node->data;
|
2014-07-18 18:07:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_free_entry(ProfBuffEntry *entry)
|
2014-07-16 17:31:25 -04:00
|
|
|
{
|
2014-07-18 18:07:08 -04:00
|
|
|
free(entry->message);
|
|
|
|
free(entry->from);
|
|
|
|
free(entry->date_fmt);
|
|
|
|
}
|
2014-07-16 17:31:25 -04:00
|
|
|
|