Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / nsgmls / ConsoleOutput.C
1 /* $XConsortium: ConsoleOutput.C /main/1 1996/07/29 16:48:10 cde-hp $ */
2 // Copyright (c) 1996 James Clark
3 // See the file COPYING for copying permission.
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include "splib.h"
10 #include "ConsoleOutput.h"
11
12 #ifdef SP_WIDE_SYSTEM
13 #include <windows.h>
14 #include <io.h>
15 #endif
16
17 #ifdef SP_NAMESPACE
18 namespace SP_NAMESPACE {
19 #endif
20
21 #ifdef SP_WIDE_SYSTEM
22
23 class ConsoleOutputCharStream : public OutputCharStream {
24 public:
25   ConsoleOutputCharStream(HANDLE h);
26   void flush();
27   void flushBuf(Char);
28 private:
29   HANDLE h_;
30 };
31
32 OutputCharStream *ConsoleOutput::makeOutputCharStream(int fd)
33 {
34   HANDLE h = (HANDLE)_get_osfhandle(fd);
35   DWORD flags;
36   if (GetConsoleMode(h, &flags))
37     return new ConsoleOutputCharStream(h);
38   else
39     return 0;
40 }
41
42 ConsoleOutputCharStream::ConsoleOutputCharStream(HANDLE h)
43 : h_(h)
44 {
45 }
46
47 void ConsoleOutputCharStream::flush()
48 {
49 }
50
51 void ConsoleOutputCharStream::flushBuf(Char c)
52 {
53   DWORD nWritten;
54   unsigned short ch = c;
55   WriteConsoleW(h_, &ch, 1, &nWritten, 0);
56 }
57
58 #else /* not SP_WIDE_SYSTEM */
59
60 OutputCharStream *ConsoleOutput::makeOutputCharStream(int)
61 {
62   return 0;
63 }
64
65 #endif  /* not SP_WIDE_SYSTEM */
66
67 #ifdef SP_NAMESPACE
68 }
69 #endif