X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Fconsole.cpp;h=a0e0c28f07cbbd506683cb92166f3def8b57b93a;hp=32b37ef745553811fc4a341d55ad7b3789e256da;hb=31e72f50fbb34d86877e5110401c49ce3fefd4bb;hpb=378ec811c8df431f5b4e7094eb1949476d3a79fe diff --git a/source/io/console.cpp b/source/io/console.cpp index 32b37ef..a0e0c28 100644 --- a/source/io/console.cpp +++ b/source/io/console.cpp @@ -6,6 +6,7 @@ #endif #include #include "console.h" +#include "handle_private.h" using namespace std; @@ -30,15 +31,15 @@ Console::Console(unsigned n) #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); + if(n==0) + tcgetattr(*handle, &orig_attr); #endif if(n==0) @@ -49,7 +50,7 @@ Console::~Console() { #ifndef WIN32 if(handle==0) - tcsetattr(handle, TCSADRAIN, &orig_attr); + tcsetattr(*handle, TCSADRAIN, &orig_attr); #endif } @@ -59,9 +60,9 @@ void Console::set_block(bool b) // XXX Dunno how to do this in win32 (void)b; #else - int flags = fcntl(0, F_GETFL); + int flags = fcntl(*handle, F_GETFL); flags = (flags&~O_NONBLOCK) | (b?0:O_NONBLOCK); - fcntl(0, F_SETFL, flags); + fcntl(*handle, F_SETFL, flags); #endif } @@ -72,13 +73,13 @@ void Console::set_local_echo(bool e) #ifdef WIN32 DWORD m; - GetConsoleMode(handle, &m); - SetConsoleMode(handle, (m&~ENABLE_ECHO_INPUT) | (e?ENABLE_ECHO_INPUT:0)); + GetConsoleMode(*handle, &m); + SetConsoleMode(*handle, (m&~ENABLE_ECHO_INPUT) | (e?ENABLE_ECHO_INPUT:0)); #else termios t; - tcgetattr(0, &t); + tcgetattr(*handle, &t); t.c_lflag = (t.c_lflag&~ECHO) | (e?ECHO:0); - tcsetattr(0, TCSADRAIN, &t); + tcsetattr(*handle, TCSADRAIN, &t); #endif } @@ -89,14 +90,14 @@ void Console::set_line_buffer(bool l) #ifdef WIN32 DWORD m; - GetConsoleMode(handle, &m); - SetConsoleMode(handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)); + GetConsoleMode(*handle, &m); + SetConsoleMode(*handle, (m&~ENABLE_LINE_INPUT) | (l?ENABLE_LINE_INPUT:0)); #else // XXX ICANON does more than just set line buffering, may need a bit more thought termios t; - tcgetattr(0, &t); + tcgetattr(*handle, &t); t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0); - tcsetattr(0, TCSADRAIN, &t); + tcsetattr(*handle, TCSADRAIN, &t); #endif } @@ -111,7 +112,7 @@ void Console::get_size(unsigned &rows, unsigned &cols) cols = 80; #else struct winsize wsz; - ioctl(handle, TIOCGWINSZ, &wsz); + ioctl(*handle, TIOCGWINSZ, &wsz); rows = wsz.ws_row; cols = wsz.ws_col; #endif @@ -124,10 +125,10 @@ unsigned Console::do_write(const char *buf, unsigned len) #ifdef WIN32 DWORD ret; - if(!WriteFile(handle, buf, len, &ret, 0)) + if(!WriteFile(*handle, buf, len, &ret, 0)) throw system_error("WriteFile"); #else - int ret = ::write(handle, buf, len); + int ret = ::write(*handle, buf, len); if(ret==-1) throw system_error("write"); #endif @@ -142,10 +143,10 @@ unsigned Console::do_read(char *buf, unsigned len) #ifdef WIN32 DWORD ret; - if(!ReadFile(handle, buf, len, &ret, 0)) + if(!ReadFile(*handle, buf, len, &ret, 0)) throw system_error("ReadFile"); #else - int ret = ::read(handle, buf, len); + int ret = ::read(*handle, buf, len); if(ret==-1) { if(errno==EAGAIN) @@ -160,11 +161,6 @@ unsigned Console::do_read(char *buf, unsigned len) return ret; } -Handle Console::get_event_handle() -{ - return 0; -} - Console &Console::instance(unsigned n) { static Console in(0);