#ifndef __CDHOUSE_H
#define __CDHOUSE_H
/*
************************************************************************
Function Prototypes
************************************************************************
*/
void StartProgramTimer(void);
void CleanAfterError(void);
void CleanBeforeEnd(void);
char *GetCurrentTimeStr (void);
/*
************************************************************************
Debugging Macros
************************************************************************
*/
/*
Debugging Macro: Test assertion, if failed list file and line number
*/
#define ASSERT(TEST) if (!(TEST)) \
printf ("Failed assertion (%s) in file %s line %i.\n", \
#TEST, __FILE__, __LINE__);
/*
Debugging Macro: Print out variable name and value
*/
#define WRITEVAR(VAR_NAME,VAR_TYPE) \
if (Debug_g) \
{ \
printf ("FILE %s LINE %i :", __FILE__, __LINE__); \
printf ("%s = ", #VAR_NAME); \
printf (#VAR_TYPE, (VAR_NAME) ); \
printf ("\n"); \
}
/*
Debugging Macro: Print out debugging note
*/
#define WRITENOT(MSG) \
if (Debug_g) \
{ \
printf ("FILE %s LINE %i :", __FILE__, __LINE__); \
printf (" (%s)\n", MSG); \
}
/*
Debugging Macro: Use BORLAND C++ DOS routine for checking memory heap
*/
#if 0
#define CHECK_HEAP \
if (heapcheck()<0) \
{ \
printf ("*** INTERNAL ERROR in %s line %i. ", __FILE__, __LINE__); \
printf ("Memory heap is corrupted.\n"); \
}
#else
#define CHECK_HEAP
#endif
/*
************************************************************************
Utility Macros
************************************************************************
*/
/*
Allocate array and test for NULL allocations
If NULL allocation then print error and call CleanAfterError()
*/
#define ALLOCATE(VAR,TYPE,NUM) \
{ \
if (VAR != NULL) \
{ \
printf ("FILE %s LINE %i: ALLOCATE is freeing variable %s\n", \
__FILE__, __LINE__, #VAR); \
free (VAR); \
} \
VAR = (TYPE *) calloc ( (NUM), sizeof ( TYPE ) ); \
if ((VAR) == NULL) \
{ \
printf ("ERROR\n"); \
printf (" Cannot allocate variable %s.\n", #VAR); \
printf (" Number of Elements %i\n", NUM); \
printf (" Size of Elements %i\n", sizeof(TYPE)); \
CleanAfterError(); \
} \
}
/*
Reallocate storage
- if new storage is zero, call free() and set pointer to NULL
- if old storage was zero, call calloc()
- if new storage > old, call realloc() and initialize new storage
- if new storage < old, call realloc()
*/
#define REALLOC(PTR,TYPE,OLD_NUM,NEW_NUM) \
{ \
/* Free existing pointer */ \
if ((NEW_NUM)==0) \
{ \
if ((PTR)!=NULL) \
{ \
free (PTR); \
(PTR) = NULL; \
} \
} \
/* Get new storage */ \
else \
{ \
if ((PTR)==NULL) \
{ \
(PTR) = (TYPE *) calloc ( (NEW_NUM), sizeof (TYPE) ); \
} \
else \
{ \
(PTR) = (TYPE *) realloc ( (PTR), (NEW_NUM) * sizeof (TYPE) ) ; \
} \
if ((PTR) == NULL) \
{ \
printf ("ERROR\n"); \
printf (" Cannot allocate variable %s.\n", #PTR); \
printf (" Number of Elements %i\n", (NEW_NUM)); \
printf (" Size of Elements %i\n", sizeof(TYPE)); \
CleanAfterError(); \
} \
if ((NEW_NUM)>(OLD_NUM)) \
memset ( &((TYPE *) (PTR))[(OLD_NUM)], 0, ((NEW_NUM)-(OLD_NUM)) * sizeof(TYPE)); \
} \
}
#define FREE(VAR) \
if ((VAR)!=NULL) \
{ \
free (VAR); \
(VAR) = NULL; \
}
/* Simple loop (this macro help reduce typos) */
#define LOOP(INDEX,LIMIT) \
for (INDEX=0; INDEX<(LIMIT); INDEX++)
/* Square a token */
#define SQR(X) ((X)*(X))
/*
************************************************************************
Global Variables
************************************************************************
*/
extern int Debug_g;
#endif