2014-04-10 00:09:35 +02:00
|
|
|
#include "internal.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
struct bm_item*
|
|
|
|
bm_item_new(const char *text)
|
2014-04-10 00:09:35 +02:00
|
|
|
{
|
2014-10-22 21:46:51 +02:00
|
|
|
struct bm_item *item;
|
|
|
|
if (!(item = calloc(1, sizeof(struct bm_item))))
|
2014-04-10 00:09:35 +02:00
|
|
|
return NULL;
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
bm_item_set_text(item, text);
|
2014-04-10 00:09:35 +02:00
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
void
|
|
|
|
bm_item_free(struct bm_item *item)
|
2014-04-10 00:09:35 +02:00
|
|
|
{
|
2014-04-10 00:41:32 +02:00
|
|
|
assert(item);
|
2014-10-22 21:46:51 +02:00
|
|
|
free(item->text);
|
2014-04-10 00:09:35 +02:00
|
|
|
free(item);
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
void
|
|
|
|
bm_item_set_userdata(struct bm_item *item, void *userdata)
|
2014-04-10 19:09:34 +02:00
|
|
|
{
|
|
|
|
assert(item);
|
|
|
|
item->userdata = userdata;
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
void*
|
|
|
|
bm_item_get_userdata(struct bm_item *item)
|
2014-04-10 19:09:34 +02:00
|
|
|
{
|
|
|
|
assert(item);
|
|
|
|
return item->userdata;
|
|
|
|
}
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
bool
|
|
|
|
bm_item_set_text(struct bm_item *item, const char *text)
|
2014-04-10 00:09:35 +02:00
|
|
|
{
|
2014-04-10 00:41:32 +02:00
|
|
|
assert(item);
|
2014-04-10 00:09:35 +02:00
|
|
|
|
|
|
|
char *copy = NULL;
|
2014-10-22 21:46:51 +02:00
|
|
|
if (text && !(copy = bm_strdup(text)))
|
|
|
|
return false;
|
2014-04-10 00:09:35 +02:00
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
free(item->text);
|
2014-04-10 00:09:35 +02:00
|
|
|
item->text = copy;
|
2014-10-22 21:46:51 +02:00
|
|
|
return true;
|
2014-04-10 00:09:35 +02:00
|
|
|
}
|
|
|
|
|
2014-10-22 21:46:51 +02:00
|
|
|
const char*
|
|
|
|
bm_item_get_text(const struct bm_item *item)
|
2014-04-10 00:09:35 +02:00
|
|
|
{
|
2014-04-10 00:41:32 +02:00
|
|
|
assert(item);
|
2014-04-10 00:09:35 +02:00
|
|
|
return item->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=8 sw=4 tw=0 :*/
|