Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libvgraph/kpvdebug.h
1808 views
1
#ifndef _KPVDEBUG_H
2
#define _KPVDEBUG_H 1
3
4
#ifdef DEBUG
5
6
_BEGIN_EXTERNS_
7
extern void abort _ARG_((void));
8
_END_EXTERNS_
9
#ifndef __LINE__
10
#define __LINE__ 0
11
#endif
12
#ifndef __FILE__
13
#define __FILE__ "Unknown"
14
#endif
15
16
static void _oops(char* file, int line)
17
{
18
char buf[1024];
19
sprintf(buf, "\nFailed at %s:%d\n", file, line);
20
write(2,buf,strlen(buf));
21
abort();
22
}
23
24
#include <sys/times.h>
25
#include <sys/resource.h>
26
static double _getTime ( void )
27
{ double tm;
28
struct rusage u;
29
getrusage ( RUSAGE_SELF, &u );
30
tm = (double)u.ru_utime.tv_sec + (double)u.ru_utime.tv_usec/1000000.0;
31
return tm;
32
}
33
34
static double _Kpvtime;
35
#define BEGTIME() (_Kpvtime = _getTime())
36
#define GETTIME() (_getTime() - _Kpvtime)
37
#define ASSERT(p) ((p) ? 0 : (_oops(__FILE__, __LINE__),0))
38
#define COUNT(n) ((n) += 1)
39
#define TALLY(c,n,v) ((c) ? ((n) += (v)) : (n))
40
#define DECLARE(t,v) t v
41
#define SET(n,v) ((n) = (v))
42
#define PRINT(fd,s,v) do {char _b[1024];sprintf(_b,s,v);write((fd),_b,strlen(_b));} while(0)
43
#define WRITE(fd,d,n) write((fd),(d),(n))
44
#define KPV(temp) (temp) /* debugging stuff that should be removed */
45
#define RETURN(x) (_oops(__FILE__, __LINE__), (x))
46
#define BREAK (_oops(__FILE__, __LINE__))
47
#define GOTO(label) do { _oops(__FILE__, __LINE__); goto label; } while(0)
48
49
#else
50
51
#define BEGTIME()
52
#define GETTIME()
53
#define ASSERT(p)
54
#define COUNT(n)
55
#define TALLY(c,n,v)
56
#define DECLARE(t,v)
57
#define SET(n,v)
58
#define PRINT(fd,s,v)
59
#define WRITE(fd,d,n)
60
#define KPV(x)
61
#define RETURN(x) return(x)
62
#define BREAK break
63
#define GOTO(label) goto label
64
65
#endif /*DEBUG*/
66
67
#endif /*_KPVDEBUG_H*/
68
69