CGR Localization
 All Classes Namespaces Files Functions Variables Macros Pages
configreader_test.cpp
1 #include "configreader.h"
2 
3 int main(int argc,char **argv)
4 {
5  if(argc != 3) return(-1);
6 
7  WatchFiles watch_files;
8  ConfigReader config;
9  const char *filename = argv[1];
10  const char *key = argv[2];
11 
12  config.init(watch_files);
13  config.addFile("config/nonexist.cfg",ConfigReader::Optional);
14  config.addFile(filename);
15  if(!config.readFiles()){
16  printf("Failed to read config\n");
17  exit(1);
18  }
19 
20  bool loop = true;
21 
22  do{
23  // print the variable value
24  const char *value = config.getStr(key,"");
25  printf("%s = \"%s\"\n",key,value);
26 
27  if(loop){
28  // poll for a change to happen, then reread config
29  while(watch_files.getEvents() == 0) usleep(100*1000);
30  if(config.isFileModified()) config.readFiles();
31  watch_files.clearEvents();
32  }
33  }while(loop);
34 
35  return(0);
36 }