*** empty log message ***

This commit is contained in:
Viktor Szakats
1999-07-31 04:11:57 +00:00
parent df036dfb2e
commit 0b77ea9f5e
32 changed files with 489 additions and 121 deletions

View File

@@ -1,3 +1,38 @@
19990731-06:00 CET Victor Szel <info@szelvesz.hu>
+ include/achoice.ch
include/common.ch
include/dbstruct.ch
include/directry.ch
include/memoedit.ch
include/dbedit.ch
include/assert.ch
include/getexit.ch
include/simpleio.ch
Missing Clipper compatible Harbour header files added.
* source/rtl/extend.c -> Fixed memory management stuff
moved to the new file source/rtl/fm.c
source/rtl/Makefile
makefile.*
+ source/rtl/fm.c
include/fm.api
include/extend.h
_xalloc(), hb_xalloc() added for Clipper compatibility.
+ include/vm.api
VM API added to provide some Clipper compatibility.
VM functions are mapped to FM calls, Heap calls
are accepted but functionality is not supported.
* include/rdd.api
include/error.ch
include/inkey.ch
include/color.ch
include/fileio.ch
include/rddsys.ch
include/box.ch
include/classes.ch
include/set.ch
Small cleanups. Missing #ifdef guards added.
+ make_tpl.sh - GNU Make laucher for bash/linux/gcc.
19990731-03:33 CET Victor Szel <info@szelvesz.hu>
! source/vm/hvm.c - Fixed some error codes.
(.OR., .AND., PVALUE)

View File

@@ -0,0 +1,22 @@
/*
* $Id$
*/
#ifndef _ACHOICE_CH
#define _ACHOICE_CH
/* User callback status codes */
#define AC_IDLE 0 /* Idle */
#define AC_HITTOP 1 /* Attempt to move above the first item */
#define AC_HITBOTTOM 2 /* Attempt to move below the last item */
#define AC_EXCEPT 3 /* Keystroke exception */
#define AC_NOITEM 4 /* There's no selectable item */
/* User callback return codes */
#define AC_ABORT 0 /* Abort ACHOICE() and return zero */
#define AC_SELECT 1 /* Select current item and return it's index */
#define AC_CONT 2 /* Continue ACHOICE() */
#define AC_GOTO 3 /* Search first chars for the last pressed key */
#define AC_REDRAW 4 /* Redraw ACHOICE() */
#endif /* _ACHOICE_CH */

29
harbour/include/assert.ch Normal file
View File

@@ -0,0 +1,29 @@
/*
* $Id$
*/
#ifndef _ASSERT_CH
#define _ASSERT_CH
#ifdef NDEBUG
/* When NDEBUG is definded, ignore all ASSERT() calls */
#command ASSERT( <exp> [, <msg>] ) =>
#else
#command ASSERT( <exp> [, <msg>] ) => ;
IF ( !(<exp>) ) ;
; OUTSTD( ;
CHR(13) + CHR(10) + PROCNAME(0) + ;
"(" + LTRIM(STR(PROCLINE())) + ")" + ;
" Assertion failed: " + ;
IF( <.msg.>, <msg>, <"exp"> ) ;
) ;
; QUIT ;
; ENDIF
#endif /* NDEBUG */
#endif /* _ASSERT_CH */

View File

