diff options
author | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-12-12 15:24:20 +0000 |
---|---|---|
committer | FlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec> | 2006-12-12 15:24:20 +0000 |
commit | 1427a87a2ad9a4fc947996fff2c7d85d265b67d3 (patch) | |
tree | 1934d74b7c394395db385425ca0391562361812d /src/common | |
parent | 00f7f9b9e2f72595e56af9c40d97fbd73408df54 (diff) | |
download | hercules-1427a87a2ad9a4fc947996fff2c7d85d265b67d3.tar.gz hercules-1427a87a2ad9a4fc947996fff2c7d85d265b67d3.tar.bz2 hercules-1427a87a2ad9a4fc947996fff2c7d85d265b67d3.tar.xz hercules-1427a87a2ad9a4fc947996fff2c7d85d265b67d3.zip |
- Minor changes to ers.
- Removed unused/hardly used cbasetypes typedefs.
- Updated txt-converter's makefile to include utils.o
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@9473 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/cbasetypes.h | 31 | ||||
-rw-r--r-- | src/common/db.c | 4 | ||||
-rw-r--r-- | src/common/db.h | 2 | ||||
-rw-r--r-- | src/common/ers.c | 137 | ||||
-rw-r--r-- | src/common/ers.h | 32 | ||||
-rw-r--r-- | src/common/showmsg.c | 12 |
6 files changed, 68 insertions, 150 deletions
diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index ff00aaa49..f02b8734c 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -54,35 +54,6 @@ ////////////////////////////////////////////////////////////////////////// -// useful typedefs -////////////////////////////////////////////////////////////////////////// -#define HAVE_UCHAR -typedef unsigned char uchar; -typedef signed char schar; -typedef signed short sshort; - -#if !defined(__FREEBSD__) && !defined(_SYS_TYPES_H) - typedef unsigned short ushort; -#endif -typedef signed int sint; // don't use (only for ie. scanf) -#if !defined(__FREEBSD__) && !defined(_SYS_TYPES_H) - typedef unsigned int uint; // don't use -#endif -typedef signed long slong; // don't use (only for ie. file-io) -#ifndef _SYS_TYPES_H - typedef unsigned long ulong; // don't use -#endif - -#ifndef WIN32 -typedef char* pchar; -typedef unsigned char* puchar; -#endif -typedef const char* cchar; -typedef void* ptr; -typedef int* pint; - - -////////////////////////////////////////////////////////////////////////// // typedefs to compensate type size change from 32bit to 64bit // MS implements LLP64 model, normal unix does LP64, // only Silicon Graphics/Cray goes ILP64 so don't care (and don't support) @@ -235,7 +206,7 @@ typedef unsigned long long uint64; ////////////////////////////// // boolean types for C -typedef int bool; +typedef char bool; #define false (1==0) #define true (1==1) diff --git a/src/common/db.c b/src/common/db.c index 28b5721e9..a65e87918 100644 --- a/src/common/db.c +++ b/src/common/db.c @@ -186,7 +186,7 @@ typedef struct db { unsigned int free_max; unsigned int free_lock; // Other - ERInterface nodes; + ERS nodes; DBComparator cmp; DBHasher hash; DBReleaser release; @@ -2165,7 +2165,7 @@ DBInterface db_alloc(const char *file, int line, DBType type, DBOptions options, db->free_max = 0; db->free_lock = 0; /* Other */ - db->nodes = ers_new((uint32)sizeof(struct dbn)); + db->nodes = ers_new(sizeof(struct dbn)); db->cmp = db_default_cmp(type); db->hash = db_default_hash(type); db->release = db_default_release(type, options); diff --git a/src/common/db.h b/src/common/db.h index b17ae27f9..2f02c1bfa 100644 --- a/src/common/db.h +++ b/src/common/db.h @@ -159,7 +159,7 @@ typedef enum { typedef union { int i; unsigned int ui; - unsigned char *str; + unsigned char *str;//## TODO change to 'const char *' } DBKey; /** diff --git a/src/common/ers.c b/src/common/ers.c index 22dd8d87e..485bab7d9 100644 --- a/src/common/ers.c +++ b/src/common/ers.c @@ -50,15 +50,14 @@ * ERS_BLOCK_ENTRIES - Number of entries in each block. * * ERS_ROOT_SIZE - Maximum number of root entry managers. * * ERLinkedList - Structure of a linked list of reusable entries. * - * ERSystem - Class of an entry manager. * + * ERS_impl - Class of an entry manager. * * ers_root - Array of root entry managers. * * ers_num - Number of root entry managers in the array. * \*****************************************************************************/ /** * Number of entries in each block. - * @private - * @see #ers_obj_alloc_entry(ERInterface eri) + * @see #ers_obj_alloc_entry(ERS eri) */ #define ERS_BLOCK_ENTRIES 4096 @@ -74,7 +73,7 @@ * Linked list of reusable entries. * The minimum size of the entries is the size of this structure. * @private - * @see ERSystem#reuse + * @see ERS_impl#reuse */ typedef struct ers_ll { struct ers_ll *next; @@ -92,7 +91,7 @@ typedef struct ers_ll { * @param size Size of the entries of the manager * @private */ -typedef struct ers { +typedef struct ers_impl { /** * Public interface of the entry manager. @@ -101,61 +100,45 @@ typedef struct ers { * @param entry_size Return the size of the entries of this manager * @param destroy Destroy this instance of the manager * @public - * @see #ERSystem - * @see common\ers.h#ERInterface */ - struct eri eri; + struct eri vtable; /** * Linked list of reusable entries. - * @private - * @see #ERSystem */ ERLinkedList reuse; /** * Array with blocks of entries. - * @private - * @see #ERSystem */ uint8 **blocks; /** * Number of unused entries in the last block. - * @private - * @see #ERSystem */ uint32 free; /** * Number of blocks in the array. - * @private - * @see #ERSystem */ uint32 num; /** * Current maximum capacity of the array. - * @private - * @see #ERSystem */ uint32 max; /** * Destroy lock. - * @private - * @see #ERSystem */ uint32 destroy; /** * Size of the entries of the manager. - * @private - * @see #ERSystem */ - uint32 size; + size_t size; -} *ERSystem; +} *ERS_impl; /** * Root array with entry managers. @@ -164,7 +147,7 @@ typedef struct ers { * @see #ERS_ROOT_SIZE * @see #ers_num */ -static ERSystem ers_root[ERS_ROOT_SIZE]; +static ERS_impl ers_root[ERS_ROOT_SIZE]; /** * Number of entry managers in the root array. @@ -176,7 +159,7 @@ static ERSystem ers_root[ERS_ROOT_SIZE]; static uint32 ers_num = 0; /*****************************************************************************\ - * (2) Protected functions. * + * (2) Object functions. * * ers_obj_alloc_entry - Allocate an entry from the manager. * * ers_obj_free_entry - Free an entry allocated from the manager. * * ers_obj_entry_size - Return the size of the entries of the manager. * @@ -188,19 +171,17 @@ static uint32 ers_num = 0; * If there are reusable entries available, it reuses one instead. * @param self Interface of the entry manager * @return An entry - * @protected * @see #ERS_BLOCK_ENTRIES * @see #ERLinkedList - * @see #ERSystem - * @see common\ers.h\ERInterface#alloc(ERInterface) + * @see ERS_impl::vtable#alloc */ -static void *ers_obj_alloc_entry(ERInterface self) +static void *ers_obj_alloc_entry(ERS self) { - ERSystem obj = (ERSystem)self; + ERS_impl obj = (ERS_impl)self; void *ret; if (obj == NULL) { - ShowError("ers_obj_alloc_entry: NULL object, aborting entry allocation.\n"); + ShowError("ers::alloc : NULL object, aborting entry allocation.\n"); return NULL; } @@ -213,11 +194,11 @@ static void *ers_obj_alloc_entry(ERInterface self) } else { // allocate a new block if (obj->num == obj->max) { // expand the block array if (obj->max == UINT32_MAX) { // No more space for blocks - ShowFatalError("ers_obj_alloc_entry: maximum number of blocks reached, increase ERS_BLOCK_ENTRIES.\n" + ShowFatalError("ers::alloc : maximum number of blocks reached, increase ERS_BLOCK_ENTRIES.\n" "exiting the program...\n"); exit(EXIT_FAILURE); } - obj->max = (obj->max<<2) +3; // = obj->max*4 +3; - overflow won't happen + obj->max = (obj->max*4)+3; // left shift bits '11' - overflow won't happen RECREATE(obj->blocks, uint8 *, obj->max); } CREATE(obj->blocks[obj->num], uint8, obj->size*ERS_BLOCK_ENTRIES); @@ -234,22 +215,20 @@ static void *ers_obj_alloc_entry(ERInterface self) * Freeing such an entry can lead to unexpected behaviour. * @param self Interface of the entry manager * @param entry Entry to be freed - * @protected * @see #ERLinkedList - * @see #ERSystem - * @see ERSystem#reuse - * @see common\ers.h\ERInterface#free(ERInterface,void *) + * @see ERS_impl#reuse + * @see ERS_impl::vtable#free */ -static void ers_obj_free_entry(ERInterface self, void *entry) +static void ers_obj_free_entry(ERS self, void *entry) { - ERSystem obj = (ERSystem)self; + ERS_impl obj = (ERS_impl)self; ERLinkedList reuse; if (obj == NULL) { - ShowError("ers_obj_free_entry: NULL object, aborting entry freeing.\n"); + ShowError("ers::free : NULL object, aborting entry freeing.\n"); return; } else if (entry == NULL) { - ShowError("ers_obj_free_entry: NULL entry, nothing to free.\n"); + ShowError("ers::free : NULL entry, nothing to free.\n"); return; } @@ -262,17 +241,15 @@ static void ers_obj_free_entry(ERInterface self, void *entry) * Return the size of the entries allocated from this manager. * @param self Interface of the entry manager * @return Size of the entries of this manager in bytes - * @protected - * @see #ERSystem - * @see ERSystem#size - * @see common\ers.h\ERInterface#enty_size(ERInterface) + * @see ERS_impl#size + * @see ERS_impl::vtable#entry_size */ -static uint32 ers_obj_entry_size(ERInterface self) +static uint32 ers_obj_entry_size(ERS self) { - ERSystem obj = (ERSystem)self; + ERS_impl obj = (ERS_impl)self; if (obj == NULL) { - ShowError("ers_obj_entry_size: NULL object, returning 0.\n"); + ShowError("ers::entry_size : NULL object, returning 0.\n"); return 0; } @@ -285,19 +262,18 @@ static uint32 ers_obj_entry_size(ERInterface self) * When destroying the manager a warning is shown if the manager has * missing/extra entries. * @param self Interface of the entry manager - * @protected * @see #ERLinkedList - * @see #ERSystem - * @see common\ers.h\ERInterface#destroy(ERInterface) + * @see ERS_impl::vtable#destroy */ -static void ers_obj_destroy(ERInterface self) +static void ers_obj_destroy(ERS self) { - ERSystem obj = (ERSystem)self; + ERS_impl obj = (ERS_impl)self; ERLinkedList reuse,old; - uint32 i, count; + uint32 i; + uint32 count; if (obj == NULL) { - ShowError("ers_obj_destroy: NULL object, aborting instance destruction.\n"); + ShowError("ers::destroy: NULL object, aborting instance destruction.\n"); return; } @@ -334,14 +310,14 @@ static void ers_obj_destroy(ERInterface self) } } if (count) { // missing entries - ShowWarning("ers_obj_destroy: %u entries missing (possible double free), continuing destruction (entry size=%u).", + ShowWarning("ers::destroy : %u entries missing (possible double free), continuing destruction (entry size=%u).", count, obj->size); } else if (reuse) { // extra entries while (reuse && count != UINT32_MAX) { count++; reuse = reuse->next; } - ShowWarning("ers_obj_destroy: %u extra entries found, continuing destruction (entry size=%u).", + ShowWarning("ers::destroy : %u extra entries found, continuing destruction (entry size=%u).", count, obj->size); } // destroy the entry manager @@ -369,17 +345,13 @@ static void ers_obj_destroy(ERInterface self) * ERS_ALIGNED that is greater or equal to size is what's actually used. * @param The requested size of the entry in bytes * @return Interface of the object - * @public - * @see #ERSystem + * @see #ERS_impl * @see #ers_root * @see #ers_num - * @see common\ers.h#ERInterface - * @see common\ers.h\ERInterface#destroy(ERInterface) - * @see common\ers.h#ers_new_(uint32) */ -ERInterface ers_new(uint32 size) +ERS ers_new(size_t size) { - ERSystem obj; + ERS_impl obj; uint32 i; if (size == 0) { @@ -398,7 +370,7 @@ ERInterface ers_new(uint32 size) if (obj->size == size) { // found a manager that handles the entry size obj->destroy++; - return &obj->eri; + return &obj->vtable; } } // create a new manager to handle the entry size @@ -407,12 +379,12 @@ ERInterface ers_new(uint32 size) "exiting the program...\n"); exit(EXIT_FAILURE); } - obj = (ERSystem)aMalloc(sizeof(struct ers)); + obj = (ERS_impl)aMalloc(sizeof(struct ers_impl)); // Public interface - obj->eri.alloc = ers_obj_alloc_entry; - obj->eri.free = ers_obj_free_entry; - obj->eri.entry_size = ers_obj_entry_size; - obj->eri.destroy = ers_obj_destroy; + obj->vtable.alloc = ers_obj_alloc_entry; + obj->vtable.free = ers_obj_free_entry; + obj->vtable.entry_size = ers_obj_entry_size; + obj->vtable.destroy = ers_obj_destroy; // Block reusage system obj->reuse = NULL; obj->blocks = NULL; @@ -423,7 +395,7 @@ ERInterface ers_new(uint32 size) // Properties obj->size = size; ers_root[ers_num++] = obj; - return &obj->eri; + return &obj->vtable; } /** @@ -432,18 +404,20 @@ ERInterface ers_new(uint32 size) * The number of entries are checked and a warning is shown if extra reusable * entries are found. * The extra entries are included in the count of reusable entries. - * @public * @see #ERLinkedList - * @see #ERSystem + * @see #ERS_impl * @see #ers_root * @see #ers_num - * @see common\ers.h#ers_report(void) */ void ers_report(void) { - uint32 i, j, used, reusable, extra; + uint32 i; + uint32 j; + uint32 used; + uint32 reusable; + uint32 extra; ERLinkedList reuse; - ERSystem obj; + ERS_impl obj; // Root system report ShowMessage(CL_BOLD"Entry Reusage System report:\n"CL_NORMAL); @@ -506,16 +480,15 @@ void ers_report(void) * The use of this is NOT recommended. * It should only be used in extreme situations to make shure all the memory * allocated by this system is released. - * @public - * @see #ERSystem + * @see #ERS_impl * @see #ers_root * @see #ers_num - * @see common\ers.h#ers_force_destroy_all(void) */ void ers_force_destroy_all(void) { - uint32 i, j; - ERSystem obj; + uint32 i; + uint32 j; + ERS_impl obj; for (i = 0; i < ers_num; i++) { obj = ers_root[i]; diff --git a/src/common/ers.h b/src/common/ers.h index 9b6b4b62d..e07ec7137 100644 --- a/src/common/ers.h +++ b/src/common/ers.h @@ -36,7 +36,6 @@ * @version 0.1 - Initial version * * @author Flavio @ Amazon Project * * @encoding US-ASCII * - * @see common#ers.c * \*****************************************************************************/ #ifndef _ERS_H_ #define _ERS_H_ @@ -47,7 +46,7 @@ * (1) All public parts of the Entry Reusage System. * * DISABLE_ERS - Define to disable this system. * * ERS_ALIGNED - Alignment of the entries in the blocks. * - * ERInterface - Interface of the entry manager. * + * ERS - Entry manager. * * ers_new - Allocate an instance of an entry manager. * * ers_report - Print a report about the current state. * * ers_force_destroy_all - Force the destruction of all the managers. * @@ -57,7 +56,6 @@ * Define this to disable the Entry Reusage System. * All code except the typedef of ERInterface will be disabled. * To allow a smooth transition, - * @public */ //#define DISABLE_ERS @@ -67,8 +65,6 @@ * This should NEVER be set to zero or less. * If greater than one, some memory can be wasted. This should never be needed * but is here just in case some aligment issues arise. - * @public - * @see #ers_new(uint32) */ #ifndef ERS_ALIGNED # define ERS_ALIGNED 1 @@ -80,8 +76,6 @@ * @param free Free an entry allocated from this manager * @param entry_size Return the size of the entries of this manager * @param destroy Destroy this instance of the manager - * @public - * @see #ers_new(uint32) */ typedef struct eri { @@ -90,9 +84,6 @@ typedef struct eri { * If there are reusable entries available, it reuses one instead. * @param self Interface of the entry manager * @return An entry - * @protected - * @see #ERInterface - * @see ERInterface#free(ERInterface,void *) */ void *(*alloc)(struct eri *self); @@ -102,9 +93,6 @@ typedef struct eri { * Freeing such an entry can lead to unexpected behaviour. * @param self Interface of the entry manager * @param entry Entry to be freed - * @protected - * @see #ERInterface - * @see ERInterface#alloc(ERInterface) */ void (*free)(struct eri *self, void *entry); @@ -112,8 +100,6 @@ typedef struct eri { * Return the size of the entries allocated from this manager. * @param self Interface of the entry manager * @return Size of the entries of this manager in bytes - * @protected - * @see #ERInterface */ uint32 (*entry_size)(struct eri *self); @@ -123,13 +109,10 @@ typedef struct eri { * When destroying the manager a warning is shown if the manager has * missing/extra entries. * @param self Interface of the entry manager - * @protected - * @see #ERInterface - * @see #ers_new(uint32) */ void (*destroy)(struct eri *self); -} *ERInterface; +} *ERS; #ifdef DISABLE_ERS // Use memory manager to allocate/free and disable other interface functions @@ -158,13 +141,8 @@ typedef struct eri { * ERS_ALIGNED that is greater or equal to size is what's actually used. * @param The requested size of the entry in bytes * @return Interface of the object - * @public - * @see #ERS_ALIGNED - * @see #ERInterface - * @see ERInterface#destroy(ERInterface) - * @see common\ers.c#ers_new(uint32) */ -ERInterface ers_new(uint32 size); +ERS ers_new(size_t size); /** * Print a report about the current state of the Entry Reusage System. @@ -172,8 +150,6 @@ ERInterface ers_new(uint32 size); * The number of entries are checked and a warning is shown if extra reusable * entries are found. * The extra entries are included in the count of reusable entries. - * @public - * @see common\ers.c#ers_report(void) */ void ers_report(void); @@ -184,8 +160,6 @@ void ers_report(void); * The use of this is NOT recommended. * It should only be used in extreme situations to make shure all the memory * allocated by this system is released. - * @public - * @see common\ers.c#ers_force_destroy_all(void) */ void ers_force_destroy_all(void); #endif /* DISABLE_ERS / not DISABLE_ERS */ diff --git a/src/common/showmsg.c b/src/common/showmsg.c index fa9ea650b..4d4fcafd6 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -230,7 +230,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) { // from here, we will skip the '\033[' // we break at the first unprocessible position // assuming regular text is starting there - uchar numbers[16], numpoint=0; + uint8 numbers[16], numpoint=0; CONSOLE_SCREEN_BUFFER_INFO info; // initialize @@ -266,7 +266,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) } else if( *q == 'm' ) { // \033[#;...;#m - Set Graphics Rendition (SGR) - uint i; + uint8 i; for(i=0; i<= numpoint; ++i) { if( 0x00 == (0xF0 & numbers[i]) ) @@ -314,7 +314,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) } else if( 0x30 == (0xF0 & numbers[i]) ) { // foreground - uint num = numbers[i]&0x0F; + uint8 num = numbers[i]&0x0F; if(num==9) info.wAttributes |= FOREGROUND_INTENSITY; if(num>7) num=7; // set white for 37, 38 and 39 info.wAttributes &= ~(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE); @@ -327,7 +327,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) } else if( 0x40 == (0xF0 & numbers[i]) ) { // background - uint num = numbers[i]&0x0F; + uint8 num = numbers[i]&0x0F; if(num==9) info.wAttributes |= BACKGROUND_INTENSITY; if(num>7) num=7; // set white for 47, 48 and 49 info.wAttributes &= ~(BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE); @@ -347,7 +347,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) // \033[0J - Clears the screen from cursor to end of display. The cursor position is unchanged. // \033[1J - Clears the screen from start to cursor. The cursor position is unchanged. // \033[2J - Clears the screen and moves the cursor to the home position (line 1, column 1). - uint num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F); + uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F); int cnt; COORD origin = {0,0}; if(num==1) @@ -373,7 +373,7 @@ int VFPRINTF(HANDLE handle, const char *fmt, va_list argptr) // \033[1K - Clears all characters from start of line to the cursor position. // \033[2K - Clears all characters of the whole line. - uint num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F); + uint8 num = (numbers[numpoint]>>4)*10+(numbers[numpoint]&0x0F); COORD origin = {0,info.dwCursorPosition.Y}; SHORT cnt; if(num==1) |