diff --git a/src/common/conf.h b/src/common/conf.h index 666853b..d223505 100644 --- a/src/common/conf.h +++ b/src/common/conf.h @@ -5,7 +5,7 @@ #define _CONF_H_ #include "../common/cbasetypes.h" -#include "libconfig.h" +#include "../../3rdparty/libconfig/libconfig.h" int conf_read_file(config_t *config, const char *config_filename); int config_setting_copy(config_setting_t *parent, const config_setting_t *src); diff --git a/src/common/utils.c b/src/common/utils.c index d799285..6986d9a 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -321,3 +321,15 @@ unsigned int get_percentage(const unsigned int A, const unsigned int B) return (unsigned int)floor(result); } + +///comparator for qsort +//comparing int +int compare_int(const void *a,const void *b) { + int *x = (int *) a; + int *y = (int *) b; + return *x - *y; +} +//comparing string +int compare_str(const void *a,const void *b) { + return (strcmp((char *)a,(char *)b)); +} diff --git a/src/common/utils.h b/src/common/utils.h index 6ce1639..b98452d 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -30,5 +30,7 @@ extern uint16 MakeWord(uint8 byte0, uint8 byte1); extern uint32 MakeDWord(uint16 word0, uint16 word1); int date2version(int date); +int compare_int(const void *a,const void *b); +int compare_str(const void *a,const void *b); #endif /* _UTILS_H_ */ diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 80bc5d0..fcfd94b 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -8486,6 +8486,11 @@ static int atcommand_mutearea_sub(struct block_list *bl,va_list ap) return 0; } +//comparing atcommand +int compare_atc(const void *a,const void *b) { + return compare_str(((struct AtCommandInfo*)a)->command,((struct AtCommandInfo*)b)->command); +} + /*========================================== * type: 1 = commands (@), 2 = charcommands (#) *------------------------------------------*/ @@ -8493,18 +8498,18 @@ 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; + AtCommandInfo *cmd, **commands_li; DBIterator *iter = db_iterator(atcommand_db); - int count = 0; + int count = 0, i=0; + CREATE(commands_li, AtCommandInfo *, db_size(atcommand_db)); + memset(line_buff,' ',CHATBOX_SIZE); line_buff[CHATBOX_SIZE-1] = 0; clif_displaymessage(fd, msg_txt(sd,273)); // "Commands available:" for (cmd = dbi_first(iter); dbi_exists(iter); cmd = dbi_next(iter)) { - unsigned int slen = 0; - switch( type ) { case COMMAND_CHARCOMMAND: if( cmd->char_groups[sd->group_pos] == 0 ) @@ -8517,9 +8522,14 @@ static void atcommand_commands_sub(struct map_session_data* sd, const int fd, At default: continue; } - - - slen = strlen(cmd->command); + strcpy(commands_li[count]->command,cmd->command); + count++; + } + dbi_destroy(iter); + + qsort(commands_li,count,sizeof(struct AtCommandInfo),compare_atc); + for(i=0; icommand); // flush the text buffer if this command won't fit into it if (slen + cur - line_buff >= CHATBOX_SIZE) { @@ -8528,13 +8538,10 @@ static void atcommand_commands_sub(struct map_session_data* sd, const int fd, At memset(line_buff,' ',CHATBOX_SIZE); line_buff[CHATBOX_SIZE-1] = 0; } - - memcpy(cur,cmd->command,slen); + memcpy(cur,commands_li[i]->command,slen); cur += slen+(10-slen%10); - - count++; } - dbi_destroy(iter); + aFree(commands_li); clif_displaymessage(fd,line_buff); sprintf(atcmd_output, msg_txt(sd,274), count); // "%d commands found." @@ -9307,7 +9314,7 @@ void atcommand_basecommands(void) { ACMD_DEF(langtype), }; AtCommandInfo* atcommand; - int i; + int i = 0; for( i = 0; i < ARRAYLENGTH(atcommand_base); i++ ) { if(atcommand_exists(atcommand_base[i].command)) { // Should not happen if atcommand_base[] array is OK