📄 cdhouse.h
字号:
#ifndef __CDHOUSE_H#define __CDHOUSE_H/*************************************************************************Function Prototypes*************************************************************************/void StartProgramTimer(void);void CleanAfterError(void);void CleanBeforeEnd(void);char *GetCurrentTimeStr (void);/*************************************************************************Debugging Macros*************************************************************************//*Debugging Macro: Print current file and line number*/#define WRITEMSG \ { \ if (Debug_g) \ printf ("In file %s at line %i.\n", __FILE__, __LINE__); \ fflush (stdin); \ }/*Debugging Macro: Test assertion, if failed list file and line number*/#define ASSERT(TEST) if (!(TEST)) \ printf ("INTERNAL ERROR: 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"); \ fflush (stdin); \ }/*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*************************************************************************//*NOTE:The following macro replace the standard C for(;;) constructIf you don't replace all occurances of this macro withthe corresponding for() statement, copy the following4 line perl script to the file fixLOOP.pl, run as follows. chmod u+x fixLOOP.pl fixLOOP.pl *.c rm *.bak (to remove backup files)This will edit in place all the *.c files and replace LOOP with for().------ start of script ------------------------------#!/usr/bin/perl -pi.bakif (!m/^#define/) { s/LOOP\s*\(\s*([^,]*?)\s*,\s*([^)]*?)\s*\)/for ( $1=0; $1<$2; $1++ )/;}------ end of script --------------------------------*//* Simple loop (this macro help reduce typos) */#define LOOP(INDEX,LIMIT) \ for (INDEX=0; INDEX<(LIMIT); INDEX++)/*Allocate array and test for NULL allocationsIf 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); \ if (CheckMem_g) \ printf ("CHECK MEM FREE %s %p %s %i\n", \ #VAR, VAR, __FILE__, __LINE__); \ free (VAR); \ VAR = NULL; \ } \ if (NUM!=0) \ { \ VAR = (TYPE *) calloc ( (NUM), sizeof ( TYPE ) ); \ if (CheckMem_g) \ printf ("CHECK MEM ALLO %s %p %s %i %li\n", \ #VAR, VAR, __FILE__, __LINE__, \ ( (long) (NUM) ) * sizeof(TYPE) ); \ if ((VAR) == NULL) \ { \ printf ("ERROR: FILE %s LINE %i\n", __FILE__, __LINE__); \ 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(VAR,TYPE,OLD_NUM,NEW_NUM) \ { \ /* Free existing pointer */ \ if ((NEW_NUM)==0) \ { \ if ((VAR)!=NULL) \ { \ if (CheckMem_g) \ printf ("CHECK MEM FREE(R0) %s %p %s %i\n", \ #VAR, VAR, __FILE__, __LINE__); \ free (VAR); \ (VAR) = NULL; \ } \ } \ /* Get new storage */ \ else \ { \ if ((VAR)==NULL) \ { \ (VAR) = (TYPE *) calloc ( (NEW_NUM), sizeof (TYPE) ); \ if (CheckMem_g) \ printf ("CHECK MEM ALLO(R) %s %p %s %i %li\n", \ #VAR, VAR, __FILE__, __LINE__, \ ( (long) (NEW_NUM) ) * sizeof(TYPE) ); \ } \ else \ { \ if (CheckMem_g) \ printf ("CHECK MEM FREE(R1) %s %p %s %i\n", \ #VAR, VAR, __FILE__, __LINE__); \ (VAR) = (TYPE *) realloc ( (VAR), (NEW_NUM) * sizeof (TYPE) ) ; \ if (CheckMem_g) \ printf ("CHECK MEM REALLO %s %p %s %i %li\n", \ #VAR, VAR, __FILE__, __LINE__, \ ( (long) (NEW_NUM) ) * sizeof(TYPE) ); \ } \ if ((VAR) == NULL) \ { \ printf ("ERROR\n"); \ printf (" Cannot allocate variable %s.\n", #VAR); \ printf (" Number of Elements %i\n", (NEW_NUM)); \ printf (" Size of Elements %i\n", sizeof(TYPE)); \ CleanAfterError(); \ } \ if ((NEW_NUM)>(OLD_NUM)) \ memset ( (VAR)+(OLD_NUM), 0, ((NEW_NUM)-(OLD_NUM)) * sizeof(TYPE)); \ } \ } #define FREE(VAR) \ if ((VAR)!=NULL) \ { \ if (CheckMem_g) \ printf ("CHECK MEM FREE %s %p %s %i\n", \ #VAR, VAR, __FILE__, __LINE__); \ free (VAR); \ (VAR) = NULL; \ }/* Error Message Prefix */#define ERROR_PREFIX printf("\nERROR xmd:%s:%i: ", __FILE__, __LINE__);/* Square a token */#define SQR(X) ((X)*(X))/* Get combined type */#define COMBINED_TYPE(T1,T2) \ ((T1) > (T2) ? ((T1)*((T1)+1)/2 + (T2)) : ((T2)*((T2)+1)/2 + (T1))) /*************************************************************************Global Variables*************************************************************************//*Do not define Debug_g if header is called from cdhouse.c*/#ifndef IS_CDHOUSE_Hextern int Debug_g;extern int CheckMem_g;#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -