+#include <stdlib.h>
+#include "genint1.h"
#include "AppConfiguration.h"
-void AppConfiguration::error(config_t *cfg)
+AppConfiguration::AppConfiguration(const char * fname)
{
+ config_init(&cfg);
+
+ /* Read the file. If there is an error, report it and exit. */
+ if(!config_read_file(&cfg, fname))
+ {
+ error();
+ config_destroy(&cfg);
+ exit(3);/* from original code. */
+ }
+}
+int AppConfiguration::getInt(const char * path)
+{
+ int value = 0;
+ if (config_lookup_int(&cfg, path, &value) == CONFIG_FALSE)
+ {
+ fprintf(stderr, "Warning: %s was not found, or bad type requested\n", path);
+ }
+ return value;
+}
+
+const char * AppConfiguration::getString(const char * path)
+{
+ const char * value;
+ if (config_lookup_string(&cfg, path, &value) == CONFIG_FALSE)
+ {
+ fprintf(stderr, "Warning: %s was not found, or bad type requested\n", path);
+ }
+ return value;
+}
+
+int AppConfiguration::error()
+{
+ if (config_error_type(&cfg) == CONFIG_ERR_NONE)
+ {
+ return FALSE;
+ }
+
fprintf(stderr, "%s: In file %s, line %d\n",
- config_error_text(cfg),
- config_error_file(cfg),
- config_error_line(cfg));
+ config_error_text(&cfg),
+ config_error_file(&cfg),
+ config_error_line(&cfg));
+ return TRUE;
+}
+
+void AppConfiguration::release()
+{
+ config_destroy(&cfg);
}