"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/lib/ConsoleOutput.cxx" (21 Jul 2005, 1298 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "ConsoleOutput.cxx" see the Fossies "Dox" file reference documentation.

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