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