@@ -5,22 +5,22 @@
#ifndef _BOX_CH
#define _BOX_CH
// #defines for DISPBOX()
/* #defines for DISPBOX() */
// Single-line
#define B_SINGLE ( CHR(218) + CHR(196) + CHR(191) + CHR(179) + ;
CHR(217) + CHR(196) + CHR(192) + CHR(179) )
/* Single-line */
#define B_SINGLE ( Chr(218) + Chr(196) + Chr(191) + Chr(179) + ;
Chr(217) + Chr(196) + Chr(192) + Chr(179) )
// Double-line
#define B_DOUBLE ( CHR(201) + CHR(205) + CHR(187) + CHR(186) + ;
CHR(188) + CHR(205) + CHR(200) + CHR(186) )
/* Double-line */
#define B_DOUBLE ( Chr(201) + Chr(205) + Chr(187) + Chr(186) + ;
Chr(188) + Chr(205) + Chr(200) + Chr(186) )
// Single-line top, double-line sides
#define B_SINGLE_DOUBLE ( CHR(214) + CHR(196) + CHR(183) + CHR(186) + ;
CHR(189) + CHR(196) + CHR(211) + CHR(186) )
/* Single-line top, double-line sides */
#define B_SINGLE_DOUBLE ( Chr(214) + Chr(196) + Chr(183) + Chr(186) + ;
Chr(189) + Chr(196) + Chr(211) + Chr(186) )
// Double-line top, single-line sides
#define B_DOUBLE_SINGLE ( CHR(213) + CHR(205) + CHR(184) + CHR(179) + ;
CHR(190) + CHR(205) + CHR(212) + CHR(179) )
/* Double-line top, single-line sides */
#define B_DOUBLE_SINGLE ( Chr(213) + Chr(205) + Chr(184) + Chr(179) + ;
Chr(190) + Chr(205) + Chr(212) + Chr(179) )
#endif /* _BOX_CH */

View File

@@ -1,11 +1,6 @@
/*
* $Id$
*/
/* $Id$
#ifndef _CLASSES_CH
#define _CLASSES_CH
/* Harbour classes commands
Harbour classes commands
Copyright(C) 1999 by Antonio Linares.
@@ -28,6 +23,9 @@
You can contact me at: alinares@fivetech.com
*/
#ifndef _CLASSES_CH
#define _CLASSES_CH
#xcommand CLASS <ClassName> [ <frm: FROM, INHERIT> <SuperClass> ] => ;
function <ClassName>() ;;
static oClass ;;

View File

@@ -2,10 +2,15 @@
* $Id$
*/
#ifndef _COLOR_CH
#define _COLOR_CH
/* attributes for color strings */
#define CLR_STANDARD 0
#define CLR_ENHANCED 1
#define CLR_BORDER 2
#define CLR_BACKGROUND 3
#define CLR_UNSELECTED 4
#define CLR_LASTCOLOR CLR_UNSELECTED
#define CLR_STANDARD 0
#define CLR_ENHANCED 1
#define CLR_BORDER 2
#define CLR_BACKGROUND 3
#define CLR_UNSELECTED 4
#define CLR_LASTCOLOR CLR_UNSELECTED
#endif /* _COLOR_CH */

33
harbour/include/common.ch Normal file
View File

@@ -0,0 +1,33 @@
/*
* $Id$
*/
#ifndef _COMMON_CH
#define _COMMON_CH
/* Friendly logical aliases */
#define TRUE .T.
#define FALSE .F.
#define YES .T.
#define NO .F.
/* Type checking macros */
#translate ISNIL( <xValue> ) => ( <xValue> == NIL )
#translate ISARRAY( <xValue> ) => ( ValType( <xValue> ) == "A" )
#translate ISBLOCK( <xValue> ) => ( ValType( <xValue> ) == "B" )
#translate ISCHAR( <xValue> ) => ( ValType( <xValue> ) == "C" )
#translate ISDATE( <xValue> ) => ( ValType( <xValue> ) == "D" )
#translate ISLOG( <xValue> ) => ( ValType( <xValue> ) == "L" )
#translate ISMEMO( <xValue> ) => ( ValType( <xValue> ) == "M" )
#translate ISNUM( <xValue> ) => ( ValType( <xValue> ) == "N" )
#translate ISOBJECT( <xValue> ) => ( ValType( <xValue> ) == "O" )
/* DEFAULT and UPDATE commands */
#xcommand DEFAULT <v1> TO <x1> [, <vn> TO <xn> ] => ;
IF <v1> == NIL ; <v1> := <x1> ; END ;
[; IF <vn> == NIL ; <vn> := <xn> ; END ]
#command UPDATE <v1> IF <exp> TO <v2> => ;
IF <exp> ; <v1> := <v2> ; END
#endif /* _COMMON_CH */

20
harbour/include/dbedit.ch Normal file
View File

