5 #include <minix/param.h>
8 /*=========================================================================*
10 *=========================================================================*/
11 int env_parse(env
, fmt
, field
, param
, min
, max
)
12 char *env
; /* environment variable to inspect */
13 char *fmt
; /* template to parse it with */
14 int field
; /* field number of value to return */
15 long *param
; /* address of parameter to get */
16 long min
, max
; /* minimum and maximum values for the parameter */
18 /* Parse an environment variable setting, something like "DPETH0=300:3".
19 * Panic if the parsing fails. Return EP_UNSET if the environment variable
20 * is not set, EP_OFF if it is set to "off", EP_ON if set to "on" or a
21 * field is left blank, or EP_SET if a field is given (return value through
22 * *param). Punctuation may be used in the environment and format string,
23 * fields in the environment string may be empty, and punctuation may be
24 * missing to skip fields. The format string contains characters 'd', 'o',
25 * 'x' and 'c' to indicate that 10, 8, 16, or 0 is used as the last argument
26 * to strtol(). A '*' means that a field should be skipped. If the format
27 * string contains something like "\4" then the string is repeated 4 characters
31 char value
[EP_BUF_SIZE
];
32 char PUNCT
[] = ":,;.";
36 if ((s
=env_get_param(env
, value
, sizeof(value
))) != 0) {
37 if (s
== ESRCH
) return(EP_UNSET
); /* only error allowed */
38 printf("WARNING: env_get_param() failed in env_parse(): %d\n",s
);
42 if (strcmp(val
, "off") == 0) return(EP_OFF
);
43 if (strcmp(val
, "on") == 0) return(EP_ON
);
48 while (*val
== ' ') val
++; /* skip spaces */
49 if (*val
== 0) return(r
); /* the proper exit point */
50 if (*fmt
== 0) break; /* too many values */
52 if (strchr(PUNCT
, *val
) != NULL
) {
53 /* Time to go to the next field. */
54 if (strchr(PUNCT
, *fmt
) != NULL
) i
++;
55 if (*fmt
++ == *val
) val
++;
56 if (*fmt
< 32) fmt
-= *fmt
; /* step back? */
58 /* Environment contains a value, get it. */
60 case '*': radix
= -1; break;
61 case 'd': radix
= 10; break;
62 case 'o': radix
= 010; break;
63 case 'x': radix
= 0x10; break;
64 case 'c': radix
= 0; break;
70 while (strchr(PUNCT
, *val
) == NULL
) val
++;
74 newpar
= strtol(val
, &end
, radix
);
76 if (end
== val
) break; /* not a number */
81 /* The field requested. */
82 if (newpar
< min
|| newpar
> max
) break;
93 /*=========================================================================*
95 *=========================================================================*/
97 int env_memory_parse(mem_chunks
, maxchunks
)
98 struct memory
*mem_chunks
; /* where to store the memory bits */
99 int maxchunks
; /* how many were found */
101 static kinfo_t kinfo
;
104 if((r
=sys_getkinfo(&kinfo
)) != OK
) return r
;
106 /* Initialize everything to zero. */
107 memset(mem_chunks
, 0, maxchunks
*sizeof(*mem_chunks
));
109 for(mm
= 0; mm
< MAXMEMMAP
; mm
++) {
110 mem_chunks
[mm
].base
= kinfo
.memmap
[mm
].addr
;
111 mem_chunks
[mm
].size
= kinfo
.memmap
[mm
].len
;