diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/cbasetypes.h | 3 | ||||
-rw-r--r-- | src/common/db.c | 70 | ||||
-rw-r--r-- | src/common/db.h | 25 | ||||
-rw-r--r-- | src/common/ers.c | 2 | ||||
-rw-r--r-- | src/common/ers.h | 2 | ||||
-rw-r--r-- | src/common/malloc.h | 2 | ||||
-rw-r--r-- | src/common/utils.c | 77 | ||||
-rw-r--r-- | src/common/utils.h | 6 | ||||
-rw-r--r-- | src/map/npc.c | 28 |
9 files changed, 100 insertions, 115 deletions
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index e8af6bc9c..67c5a45db 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -157,7 +157,8 @@ typedef unsigned long int ppuint32; // integer with exact processor width (and best speed) // size_t already defined in stdio.h ////////////////////////////// -// +#include <string.h>// size_t + #if defined(WIN32) && !defined(MINGW) // does not have a signed size_t ////////////////////////////// #if defined(_WIN64) // naive 64bit windows platform diff --git a/src/common/db.c b/src/common/db.c index f25afb5c3..98d7ae032 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -75,10 +75,6 @@ #include "../common/showmsg.h" #include "../common/ers.h" -//TODO: get rid of this -#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c)) -#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c)) - /*****************************************************************************\ * (1) Private typedefs, enums, structures, defines and global variables of * * the database system. * @@ -642,7 +638,7 @@ static void db_dup_key_free(DB_impl db, DBKey key) switch (db->type) { case DB_STRING: case DB_ISTRING: - aFree(key.str); + aFree((char*)key.str); return; default: @@ -962,7 +958,7 @@ static unsigned int db_uint_hash(DBKey key, unsigned short maxlen) */ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) { - unsigned char *k = key.str; + const char *k = key.str; unsigned int hash = 0; unsigned short i; @@ -972,8 +968,9 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) if (maxlen == 0) maxlen = UINT16_MAX; - for (i = 0; *k; i++) { - hash = (hash*33 + *k++)^(hash>>24); + for (i = 0; *k; ++i) { + hash = (hash*33 + ((unsigned char)*k))^(hash>>24); + k++; if (i == maxlen) break; } @@ -992,7 +989,7 @@ static unsigned int db_string_hash(DBKey key, unsigned short maxlen) */ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen) { - unsigned char *k = key.str; + const char *k = key.str; unsigned int hash = 0; unsigned short i; @@ -1003,7 +1000,7 @@ static unsigned int db_istring_hash(DBKey key, unsigned short maxlen) maxlen = UINT16_MAX; for (i = 0; *k; i++) { - hash = (hash*33 + LOWER(*k))^(hash>>24); + hash = (hash*33 + ((unsigned char)TOLOWER(*k)))^(hash>>24); k++; if (i == maxlen) break; @@ -1044,7 +1041,7 @@ static void db_release_key(DBKey key, void *data, DBRelease which) #ifdef DB_ENABLE_STATS COUNT(db_release_key); #endif /* DB_ENABLE_STATS */ - if (which&DB_RELEASE_KEY) aFree(key.str); // needs to be a pointer + if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer } /** @@ -1083,7 +1080,7 @@ static void db_release_both(DBKey key, void *data, DBRelease which) #ifdef DB_ENABLE_STATS COUNT(db_release_both); #endif /* DB_ENABLE_STATS */ - if (which&DB_RELEASE_KEY) aFree(key.str); // needs to be a pointer + if (which&DB_RELEASE_KEY) aFree((char*)key.str); // needs to be a pointer if (which&DB_RELEASE_DATA) aFree(data); } @@ -1893,19 +1890,18 @@ static DBOptions db_obj_options(DB self) } /*****************************************************************************\ - * (5) Section with public functions. * - * db_fix_options - Apply database type restrictions to the options. * - * db_default_cmp - Get the default comparator for a type of database. * - * db_default_hash - Get the default hasher for a type of database. * - * db_default_release - Get the default releaser for a type of database * - * with the specified options. * - * db_custom_release - Get a releaser that behaves a certains way. * - * db_alloc - Allocate a new database. * - * db_i2key - Manual cast from 'int' to 'DBKey'. * - * db_ui2key - Manual cast from 'unsigned int' to 'DBKey'. * - * db_str2key - Manual cast from 'unsigned char *' to 'DBKey'. * - * db_init - Initialize the database system. * - * db_final - Finalize the database system. * + * (5) Section with public functions. + * db_fix_options - Apply database type restrictions to the options. + * db_default_cmp - Get the default comparator for a type of database. + * db_default_hash - Get the default hasher for a type of database. + * db_default_release - Get the default releaser for a type of database with the specified options. + * db_custom_release - Get a releaser that behaves a certains way. + * db_alloc - Allocate a new database. + * db_i2key - Manual cast from 'int' to 'DBKey'. + * db_ui2key - Manual cast from 'unsigned int' to 'DBKey'. + * db_str2key - Manual cast from 'unsigned char *' to 'DBKey'. + * db_init - Initializes the database system. + * db_final - Finalizes the database system. \*****************************************************************************/ /** @@ -2137,8 +2133,6 @@ DB db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned * @return The key as a DBKey union * @public * @see #DB_MANUAL_CAST_TO_UNION - * @see #db_ui2key(unsigned int) - * @see #db_str2key(unsigned char *) */ DBKey db_i2key(int key) { @@ -2157,10 +2151,7 @@ DBKey db_i2key(int key) * @param key Key to be casted * @return The key as a DBKey union * @public - * @see common\db.h#DB_MANUAL_CAST_TO_UNION - * @see #db_i2key(int) - * @see #db_str2key(unsigned char *) - * @see common\db.h#db_ui2key(unsigned int) + * @see #DB_MANUAL_CAST_TO_UNION */ DBKey db_ui2key(unsigned int key) { @@ -2174,17 +2165,14 @@ DBKey db_ui2key(unsigned int key) } /** - * Manual cast from 'unsigned char *' to the union DBKey. + * Manual cast from 'const char *' to the union DBKey. * Created for compilers that don't support casting to unions. * @param key Key to be casted * @return The key as a DBKey union * @public - * @see common\db.h#DB_MANUAL_CAST_TO_UNION - * @see #db_i2key(int) - * @see #db_ui2key(unsigned int) - * @see common\db.h#db_str2key(unsigned char *) + * @see #DB_MANUAL_CAST_TO_UNION */ -DBKey db_str2key(unsigned char *key) +DBKey db_str2key(const char *key) { DBKey ret; @@ -2197,10 +2185,9 @@ DBKey db_str2key(unsigned char *key) #endif /* DB_MANUAL_CAST_TO_UNION */ /** - * Initialize the database system. + * Initializes the database system. * @public * @see #db_final(void) - * @see common\db.h#db_init(void) */ void db_init(void) { @@ -2210,12 +2197,9 @@ void db_init(void) } /** - * Finalize the database system. - * Frees the memory used by the block reusage system. + * Finalizes the database system. * @public - * @see common\db.h#DB_FINAL_NODE_CHECK * @see #db_init(void) - * @see common\db.h#db_final(void) */ void db_final(void) { diff --git a/src/common/db.h b/src/common/db.h index 0c19b5fc2..992469f66 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -78,7 +78,7 @@ * @see #DBReleaser * @see #db_custom_release(DBRelease) */ -typedef enum { +typedef enum DBRelease { DB_RELEASE_NOTHING = 0, DB_RELEASE_KEY = 1, DB_RELEASE_DATA = 2, @@ -102,7 +102,7 @@ typedef enum { * @see #db_default_release(DBType,DBOptions) * @see #db_alloc(const char *,int,DBType,DBOptions,unsigned short) */ -typedef enum { +typedef enum DBType { DB_INT, DB_UINT, DB_STRING, @@ -154,7 +154,7 @@ typedef enum db_opt { typedef union dbkey { int i; unsigned int ui; - unsigned char *str;//## TODO change to 'const char *' + const char *str; } DBKey; /** @@ -272,7 +272,7 @@ struct dbt { * @protected * @see #db_get(DB,DBKey) */ - void *(*get)(struct dbt *dbi, DBKey key); + void *(*get)(DB self, DBKey key); /** * Just calls {@link DB#vgetall(DB,void **,unsigned int,DBMatch,va_list)}. @@ -498,8 +498,8 @@ struct dbt { #else /* not DB_MANUAL_CAST_TO_UNION */ # define i2key(k) ((DBKey)(int)(k)) # define ui2key(k) ((DBKey)(unsigned int)(k)) -# define str2key(k) ((DBKey)(unsigned char *)(k)) -#endif /* DB_MANUAL_CAST_TO_UNION / not DB_MANUAL_CAST_TO_UNION */ +# define str2key(k) ((DBKey)(const char *)(k)) +#endif /* not DB_MANUAL_CAST_TO_UNION */ #define db_get(db,k) (db)->get((db),(k)) #define idb_get(db,k) (db)->get((db),i2key(k)) @@ -638,9 +638,6 @@ DB db_alloc(const char *file, int line, DBType type, DBOptions options, unsigned * @return The key as a DBKey union * @public * @see #DB_MANUAL_CAST_TO_UNION - * @see #db_ui2key(unsigned int) - * @see #db_str2key(unsigned char *) - * @see common\db.c#db_i2key(int) */ DBKey db_i2key(int key); @@ -651,9 +648,6 @@ DBKey db_i2key(int key); * @return The key as a DBKey union * @public * @see #DB_MANUAL_CAST_TO_UNION - * @see #db_i2key(int) - * @see #db_str2key(unsigned char *) - * @see common\db.c#db_ui2key(unsigned int) */ DBKey db_ui2key(unsigned int key); @@ -664,18 +658,14 @@ DBKey db_ui2key(unsigned int key); * @return The key as a DBKey union * @public * @see #DB_MANUAL_CAST_TO_UNION - * @see #db_i2key(int) - * @see #db_ui2key(unsigned int) - * @see common\db.c#db_str2key(unsigned char *) */ -DBKey db_str2key(unsigned char *key); +DBKey db_str2key(const char *key); #endif /* DB_MANUAL_CAST_TO_UNION */ /** * Initialize the database system. * @public * @see #db_final(void) - * @see common\db.c#db_init(void) */ void db_init(void); @@ -684,7 +674,6 @@ void db_init(void); * Frees the memory used by the block reusage system. * @public * @see #db_init(void) - * @see common\db.c#db_final(void) */ void db_final(void); diff --git a/src/common/ers.c b/src/common/ers.c index 485bab7d9..109378d5f 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -349,7 +349,7 @@ static void ers_obj_destroy(ERS self) * @see #ers_root * @see #ers_num */ -ERS ers_new(size_t size) +ERS ers_new(uint32 size) { ERS_impl obj; uint32 i; diff --git a/src/common/ers.h b/src/common/ers.h index e07ec7137..51b12d8a2 100644 --- a/src/common/ers.h +++ b/src/common/ers.h @@ -142,7 +142,7 @@ typedef struct eri { * @param The requested size of the entry in bytes * @return Interface of the object */ -ERS ers_new(size_t size); +ERS ers_new(uint32 size); /** * Print a report about the current state of the Entry Reusage System. diff --git a/src/common/malloc.h b/src/common/malloc.h index 5411d670d..43eff40f1 100644 --- a/src/common/malloc.h +++ b/src/common/malloc.h @@ -4,6 +4,8 @@ #ifndef _MALLOC_H_ #define _MALLOC_H_ +#include "../common/cbasetypes.h" + // Q: What are the 'a'-variant allocation functions? // A: They allocate memory from the stack, which is automatically // freed when the invoking function returns. diff --git a/src/common/utils.c b/src/common/utils.c index 2f5cf8705..d6a017c95 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -1,6 +1,12 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder +#include "../common/cbasetypes.h" +#include "../common/mmo.h" +#include "../common/malloc.h" +#include "../common/showmsg.h" +#include "utils.h" + #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -14,42 +20,41 @@ #include <sys/stat.h> #endif -#include "utils.h" -#include "../common/mmo.h" -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "../common/cbasetypes.h" - -void dump(unsigned char* buffer, int num) +#ifdef UTIL_DUMP +void dump(const unsigned char* buffer, int num) { - int icnt, jcnt; - - printf(" Hex ASCII\n"); - printf(" ----------------------------------------------- ----------------"); - - for (icnt = 0; icnt < num; icnt += 16) { - printf("\n%p ", &buffer[icnt]); - for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) { - if (jcnt < num) { - printf("%02hX ", buffer[jcnt]); - } else - printf(" "); - } - - printf(" | "); - - for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) { - if (jcnt < num) { - if (buffer[jcnt] > 31 && buffer[jcnt] < 127) - printf("%c", buffer[jcnt]); - else - printf("."); - } else - printf(" "); - } - } - printf("\n"); + int icnt, jcnt; + + printf(" Hex ASCII\n"); + printf(" ----------------------------------------------- ----------------"); + + for (icnt = 0; icnt < num; icnt += 16) + { + printf("\n%p ", &buffer[icnt]); + for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) + { + if (jcnt < num) + printf("%02hX ", buffer[jcnt]); + else + printf(" "); + } + + printf(" | "); + + for (jcnt = icnt; jcnt < icnt + 16; ++jcnt) + { + if (jcnt < num) { + if (buffer[jcnt] > 31 && buffer[jcnt] < 127) + printf("%c", buffer[jcnt]); + else + printf("."); + } else + printf(" "); + } + } + printf("\n"); } +#endif // Allocate a StringBuf [MouseJstr] struct StringBuf * StringBuf_Malloc() @@ -141,7 +146,7 @@ char * StringBuf_Value(struct StringBuf *sbuf) #ifdef WIN32 -char* checkpath(char *path, const char *srcpath) +static char* checkpath(char *path, const char *srcpath) { // just make sure the char*path is not const char *p=path; if(NULL!=path && NULL!=srcpath) @@ -202,7 +207,7 @@ void findfile(const char *p, const char *pat, void (func)(const char*)) #define MAX_DIR_PATH 2048 -char* checkpath(char *path, const char*srcpath) +static char* checkpath(char *path, const char*srcpath) { // just make sure the char*path is not const char *p=path; if(NULL!=path && NULL!=srcpath) diff --git a/src/common/utils.h b/src/common/utils.h index 3fd0aeacc..3ee419c6f 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -6,7 +6,11 @@ #include <stdarg.h> -void dump(unsigned char *buffer, int num); +// Function that dumps the hex of the first num bytes of the buffer to the screen +//#define UTIL_DUMP +#ifdef UTIL_DUMP +void dump(const unsigned char* buffer, int num); +#endif struct StringBuf { char *buf_; diff --git a/src/map/npc.c b/src/map/npc.c index 941eec4c8..bf10e6230 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1,12 +1,6 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <time.h> - #include "../common/cbasetypes.h" #include "../common/timer.h" #include "../common/nullpo.h" @@ -17,7 +11,6 @@ #include "../common/db.h" #include "map.h" #include "log.h" -#include "npc.h" #include "clif.h" #include "intif.h" #include "pc.h" @@ -29,11 +22,18 @@ #include "battle.h" #include "skill.h" #include "unit.h" +#include "npc.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> +#include <time.h> + struct npc_src_list { struct npc_src_list * next; -// struct npc_src_list * prev; //[Shinomori] char name[4]; }; @@ -67,7 +67,7 @@ static struct { //Holds pointers to the commonly executed scripts for speedup. [Skotlex] struct npc_data *nd; struct event_data *event[UCHAR_MAX]; - unsigned char *event_name[UCHAR_MAX]; + const char *event_name[UCHAR_MAX]; unsigned char event_count; } script_event[NPCE_MAX]; @@ -320,7 +320,7 @@ int npc_event_sub(struct map_session_data *, struct event_data *, const unsigned */ int npc_event_doall_sub(DBKey key,void *data,va_list ap) { - unsigned char*p = key.str; + const char*p = key.str; struct event_data *ev; int *c; int rid; @@ -362,7 +362,7 @@ int npc_event_doall_id(const unsigned char *name, int rid) int npc_event_do_sub(DBKey key,void *data,va_list ap) { - unsigned char *p = key.str; + const char *p = key.str; struct event_data *ev; int *c; const unsigned char *name; @@ -511,7 +511,7 @@ int npc_cleareventtimer(struct npc_data *nd) int npc_do_ontimer_sub(DBKey key,void *data,va_list ap) { - unsigned char *p = key.str; + const char *p = key.str; struct event_data *ev = (struct event_data *)data; int *c = va_arg(ap,int *); // struct map_session_data *sd=va_arg(ap,struct map_session_data *); @@ -2900,10 +2900,10 @@ int npc_script_event(TBL_PC* sd, int type) { static int npc_read_event_script_sub(DBKey key,void *data,va_list ap) { - unsigned char *p = key.str; + const char *p = key.str; unsigned char *name = va_arg(ap,unsigned char *); struct event_data **event_buf = va_arg(ap,struct event_data**); - unsigned char **event_name = va_arg(ap,unsigned char **); + const char **event_name = va_arg(ap,const char **); unsigned char *count = va_arg(ap,char *);; if (*count >= UCHAR_MAX) return 0; |