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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 {$R-}
17 { $DEFINE CBLOG}
20 interface
22 uses
23 SysUtils;
25 type
39 // start Write/WriteLn driver. it will write everything to cbuf.
42 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
43 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
47 implementation
49 uses
50 {$IFDEF ANDROID}
51 SDL2,
52 {$ENDIF}
55 var
62 begin
63 {$IFDEF FPC_LITTLE_ENDIAN}
64 Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]);
65 {$ELSE}
66 Result := Format('%d.%d.%d.%d', [(ip shr 24), (ip shr 16) and $FF, (ip shr 8) and $FF, ip and $FF]);
67 {$ENDIF}
72 begin
75 Exit;
81 begin
86 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
87 begin
92 // returns formatted string if `writerCB` is `nil`, empty string otherwise
93 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
94 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
97 var
101 {$IFDEF ANDROID}
103 {$ENDIF}
104 begin
108 {$IFDEF ANDROID}
115 {$ENDIF}
118 begin
129 var
139 begin
142 begin
150 var
154 begin
158 begin
164 begin
168 // print string
170 begin
177 continue;
179 // process newline
181 begin
192 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
195 begin
200 begin
202 begin
208 writeln;
214 begin
216 try
220 exit;
225 begin
231 if writeTime then begin xlogPrefix += '['; xlogPrefix += TimeToStr(Time); xlogPrefix += '] '; end;
243 begin
248 //if fopened then CloseFile(xlogFile);
253 begin
258 begin
259 try
268 {$I-}
270 var
272 begin
275 begin
281 if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end;
287 begin
293 // ////////////////////////////////////////////////////////////////////////// //
294 (* Write/WriteLn driver *)
295 //
296 // control codes:
297 // CR, LF, BS
298 // TAB: tab space = 4
299 //
300 // userData[1]: current x (for tabs)
301 // userData[2]: #13 was eaten, we should skip next #10
302 //
303 type
306 const
312 var
317 begin
321 begin
322 // look for some special char
326 begin
331 {$IFDEF CBLOG}
333 {$ENDIF}
336 begin
342 continue;
344 // process special chars
348 // tab
350 begin
351 {$IFDEF CBLOG}
353 {$ENDIF}
354 repeat
358 continue;
360 // cr, lf
362 begin
363 {$IFDEF CBLOG}
365 {$ENDIF}
367 begin
372 continue;
381 begin
390 var
393 begin
403 begin
408 begin
414 begin
416 begin
419 begin
422 begin
437 begin
438 //e_InitWritelnDriver();