@@ -0,0 +1,20 @@
/*
* $Id$
*/
#ifndef _DBEDIT_CH
#define _DBEDIT_CH
/* User function entry modes */
#define DE_IDLE 0 /* Idle */
#define DE_HITTOP 1 /* Attempt to cursor past top of file */
#define DE_HITBOTTOM 2 /* Attempt to cursor past bottom of file */
#define DE_EMPTY 3 /* No records in work area */
#define DE_EXCEPT 4 /* Key exception */
/* User function return codes */
#define DE_ABORT 0 /* Abort DBEDIT() */
#define DE_CONT 1 /* Continue DBEDIT() */
#define DE_REFRESH 2 /* Force reread/redisplay of all data rows */
#endif /* _DBEDIT_CH */

View File

@@ -0,0 +1,18 @@
/*
* $Id$
*/
#ifndef _DBSTRUCT_CH
#define _DBSTRUCT_CH
/* Positions for field structure array */
#define DBS_NAME 1
#define DBS_TYPE 2
#define DBS_LEN 3
#define DBS_DEC 4
/* Length of the field structure array */
#define DBS_ALEN 4
#endif /* _DBSTRUCT_CH */

View File

@@ -0,0 +1,19 @@
/*
* $Id$
*/
#ifndef _DIRECTRY_CH
#define _DIRECTRY_CH
/* Positions for DIRECTORY() array */
#define F_NAME 1
#define F_SIZE 2
#define F_DATE 3
#define F_TIME 4
#define F_ATTR 5
/* Length of DIRECTORY() array */
#define F_LEN 5
#endif /* _DIRECTRY_CH */

View File

@@ -5,14 +5,13 @@
#ifndef _ERROR_CH
#define _ERROR_CH
// Severity levels (oError:severity)
/* Severity levels (oError:severity) */
#define ES_WHOCARES 0
#define ES_WARNING 1
#define ES_ERROR 2
#define ES_CATASTROPHIC 3
// Generic error codes (oError:genCode)
/* Generic error codes (oError:genCode) */
#define EG_ARG 1
#define EG_BOUND 2
#define EG_STROVERFLOW 3

View File

@@ -262,7 +262,8 @@ void hb_retnl( long lNumber ); /* returns a long number */
void hb_retnd( double dNumber ); /* returns a double */
void hb_reta( ULONG ulLen ); /* returns an array with a specific length */
void * hb_xgrab( ULONG lSize ); /* allocates memory */
void * hb_xalloc( ULONG lSize ); /* allocates memory, returns NULL on failure */
void * hb_xgrab( ULONG lSize ); /* allocates memory, exists on failure */
void * hb_xrealloc( void * pMem, ULONG lSize ); /* reallocates memory */
void hb_xfree( void * pMem ); /* frees memory */
ULONG hb_xsize( void * pMem ); /* returns the size of an allocated memory block */

View File

@@ -75,7 +75,7 @@
#define FS_END 0x0002 /* Seek from end of file */
/* File system error codes */
#define FS_ERROR -1 /* Unspecified error */
#define FS_ERROR (-1) /* Unspecified error */
/* Extended file open mode flags */
#define FXO_TRUNCATE 0x0100 /* Create (truncate if exists) */

View File

@@ -7,6 +7,7 @@
#include "extend.h"
#define _xalloc hb_xalloc
#define _xgrab hb_xgrab
#define _xrealloc hb_xrealloc
#define _xfree hb_xfree

View File

@@ -0,0 +1,19 @@
/*
* $Id$
*/
#ifndef _GETEXIT_CH
#define _GETEXIT_CH
/* get:exitState values */
#define GE_NOEXIT 0 /* no exit attempted (blank) */
#define GE_UP 1
#define GE_DOWN 2
#define GE_TOP 3
#define GE_BOTTOM 4
#define GE_ENTER 5
#define GE_WRITE 6
#define GE_ESCAPE 7
#define GE_WHEN 8 /* when clause unsatisfied */
#endif /* _GETEXIT_CH */

View File

