Deleted Added
full compact
subr_hints.c (78135) subr_hints.c (79696)
1/*-
2 * Copyright (c) 2000,2001 Peter Wemm <peter@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2000,2001 Peter Wemm <peter@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/kern/subr_hints.c 78135 2001-06-12 09:40:04Z peter $
26 * $FreeBSD: head/sys/kern/subr_hints.c 79696 2001-07-14 00:23:10Z peter $
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/bus.h>
32
33/*
34 * Access functions for device resources.
35 */
36
37extern char static_hints[]; /* by config for now */
27 */
28
29#include <sys/param.h>
30#include <sys/systm.h>
31#include <sys/bus.h>
32
33/*
34 * Access functions for device resources.
35 */
36
37extern char static_hints[]; /* by config for now */
38extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */
39static char *hintp;
38
39/*
40 * Evil wildcarding resource string lookup.
41 * This walks the supplied env string table and returns a match.
42 * The start point can be remembered for incremental searches.
43 */
44static int
40
41/*
42 * Evil wildcarding resource string lookup.
43 * This walks the supplied env string table and returns a match.
44 * The start point can be remembered for incremental searches.
45 */
46static int
45res_find(const char *cp, int *line, int *startln,
47res_find(int *line, int *startln,
46 const char *name, int *unit, const char *resname, const char *value,
47 const char **ret_name, int *ret_namelen, int *ret_unit,
48 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
49{
50 int n = 0, hit;
51 char r_name[32];
52 int r_unit;
53 char r_resname[32];
54 char r_value[128];
48 const char *name, int *unit, const char *resname, const char *value,
49 const char **ret_name, int *ret_namelen, int *ret_unit,
50 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
51{
52 int n = 0, hit;
53 char r_name[32];
54 int r_unit;
55 char r_resname[32];
56 char r_value[128];
55 const char *s;
57 const char *s, *cp;
56 char *p;
57
58 char *p;
59
60 if (hintp == NULL) {
61 switch (hintmode) {
62 case 0: /* config supplied nothing */
63 hintp = kern_envp;
64 break;
65 case 1: /* static hints only */
66 hintp = static_hints;
67 break;
68 case 2: /* fallback mode */
69 cp = kern_envp;
70 while (cp) {
71 if (strncmp(cp, "hint.", 5) == 0) {
72 cp = NULL;
73 hintp = kern_envp;
74 break;
75 }
76 while (*cp != '\0')
77 cp++;
78 cp++;
79 if (*cp == '\0') {
80 cp = NULL;
81 hintp = static_hints;
82 break;
83 }
84 }
85 break;
86 default:
87 break;
88 }
89 if (hintp == NULL)
90 hintp = kern_envp;
91 }
92
93 cp = hintp;
58 while (cp) {
59 hit = 1;
60 (*line)++;
61 if (strncmp(cp, "hint.", 5) != 0)
62 hit = 0;
63 else
64 n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%128s",
65 r_name, &r_unit, r_resname, r_value);

--- 62 unchanged lines hidden (view full) ---

128 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
129{
130 int i;
131 int un;
132
133 *line = 0;
134
135 /* Search for exact unit matches first */
94 while (cp) {
95 hit = 1;
96 (*line)++;
97 if (strncmp(cp, "hint.", 5) != 0)
98 hit = 0;
99 else
100 n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%128s",
101 r_name, &r_unit, r_resname, r_value);

--- 62 unchanged lines hidden (view full) ---

164 const char **ret_resname, int *ret_resnamelen, const char **ret_value)
165{
166 int i;
167 int un;
168
169 *line = 0;
170
171 /* Search for exact unit matches first */
136 i = res_find(kern_envp, line, startln, name, unit, resname, value,
172 i = res_find(line, startln, name, unit, resname, value,
137 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
138 ret_value);
139 if (i == 0)
140 return 0;
173 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
174 ret_value);
175 if (i == 0)
176 return 0;
141 i = res_find(static_hints, line, startln, name, unit, resname, value,
142 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
143 ret_value);
144 if (i == 0)
145 return 0;
146 if (unit == NULL)
147 return ENOENT;
148 /* If we are still here, search for wildcard matches */
149 un = -1;
177 if (unit == NULL)
178 return ENOENT;
179 /* If we are still here, search for wildcard matches */
180 un = -1;
150 i = res_find(kern_envp, line, startln, name, &un, resname, value,
181 i = res_find(line, startln, name, &un, resname, value,
151 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
152 ret_value);
153 if (i == 0)
154 return 0;
182 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
183 ret_value);
184 if (i == 0)
185 return 0;
155 un = -1;
156 i = res_find(static_hints, line, startln, name, &un, resname, value,
157 ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
158 ret_value);
159 if (i == 0)
160 return 0;
161 return ENOENT;
162}
163
164int
165resource_int_value(const char *name, int unit, const char *resname, int *result)
166{
167 int error;
168 const char *str;

--- 136 unchanged lines hidden ---
186 return ENOENT;
187}
188
189int
190resource_int_value(const char *name, int unit, const char *resname, int *result)
191{
192 int error;
193 const char *str;

--- 136 unchanged lines hidden ---