summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-03-09 14:31:15 +0000
committergepard1984 <gepard1984@54d463be-8e91-2dee-dedb-b68131a5f0ec>2012-03-09 14:31:15 +0000
commit33369a948f2d6ba2059f81816ea7b16e486090ba (patch)
treeb08a112ecbacf193f3a98c2bcc05a01fddef5feb
parent440542802577e5f3f67081803873bc87642a3f48 (diff)
downloadhercules-33369a948f2d6ba2059f81816ea7b16e486090ba.tar.gz
hercules-33369a948f2d6ba2059f81816ea7b16e486090ba.tar.bz2
hercules-33369a948f2d6ba2059f81816ea7b16e486090ba.tar.xz
hercules-33369a948f2d6ba2059f81816ea7b16e486090ba.zip
Code cleanup: replaced `DBIterator` function calls with macros where possible.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@15668 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--src/char/int_auction.c16
-rw-r--r--src/char/int_guild.c5
-rw-r--r--src/map/atcommand.c10
-rw-r--r--src/map/guild.c12
-rw-r--r--src/map/map.c9
-rw-r--r--src/map/mapreg_sql.c8
-rw-r--r--src/map/npc.c4
-rw-r--r--src/map/party.c18
-rw-r--r--src/map/pc_groups.c22
9 files changed, 46 insertions, 58 deletions
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index 04e321062..4fc9215a0 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -27,16 +27,14 @@ static int auction_count(int char_id, bool buy)
{
int i = 0;
struct auction_data *auction;
- DBIterator* iter;
- DBKey key;
+ DBIterator *iter = db_iterator(auction_db_);
- iter = auction_db_->iterator(auction_db_);
- for( auction = (struct auction_data*)iter->first(iter,&key); iter->exists(iter); auction = (struct auction_data*)iter->next(iter,&key) )
+ for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
{
if( (buy && auction->buyer_id == char_id) || (!buy && auction->seller_id == char_id) )
i++;
}
- iter->destroy(iter);
+ dbi_destroy(iter);
return i;
}
@@ -258,15 +256,13 @@ static void mapif_parse_Auction_requestlist(int fd)
int price = RFIFOL(fd,10);
short type = RFIFOW(fd,8), page = max(1,RFIFOW(fd,14));
unsigned char buf[5 * sizeof(struct auction_data)];
- DBIterator* iter;
- DBKey key;
+ DBIterator *iter = db_iterator(auction_db_);
struct auction_data *auction;
short i = 0, j = 0, pages = 1;
memcpy(searchtext, RFIFOP(fd,16), NAME_LENGTH);
- iter = auction_db_->iterator(auction_db_);
- for( auction = (struct auction_data*)iter->first(iter,&key); iter->exists(iter); auction = (struct auction_data*)iter->next(iter,&key) )
+ for( auction = dbi_first(iter); dbi_exists(iter); auction = dbi_next(iter) )
{
if( (type == 0 && auction->type != IT_ARMOR && auction->type != IT_PETARMOR) ||
(type == 1 && auction->type != IT_WEAPON) ||
@@ -291,7 +287,7 @@ static void mapif_parse_Auction_requestlist(int fd)
memcpy(WBUFP(buf, j * len), auction, len);
j++; // Found Results
}
- iter->destroy(iter);
+ dbi_destroy(iter);
mapif_Auction_sendlist(fd, char_id, j, pages, buf);
}
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index d0f41b541..d2e74ee1d 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -49,14 +49,13 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data)
{
static int last_id = 0; //To know in which guild we were.
int state = 0; //0: Have not reached last guild. 1: Reached last guild, ready for save. 2: Some guild saved, don't do further saving.
- DBIterator* iter;
+ DBIterator *iter = db_iterator(guild_db_);
DBKey key;
struct guild* g;
if( last_id == 0 ) //Save the first guild in the list.
state = 1;
- iter = guild_db_->iterator(guild_db_);
for( g = (struct guild*)iter->first(iter,&key); iter->exists(iter); g = (struct guild*)iter->next(iter,&key) )
{
if( state == 0 && g->guild_id == last_id )
@@ -79,7 +78,7 @@ static int guild_save_timer(int tid, unsigned int tick, int id, intptr_t data)
db_remove(guild_db_, key);
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
if( state != 2 ) //Reached the end of the guild db without saving.
last_id = 0; //Reset guild saved, return to beginning.
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index bf7e7d66e..7bab524e7 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1608,13 +1608,13 @@ ACMD_FUNC(help)
StringBuf_AppendStr(&buf, "Available aliases:");
command_info = get_atcommandinfo_byname(command_name);
iter = db_iterator(atcommand_alias_db);
- for (alias_info = (AliasInfo*)dbi_first(iter); dbi_exists(iter); alias_info = (AliasInfo*)dbi_next(iter)) {
+ for (alias_info = dbi_first(iter); dbi_exists(iter); alias_info = dbi_next(iter)) {
if (alias_info->command == command_info) {
StringBuf_Printf(&buf, " %s", alias_info->alias);
has_aliases = true;
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
if (has_aliases)
clif_displaymessage(fd, StringBuf_Value(&buf));
StringBuf_Destroy(&buf);
@@ -8268,7 +8268,7 @@ static void atcommand_commands_sub(struct map_session_data* sd, const int fd, At
char line_buff[CHATBOX_SIZE];
char* cur = line_buff;
AtCommandInfo* cmd;
- DBIterator* iter = atcommand_db->iterator(atcommand_db);
+ DBIterator *iter = db_iterator(atcommand_db);
int count = 0;
memset(line_buff,' ',CHATBOX_SIZE);
@@ -8276,7 +8276,7 @@ static void atcommand_commands_sub(struct map_session_data* sd, const int fd, At
clif_displaymessage(fd, msg_txt(273)); // "Commands available:"
- for (cmd = (AtCommandInfo*)iter->first(iter, NULL); iter->exists(iter); cmd = (AtCommandInfo*)iter->next(iter, NULL)) {
+ for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) {
unsigned int slen = 0;
if (!pc_can_use_command(sd, cmd->command, type))
@@ -8298,7 +8298,7 @@ static void atcommand_commands_sub(struct map_session_data* sd, const int fd, At
count++;
}
- iter->destroy(iter);
+ dbi_destroy(iter);
clif_displaymessage(fd,line_buff);
sprintf(atcmd_output, msg_txt(274), count); // "%d commands found."
diff --git a/src/map/guild.c b/src/map/guild.c
index 70f5361bb..deb603473 100644
--- a/src/map/guild.c
+++ b/src/map/guild.c
@@ -187,14 +187,14 @@ struct guild* guild_search(int guild_id)
struct guild* guild_searchname(char* str)
{
struct guild* g;
+ DBIterator *iter = db_iterator(guild_db);
- DBIterator* iter = guild_db->iterator(guild_db);
- for( g = (struct guild*)iter->first(iter,NULL); iter->exists(iter); g = (struct guild*)iter->next(iter,NULL) )
+ for( g = dbi_first(iter); dbi_exists(iter); g = dbi_next(iter) )
{
if( strcmpi(g->name, str) == 0 )
break;
}
- iter->destroy(iter);
+ dbi_destroy(iter);
return g;
}
@@ -209,14 +209,14 @@ struct guild_castle* guild_castle_search(int gcid)
struct guild_castle* guild_mapindex2gc(short mapindex)
{
struct guild_castle* gc;
+ DBIterator *iter = db_iterator(castle_db);
- DBIterator* iter = castle_db->iterator(castle_db);
- for( gc = (struct guild_castle*)iter->first(iter,NULL); iter->exists(iter); gc = (struct guild_castle*)iter->next(iter,NULL) )
+ for( gc = dbi_first(iter); dbi_exists(iter); gc = dbi_next(iter) )
{
if( gc->mapindex == mapindex )
break;
}
- iter->destroy(iter);
+ dbi_destroy(iter);
return gc;
}
diff --git a/src/map/map.c b/src/map/map.c
index eab54353a..73a9445ef 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1876,7 +1876,7 @@ void map_foreachpc(int (*func)(struct map_session_data* sd, va_list args), ...)
struct map_session_data* sd;
iter = db_iterator(pc_db);
- for( sd = (struct map_session_data*)iter->first(iter,NULL); iter->exists(iter); sd = (struct map_session_data*)iter->next(iter,NULL) )
+ for( sd = dbi_first(iter); dbi_exists(iter); sd = dbi_next(iter) )
{
va_list args;
int ret;
@@ -2619,15 +2619,14 @@ void map_iwall_get(struct map_session_data *sd)
{
struct iwall_data *iwall;
DBIterator* iter;
- DBKey key;
int x1, y1;
int i;
if( map[sd->bl.m].iwall_num < 1 )
return;
- iter = iwall_db->iterator(iwall_db);
- for( iwall = (struct iwall_data *)iter->first(iter,&key); iter->exists(iter); iwall = (struct iwall_data *)iter->next(iter,&key) )
+ iter = db_iterator(iwall_db);
+ for( iwall = dbi_first(iter); dbi_exists(iter); iwall = dbi_next(iter) )
{
if( iwall->m != sd->bl.m )
continue;
@@ -2638,7 +2637,7 @@ void map_iwall_get(struct map_session_data *sd)
clif_changemapcell(sd->fd, iwall->m, x1, y1, map_getcell(iwall->m, x1, y1, CELL_GETTYPE), SELF);
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
}
void map_iwall_remove(const char *wall_name)
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index 455da0f49..365fdc8ce 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -149,7 +149,7 @@ static void script_save_mapreg(void)
void* data;
DBKey key;
- iter = mapreg_db->iterator(mapreg_db);
+ iter = db_iterator(mapreg_db);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
int num = (key.i & 0x00ffffff);
@@ -162,9 +162,9 @@ static void script_save_mapreg(void)
if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%d' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, (int)data, name, i) )
Sql_ShowDebug(mmysql_handle);
}
- iter->destroy(iter);
+ dbi_destroy(iter);
- iter = mapregstr_db->iterator(mapregstr_db);
+ iter = db_iterator(mapregstr_db);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
int num = (key.i & 0x00ffffff);
@@ -179,7 +179,7 @@ static void script_save_mapreg(void)
if( SQL_ERROR == Sql_Query(mmysql_handle, "UPDATE `%s` SET `value`='%s' WHERE `varname`='%s' AND `index`='%d'", mapreg_table, tmp_str2, name, i) )
Sql_ShowDebug(mmysql_handle);
}
- iter->destroy(iter);
+ dbi_destroy(iter);
mapreg_dirty = false;
}
diff --git a/src/map/npc.c b/src/map/npc.c
index 2301076c2..86d649cde 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -3364,7 +3364,7 @@ void npc_read_event_script(void)
strncpy(name+2,config[i].event_name,62);
script_event[i].event_count = 0;
- iter = ev_db->iterator(ev_db);
+ iter = db_iterator(ev_db);
for( data = iter->first(iter,&key); iter->exists(iter); data = iter->next(iter,&key) )
{
const char* p = key.str;
@@ -3384,7 +3384,7 @@ void npc_read_event_script(void)
script_event[i].event_count++;
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
}
if (battle_config.etc_log) {
diff --git a/src/map/party.c b/src/map/party.c
index 8f8a0cd8a..52be4e807 100644
--- a/src/map/party.c
+++ b/src/map/party.c
@@ -132,13 +132,13 @@ struct party_data* party_searchname(const char* str)
{
struct party_data* p;
- DBIterator* iter = party_db->iterator(party_db);
- for( p = (struct party_data*)iter->first(iter,NULL); iter->exists(iter); p = (struct party_data*)iter->next(iter,NULL) )
+ DBIterator *iter = db_iterator(party_db);
+ for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) )
{
if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 )
break;
}
- iter->destroy(iter);
+ dbi_destroy(iter);
return p;
}
@@ -864,9 +864,9 @@ int party_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data)
{
struct party_data* p;
- DBIterator* iter = party_db->iterator(party_db);
+ DBIterator *iter = db_iterator(party_db);
// for each existing party,
- for( p = (struct party_data*)iter->first(iter,NULL); iter->exists(iter); p = (struct party_data*)iter->next(iter,NULL) )
+ for( p = dbi_first(iter); dbi_exists(iter); p = dbi_next(iter) )
{
int i;
@@ -894,7 +894,7 @@ int party_send_xy_timer(int tid, unsigned int tick, int id, intptr_t data)
}
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
return 0;
}
@@ -1217,11 +1217,11 @@ void party_booking_search(struct map_session_data *sd, short level, short mapid,
int i, count=0;
struct party_booking_ad_info* result_list[PARTY_BOOKING_RESULTS];
bool more_result = false;
- DBIterator* iter = party_booking_db->iterator(party_booking_db);
+ DBIterator* iter = db_iterator(party_booking_db);
memset(result_list, 0, sizeof(result_list));
- for( pb_ad = (struct party_booking_ad_info*)iter->first(iter,NULL); iter->exists(iter); pb_ad = (struct party_booking_ad_info*)iter->next(iter,NULL) )
+ for( pb_ad = dbi_first(iter); dbi_exists(iter); pb_ad = dbi_next(iter) )
{
if (pb_ad->index < lastindex || (level && (pb_ad->p_detail.level < level-15 || pb_ad->p_detail.level > level)))
continue;
@@ -1244,7 +1244,7 @@ void party_booking_search(struct map_session_data *sd, short level, short mapid,
count++;
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
clif_PartyBookingSearchAck(sd->fd, result_list, count, more_result);
}
diff --git a/src/map/pc_groups.c b/src/map/pc_groups.c
index 379968c79..74215eab9 100644
--- a/src/map/pc_groups.c
+++ b/src/map/pc_groups.c
@@ -161,10 +161,8 @@ static void read_config(void)
group_count = config_setting_length(groups); // Save number of groups
// Check if all commands and permissions exist
- iter = pc_group_db->iterator(pc_group_db);
- for (group_settings = (GroupSettings*)iter->first(iter, NULL);
- iter->exists(iter);
- group_settings = (GroupSettings*)iter->next(iter, NULL)) {
+ iter = db_iterator(pc_group_db);
+ for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
config_setting_t *commands = group_settings->commands, *permissions = group_settings->permissions;
int count = 0, i;
@@ -203,15 +201,13 @@ static void read_config(void)
}
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
// Apply inheritance
i = 0; // counter for processed groups
while (i < group_count) {
- iter = pc_group_db->iterator(pc_group_db);
- for (group_settings = (GroupSettings*)iter->first(iter, NULL);
- iter->exists(iter);
- group_settings = (GroupSettings*)iter->next(iter, NULL)) {
+ iter = db_iterator(pc_group_db);
+ for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
config_setting_t *inherit = NULL,
*commands = group_settings->commands,
*permissions = group_settings->permissions;
@@ -265,7 +261,7 @@ static void read_config(void)
group_settings->inheritance_done = true; // we're done with this group
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
if (++loop > group_count) {
ShowWarning("pc_groups:read_config: Could not process inheritance rules, check your config '%s' for cycles...\n",
@@ -276,9 +272,7 @@ static void read_config(void)
// Pack permissions into GroupSettings.e_permissions for faster checking
iter = db_iterator(pc_group_db);
- for (group_settings = (GroupSettings*)dbi_first(iter);
- dbi_exists(iter);
- group_settings = (GroupSettings*)dbi_next(iter)) {
+ for (group_settings = dbi_first(iter); dbi_exists(iter); group_settings = dbi_next(iter)) {
config_setting_t *permissions = group_settings->permissions;
int i, count = config_setting_length(permissions);
@@ -294,7 +288,7 @@ static void read_config(void)
group_settings->e_permissions |= permission_name[j].permission;
}
}
- iter->destroy(iter);
+ dbi_destroy(iter);
}
ShowStatus("Done reading '"CL_WHITE"%d"CL_RESET"' groups in '"CL_WHITE"%s"CL_RESET"'.\n", group_count, config_filename);