@@ -2,6 +2,9 @@
* $Id$
*/
#ifndef _INKEY_CH
#define _INKEY_CH
// Input event masks
#define INKEY_MOVE 1
@@ -93,8 +96,6 @@
#define K_ALT_PGUP 409 // * Alt-PgUp
#define K_ALT_PGDN 417 // * Alt-PgDn
// Misc. keys
#define K_ENTER 13 // Enter, Ctrl-M
@@ -114,7 +115,6 @@
#define K_ALT_EQUALS 387 // * Alt-Equals
#define K_ALT_ESC 257 // * Alt-Esc
// Keypad keys
#define KP_ALT_ENTER 422 // * Keypad Alt-Enter
@@ -131,7 +131,6 @@
#define KP_ALT_MINUS 330 // * Keypad Alt--
#define KP_ALT_PLUS 334 // * Keypad Alt-+
// Editing keys
#define K_INS 22 // Ins, Ctrl-V
@@ -150,7 +149,6 @@
#define K_ALT_BS 270 // * Alt-Backspace
#define K_ALT_TAB 421 // * Alt-Tab
// Control keys
#define K_CTRL_A 1 // Ctrl-A, Home
@@ -180,4 +178,4 @@
#define K_CTRL_Y 25 // Ctrl-Y
#define K_CTRL_Z 26 // Ctrl-Z, Ctrl-Left arrow
#endif /* _INKEY_CH */

View File

@@ -0,0 +1,27 @@
/*
* $Id$
*/
#ifndef _MEMOEDIT_CH
#define _MEMOEDIT_CH
/* User callback status modes */
#define ME_IDLE 0 /* Idle, all keys processed */
#define ME_UNKEY 1 /* Unknown key, memo unaltered */
#define ME_UNKEYX 2 /* Unknown key, memo altered */
#define ME_INIT 3 /* Initialization mode */
/* User callback return codes */
#define ME_DEFAULT 0 /* Perform default action */
#define ME_IGNORE 32 /* Ignore unknown key */
#define ME_DATA 33 /* Treat unknown key as data */
#define ME_TOGGLEWRAP 34 /* Toggle word-wrap mode */
#define ME_TOGGLESCROLL 35 /* Toggle scrolling mode */
#define ME_WORDRIGHT 100 /* Perform word-right operation */
#define ME_BOTTOMRIGHT 101 /* Perform bottom-right operation */
/* NOTE: Return codes 1-31 cause MEMOEDIT() to perform the */
/* edit action corresponding to the key whose value is returned. */
#endif /* _MEMOEDIT_CH */

View File

@@ -2,8 +2,8 @@
* $Id$
*/
#ifndef HB_RDD_API
#define HB_RDD_API
#ifndef HB_RDD_API_
#define HB_RDD_API_
typedef PBYTE BYTEP;
@@ -985,4 +985,4 @@ extern USHORT hb_rddExtendType( USHORT fieldType );
extern USHORT hb_rddFieldType( USHORT extendType );
#endif
#endif /* HB_RDD_API_ */

View File

@@ -2,11 +2,11 @@
* $Id$
*/
#ifndef HB_RDDSYS_CH
#define HB_RDDSYS_CH
#ifndef _RDDSYS_CH
#define _RDDSYS_CH
#define RDT_FULL 1
#define RDT_TRANSFER 2
#define RDT_HIDDEN 255
#define RDT_FULL 1
#define RDT_TRANSFER 2
#define RDT_HIDDEN 255
#endif
#endif /* _RDDSYS_CH */

View File

@@ -38,6 +38,9 @@
V 1.0 David G. Holm Initial version.
*/
#ifndef _SET_CH
#define _SET_CH
#define _SET_ALTERNATE 1
#define _SET_ALTFILE 2
#define _SET_BELL 3
@@ -77,3 +80,5 @@
#define _SET_TYPEAHEAD 37
#define _SET_UNIQUE 38
#define _SET_WRAP 39
#endif /* _SET_CH */

View File

@@ -2,8 +2,13 @@
* $Id$
*/
#define SC_NONE 0
#define SC_NORMAL 1
#define SC_INSERT 2
#define SC_SPECIAL1 3
#define SC_SPECIAL2 4
#ifndef _SETCURS_CH
#define _SETCURS_CH
#define SC_NONE 0
#define SC_NORMAL 1
#define SC_INSERT 2
#define SC_SPECIAL1 3
#define SC_SPECIAL2 4
#endif /* _SETCURS_CH */

