9 #include "daq/rfarm/manager/RFConf.h"
18 RFConf::RFConf(
const char* filename)
20 m_fd = fopen(filename,
"r");
22 fprintf(stderr,
"RFConf : config file not found %s\n", filename);
34 char* RFConf::getconf(
const char* key1,
const char* key2,
const char* key3)
36 char buf[1024], keybuf[256];
37 char* p, *q, *keyp, *delp, *valp;
47 sprintf(keybuf,
"%s.%s.%s", key1, key2, key3);
49 sprintf(keybuf,
"%s.%s", key1, key2);
60 while (fgets(buf,
sizeof(buf), m_fd)) {
63 p = strchr(buf,
'\n');
65 fprintf(stderr,
"RFConf : line %d too long\n", line);
66 while (fgets(buf,
sizeof(buf), m_fd) && !strchr(buf,
'\n'))
74 keyp = valp = delp = 0;
75 for (p = buf; *p && *p !=
'#'; p++) {
77 if (! isspace(*p)) keyp = p;
80 if (!isspace(*(p + 1)) && *(p + 1) !=
':') {
81 fprintf(stderr,
"RFConf : invalid key at line %d\n", line);
85 }
else if (*p ==
':') {
93 }
else if (! isspace(*p)) {
95 }
else if (! isspace(*(p + 1))) {
100 for (*q-- = 0; isspace(*q); *q-- = 0)
104 cur->next = (
RFConf_t*)malloc(
sizeof(*cur));
107 cur->key = (
char*)malloc(strlen(keyp) + 1);
108 strcpy(cur->key, keyp);
110 cur->val = (
char*)malloc(strlen(valp) + 1);
111 strcpy(cur->val, valp);
117 }
else if (! top.val) {
122 for (cur = ⊤ cur; cur = cur->next) {
123 if (cur->key == NULL)
continue;
124 if (strcmp(cur->key, keybuf) == 0)
return cur->val;
127 printf(
"RFConf: Key %s not found\n", keybuf);
128 printf(
"nitem = %d, keybuf = %s\n", nitem, keybuf);
132 int RFConf::getconfi(
const char* key1,
const char* key2,
const char* key3)
134 return atoi(getconf(key1, key2, key3));
Abstract base class for different kinds of events.