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];
39 struct RFConf_t top, *cur;
46 sprintf(keybuf,
"%s.%s.%s", key1, key2, key3);
48 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 const char* keyp =
nullptr;
77 const char* valp =
nullptr;
78 for (p = buf; *p && *p !=
'#'; p++) {
80 if (! isspace(*p)) keyp = p;
83 if (!isspace(*(p + 1)) && *(p + 1) !=
':') {
84 fprintf(stderr,
"RFConf : invalid key at line %d\n", line);
88 }
else if (*p ==
':') {
96 }
else if (! isspace(*p)) {
98 }
else if (! isspace(*(p + 1))) {
103 for (*q-- = 0; isspace(*q); *q-- = 0)
107 cur->next =
static_cast<RFConf_t*
>(malloc(
sizeof(*cur)));
108 if (cur->next == 0)
return NULL;
111 cur->key =
static_cast<char*
>(malloc(strlen(keyp) + 1));
112 strcpy(cur->key, keyp);
114 cur->val =
static_cast<char*
>(malloc(strlen(valp) + 1));
115 strcpy(cur->val, valp);
121 }
else if (! top.val) {
126 for (cur = ⊤ cur; cur = cur->next) {
127 if (cur->key == NULL)
continue;
128 if (strcmp(cur->key, keybuf) == 0)
return cur->val;
131 printf(
"RFConf: Key %s not found\n", keybuf);
132 printf(
"nitem = %d, keybuf = %s\n", nitem, keybuf);
136int RFConf::getconfi(
const char* key1,
const char* key2,
const char* key3)
138 return atoi(getconf(key1, key2, key3));
Abstract base class for different kinds of events.