9#include "daq/rfarm/manager/RFConf.h"
18RFConf::RFConf(
const char* filename)
20 m_fd = fopen(filename,
"r");
22 fprintf(stderr,
"RFConf : config file not found %s\n", filename);
34char* RFConf::getconf(
const char* key1,
const char* key2,
const char* key3)
36 char buf[1024], keybuf[256];
46 sprintf(keybuf,
"%s.%s.%s", key1, key2, key3);
48 sprintf(keybuf,
"%s.%s", key1, key2);
59 while (fgets(buf,
sizeof(buf), m_fd)) {
62 p = strchr(buf,
'\n');
64 fprintf(stderr,
"RFConf : line %d too long\n", line);
65 while (fgets(buf,
sizeof(buf), m_fd) && !strchr(buf,
'\n'))
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);
133int RFConf::getconfi(
const char* key1,
const char* key2,
const char* key3)
135 return atoi(getconf(key1, key2, key3));
Abstract base class for different kinds of events.