comparison tango/lib/compiler/llvmdc/util/console.d @ 132:1700239cab2e trunk

[svn r136] MAJOR UNSTABLE UPDATE!!! Initial commit after moving to Tango instead of Phobos. Lots of bugfixes... This build is not suitable for most things.
author lindquist
date Fri, 11 Jan 2008 17:57:40 +0100
parents
children 44a95ac7368a
comparison
equal deleted inserted replaced
131:5825d48b27d1 132:1700239cab2e
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
78 Console opCall (uint i)
79 {
80 char[10] tmp = void;
81
82 return console (intToUtf8 (tmp, i));
83 }
84 }
85
86 Console console;