View File

@@ -0,0 +1,20 @@
/*
* $Id$
*/
#ifndef _SIMPLEIO_CH
#define _SIMPLEIO_CH
#command ? [ <xList,...> ] => ;
( OutStd( Chr(13) + Chr(10) ) [, OutStd(<xList>)] )
#command ?? [ <xList,...> ] => ;
OutStd( <xList> )
#command ACCEPT TO <idVar> => ;
<idVar> := StrTran( FReadStr(0, 256), Chr(13) + Chr(10) )
#command ACCEPT <cPrompt> TO <idVar> => ;
? <cPrompt> ; ACCEPT TO <idVar>
#endif /* _SIMPLEIO_CH */

40
harbour/include/vm.api Normal file
View File

@@ -0,0 +1,40 @@
/*
* $Id$
*/
#ifndef HB_VM_API_
#define HB_VM_API_
#define HANDLE void*
/* Standard */
#define _xvalloc(size, flags) hb_xalloc(size)
#define _xvfree(h) hb_xfree(h)
#define _xvrealloc(h, size, flags) hb_xrealloc(h, size)
#define _xvlock(h) (h)
#define _xvunlock(h) /* dummy */
/* Wire */
#define _xvwire(h) (h)
#define _xvunwire(h) /* dummy */
/* State */
#define _xvlockcount(h) (0)
#define _xvsize(h) hb_xsize(h)
/* -------------------------------------------------------- */
/* Warning: Heap functionality is not supported by Harbour. */
/* All functions will emulate constant failure. */
/* -------------------------------------------------------- */
/* Heap */
#define _xvheapnew(size) (0)
#define _xvheapdestroy(h) /* dummy */
#define _xvheapresize(h, size) /* dummy */
#define _xvheapalloc(h, size) (0)
#define _xvheapfree(h, offset) /* dummy */
#define _xvheaplock(h, offset) (0)
#define _xvheapunlock(h, offset) /* dummy */
#endif /* HB_VM_API_ */

19
harbour/make_tpl.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/bash
# ---------------------------------------------------------------
# Template to initialize the environment before starting
# the GNU make system for Harbour (Linux version)
#
# For further information about the GNU make system please
# check doc/gmake.txt
# ---------------------------------------------------------------
export HB_ARCHITECTURE=linux
export HB_COMPILER=gcc
# ---------------------------------------------------------------
# Start the GNU make system
make clean
make

View File

@@ -14,7 +14,7 @@ PROJECT: harbour.lib libs\b16\terminal.lib libs\win16\terminal.lib harbour.exe
harbour.lib : arrays.obj asort.obj classes.obj codebloc.obj dates.obj \
dates2.obj datesx.obj \
debug.obj descend.obj devoutp.obj dynsym.obj environ.obj error.obj \
errorapi.obj errorsys.obj extend.obj files.obj \
errorapi.obj errorsys.obj extend.obj files.obj fm.obj \
hardcr.obj initsymb.obj itemapi.obj math.obj memvars.obj \
mathx.obj mtran.obj objfunc.obj set.obj setcolor.obj stringp.obj \
strings.obj stringsx.obj tclass.obj transfrm.obj
@@ -46,6 +46,7 @@ errorapi.obj : errorapi.c extend.h hbdefs.h
errorsys.obj : errorsys.c extend.h hbdefs.h
extend.obj : extend.c extend.h hbdefs.h
files.obj : extend.c extend.h hbdefs.h
fm.obj : fm.c extend.h hbdefs.h
hardcr.obj : hardcr.c extend.h hbdefs.h
initsymb.obj : initsymb.c extend.h hbdefs.h
itemapi.obj : itemapi.c extend.h hbdefs.h

View File

