2 * nvlist.c - Minimal linked list library for name-value pairs
3 * Copyright (c) 2006-07 Red Hat Inc., Durham, North Carolina.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Steve Grubb <sgrubb@redhat.com>
28 #include "interpret.h"
29 #include "auparse-idata.h"
32 void nvlist_create(nvlist *l)
39 static void nvlist_last(nvlist *l)
41 register nvnode* window;
48 window = window->next;
52 nvnode *nvlist_next(nvlist *l)
55 l->cur = l->cur->next;
59 void nvlist_append(nvlist *l, nvnode *node)
61 nvnode* newnode = malloc(sizeof(nvnode));
63 newnode->name = node->name;
64 newnode->val = node->val;
65 newnode->interp_val = NULL;
66 newnode->item = l->cnt;
69 // if we are at top, fix this up
72 else { // Otherwise add pointer to newnode
73 if (l->cnt == (l->cur->item+1)) {
74 l->cur->next = newnode;
78 l->cur->next = newnode;
82 // make newnode current
88 * This function will start at current index and scan for a name
90 int nvlist_find_name(nvlist *l, const char *name)
92 register nvnode* window = l->cur;
95 if (strcmp(window->name, name) == 0) {
100 window = window->next;
105 extern int interp_adjust_type(int rtype, const char *name, const char *val);
106 int nvlist_get_cur_type(const rnode *r)
108 const nvlist *l = &r->nv;
109 return auparse_interp_adjust_type(r->type, l->cur->name, l->cur->val);
112 const char *nvlist_interp_cur_val(const rnode *r)
114 const nvlist *l = &r->nv;
115 if (l->cur->interp_val)
116 return l->cur->interp_val;
120 void nvlist_clear(nvlist* l)
123 register nvnode* current;
127 nextnode=current->next;
130 free(current->interp_val);