#include //for use of exit() #include //for use of libconfig #include int main(int argc, char *argv[]) { fprintf(stdout,"main() Started...\n"); /*read command line*/ if (argc > 1){ printf("main() argv[1]: %s\n", argv[1]); }else{ fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } config_t cfg; const char *str; int port; /*initialise new and EMPTY config*/ config_init(&cfg); /* Read the file. If there is an error, report it and exit. */ /*TODO Make sure argv is a valid file name!*/ if(! config_read_file(&cfg, argv[1])) { fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg)); /*destroy config, BUT NOT the structure*/ config_destroy(&cfg); return(EXIT_FAILURE); } /*lookup db string*/ if(config_lookup_string(&cfg, "pq.db", &str)){ printf("db: %s\n", str); }else{ fprintf(stderr, "No 'db' setting in configuration file.\n"); } /*lookup port int*/ if(config_lookup_int(&cfg, "pq.port", &port)){ printf("port: %d\n", port); }else{ fprintf(stderr, "No 'port' setting in configuration file.\n"); } config_destroy(&cfg); fprintf(stdout,"main() Done.\n"); return(EXIT_SUCCESS); }