-/* $Id$
-
-This file is part of libmspio
-Copyright © 2008 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
#ifndef WIN32
#include <errno.h>
#include <fcntl.h>
if(n>2)
throw InvalidParameterValue("Invalid parameter for Console::Console");
- mode=(n==0 ? M_READ : M_WRITE);
+ mode = (n==0 ? M_READ : M_WRITE);
#ifdef WIN32
switch(n)
{
- case 0: handle=GetStdHandle(STD_INPUT_HANDLE); break;
- case 1: handle=GetStdHandle(STD_OUTPUT_HANDLE); break;
- case 2: handle=GetStdHandle(STD_ERROR_HANDLE); break;
+ case 0: handle = GetStdHandle(STD_INPUT_HANDLE); break;
+ case 1: handle = GetStdHandle(STD_OUTPUT_HANDLE); break;
+ case 2: handle = GetStdHandle(STD_ERROR_HANDLE); break;
}
#else
- handle=n;
+ handle = n;
if(handle==0)
tcgetattr(handle, &orig_attr);
// XXX Dunno how to do this in win32
(void)b;
#else
- int flags=fcntl(0, F_GETFL);
- flags=(flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
+ int flags = fcntl(0, F_GETFL);
+ flags = (flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
fcntl(0, F_SETFL, flags);
#endif
}
#else
termios t;
tcgetattr(0, &t);
- t.c_lflag=(t.c_lflag&~ECHO) | (e?ECHO:0);
+ t.c_lflag = (t.c_lflag&~ECHO) | (e?ECHO:0);
tcsetattr(0, TCSADRAIN, &t);
#endif
}
// XXX ICANON does more than just set line buffering, may need a bit more thought
termios t;
tcgetattr(0, &t);
- t.c_lflag=(t.c_lflag&~ICANON) | (l?ICANON:0);
+ t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0);
tcsetattr(0, TCSADRAIN, &t);
#endif
}
#ifdef WIN32
// XXX Figure out how to do this
- rows=24;
- cols=80;
+ rows = 24;
+ cols = 80;
#else
struct winsize wsz;
ioctl(handle, TIOCGWINSZ, &wsz);
- rows=wsz.ws_row;
- cols=wsz.ws_col;
+ rows = wsz.ws_row;
+ cols = wsz.ws_col;
#endif
}
if(!WriteFile(handle, buf, len, &ret, 0))
throw SystemError("Writing to console failed", GetLastError());
#else
- int ret=::write(handle, buf, len);
+ int ret = ::write(handle, buf, len);
if(ret==-1)
throw SystemError("Writing to console failed", errno);
#endif
if(!ReadFile(handle, buf, len, &ret, 0))
throw SystemError("Reading from console failed", GetLastError());
#else
- int ret=::read(handle, buf, len);
+ int ret = ::read(handle, buf, len);
if(ret==-1)
{
if(errno==EAGAIN)
throw SystemError("Reading from console failed", errno);
}
else if(ret==0)
- eof_flag=true;
+ eof_flag = true;
#endif
return ret;
throw InvalidParameterValue("Unknown Console instance requested");
}
-Console &cin=Console::instance(0);
-Console &cout=Console::instance(1);
-Console &cerr=Console::instance(2);
+Console &cin = Console::instance(0);
+Console &cout = Console::instance(1);
+Console &cerr = Console::instance(2);
} // namespace IO
} // namespace Msp