1%%%----------------------------------------------------------------------
2%%% File    : yaws_debug.hrl
3%%% Author  : Claes Wikstrom <klacke@hyber.org>
4%%% Purpose :
5%%% Created :  7 Feb 2002 by Claes Wikstrom <klacke@hyber.org>
6%%%----------------------------------------------------------------------
7
8-author('klacke@hyber.org').
9
10
11
12-define(F(Format,Args),
13         lists:flatten(io_lib:format(Format,Args))).
14
15-define(f(L), lists:flatten(L)).
16
17-define(W(A), ?F("~w", [A])).
18
19-define(format_record(Rec, Name),
20        yaws_debug:format_record(Rec, Name, record_info(fields, Name))).
21
22
23
24-define(Trace(What, Fmt, Args), if Trace == false ->
25                                        ok;
26                                   _ ->
27                                        yaws_debug:dtrace(What,Fmt,Args)
28                                end).
29
30
31
32-ifdef(debug).
33
34
35%% Possible Ops are, equal | neq | integer | list | {list, length, equal}
36%% | greater | min | max | interval | {in, X , List}
37
38
39
40
41-define(Dassert(X,Op,Y,Msg),
42        yaws_debug:assert(Op,X,Y,{assert,?FILE,?LINE,Msg})).
43
44
45-define(Dalert(X,Op,Y,Msg),
46        yaws_debug:assert(Op,X,Y,{alert,?FILE,?LINE,Msg})).
47
48-define(Deval(Expr),Expr).
49
50-define(Debug(F, A),
51        yaws_debug:assert([],0,0,{{debug,"DEBUG"}, ?FILE,?LINE,F, A})).
52
53
54%% ease of use, just do ?Dvar(Variable)
55-define(Dvar(Var), ?Debug("Var = ~p~n", [Var])).
56
57-define(TC(L), yaws_debug:typecheck(L, ?FILE, ?LINE)).
58
59
60-define(Derror(Fmt,Args),
61        yaws_debug:assert([],0,0,{{debug,"ERROR"}, ?FILE,?LINE,Fmt,Args})).
62
63
64-define(Dformat(Fmt,Args),
65        yaws_debug:assert([],0,0,{format, ?FILE,?LINE,Fmt,Args})).
66
67
68-define(Dfunassert(Fun, Msg),
69        yaws_debug:assert('fun', Fun, 0, {assert,?FILE,?LINE,Msg})).
70
71-else. %% not debug_mode
72
73-define(DLOG(F, A), ?LOG(F, A)).
74-define(Dassert(X,Op,Y,Msg),debug_disabled).
75-define(Dalert(X,Op,Y,Msg),debug_disabled).
76-define(Deval(Expr),debug_disabled).
77-define(Debug(F, A),debug_disabled).
78-define(Dvar(Var), debug_disabled).
79-define(Dformat(Fmt,Args),debug_disabled).
80-define(Dfunassert(Fun, Msg), debug_disabled).
81-define(Derror(Fmt,Args),debug_disabled).
82-define(TC(L), debug_disabled).
83
84-endif. %% debug defined
85
86