@@ -56,6 +56,7 @@ errorapi.obj : errorapi.c extend.h hbdefs.h ctoharb.h
errorsys.obj : errorsys.prg extend.h hbdefs.h init.h pcode.h
extend.obj : extend.c extend.h hbdefs.h set.h dates.h
files.obj : extend.c extend.h hbdefs.h
fm.obj : fm.c extend.h hbdefs.h
gtapi.obj : gtapi.c extend.h hbdefs.h gtapi.h
hardcr.obj : hardcr.c extend.h hbdefs.h
itemapi.obj : itemapi.c extend.h hbdefs.h ctoharb.h itemapi.h set.h dates.h

View File

@@ -42,6 +42,7 @@ errorapi.obj : errorapi.c extend.h hbdefs.h
errorsys.obj : errorsys.c extend.h hbdefs.h
extend.obj : extend.c extend.h hbdefs.h
files.obj : files.c extend.h hbdefs.h
fm.obj : fm.c extend.h hbdefs.h
hardcr.obj : hardcr.c extend.h hbdefs.h
hb_f.obj : hb_f.c extend.h hbdefs.h
initsymb.obj : initsymb.c extend.h hbdefs.h

View File

@@ -42,6 +42,7 @@ errorapi.obj : errorapi.c extend.h hbdefs.h
errorsys.obj : errorsys.c extend.h hbdefs.h
extend.obj : extend.c extend.h hbdefs.h
files.obj : files.c extend.h hbdefs.h
fm.obj : fm.c extend.h hbdefs.h
hardcr.obj : hardcr.c extend.h hbdefs.h
hb_f.obj : hb_f.c extend.h hbdefs.h
initsymb.obj : initsymb.c extend.h hbdefs.h

View File

@@ -273,6 +273,9 @@ $(OBJ_DIR)\extend.obj : $(RTL_DIR)\extend.c
$(OBJ_DIR)\files.obj : $(RTL_DIR)\files.c
$(CC) $(CLIBFLAGS) -Fo$@ $**
$(OBJ_DIR)\fm.obj : $(RTL_DIR)\fm.c
$(CC) $(CLIBFLAGS) -Fo$@ $**
$(OBJ_DIR)\gtapi.obj : $(RTL_DIR)\gtapi.c
$(CC) $(CLIBFLAGS) -Fo$@ $**

View File

@@ -17,6 +17,7 @@ C_SOURCES=\
errorapi.c \
extend.c \
files.c \
fm.c \
gtapi.c \
hardcr.c \
inkey.c \

View File

@@ -22,20 +22,12 @@
You can contact me at: alinares@fivetech.com
*/
#ifndef __MPW__
#include <malloc.h>
#endif
#include "set.h"
#include <stdlib.h>
#include "set.h"
#include "extend.h"
#include "dates.h"
#include "item.api"
ULONG ulMemoryBlocks = 0;
ULONG ulMemoryMaxBlocks = 0;
ULONG ulMemoryMaxConsumed = 0;
ULONG ulMemoryConsumed = 0;
PHB_ITEM hb_param( int iParam, WORD wMask )
{
WORD wType;
@@ -869,63 +861,3 @@ void hb_stornd( double dValue, int iParam, ... )
}
}
void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory */
{
void * pMem = malloc( ulSize + sizeof( ULONG ) );
if( ! pMem )
{
printf( "\n_xgrab error: can't allocate memory!\n" );
exit( 1 );
}
* ( ( ULONG * ) pMem ) = ulSize; /* we store the block size into it */
ulMemoryConsumed += ulSize;
ulMemoryMaxConsumed += ulSize;
ulMemoryBlocks++;
ulMemoryMaxBlocks++;
return ( char * ) pMem + sizeof( ULONG );
}
void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */
{
ULONG ulMemSize = * ( ULONG * ) ( ( char * ) pMem - sizeof( ULONG ) );
void * pResult = realloc( ( char * ) pMem - sizeof( ULONG ), ulSize + sizeof( ULONG ) );
if( ! pResult )
{
printf( "\n_xrealloc error: can't reallocate memory!\n" );
exit( 1 );
}
* ( ( ULONG * ) pResult ) = ulSize; /* we store the block size into it */
if( ! ulSize )
ulMemoryBlocks--;
ulMemoryConsumed += ( ulSize - ulMemSize );
if( ulSize > ulMemSize )
ulMemoryMaxConsumed += ulSize - ulMemSize;
return ( char * ) pResult + sizeof( ULONG );
}
void hb_xfree( void * pMem ) /* frees fixed memory */
{
ULONG ulMemSize = * ( ULONG * ) ( ( char * ) pMem - sizeof( ULONG ) );
if( pMem )
free( ( char * ) pMem - sizeof( ULONG ) );
else
printf( "\nCalling hb_xfree() with a null pointer!\n" );
ulMemoryConsumed -= ulMemSize;
ulMemoryBlocks--;
}
ULONG hb_xsize( void * pMem ) /* returns the size of an allocated memory block */
{
return * ( ULONG * ) ( ( char * ) pMem - sizeof( ULONG ) );
}

