Add env_setargs call for access to argc/argv.
static dpeth_t de_table[DE_PORT_NR];
static u16_t eth_ign_proto;
-static int arg_c;
-static char **arg_v;
/* Configuration */
typedef struct dp_conf
dpeth_t *dep;
long v;
- arg_c= argc;
- arg_v= argv;
+ env_setargs(argc, argv);
for (i= 0, dep= de_table; i<DE_PORT_NR; i++, dep++)
{
}
v= 0;
- (void) env_parse_x(arg_c, arg_v,
- "ETH_IGN_PROTO", "x", 0, &v, 0x0000L, 0xFFFFL);
+ (void) env_parse("ETH_IGN_PROTO", "x", 0, &v, 0x0000L, 0xFFFFL);
eth_ign_proto= htons((u16_t) v);
while (TRUE)
for (i= 0, dep= de_table; i<DE_PORT_NR; i++, dep++)
{
envvar= dp_conf[i].dpc_envvar;
- if (!(dep->de_pci= env_prefix_x(arg_c, arg_v, envvar, "pci")))
+ if (!(dep->de_pci= env_prefix(envvar, "pci")))
continue; /* no PCI config */
v= 0;
- (void) env_parse_x(arg_c, arg_v, envvar, envfmt, 1, &v, 0, 255);
+ (void) env_parse(envvar, envfmt, 1, &v, 0, 255);
dep->de_pcibus= v;
v= 0;
- (void) env_parse_x(arg_c, arg_v, envvar, envfmt, 2, &v, 0, 255);
+ (void) env_parse(envvar, envfmt, 2, &v, 0, 255);
dep->de_pcidev= v;
v= 0;
- (void) env_parse_x(arg_c, arg_v, envvar, envfmt, 3, &v, 0, 255);
+ (void) env_parse(envvar, envfmt, 3, &v, 0, 255);
dep->de_pcifunc= v;
}
for (i= 0; i < 6; i++)
{
v= dep->de_address.ea_addr[i];
- if (env_parse_x(arg_c, arg_v,
- eakey, eafmt, i, &v, 0x00L, 0xFFL) != EP_SET)
+ if (env_parse(eakey, eafmt, i, &v, 0x00L, 0xFFL) != EP_SET)
{
break;
}
/* Get the default settings and modify them from the environment. */
dep->de_mode= DEM_SINK;
v= dcp->dpc_port;
- switch (env_parse_x(arg_c, arg_v,
- dcp->dpc_envvar, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL)) {
+ switch (env_parse(dcp->dpc_envvar, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL)) {
case EP_OFF:
dep->de_mode= DEM_DISABLED;
break;
dep->de_base_port= v;
v= dcp->dpc_irq | DEI_DEFAULT;
- (void) env_parse_x(arg_c, arg_v, dcp->dpc_envvar, dpc_fmt, 1, &v, 0L,
+ (void) env_parse(dcp->dpc_envvar, dpc_fmt, 1, &v, 0L,
(long) NR_IRQ_VECTORS - 1);
dep->de_irq= v;
v= dcp->dpc_mem;
- (void) env_parse_x(arg_c, arg_v,
- dcp->dpc_envvar, dpc_fmt, 2, &v, 0L, 0xFFFFFL);
+ (void) env_parse(dcp->dpc_envvar, dpc_fmt, 2, &v, 0L, 0xFFFFFL);
dep->de_linmem= v;
v= 0;
- (void) env_parse_x(arg_c, arg_v,
- dcp->dpc_envvar, dpc_fmt, 3, &v, 0x2000L, 0x8000L);
+ (void) env_parse(dcp->dpc_envvar, dpc_fmt, 3, &v, 0x2000L, 0x8000L);
dep->de_ramsize= v;
}
fi
# start only network drivers that are in use
- for driver in rtl8139 fxp dpeth
+ for driver in rtl8139 fxp dpeth dp8390
do
if grep " $driver " /etc/inet.conf > /dev/null
then
#define EP_SET 3 /* var = 1:2:3 (nonblank field) */
#define EP_EGETKENV 4 /* sys_getkenv() failed ... */
-_PROTOTYPE( int get_mon_param, (char *key, char *value, int max_size) );
+_PROTOTYPE( void env_setargs, (int argc, char *argv[]) );
+_PROTOTYPE( int env_get_param, (char *key, char *value, int max_size) );
_PROTOTYPE( int env_prefix, (char *env, char *prefix) );
-_PROTOTYPE( int env_prefix_x, (int argc, char *argv[],
- char *env, char *prefix) );
_PROTOTYPE( void env_panic, (char *key) );
_PROTOTYPE( int env_parse, (char *env, char *fmt, int field, long *param,
long min, long max) );
-_PROTOTYPE( int env_parse_x, (int argc, char *argv[], char *env,
- char *fmt, int field, long *param, long min, long max) );
-
#define fkey_map(fkeys, sfkeys) fkey_ctl(FKEY_MAP, (fkeys), (sfkeys))
#define fkey_unmap(fkeys, sfkeys) fkey_ctl(FKEY_UNMAP, (fkeys), (sfkeys))
$(LIBUTILS)(kputc.o) \
$(LIBUTILS)(tickdelay.o) \
$(LIBUTILS)(getuptime.o) \
- $(LIBUTILS)(get_mon_prm.o) \
+ $(LIBUTILS)(env_get_prm.o) \
$(LIBUTILS)(env_parse.o) \
$(LIBUTILS)(env_panic.o) \
$(LIBUTILS)(env_prefix.o) \
$(LIBUTILS)(tickdelay.o): tickdelay.c
$(CC1) tickdelay.c
-$(LIBUTILS)(get_mon_prm.o): get_mon_prm.c
- $(CC1) get_mon_prm.c
+$(LIBUTILS)(env_get_prm.o): env_get_prm.c
+ $(CC1) env_get_prm.c
$(LIBUTILS)(env_parse.o): env_parse.c
$(CC1) env_parse.c
--- /dev/null
+#include "sysutil.h"
+#include <minix/config.h>
+#include <string.h>
+
+PRIVATE int argc = 0;
+PRIVATE char **argv = NULL;
+
+FORWARD _PROTOTYPE( char *find_key, (const char *params, const char *key));
+
+/*===========================================================================*
+ * env_setargs *
+ *===========================================================================*/
+PUBLIC void env_setargs(arg_c, arg_v)
+int arg_c;
+char *arg_v[];
+{
+ argc= arg_c;
+ argv= arg_v;
+}
+
+/*===========================================================================*
+ * env_get_param *
+ *===========================================================================*/
+PUBLIC int env_get_param(key, value, max_len)
+char *key; /* which key to look up */
+char *value; /* where to store value */
+int max_len; /* maximum length of value */
+{
+ message m;
+ static char mon_params[128*sizeof(char *)]; /* copy parameters here */
+ char *key_value;
+ int i, s, keylen;
+
+ if (key == NULL)
+ return EINVAL;
+
+ keylen= strlen(key);
+ for (i= 1; i<argc; i++)
+ {
+ if (strncmp(argv[i], key, keylen) != 0)
+ continue;
+ if (strlen(argv[i]) <= keylen)
+ continue;
+ if (argv[i][keylen] != '=')
+ continue;
+ key_value= argv[i]+keylen+1;
+ if (strlen(key_value)+1 > EP_BUF_SIZE)
+ return(E2BIG);
+ strcpy(value, key_value);
+ return OK;
+ }
+
+ /* Get copy of boot monitor parameters. */
+ m.m_type = SYS_GETINFO;
+ m.I_REQUEST = GET_MONPARAMS;
+ m.I_PROC_NR = SELF;
+ m.I_VAL_LEN = sizeof(mon_params);
+ m.I_VAL_PTR = mon_params;
+ if ((s=_taskcall(SYSTASK, SYS_GETINFO, &m)) != OK) {
+ printf("SYS_GETINFO: %d (size %u)\n", s, sizeof(mon_params));
+ return(s);
+ }
+
+ /* We got a copy, now search requested key. */
+ if ((key_value = find_key(mon_params, key)) == NULL)
+ return(ESRCH);
+
+ /* Value found, make the actual copy (as far as possible). */
+ strncpy(value, key_value, max_len);
+
+ /* See if it fits in the client's buffer. */
+ if ((strlen(key_value)+1) > max_len) return(E2BIG);
+ return(OK);
+}
+
+
+/*==========================================================================*
+ * find_key *
+ *==========================================================================*/
+PRIVATE char *find_key(params,name)
+const char *params;
+const char *name;
+{
+ register const char *namep;
+ register char *envp;
+
+ for (envp = (char *) params; *envp != 0;) {
+ for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
+ ;
+ if (*namep == '\0' && *envp == '=')
+ return(envp + 1);
+ while (*envp++ != 0)
+ ;
+ }
+ return(NULL);
+}
+
{
static char value[EP_BUF_SIZE] = "<unknown>";
int s;
- if ((s=get_mon_param(key, value, sizeof(value))) == 0) {
+ if ((s=env_get_param(key, value, sizeof(value))) == 0) {
if (s != ESRCH) /* only error allowed */
printf("WARNING: get_mon_param() failed in env_panic(): %d\n", s);
}
int field; /* field number of value to return */
long *param; /* address of parameter to get */
long min, max; /* minimum and maximum values for the parameter */
-{
- return env_parse_x(0, NULL, env, fmt, field, param, min, max);
-}
-
-/*=========================================================================*
- * env_parse_x *
- *=========================================================================*/
-PUBLIC int env_parse_x(argc, argv, env, fmt, field, param, min, max)
-int argc;
-char *argv[];
-char *env; /* environment variable to inspect */
-char *fmt; /* template to parse it with */
-int field; /* field number of value to return */
-long *param; /* address of parameter to get */
-long min, max; /* minimum and maximum values for the parameter */
{
/* Parse an environment variable setting, something like "DPETH0=300:3".
* Panic if the parsing fails. Return EP_UNSET if the environment variable
long newpar;
int s, i, radix, r, keylen;
- keylen= strlen(env);
- for (i= 0; i<argc; i++)
- {
- if (strncmp(argv[i], env, keylen) != 0)
- continue;
- if (strlen(argv[i]) <= keylen)
- continue;
- if (argv[i][keylen] != '=')
- continue;
- val= argv[i]+keylen+1;
- if (strlen(val)+1 > EP_BUF_SIZE)
- {
- printf("WARNING: env_parse() failed: argument too long\n");
- return(EP_EGETKENV);
- }
- strcpy(value, val);
- }
-
- if (i >= argc && (s=get_mon_param(env, value, sizeof(value))) != 0) {
+ if ((s=env_get_param(env, value, sizeof(value))) != 0) {
if (s == ESRCH) return(EP_UNSET); /* only error allowed */
printf("WARNING: get_mon_param() failed in env_parse(): %d\n",s);
return(EP_EGETKENV);
PUBLIC int env_prefix(env, prefix)
char *env; /* environment variable to inspect */
char *prefix; /* prefix to test for */
-{
- return env_prefix_x(0, NULL, env, prefix);
-}
-
-
-/*=========================================================================*
- * env_prefix_x *
- *=========================================================================*/
-PUBLIC int env_prefix_x(argc, argv, env, prefix)
-int argc;
-char *argv[];
-char *env; /* environment variable to inspect */
-char *prefix; /* prefix to test for */
{
/* An environment setting may be prefixed by a word, usually "pci".
* Return TRUE if a given prefix is used.
char *val;
size_t n;
- keylen= strlen(env);
- for (i= 0; i<argc; i++)
- {
- printf("env_prefix_x: argv[%d] = '%s'\n", i, argv[i]);
- if (strncmp(argv[i], env, keylen) != 0)
- continue;
- if (strlen(argv[i]) <= keylen)
- continue;
- if (argv[i][keylen] != '=')
- continue;
- val= argv[i]+keylen+1;
- if (strlen(val)+1 > EP_BUF_SIZE)
- {
- printf("WARNING: env_parse() failed: argument too long\n");
- return(EP_EGETKENV);
- }
- strcpy(value, val);
- }
-
- if (i >= argc && (s = get_mon_param(env, value, sizeof(value))) != 0) {
+ if ((s = env_get_param(env, value, sizeof(value))) != 0) {
if (s != ESRCH) /* only error allowed */
printf("WARNING: get_mon_param() failed in env_prefix(): %d\n", s);
}
+++ /dev/null
-#include "sysutil.h"
-#include <minix/config.h>
-#include <string.h>
-
-FORWARD _PROTOTYPE( char *find_key, (const char *params, const char *key));
-
-/*===========================================================================*
- * get_mon_param *
- *===========================================================================*/
-PUBLIC int get_mon_param(key, value, max_len)
-char *key; /* which key to look up */
-char *value; /* where to store value */
-int max_len; /* maximum length of value */
-{
- message m;
- static char mon_params[128*sizeof(char *)]; /* copy parameters here */
- char *key_value;
- int s;
-
- if (key != NULL) {
- /* Get copy of boot monitor parameters. */
- m.m_type = SYS_GETINFO;
- m.I_REQUEST = GET_MONPARAMS;
- m.I_PROC_NR = SELF;
- m.I_VAL_LEN = sizeof(mon_params);
- m.I_VAL_PTR = mon_params;
- if ((s=_taskcall(SYSTASK, SYS_GETINFO, &m)) != OK) {
- printf("SYS_GETINFO: %d (size %u)\n", s, sizeof(mon_params));
- return(s);
- }
-
- /* We got a copy, now search requested key. */
- if ((key_value = find_key(mon_params, key)) == NULL)
- return(ESRCH);
-
- /* Value found, make the actual copy (as far as possible). */
- strncpy(value, key_value, max_len);
-
- /* See if it fits in the client's buffer. */
- if ((strlen(key_value)+1) > max_len) return(E2BIG);
- return(OK);
- }
- return(EINVAL);
-}
-
-
-/*==========================================================================*
- * find_key *
- *==========================================================================*/
-PRIVATE char *find_key(params,name)
-const char *params;
-const char *name;
-{
- register const char *namep;
- register char *envp;
-
- for (envp = (char *) params; *envp != 0;) {
- for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++)
- ;
- if (*namep == '\0' && *envp == '=')
- return(envp + 1);
- while (*envp++ != 0)
- ;
- }
- return(NULL);
-}
-