-
Notifications
You must be signed in to change notification settings - Fork 5
/
dbg.cls
82 lines (59 loc) · 1.71 KB
/
dbg.cls
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
'
' vim: ft=vb
'
' dbg.cls
'
option explicit
private indent_ as integer
private dbgWriter_ as dbgWriter
private function removeSpecialCharacters(txt as string) ' {
removeSpecialCharacters = replace(txt , "{" , "[")
removeSpecialCharacters = replace(removeSpecialCharacters, "}" , "]")
removeSpecialCharacters = replace(removeSpecialCharacters, chr(10), " ")
removeSpecialCharacters = replace(removeSpecialCharacters, chr(13), " ")
end function ' }
public sub init(dbgWriter__ as dbgWriter) ' {
indent_ = 0
set dbgWriter_ = dbgWriter__
end sub ' }
private sub text_(txt as string) ' {
dbgWriter_.out format(now(), "yyyy-mm-dd hh:MM:ss") & " " & space(indent_) & txt
end sub ' }
public sub text(txt as string) ' {
text_ removeSpecialCharacters(txt)
end sub ' }
public sub indent(txt as string) ' {
if not enabled then
exit sub
end if
text_ "{ " & removeSpecialCharacters(txt)
indent_ = indent_ + 2
end sub ' }
public sub dedent() ' {
if not enabled then
exit sub
end if
indent_ = indent_ - 2
if indent_ < 0 then
indent_ = 0
text "! dbg: Warning, indent_ was set to 0"
end if
text_ "}"
end sub ' }
public sub unhandledError() ' {
text ("Caught unhandled error: " & err.description)
dedent
err.raise err.number, err.source, err.description
end sub ' }
function enabled() as boolean ' {
' if environ$("username") = "René" and environ$("computername") = "THINKPAD" then
enabled = true
' else
' enabled = false
' end if
end function ' }
public sub checkIndentation(expectedIndent as long, txt as string) ' {
if indent_ <> expectedIndent then
text_("indent check failed, " & txt)
end if
end sub ' }