aboutsummaryrefslogtreecommitdiff
path: root/src/param.c
blob: 8921019a8dae3f43ead0562766c92aad98243565 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "param.h"

#include "log.h"
#include <stdlib.h>
#include <string.h>


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Parameter
 */
int magi_param_list_add(
    struct magi_param_list ** list, struct magi_param * item)
{
    struct magi_param_list * old = *list;
    int                      ok  = 1;
    *list                        = malloc(sizeof(**list));
    if (*list) {
        (*list)->next = old;
        (*list)->item = *item;
    } else {
        ok = 0;
        magi_log("[param:list] Cannot allocate new list node.");
        *list = old;
    }
    return ok;
}

struct magi_param * magi_param_list_get(
    struct magi_param_list * list, const char * name)
{
    struct magi_param * item = 0;
    if (list && name) {
        if (!strcmp(list->item.name, name)) {
            item = &list->item;
        } else {
            item = magi_param_list_get(list->next, name);
        }
    }
    return item;
}

void magi_param_list_destroy(struct magi_param_list * list)
{
    if (list) {
        magi_param_list_destroy(list->next);
        free(list->next);
        free(list->item.name);
        free(list->item.data);
    }
}