conf.c 1.3 KB

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