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"
40 static void dvar_free(dvar_t *lastp);
43 dvar_t *dvlastp = &dvbase;
46 dvar_get(const char *name)
50 for (var = dvbase; var; var = var->next) {
51 if (strcmp(name, var->name) == 0)
58 dvar_set(const char *name, char **data, int count)
62 for (var = dvbase; var; var = var->next) {
63 if (strcmp(name, var->name) == 0)
67 var = malloc(sizeof(*var) + strlen(name) + 1);
68 var->name = (char *)(void *)(var + 1);
69 strcpy(var->name, name);
74 while (--var->count >= 0)
75 free(var->data[var->count]);
77 /* var->data = NULL; not needed */
80 var->data = malloc(sizeof(char *) * (count + 1));
81 var->data[count] = NULL;
83 var->data[count] = strdup(data[count]);
87 dvar_unset(const char *name)
94 if ((p = strchr(name, '*')) != NULL) {
95 while ((var = *lastp) != NULL) {
96 if (strlen(var->name) >= p - name &&
97 strncmp(var->name, name, p - name) == 0) {
104 while ((var = *lastp) != NULL) {
105 if (strcmp(name, var->name) == 0) {
121 dvar_next(dvar_t var)
127 dvar_free(dvar_t *lastp)
129 dvar_t dvar = *lastp;
131 if (dvlastp == &dvar->next)
134 while (--dvar->count >= 0)
135 free(dvar->data[dvar->count]);
141 dvar_istrue(dvar_t var)
145 if (var != NULL && (strcasecmp(var->data[0], "yes") == 0 ||
146 strcasecmp(var->data[0], "true") == 0 ||
147 strcasecmp(var->data[0], "on") == 0 ||
148 strcasecmp(var->data[0], "1") == 0))