2 * Copyright (c) 2010 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include "bootstrap.h"
41 dvar_t
*dvlastp
= &dvbase
;
44 dvar_get(const char *name
)
48 for (var
= dvbase
; var
; var
= var
->next
) {
49 if (strcmp(name
, var
->name
) == 0)
56 dvar_set(const char *name
, char **data
, int count
)
60 for (var
= dvbase
; var
; var
= var
->next
) {
61 if (strcmp(name
, var
->name
) == 0)
65 var
= malloc(sizeof(*var
) + strlen(name
) + 1);
66 var
->name
= (char *)(void *)(var
+ 1);
67 strcpy(var
->name
, name
);
72 while (--var
->count
>= 0)
73 free(var
->data
[var
->count
]);
75 /* var->data = NULL; not needed */
78 var
->data
= malloc(sizeof(char *) * (count
+ 1));
79 var
->data
[count
] = NULL
;
81 var
->data
[count
] = strdup(data
[count
]);
85 dvar_copy(dvar_t ovar
)
90 var
= malloc(sizeof(*var
));
91 bzero(var
, sizeof(*var
));
95 var
->data
= malloc(sizeof(char *) * (count
+ 1));
96 var
->data
[count
] = NULL
;
98 var
->data
[count
] = strdup(ovar
->data
[count
]);
103 dvar_unset(const char *name
)
110 if ((p
= strchr(name
, '*')) != NULL
) {
111 while ((var
= *lastp
) != NULL
) {
112 if (strlen(var
->name
) >= p
- name
&&
113 strncmp(var
->name
, name
, p
- name
) == 0) {
120 while ((var
= *lastp
) != NULL
) {
121 if (strcmp(name
, var
->name
) == 0) {
137 dvar_next(dvar_t var
)
149 dvar_nextp(dvar_t var
)
155 dvar_free(dvar_t
*lastp
)
157 dvar_t dvar
= *lastp
;
159 if (dvlastp
== &dvar
->next
)
162 while (--dvar
->count
>= 0)
163 free(dvar
->data
[dvar
->count
]);
169 dvar_istrue(dvar_t var
)
173 if (var
!= NULL
&& (strcasecmp(var
->data
[0], "yes") == 0 ||
174 strcasecmp(var
->data
[0], "true") == 0 ||
175 strcasecmp(var
->data
[0], "on") == 0 ||
176 strcasecmp(var
->data
[0], "1") == 0))