diff options
author | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
---|---|---|
committer | Taru Karttunen <taruti@taruti.net> | 2011-03-30 15:46:40 +0300 |
commit | e5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch) | |
tree | d8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/boot/alphapc/conf.c |
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/boot/alphapc/conf.c')
-rwxr-xr-x | sys/src/boot/alphapc/conf.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sys/src/boot/alphapc/conf.c b/sys/src/boot/alphapc/conf.c new file mode 100755 index 000000000..8a4858d92 --- /dev/null +++ b/sys/src/boot/alphapc/conf.c @@ -0,0 +1,75 @@ +#include "u.h" +#include "mem.h" +#include "dat.h" +#include "fns.h" +#include "lib.h" + +static char *confname[MAXCONF]; +static char *confval[MAXCONF]; +static int nconf; +static char bootargs[BOOTARGSLEN]; + +char* +getconf(char *name) +{ + int i; + + for(i = 0; i < nconf; i++) + if(strcmp(confname[i], name) == 0) + return confval[i]; + return 0; +} + +void +setconf(char *buf) +{ + char *cp, *line[MAXCONF]; + int i, n; + + /* + * Keep a pristine copy. + * Should change this to pass the parsed strings + * to the booted programme instead of the raw + * string, then it only gets done once. + */ + strcpy(bootargs, buf); + /* print("boot: stashing /alpha/conf boot args at 0x%lux\n", + bootargs); /* DEBUG */ + conf.bootargs = bootargs; + + n = getcfields(buf, line, MAXCONF, "\n"); + for(i = 0; i < n; i++){ + if(*line[i] == '#') + continue; + cp = strchr(line[i], '='); + if(cp == nil) + continue; + *cp++ = 0; + if(cp - line[i] >= NAMELEN+1) + *(line[i]+NAMELEN-1) = 0; + confname[nconf] = line[i]; + confval[nconf] = cp; + nconf++; + } +} + +int +getcfields(char* lp, char** fields, int n, char* sep) +{ + int i; + + for(i = 0; lp && *lp && i < n; i++){ + while(*lp && strchr(sep, *lp) != 0) + *lp++ = 0; + if(*lp == 0) + break; + fields[i] = lp; + while(*lp && strchr(sep, *lp) == 0){ + if(*lp == '\\' && *(lp+1) == '\n') + *lp++ = ' '; + lp++; + } + } + + return i; +} |