1 /* nv_pair_list.c - the itsy package management system
5 Copyright (C) 2001 University of Southern California
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
21 #include "void_list.h"
22 #include "nv_pair_list.h"
24 int nv_pair_list_elt_init(nv_pair_list_elt_t
*elt
, nv_pair_t
*data
)
26 return void_list_elt_init((void_list_elt_t
*) elt
, data
);
29 void nv_pair_list_elt_deinit(nv_pair_list_elt_t
*elt
)
31 void_list_elt_deinit((void_list_elt_t
*) elt
);
34 int nv_pair_list_init(nv_pair_list_t
*list
)
36 return void_list_init((void_list_t
*) list
);
39 void nv_pair_list_deinit(nv_pair_list_t
*list
)
41 nv_pair_list_elt_t
*iter
;
44 for (iter
= list
->head
; iter
; iter
= iter
->next
) {
46 nv_pair_deinit(nv_pair
);
48 /* malloced in nv_pair_list_append */
52 void_list_deinit((void_list_t
*) list
);
55 nv_pair_t
*nv_pair_list_append(nv_pair_list_t
*list
, const char *name
, const char *value
)
59 /* freed in nv_pair_list_deinit */
60 nv_pair_t
*nv_pair
= malloc(sizeof(nv_pair_t
));
62 if (nv_pair
== NULL
) {
63 fprintf(stderr
, "%s: out of memory\n", __FUNCTION__
);
66 nv_pair_init(nv_pair
, name
, value
);
68 err
= void_list_append((void_list_t
*) list
, nv_pair
);
76 int nv_pair_list_push(nv_pair_list_t
*list
, nv_pair_t
*data
)
78 return void_list_push((void_list_t
*) list
, data
);
81 nv_pair_list_elt_t
*nv_pair_list_pop(nv_pair_list_t
*list
)
83 return (nv_pair_list_elt_t
*) void_list_pop((void_list_t
*) list
);
86 char *nv_pair_list_find(nv_pair_list_t
*list
, char *name
)
88 nv_pair_list_elt_t
*iter
;
91 for (iter
= list
->head
; iter
; iter
= iter
->next
) {
93 if (strcmp(nv_pair
->name
, name
) == 0) {
94 return nv_pair
->value
;