Mercurial > projects > ldc
annotate tango/lib/compiler/llvmdc/util/console.d @ 133:44a95ac7368a trunk
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
In particular, assertions has been fixed to include file/line info, and much more!
author | lindquist |
---|---|
date | Mon, 14 Jan 2008 05:11:54 +0100 |
parents | 1700239cab2e |
children | e984333d6ac6 |
rev | line source |
---|---|
132 | 1 /******************************************************************************* |
2 | |
3 copyright: Copyright (c) 2004 Tango group. All rights reserved | |
4 | |
5 license: BSD style: $(LICENSE) | |
6 | |
7 version: Initial release: July 2006 | |
8 | |
9 | |
10 Various low-level console oriented utilities | |
11 | |
12 *******************************************************************************/ | |
13 | |
14 module util.console; | |
15 | |
16 private import util.string; | |
17 | |
18 version (Win32) | |
19 { | |
20 private extern (Windows) int GetStdHandle (int); | |
21 private extern (Windows) int WriteFile (int, char*, int, int*, void*); | |
22 } | |
23 | |
24 else | |
25 | |
26 version (Posix) | |
27 { | |
28 private extern (C) ptrdiff_t write (int, void*, size_t); | |
29 } | |
30 | |
31 /+ | |
32 // emit a char[] to the console. Note that Win32 does not handle utf8, but | |
33 // then neither does fprintf (stderr). This will handle redirection though. | |
34 // May need to remedy the utf8 issue | |
35 int console (char[] s) | |
36 { | |
37 version (Win32) | |
38 { | |
39 int count; | |
40 if (WriteFile (GetStdHandle(0xfffffff5), s.ptr, s.length, &count, null)) | |
41 return count; | |
42 return -1; | |
43 } | |
44 else | |
45 version (Posix) | |
46 { | |
47 return write (2, s.ptr, s.length); | |
48 } | |
49 } | |
50 | |
51 // emit an integer to the console | |
52 int console (uint i) | |
53 { | |
54 char[10] tmp = void; | |
55 | |
56 return console (intToUtf8 (tmp, i)); | |
57 } | |
58 +/ | |
59 | |
60 struct Console | |
61 { | |
62 Console opCall (char[] s) | |
63 { | |
64 version (Win32) | |
65 { | |
66 int count; | |
67 WriteFile (GetStdHandle(0xfffffff5), s.ptr, s.length, &count, null); | |
68 } | |
69 else | |
70 version (Posix) | |
71 { | |
72 write (2, s.ptr, s.length); | |
73 } | |
74 return *this; | |
75 } | |
76 | |
77 // emit an integer to the console | |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
78 Console opCall (size_t i) |
132 | 79 { |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
80 char[20] tmp = void; |
132 | 81 |
82 return console (intToUtf8 (tmp, i)); | |
83 } | |
84 } | |
85 | |
86 Console console; |