Experimental usage.
[vlp.git] / src / global / AppConfiguration.cpp
1 #include <stdlib.h>
2 #include "genint1.h"
3 #include "AppConfiguration.h"
4
5 AppConfiguration::AppConfiguration(const char * fname)
6 {
7   config_init(&cfg);
8   
9   /* Read the file. If there is an error, report it and exit. */
10   if(!config_read_file(&cfg, fname)) 
11   {
12     error();
13     config_destroy(&cfg);
14     exit(3);/* from original code. */
15   }
16 }
17 int AppConfiguration::getInt(const char * path)
18 {
19     int value = 0;
20     if (config_lookup_int(&cfg, path, &value) == CONFIG_FALSE)
21     {
22         fprintf(stderr, "Warning: %s was not found, or bad type requested\n", path);
23     }
24     return value;
25 }
26
27 const char * AppConfiguration::getString(const char * path)
28 {
29     const char * value;
30     if (config_lookup_string(&cfg, path, &value) == CONFIG_FALSE)
31     {
32         fprintf(stderr, "Warning: %s was not found, or bad type requested\n", path);
33     }
34     return value;
35 }
36
37 int AppConfiguration::error()
38 {
39     if (config_error_type(&cfg) == CONFIG_ERR_NONE)
40     {
41         return FALSE;
42     }
43     
44     fprintf(stderr, "%s: In file %s, line %d\n",
45         config_error_text(&cfg),
46         config_error_file(&cfg),
47         config_error_line(&cfg));
48     return TRUE;
49 }
50
51 void AppConfiguration::release()
52 {
53     config_destroy(&cfg);
54 }