10 #include "daq/rfarm/manager/RFConf.h"
19 RFConf::RFConf(
const char* filename)
21 m_fd = fopen(filename,
"r");
23 fprintf(stderr,
"RFConf : config file not found %s\n", filename);
35 char* RFConf::getconf(
const char* key1,
const char* key2,
const char* key3)
37 char buf[1024], keybuf[256];
38 char* p, *q, *keyp, *delp, *valp;
48 sprintf(keybuf,
"%s.%s.%s", key1, key2, key3);
50 sprintf(keybuf,
"%s.%s", key1, key2);
61 while (fgets(buf,
sizeof(buf), m_fd)) {
64 p = strchr(buf,
'\n');
66 fprintf(stderr,
"RFConf : line %d too long\n", line);
67 while (fgets(buf,
sizeof(buf), m_fd) && !strchr(buf,
'\n'))
75 keyp = valp = delp = 0;
76 for (p = buf; *p && *p !=
'#'; p++) {
78 if (! isspace(*p)) keyp = p;
81 if (!isspace(*(p + 1)) && *(p + 1) !=
':') {
82 fprintf(stderr,
"RFConf : invalid key at line %d\n", line);
86 }
else if (*p ==
':') {
94 }
else if (! isspace(*p)) {
96 }
else if (! isspace(*(p + 1))) {
101 for (*q-- = 0; isspace(*q); *q-- = 0)
105 cur->next = (
RFConf_t*)malloc(
sizeof(*cur));
108 cur->key = (
char*)malloc(strlen(keyp) + 1);
109 strcpy(cur->key, keyp);
111 cur->val = (
char*)malloc(strlen(valp) + 1);
112 strcpy(cur->val, valp);
118 }
else if (! top.val) {
123 for (cur = ⊤ cur; cur = cur->next) {
124 if (cur->key == NULL)
continue;
125 if (strcmp(cur->key, keybuf) == 0)
return cur->val;
128 printf(
"RFConf: Key %s not found\n", keybuf);
129 printf(
"nitem = %d, keybuf = %s\n", nitem, keybuf);
133 int RFConf::getconfi(
const char* key1,
const char* key2,
const char* key3)
135 return atoi(getconf(key1, key2, key3));