[go: up one dir, main page]

Menu

[r6]: / trunk / xmdview-1.1 / cdhouse.h  Maximize  Restore  History

Download this file

158 lines (141 with data), 3.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#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