X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fconsole.cpp;h=fed47bef04c25445b215aa857ca28433ea9251aa;hp=f606a09fcceb64406500dac6c00d9b532b108244;hb=49c1f3c3ffdf318579a809f3f800442c0c76c818;hpb=41ea778b16825c3c701c6600a76eaf628831f028 diff --git a/source/console.cpp b/source/console.cpp index f606a09..fed47be 100644 --- a/source/console.cpp +++ b/source/console.cpp @@ -1,10 +1,3 @@ -/* $Id$ - -This file is part of libmspio -Copyright © 2008 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - #ifndef WIN32 #include #include @@ -30,17 +23,17 @@ Console::Console(unsigned n) 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); @@ -64,8 +57,8 @@ void Console::set_block(bool b) // 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 } @@ -82,7 +75,7 @@ void Console::set_local_echo(bool e) #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 } @@ -100,7 +93,7 @@ void Console::set_line_buffer(bool l) // 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 } @@ -112,13 +105,13 @@ void Console::get_size(unsigned &rows, unsigned &cols) #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 } @@ -137,7 +130,7 @@ unsigned Console::do_write(const char *buf, unsigned len) 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 @@ -155,7 +148,7 @@ unsigned Console::do_read(char *buf, unsigned len) 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) @@ -164,7 +157,7 @@ unsigned Console::do_read(char *buf, unsigned len) throw SystemError("Reading from console failed", errno); } else if(ret==0) - eof_flag=true; + eof_flag = true; #endif return ret; @@ -186,9 +179,9 @@ Console &Console::instance(unsigned n) 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