-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQLOG.PAS
executable file
·108 lines (91 loc) · 1.71 KB
/
QLOG.PAS
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{ Copyright 2015 Jerome Shidel }
(*
This project and related files are subject to either the terms
specified in the included LICENSE.TXT file or the GNU GPLv2.0.
*)
unit QLog; { QuickCrt Simple Log File }
{$I QCRT.DEF}
interface
uses QCrt;
procedure LogInc;
procedure LogDec;
procedure WriteLog(S : String);
implementation
var
TextFile : Text;
IsOpen : boolean;
Indent : integer;
OldExitProc : Pointer;
procedure QLogExitProc; far;
begin
ExitProc := OldExitProc;
if IsOpen then begin
LogDec;
Append(TextFile);
WriteLn(TextFile, 'CLOSED');
Close(TextFile);
end;
end;
procedure InitQLog;
begin
IsOpen := False;
Indent := 0;
OldExitProc := ExitProc;
ExitProc := @QLogExitProc;
end;
procedure OpenLog;
var
INDEX : integer;
LOG : String;
begin
LOG := ParamStr(0);
INDEX := Length(LOG);
while LOG[INDEX] <> '.' do Dec(Index);
LOG := Copy(LOG, 1, INDEX) + 'LOG';
{$F-}
Assign(TextFile, LOG);
{$IFDEF DEVLOG_CLEAN}
Rewrite(TextFile);
{$ELSE}
Append(TextFile);
if IOResult <> 0 then
Rewrite(TextFile);
{$ENDIF}
Close(TextFile);
IsOpen := IOResult = 0;
if IsOpen then WriteLog('OPEN LOG');
LogInc;
IsOpen := IOResult = 0;
{$F+}
end;
function Indentation : String;
var
Index : integer;
S : String;
begin
S := '';
for INDEX := 1 to Indent do
S := S + #09 {#32};
Indentation := S;
end;
procedure LogInc;
begin
Inc(Indent);
end;
procedure LogDec;
begin
Dec(Indent);
end;
procedure WriteLog(S : String);
begin
if Not IsOpen then OpenLog;
if IsOpen then begin
Append(TextFile);
WriteLn(TextFile, Indentation + S);
CLose(TextFile);
end;
end;
begin
InitQLog;
end.