itemheap functions added.
FossilOrigin-Name: 6636f179aa11185d2ae593e20a31251e4f9ca37291c02d52aa9685ff73abbae1
This commit is contained in:
parent
a2469b79b3
commit
10b31c61d6
@ -1,29 +1,76 @@
|
|||||||
|
|
||||||
#include "item.h"
|
|
||||||
#include "capwap_items.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
struct cw_item * cw_item_get_by_id(int id,struct cw_item *table)
|
This file is part of libcapwap.
|
||||||
{
|
|
||||||
int i;
|
libcapwap is free software: you can redistribute it and/or modify
|
||||||
while (table->id != CW_ITEM_NONE) {
|
it under the terms of the GNU General Public License as published by
|
||||||
if (table->id == id)
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
return table;
|
(at your option) any later version.
|
||||||
table++;
|
|
||||||
|
libcapwap is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct cw_item * cw_item_get_by_name(const char *id,struct cw_item *table)
|
|
||||||
|
#include "item.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
|
|
||||||
|
const char CW_ITEM_NONE[] = "";
|
||||||
|
|
||||||
|
struct cw_itemdef *cw_item_get_by_name(const char *id, struct cw_itemdef *table)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
while (table->id != CW_ITEM_NONE) {
|
while (table->id != CW_ITEM_NONE) {
|
||||||
if (!strcmp(table->id,id))
|
if (!strcmp(table->id, id))
|
||||||
return table;
|
return table;
|
||||||
table++;
|
table++;
|
||||||
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static int cmp(const void *x1, const void *x2)
|
||||||
|
{
|
||||||
|
cw_itemdef_t *i1, *i2;
|
||||||
|
i1 = (cw_itemdef_t *) x1;
|
||||||
|
i2 = (cw_itemdef_t *) x2;
|
||||||
|
int rc = strcmp(i1->id, i2->id);
|
||||||
|
if (rc != 0)
|
||||||
|
return rc;
|
||||||
|
return strcmp(i1->sub_id, i2->sub_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cw_itemdef_t * cw_itemdef_get(cw_itemdefheap_t t, const char *id, const char *sub_id)
|
||||||
|
{
|
||||||
|
cw_itemdef_t idef;
|
||||||
|
idef.id = id;
|
||||||
|
idef.sub_id = !sub_id ? CW_ITEM_NONE : sub_id;
|
||||||
|
return mavl_get(t, &idef);
|
||||||
|
}
|
||||||
|
|
||||||
|
cw_itemdefheap_t cw_itemdefheap_create()
|
||||||
|
{
|
||||||
|
return mavl_create(cmp, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int cw_itemdefheap_register(cw_itemdefheap_t t, cw_itemdef_t * defs)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
while (defs->id != CW_ITEM_NONE) {
|
||||||
|
cw_itemdef_t *a = mavl_add(t, defs);
|
||||||
|
if (a != defs) {
|
||||||
|
cw_log(LOG_ERR, "Duplicated item: %s", defs->id);
|
||||||
|
} else
|
||||||
|
n++;
|
||||||
|
defs++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user