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
24 type
40 // start Write/WriteLn driver. it will write everything to cbuf.
43 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
44 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
48 implementation
50 uses
51 {$IFDEF ANDROID}
52 SDL2,
53 {$ENDIF}
56 var
63 begin
67 begin
68 e_DeinitLog
73 begin
74 {$IFDEF FPC_LITTLE_ENDIAN}
75 Result := Format('%d.%d.%d.%d', [ip and $FF, (ip shr 8) and $FF, (ip shr 16) and $FF, (ip shr 24)]);
76 {$ELSE}
77 Result := Format('%d.%d.%d.%d', [(ip shr 24), (ip shr 16) and $FF, (ip shr 8) and $FF, ip and $FF]);
78 {$ENDIF}
83 begin
86 Exit;
92 begin
97 procedure e_LogWriteln (const s: AnsiString; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true);
98 begin
103 // returns formatted string if `writerCB` is `nil`, empty string otherwise
104 //function formatstrf (const fmt: AnsiString; args: array of const; writerCB: TFormatStrFCallback=nil): AnsiString;
105 //TFormatStrFCallback = procedure (constref buf; len: SizeUInt);
108 var
112 {$IFDEF ANDROID}
114 {$ENDIF}
115 begin
119 {$IFDEF ANDROID}
126 {$ENDIF}
129 begin
140 var
150 begin
153 begin
161 var
165 begin
169 begin
175 begin
179 // print string
181 begin
188 continue;
190 // process newline
192 begin
203 procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: TMsgType=TMsgType.Notify; writeTime: Boolean=true; writeConsole: Boolean=true);
206 begin
211 begin
213 begin
219 writeln;
225 begin
227 try
231 exit;
236 begin
242 if writeTime then begin xlogPrefix += '['; xlogPrefix += TimeToStr(Time); xlogPrefix += '] '; end;
254 begin
259 //if fopened then CloseFile(xlogFile);
264 begin
269 begin
270 try
279 {$I-}
281 var
283 begin
286 begin
292 if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end;
298 begin
304 // ////////////////////////////////////////////////////////////////////////// //
305 (* Write/WriteLn driver *)
306 //
307 // control codes:
308 // CR, LF, BS
309 // TAB: tab space = 4
310 //
311 // userData[1]: current x (for tabs)
312 // userData[2]: #13 was eaten, we should skip next #10
313 //
314 type
317 const
323 var
328 begin
332 begin
333 // look for some special char
337 begin
342 {$IFDEF CBLOG}
344 {$ENDIF}
347 begin
353 continue;
355 // process special chars
359 // tab
361 begin
362 {$IFDEF CBLOG}
364 {$ENDIF}
365 repeat
369 continue;
371 // cr, lf
373 begin
374 {$IFDEF CBLOG}
376 {$ENDIF}
378 begin
383 continue;
392 begin
401 var
404 begin
414 begin
419 begin
425 begin
427 begin
430 begin
433 begin
448 begin
449 //e_InitWritelnDriver();