aboutsummaryrefslogtreecommitdiff
path: root/src/settings.cc
diff options
context:
space:
mode:
authorYour Name <you@example.com>2021-05-13 17:20:26 -0400
committerYour Name <you@example.com>2021-05-13 17:20:26 -0400
commit5a6248518654ec97d95d2c463e3ffb4be7bbf456 (patch)
treea6ebb6bb26ba2a6b4abc3829a81c58ae97fd2e05 /src/settings.cc
downloadannotator-5a6248518654ec97d95d2c463e3ffb4be7bbf456.tar.gz
annotator-5a6248518654ec97d95d2c463e3ffb4be7bbf456.tar.bz2
annotator-5a6248518654ec97d95d2c463e3ffb4be7bbf456.zip
Initial commit
Diffstat (limited to 'src/settings.cc')
-rw-r--r--src/settings.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/settings.cc b/src/settings.cc
new file mode 100644
index 0000000..d19acde
--- /dev/null
+++ b/src/settings.cc
@@ -0,0 +1,28 @@
+#include "settings.h"
+#include <confuse.h>
+#include <errno.h>
+#include <cstring>
+#include <stdexcept>
+
+namespace settings {
+ std::vector<std::string> getLabels() {
+ cfg_opt_t opts[] = {
+ CFG_STR_LIST("labels", NULL, CFGF_NONE),
+ CFG_END()
+ };
+ cfg_t *cfg = cfg_init(opts, CFGF_IGNORE_UNKNOWN);
+ if(cfg_parse(cfg, "annotator.conf") == CFG_PARSE_ERROR) {
+ throw std::runtime_error("Configuration file annotator.conf could not be read: " + std::string(strerror(errno)));
+ }
+ try {
+ std::vector<std::string> ret;
+ std::size_t i;
+ for(i = 0; i < cfg_size(cfg, "labels"); i++) {
+ ret.push_back(cfg_getnstr(cfg, "labels", i));
+ }
+ return ret;
+ } catch(std::exception& e) {
+ throw std::runtime_error("Cannot find 'labels' in configuration file");
+ }
+ }
+}