1 (*
2 * Hedgewars, a free turn based strategy game
3 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *)
18
19 {$INCLUDE "options.inc"}
20
21 unit uConsole;
22 interface
23
24
25 procedure WriteToConsole(s: shortstring);
26 procedure WriteLnToConsole(s: shortstring);
27
28 var lastConsoleline : shortstring;
29
30 implementation
31 uses uUtils {$IFDEF ANDROID}, log in 'log.pas'{$ENDIF};
32
33
34 procedure WriteToConsole(s: shortstring);
35 begin
36 {$IFNDEF NOCONSOLE}
37 AddFileLog('[Con] ' + s);
38 {$IFDEF ANDROID}
innull39 //TODO integrate this function in the uMobile record
40 Log.__android_log_write(Log.Android_LOG_DEBUG, 'HW_Engine', ShortStringAsPChar('[Con]' + s));
41 {$ELSE}
42 Write(stderr, s);
43 {$ENDIF}
44 {$ENDIF}
45 end;
46
47 procedure WriteLnToConsole(s: shortstring);
48 begin
49 {$IFNDEF NOCONSOLE}
50 WriteToConsole(s);
51 {$IFNDEF ANDROID}
52 WriteLn(stderr, '');
53 {$ENDIF}
54 {$ENDIF}
55 lastConsoleline:= s;
56 end;
57 {$IFDEF ANDROID}
ShortStringAsPCharnull58 function ShortStringAsPChar(s: shortstring) : PChar;
59 begin
60 if Length(s) = High(s) then
61 Dec(s[0]);
62 s[Ord(Length(s))+1] := #0;
63 // returning pointer to stack, rly?
64 ShortStringAsPChar:= @s[1];
65 end;
66 {$ENDIF}
67
68 end.
69