Link with C++ linker
[oweals/cde.git] / cde / programs / nsgmls / ConsoleOutput.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: ConsoleOutput.C /main/1 1996/07/29 16:48:10 cde-hp $ */
24 // Copyright (c) 1996 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30
31 #include "splib.h"
32 #include "ConsoleOutput.h"
33
34 #ifdef SP_WIDE_SYSTEM
35 #include <windows.h>
36 #include <io.h>
37 #endif
38
39 #ifdef SP_NAMESPACE
40 namespace SP_NAMESPACE {
41 #endif
42
43 #ifdef SP_WIDE_SYSTEM
44
45 class ConsoleOutputCharStream : public OutputCharStream {
46 public:
47   ConsoleOutputCharStream(HANDLE h);
48   void flush();
49   void flushBuf(Char);
50 private:
51   HANDLE h_;
52 };
53
54 OutputCharStream *ConsoleOutput::makeOutputCharStream(int fd)
55 {
56   HANDLE h = (HANDLE)_get_osfhandle(fd);
57   DWORD flags;
58   if (GetConsoleMode(h, &flags))
59     return new ConsoleOutputCharStream(h);
60   else
61     return 0;
62 }
63
64 ConsoleOutputCharStream::ConsoleOutputCharStream(HANDLE h)
65 : h_(h)
66 {
67 }
68
69 void ConsoleOutputCharStream::flush()
70 {
71 }
72
73 void ConsoleOutputCharStream::flushBuf(Char c)
74 {
75   DWORD nWritten;
76   unsigned short ch = c;
77   WriteConsoleW(h_, &ch, 1, &nWritten, 0);
78 }
79
80 #else /* not SP_WIDE_SYSTEM */
81
82 OutputCharStream *ConsoleOutput::makeOutputCharStream(int)
83 {
84   return 0;
85 }
86
87 #endif  /* not SP_WIDE_SYSTEM */
88
89 #ifdef SP_NAMESPACE
90 }
91 #endif