]> git.lizzy.rs Git - plan9front.git/blob - sys/src/boot/alphapc/conf.c
Import sources from 2011-03-30 iso image - lib
[plan9front.git] / sys / src / boot / alphapc / conf.c
1 #include        "u.h"
2 #include        "mem.h"
3 #include        "dat.h"
4 #include        "fns.h"
5 #include        "lib.h"
6
7 static char *confname[MAXCONF];
8 static char *confval[MAXCONF];
9 static int nconf;
10 static char bootargs[BOOTARGSLEN];
11
12 char*
13 getconf(char *name)
14 {
15         int i;
16
17         for(i = 0; i < nconf; i++)
18                 if(strcmp(confname[i], name) == 0)
19                         return confval[i];
20         return 0;
21 }
22
23 void
24 setconf(char *buf)
25 {
26         char *cp, *line[MAXCONF];
27         int i, n;
28
29         /*
30          * Keep a pristine copy.
31          * Should change this to pass the parsed strings
32          * to the booted programme instead of the raw
33          * string, then it only gets done once.
34          */
35         strcpy(bootargs, buf);
36         /* print("boot: stashing /alpha/conf boot args at 0x%lux\n",
37                 bootargs);                      /* DEBUG */
38         conf.bootargs = bootargs;
39
40         n = getcfields(buf, line, MAXCONF, "\n");
41         for(i = 0; i < n; i++){
42                 if(*line[i] == '#')
43                         continue;
44                 cp = strchr(line[i], '=');
45                 if(cp == nil)
46                         continue;
47                 *cp++ = 0;
48                 if(cp - line[i] >= NAMELEN+1)
49                         *(line[i]+NAMELEN-1) = 0;
50                 confname[nconf] = line[i];
51                 confval[nconf] = cp;
52                 nconf++;
53         }
54 }
55
56 int
57 getcfields(char* lp, char** fields, int n, char* sep)
58 {
59         int i;
60
61         for(i = 0; lp && *lp && i < n; i++){
62                 while(*lp && strchr(sep, *lp) != 0)
63                         *lp++ = 0;
64                 if(*lp == 0)
65                         break;
66                 fields[i] = lp;
67                 while(*lp && strchr(sep, *lp) == 0){
68                         if(*lp == '\\' && *(lp+1) == '\n')
69                                 *lp++ = ' ';
70                         lp++;
71                 }
72         }
73
74         return i;
75 }