1 #ifndef DEBUG_H
2 #define DEBUG_H
3 
4 #include <learning/real.h>
5 
6 #ifdef _MSC_VER
7 #define Serror   printf("# ERROR (%s:  %d) ", __FILE__, __LINE__); printf
8 #define Swarning  printf("# WARNING (%s:  %d) ", __FILE__, __LINE__); printf
9 #else // _MSC_VER
10 #define Serror   printf("# ERROR (%s - %s:  %d) ", __FUNCTION__,__FILE__, __LINE__); printf
11 #define Swarning  printf("# WARNING (%s - %s:  %d) ", __FUNCTION__,__FILE__, __LINE__); printf
12 #endif // _MSC_VER
13 
14 
15 //#define logmsg (void)
16 //#define dbgmsg (void)
17 #define logmsg printf ("# "); printf
18 #define dbgmsg printf ("# "); printf
19 
20 #define Smessage printf("# "); printf
21 //#define error printf("# ERROR: %s:%d ",__FILE__,__LINE__); printf
22 //#define warning printfww1("# Warning: %s:%d ",__FILE__,__LINE__); printfww2
23 
24 
25 
26 #define ReadFile(f,fs) ((fs=fopen(f,"rb"))!=NULL)
27 #define WriteFile(f,fs) ((fs=fopen(f,"wb"))!=NULL)
28 #define CloseFile(f) {assert(f); fclose(f); f = NULL;}
29 
30 #define AllocM(type,x) ((type *) malloc (sizeof(type)*(x)))
31 #define FreeM(address) if (address) {free(address); address = NULL;} else fprintf(stderr,"ERROR: pointer already freed\n");
32 
33 #define ObjCopy(new_obj,cl_nam) (memcpy (new_obj, &cl_nam ## _class, sizeof(cl_nam)))
34 
35 
36 /* Some cool error codes to use */
37 #define DEC_MEM_ERROR    0x0001
38 #define DEC_RES_INVALID  0x0002
39 #define DEC_SANITY_ERROR 0x0004
40 #define DEC_ARG_INVALID  0x1000
41 #define DEC_ARG_CORRUPT  0x2000
42 
43 
44 #define DEC_MASK 0xffff
45 
46 //typedef float real;
47 
48 
49 int ShowError(int ec);
50 
51 
52 long FileLength(char* fname);
53 
54 #endif
55