1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
/*
FALCON - The Falcon Programming Language
FILE: vm_stdstreams_win.cpp
Windows specific standard streams factories.
-------------------------------------------------------------------
Author: Giancarlo Niccolai
Begin: ven ago 25 2006
-------------------------------------------------------------------
(C) Copyright 2004: the FALCON developers (see list in AUTHORS file)
See LICENSE file for licensing details.
*/
/** \file
Windows specifi standard streams factories.
Actually, the same as unix, but using also the CRLF transcoder.
*/
#include <falcon/fstream.h>
#include <falcon/transcoding.h>
#include <falcon/stdstreams.h>
#include <falcon/streambuffer.h>
namespace Falcon {
Stream *stdInputStream()
{
Stream *stdin = new StreamBuffer( new StdInStream );
String enc;
Falcon::Transcoder *coder;
if ( Falcon::GetSystemEncoding( enc ) )
{
coder = Falcon::TranscoderFactory( enc );
if ( coder == 0 ) {
coder = new TranscoderByte(0);
}
}
else
coder = new TranscoderByte(0);
coder->setUnderlying( stdin, true );
/*Falcon::Transcoder *wincoder = new TranscoderEOL(0);
wincoder->setUnderlying( coder, true );*/
return coder;
}
Stream *stdOutputStream()
{
Stream *stdout = new StreamBuffer( new StdOutStream );
String enc;
Falcon::Transcoder *coder;
if ( Falcon::GetSystemEncoding( enc ) )
{
coder = Falcon::TranscoderFactory( enc );
if ( coder == 0 ) {
coder = new TranscoderByte(0);
}
}
else
coder = new TranscoderByte(0);
coder->setUnderlying( stdout, true );
Falcon::Transcoder *wincoder = new TranscoderEOL(0);
wincoder->setUnderlying( coder, true );
return wincoder;
}
Stream *stdErrorStream()
{
Stream *stderr = new StreamBuffer( new StdErrStream );
String enc;
Falcon::Transcoder *coder;
if ( Falcon::GetSystemEncoding( enc ) )
{
coder = Falcon::TranscoderFactory( enc );
if ( coder == 0 ) {
coder = new TranscoderByte(0);
}
}
else
coder = new TranscoderByte(0);
coder->setUnderlying( stderr, true );
Falcon::Transcoder *wincoder = new TranscoderEOL(0);
wincoder->setUnderlying( coder, true );
return wincoder;
}
Stream *DefaultTextTranscoder( Stream *underlying, bool own )
{
String encoding;
if ( ! GetSystemEncoding( encoding ) )
{
Falcon::Transcoder *wincoder = new TranscoderEOL(0);
wincoder->setUnderlying( underlying, own );
return wincoder;
}
Transcoder *encap = TranscoderFactory( encoding );
encap->setUnderlying( underlying, own );
// the wincoder owns the underlying for sure.
Falcon::Transcoder *wincoder = new TranscoderEOL(0);
wincoder->setUnderlying( encap, true );
return wincoder;
}
Stream *AddSystemEOL( Stream *underlying, bool own )
{
return new TranscoderEOL( underlying, own );
}
}
/* end of stdstreams_win.cpp */
|