1 (* Copyright (C) DooM 2D:Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 {$R-}
18 { $DEFINE CBLOG}
21 interface
23 uses
24 SysUtils;
26 type
36 procedure e_WriteLog (TextLine: String; RecordCategory: TRecordCategory; WriteTime: Boolean=True);
40 // start Write/WriteLn driver. it will write everything to cbuf.
43 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true);
46 var
50 implementation
52 uses
55 var
62 begin
63 Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]);
67 procedure e_WriteLog (TextLine: String; RecordCategory: TRecordCategory; WriteTime: Boolean=True);
68 begin
71 (*
72 var
73 LogFile: TextFile;
74 Prefix: ShortString = '';
75 OutStr: String;
76 begin
77 if driverInited and (length(TextLine) > 0) then
78 begin
79 case RecordCategory of
80 MSG_FATALERROR: write('FATAL: ');
81 MSG_WARNING: write('WARNING: ');
82 end;
83 writeln(TextLine);
84 end;
86 if FileName = '' then Exit;
88 Assign(LogFile, FileName);
89 try
90 if FileExists(FileName) then
91 Append(LogFile)
92 else
93 Rewrite(LogFile);
94 try
95 if FirstRecord then
96 begin
97 Writeln(LogFile, '--- Log started at '+TimeToStr(Time)+' ---');
98 FirstRecord := False;
99 end;
100 case RecordCategory of
101 MSG_FATALERROR: Prefix := '!!!';
102 MSG_WARNING: Prefix := '! ';
103 MSG_NOTIFY: Prefix := '***';
104 end;
105 if WriteTime then
106 OutStr := '['+TimeToStr(Time)+'] '+Prefix+' '+TextLine
107 else
108 OutStr := Prefix+' '+TextLine;
109 Writeln(LogFile, OutStr);
110 if e_WriteToStdOut then
111 Writeln(OutStr);
112 finally
113 Close(LogFile);
114 end;
115 except // sorry
116 end;
117 end;
118 *)
121 // returns formatted string if `writerCB` is `nil`, empty string otherwise
122 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
123 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
126 var
130 begin
134 begin
145 var
155 begin
158 begin
166 var
170 begin
174 begin
180 begin
184 // print string
186 begin
193 continue;
195 // process newline
197 begin
208 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true);
211 begin
216 begin
218 begin
224 writeln;
230 begin
232 try
236 exit;
241 begin
247 if writeTime then begin xlogPrefix += '['; xlogPrefix += TimeToStr(Time); xlogPrefix += '] '; end;
259 begin
264 //if fopened then CloseFile(xlogFile);
269 begin
274 begin
275 try
285 begin
291 // ////////////////////////////////////////////////////////////////////////// //
292 (* Write/WriteLn driver *)
293 //
294 // control codes:
295 // CR, LF, BS
296 // TAB: tab space = 4
297 //
298 // userData[1]: current x (for tabs)
299 // userData[2]: #13 was eaten, we should skip next #10
300 //
301 type
304 const
310 var
315 begin
319 begin
320 // look for some special char
324 begin
329 {$IFDEF CBLOG}
331 {$ENDIF}
334 begin
340 continue;
342 // process special chars
346 // tab
348 begin
349 {$IFDEF CBLOG}
351 {$ENDIF}
352 repeat
356 continue;
358 // cr, lf
360 begin
361 {$IFDEF CBLOG}
363 {$ENDIF}
365 begin
370 continue;
379 begin
388 var
391 begin
401 begin
406 begin
412 begin
414 begin
417 begin
420 begin
435 begin
436 //e_InitWritelnDriver();