diff options
-rw-r--r-- | src/common/HPM.c | 2 | ||||
-rw-r--r-- | src/common/conf.c | 16 | ||||
-rw-r--r-- | src/common/conf.h | 2 | ||||
-rw-r--r-- | src/common/socket.c | 2 | ||||
-rw-r--r-- | src/map/atcommand.c | 6 | ||||
-rw-r--r-- | src/map/battleground.c | 2 | ||||
-rw-r--r-- | src/map/channel.c | 2 | ||||
-rw-r--r-- | src/map/clif.c | 8 | ||||
-rw-r--r-- | src/map/itemdb.c | 21 | ||||
-rw-r--r-- | src/map/map.c | 2 | ||||
-rw-r--r-- | src/map/mob.c | 5 | ||||
-rw-r--r-- | src/map/pc.c | 4 | ||||
-rw-r--r-- | src/map/pc_groups.c | 2 | ||||
-rw-r--r-- | src/map/quest.c | 5 | ||||
-rw-r--r-- | src/map/script.c | 11 | ||||
-rw-r--r-- | src/map/status.c | 12 | ||||
-rw-r--r-- | src/test/test_libconfig.c | 6 |
17 files changed, 54 insertions, 54 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c index d9c3262d7..0cb23019a 100644 --- a/src/common/HPM.c +++ b/src/common/HPM.c @@ -628,7 +628,7 @@ void hplugins_config_read(void) { fclose(fp); } - if (libconfig->read_file(&plugins_conf, config_filename)) + if (!libconfig->load_file(&plugins_conf, config_filename)) return; plist = libconfig->lookup(&plugins_conf, "plugins_list"); diff --git a/src/common/conf.c b/src/common/conf.c index b7c4f0734..ca9b7cbbc 100644 --- a/src/common/conf.c +++ b/src/common/conf.c @@ -32,7 +32,7 @@ struct libconfig_interface libconfig_s; struct libconfig_interface *libconfig; /** - * Initializes 'config' and reads a configuration file. + * Initializes 'config' and loads a configuration file. * * Shows error and destroys 'config' in case of failure. * It is the caller's care to destroy 'config' in case of success. @@ -40,17 +40,19 @@ struct libconfig_interface *libconfig; * @param config The config file to initialize. * @param config_filename The file to read. * - * @retval 1 in case of failure. + * @retval CONFIG_TRUE in case of success. + * @retval CONFIG_FALSE in case of failure. */ -int conf_read_file(config_t *config, const char *config_filename) { +int config_load_file(config_t *config, const char *config_filename) +{ libconfig->init(config); - if (!libconfig->read_file_src(config, config_filename)) { + if (libconfig->read_file_src(config, config_filename) != CONFIG_TRUE) { ShowError("%s:%d - %s\n", config_error_file(config), config_error_line(config), config_error_text(config)); libconfig->destroy(config); - return 1; + return CONFIG_FALSE; } - return 0; + return CONFIG_TRUE; } // @@ -436,7 +438,7 @@ void libconfig_defaults(void) { libconfig->lookup_bool = config_lookup_bool; libconfig->lookup_string = config_lookup_string; /* those are custom and are from src/common/conf.c */ - libconfig->read_file = conf_read_file; + libconfig->load_file = config_load_file; libconfig->setting_copy_simple = config_setting_copy_simple; libconfig->setting_copy_elem = config_setting_copy_elem; libconfig->setting_copy_aggregate = config_setting_copy_aggregate; diff --git a/src/common/conf.h b/src/common/conf.h index 8bec2704f..3bcb4526f 100644 --- a/src/common/conf.h +++ b/src/common/conf.h @@ -100,7 +100,7 @@ struct libconfig_interface { /* those are custom and are from src/common/conf.c */ /* Functions to copy settings from libconfig/contrib */ - int (*read_file) (config_t *config, const char *config_filename); + int (*load_file) (config_t *config, const char *config_filename); void (*setting_copy_simple) (config_setting_t *parent, const config_setting_t *src); void (*setting_copy_elem) (config_setting_t *parent, const config_setting_t *src); void (*setting_copy_aggregate) (config_setting_t *parent, const config_setting_t *src); diff --git a/src/common/socket.c b/src/common/socket.c index 740c07bdc..be144fd50 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -1726,7 +1726,7 @@ void socket_net_config_read(const char *filename) int i; nullpo_retv(filename); - if (libconfig->read_file(&network_config, filename)) { + if (!libconfig->load_file(&network_config, filename)) { ShowError("LAN Support configuration file is not found: '%s'. This server won't be able to accept connections from any servers.\n", filename); return; } diff --git a/src/map/atcommand.c b/src/map/atcommand.c index bc539837d..3966ff2f1 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -3615,14 +3615,14 @@ ACMD(reloadskilldb) ACMD(reloadatcommand) { config_t run_test; - if (libconfig->read_file(&run_test, "conf/groups.conf")) { + if (!libconfig->load_file(&run_test, "conf/groups.conf")) { clif->message(fd, msg_fd(fd,1036)); // Error reading groups.conf, reload failed. return false; } libconfig->destroy(&run_test); - if (libconfig->read_file(&run_test, map->ATCOMMAND_CONF_FILENAME)) { + if (!libconfig->load_file(&run_test, map->ATCOMMAND_CONF_FILENAME)) { clif->message(fd, msg_fd(fd,1037)); // Error reading atcommand.conf, reload failed. return false; } @@ -10012,7 +10012,7 @@ void atcommand_config_read(const char* config_filename) { int num_aliases = 0; nullpo_retv(config_filename); - if (libconfig->read_file(&atcommand_config, config_filename)) + if (!libconfig->load_file(&atcommand_config, config_filename)) return; // Command symbols diff --git a/src/map/battleground.c b/src/map/battleground.c index e3fedbf34..995122d52 100644 --- a/src/map/battleground.c +++ b/src/map/battleground.c @@ -334,7 +334,7 @@ void bg_config_read(void) { config_setting_t *data = NULL; const char *config_filename = "conf/battlegrounds.conf"; // FIXME hardcoded name - if (libconfig->read_file(&bg_conf, config_filename)) + if (!libconfig->load_file(&bg_conf, config_filename)) return; data = libconfig->lookup(&bg_conf, "battlegrounds"); diff --git a/src/map/channel.c b/src/map/channel.c index d778b355d..c1b28fd84 100644 --- a/src/map/channel.c +++ b/src/map/channel.c @@ -593,7 +593,7 @@ void read_channels_config(void) config_setting_t *chsys = NULL; const char *config_filename = "conf/channels.conf"; // FIXME hardcoded name - if (libconfig->read_file(&channels_conf, config_filename)) + if (!libconfig->load_file(&channels_conf, config_filename)) return; chsys = libconfig->lookup(&channels_conf, "chsys"); diff --git a/src/map/clif.c b/src/map/clif.c index 3b2f255ef..5b9e9c99e 100644 --- a/src/map/clif.c +++ b/src/map/clif.c @@ -17317,10 +17317,8 @@ void clif_cashshop_db(void) { clif->cs.item_count[i] = 0; } - if (libconfig->read_file(&cashshop_conf, config_filename)) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&cashshop_conf, config_filename)) return; - } cashshop = libconfig->lookup(&cashshop_conf, "cash_shop"); @@ -18377,10 +18375,8 @@ bool clif_parse_roulette_db(void) { clif->rd.items[i] = 0; } - if (libconfig->read_file(&roulette_conf, config_filename)) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&roulette_conf, config_filename)) return false; - } roulette = libconfig->lookup(&roulette_conf, "roulette"); if( roulette != NULL && (levels = libconfig->setting_get_elem(roulette, 0)) != NULL ) { diff --git a/src/map/itemdb.c b/src/map/itemdb.c index bd552dd16..83535f294 100644 --- a/src/map/itemdb.c +++ b/src/map/itemdb.c @@ -648,10 +648,8 @@ void itemdb_read_groups(void) { int i = 0, count = 0, c; unsigned int *gsize = NULL; - if (libconfig->read_file(&item_group_conf, config_filename)) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&item_group_conf, config_filename)) return; - } gsize = aMalloc( libconfig->setting_length(item_group_conf.root) * sizeof(unsigned int) ); @@ -946,10 +944,8 @@ void itemdb_read_packages(void) { return; } - if (libconfig->read_file(&item_packages_conf, config_filename)) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&item_packages_conf, config_filename)) return; - } must = aMalloc( libconfig->setting_length(item_packages_conf.root) * sizeof(unsigned int) ); random = aMalloc( libconfig->setting_length(item_packages_conf.root) * sizeof(unsigned int) ); @@ -1170,10 +1166,8 @@ void itemdb_read_chains(void) { #endif int i = 0, count = 0; - if (libconfig->read_file(&item_chain_conf, config_filename)) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&item_chain_conf, config_filename)) return; - } CREATE(itemdb->chains, struct item_chain, libconfig->setting_length(item_chain_conf.root)); itemdb->chain_count = (unsigned short)libconfig->setting_length(item_chain_conf.root); @@ -1885,13 +1879,18 @@ int itemdb_readdb_libconfig(const char *filename) { int i = 0, count = 0; nullpo_ret(filename); + sprintf(filepath, "%s/%s", map->db_path, filename); - memset(&duplicate,0,sizeof(duplicate)); - if( libconfig->read_file(&item_db_conf, filepath) || !(itdb = libconfig->setting_get_member(item_db_conf.root, "item_db")) ) { + if (!libconfig->load_file(&item_db_conf, filepath)) + return 0; + + if ((itdb = libconfig->setting_get_member(item_db_conf.root, "item_db")) == NULL) { ShowError("can't read %s\n", filepath); return 0; } + memset(&duplicate,0,sizeof(duplicate)); + while( (it = libconfig->setting_get_elem(itdb,i++)) ) { int nameid = itemdb->readdb_libconfig_sub(it, i-1, filename); diff --git a/src/map/map.c b/src/map/map.c index 3dad25fce..3089f7ce0 100644 --- a/src/map/map.c +++ b/src/map/map.c @@ -4990,7 +4990,7 @@ void read_map_zone_db(void) { #else const char *config_filename = "db/pre-re/map_zone_db.conf"; // FIXME hardcoded name #endif - if (libconfig->read_file(&map_zone_db, config_filename)) + if (!libconfig->load_file(&map_zone_db, config_filename)) return; zones = libconfig->lookup(&map_zone_db, "zones"); diff --git a/src/map/mob.c b/src/map/mob.c index 86f3ddc0d..fc6e23427 100644 --- a/src/map/mob.c +++ b/src/map/mob.c @@ -4431,7 +4431,10 @@ int mob_read_libconfig(const char *filename, bool ignore_missing) if (ignore_missing && !exists(filepath)) return 0; - if (libconfig->read_file(&mob_db_conf, filepath) || !(mdb = libconfig->setting_get_member(mob_db_conf.root, "mob_db"))) { + if (!libconfig->load_file(&mob_db_conf, filepath)) + return 0; + + if ((mdb = libconfig->setting_get_member(mob_db_conf.root, "mob_db")) == NULL) { ShowError("can't read %s\n", filepath); return 0; } diff --git a/src/map/pc.c b/src/map/pc.c index 8d1df71a9..8fe1b7c57 100644 --- a/src/map/pc.c +++ b/src/map/pc.c @@ -10651,10 +10651,8 @@ void pc_read_skill_tree(void) bool loaded[CLASS_COUNT] = { false }; safesnprintf(config_filename, sizeof(config_filename), "%s/"DBPATH"skill_tree.conf", map->db_path); - if (libconfig->read_file(&skill_tree_conf, config_filename)) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&skill_tree_conf, config_filename)) return; - } // Foreach job while ((skt = libconfig->setting_get_elem(skill_tree_conf.root, i++))) { diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c index bd46b9616..5a86030fc 100644 --- a/src/map/pc_groups.c +++ b/src/map/pc_groups.c @@ -68,7 +68,7 @@ static void read_config(void) { const char *config_filename = "conf/groups.conf"; // FIXME hardcoded name int group_count = 0; - if (libconfig->read_file(&pc_group_config, config_filename)) + if (!libconfig->load_file(&pc_group_config, config_filename)) return; groups = libconfig->lookup(&pc_group_config, "groups"); diff --git a/src/map/quest.c b/src/map/quest.c index 0dbea56f8..9af7c8ea2 100644 --- a/src/map/quest.c +++ b/src/map/quest.c @@ -533,7 +533,10 @@ int quest_read_db(void) const char *filename = "quest_db.conf"; sprintf(filepath, "%s/%s", map->db_path, filename); - if (libconfig->read_file(&quest_db_conf, filepath) || !(qdb = libconfig->setting_get_member(quest_db_conf.root, "quest_db"))) { + if (!libconfig->load_file(&quest_db_conf, filepath)) + return -1; + + if ((qdb = libconfig->setting_get_member(quest_db_conf.root, "quest_db")) == NULL) { ShowError("can't read %s\n", filepath); return -1; } diff --git a/src/map/script.c b/src/map/script.c index f3c839555..eb8879a2a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2297,7 +2297,10 @@ void read_constdb(void) sprintf(filepath, "%s/constants.conf", map->db_path); - if (libconfig->read_file(&constants_conf, filepath) || !(cdb = libconfig->setting_get_member(constants_conf.root, "constants_db"))) { + if (!libconfig->load_file(&constants_conf, filepath)) + return; + + if ((cdb = libconfig->setting_get_member(constants_conf.root, "constants_db")) == NULL) { ShowError("can't read %s\n", filepath); return; } @@ -4822,12 +4825,10 @@ void script_load_translations(void) { script->add_language("English");/* 0 is default, which is whatever is in the npc files hardcoded (in our case, English) */ - if (libconfig->read_file(&translations_conf, config_filename)) { - ShowError("load_translations: can't read '%s'\n", config_filename); + if (!libconfig->load_file(&translations_conf, config_filename)) return; - } - if( !(translations = libconfig->lookup(&translations_conf, "translations")) ) { + if ((translations = libconfig->lookup(&translations_conf, "translations")) == NULL) { ShowError("load_translations: invalid format on '%s'\n",config_filename); return; } diff --git a/src/map/status.c b/src/map/status.c index 26db1750b..32f7bc2d8 100644 --- a/src/map/status.c +++ b/src/map/status.c @@ -12770,10 +12770,9 @@ void status_read_job_db(void) { /* [malufett/Hercules] */ const char *config_filename = "db/pre-re/job_db.conf"; #endif - if ( libconfig->read_file(&job_db_conf, config_filename) ) { - ShowError("can't read %s\n", config_filename); + if (!libconfig->load_file(&job_db_conf, config_filename)) return; - } + while ( (jdb = libconfig->setting_get_elem(job_db_conf.root, i++)) ) { int class_, idx; const char *name = config_setting_name(jdb); @@ -12932,11 +12931,10 @@ int status_readdb_refine_libconfig(const char *filename) { int i = 0, count = 0,type = 0; sprintf(filepath, "%s/%s", map->db_path, filename); - memset(&duplicate,0,sizeof(duplicate)); - if( libconfig->read_file(&refine_db_conf, filepath) ) { - ShowError("can't read %s\n", filepath); + if (!libconfig->load_file(&refine_db_conf, filepath)) return 0; - } + + memset(&duplicate,0,sizeof(duplicate)); while((r = libconfig->setting_get_elem(refine_db_conf.root,i++))) { char *name = config_setting_name(r); diff --git a/src/test/test_libconfig.c b/src/test/test_libconfig.c index 3fcc9692f..e5e6b4d70 100644 --- a/src/test/test_libconfig.c +++ b/src/test/test_libconfig.c @@ -122,11 +122,11 @@ static const char *test_libconfig_read(void) return NULL; } -static const char *test_libconfig_read_file(void) +static const char *test_libconfig_load_file(void) { config_t config; #define FILENAME "src/test/libconfig/test.conf" - if (libconfig->read_file(&config, FILENAME) != 0) { + if (libconfig->load_file(&config, FILENAME) == CONFIG_FALSE) { return "Unable to read file '" FILENAME "'."; } #undef FILENAME @@ -809,7 +809,7 @@ int do_init(int argc, char **argv) TEST("libconfig->init and libconfig->destroy", test_libconfig_init_destroy); TEST("libconfig->read_file_src", test_libconfig_read_file_src); TEST("libconfig->read", test_libconfig_read); - TEST("libconfig->read_file", test_libconfig_read_file); + TEST("libconfig->load_file", test_libconfig_load_file); (void)test_libconfig_write; //TEST("libconfig->write", test_libconfig_write); (void)test_libconfig_write_file; //TEST("libconfig->write_file", test_libconfig_write_file); TEST("libconfig->read_string", test_libconfig_read_string); |