115
harbour/source/rtl/fm.c Normal file
View File

@@ -0,0 +1,115 @@
/*
* $Id$
Copyright(C) 1999 by Antonio Linares.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to:
The Free Software Foundation, Inc.,
675 Mass Ave, Cambridge, MA 02139, USA.
You can contact me at: alinares@fivetech.com
*/
#ifndef __MPW__
#include <malloc.h>
#endif
#include <stdlib.h>
#include "extend.h"
ULONG ulMemoryBlocks = 0;
ULONG ulMemoryMaxBlocks = 0;
ULONG ulMemoryMaxConsumed = 0;
ULONG ulMemoryConsumed = 0;
void * hb_xalloc( ULONG ulSize ) /* allocates fixed memory, returns NULL on failure */
{
void * pMem = malloc( ulSize + sizeof( ULONG ) );
if( ! pMem )
{
return pMem;
}
* ( ( ULONG * ) pMem ) = ulSize; /* we store the block size into it */
ulMemoryConsumed += ulSize;
ulMemoryMaxConsumed += ulSize;
ulMemoryBlocks++;
ulMemoryMaxBlocks++;
return ( char * ) pMem + sizeof( ULONG );
}
void * hb_xgrab( ULONG ulSize ) /* allocates fixed memory, exits on failure */
{
void * pMem = malloc( ulSize + sizeof( ULONG ) );
if( ! pMem )
{
printf( "\n_xgrab error: can't allocate memory!\n" );
exit( 1 );
}
* ( ( ULONG * ) pMem ) = ulSize; /* we store the block size into it */
ulMemoryConsumed += ulSize;
ulMemoryMaxConsumed += ulSize;
ulMemoryBlocks++;
ulMemoryMaxBlocks++;
return ( char * ) pMem + sizeof( ULONG );
}
void * hb_xrealloc( void * pMem, ULONG ulSize ) /* reallocates memory */
{
ULONG ulMemSize = * ( ULONG * ) ( ( char * ) pMem - sizeof( ULONG ) );
void * pResult = realloc( ( char * ) pMem - sizeof( ULONG ), ulSize + sizeof( ULONG ) );
if( ! pResult )
{
printf( "\n_xrealloc error: can't reallocate memory!\n" );
exit( 1 );
}
* ( ( ULONG * ) pResult ) = ulSize; /* we store the block size into it */
if( ! ulSize )
ulMemoryBlocks--;
ulMemoryConsumed += ( ulSize - ulMemSize );
if( ulSize > ulMemSize )
ulMemoryMaxConsumed += ulSize - ulMemSize;
return ( char * ) pResult + sizeof( ULONG );
}
void hb_xfree( void * pMem ) /* frees fixed memory */
{
ULONG ulMemSize = * ( ULONG * ) ( ( char * ) pMem - sizeof( ULONG ) );
if( pMem )
free( ( char * ) pMem - sizeof( ULONG ) );
else
printf( "\nCalling hb_xfree() with a null pointer!\n" );
ulMemoryConsumed -= ulMemSize;
ulMemoryBlocks--;
}
ULONG hb_xsize( void * pMem ) /* returns the size of an allocated memory block */
{
return * ( ULONG * ) ( ( char * ) pMem - sizeof( ULONG ) );
}