aboutsummaryrefslogtreecommitdiffhomepage
path: root/input_common.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-18 16:30:30 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-11-18 16:30:30 -0800
commit9992b8eb0e3366ff8a3948aa0b66a19c3c12c737 (patch)
tree6dda0fef85812016fbba9ea067c9d586092b506d /input_common.cpp
parentbab69f26724028d16054a3daf5c78aad7c67bb2d (diff)
Apply new indentation, brace, and whitespace style
Diffstat (limited to 'input_common.cpp')
-rw-r--r--input_common.cpp265
1 files changed, 133 insertions, 132 deletions
diff --git a/input_common.cpp b/input_common.cpp
index 8f973836..7795629f 100644
--- a/input_common.cpp
+++ b/input_common.cpp
@@ -51,9 +51,9 @@ static int (*interrupt_handler)();
static void (*poll_handler)();
-void input_common_init( int (*ih)() )
+void input_common_init(int (*ih)())
{
- interrupt_handler = ih;
+ interrupt_handler = ih;
}
void input_common_set_poll_callback(void (*handler)(void))
@@ -73,192 +73,193 @@ void input_common_destroy()
static wint_t readb()
{
/* do_loop must be set on every path through the loop; leaving it uninitialized allows the static analyzer to assist in catching mistakes. */
- unsigned char arr[1];
- bool do_loop;
+ unsigned char arr[1];
+ bool do_loop;
- do
- {
+ do
+ {
/* Invoke any poll handler */
if (poll_handler)
poll_handler();
- fd_set fdset;
- int fd_max=0;
- int ioport = iothread_port();
- int res;
+ fd_set fdset;
+ int fd_max=0;
+ int ioport = iothread_port();
+ int res;
- FD_ZERO( &fdset );
- FD_SET( 0, &fdset );
- if( env_universal_server.fd > 0 )
- {
- FD_SET( env_universal_server.fd, &fdset );
- if (fd_max < env_universal_server.fd) fd_max = env_universal_server.fd;
- }
- if (ioport > 0) {
- FD_SET( ioport, &fdset );
- if (fd_max < ioport) fd_max = ioport;
- }
+ FD_ZERO(&fdset);
+ FD_SET(0, &fdset);
+ if (env_universal_server.fd > 0)
+ {
+ FD_SET(env_universal_server.fd, &fdset);
+ if (fd_max < env_universal_server.fd) fd_max = env_universal_server.fd;
+ }
+ if (ioport > 0)
+ {
+ FD_SET(ioport, &fdset);
+ if (fd_max < ioport) fd_max = ioport;
+ }
- res = select( fd_max + 1, &fdset, 0, 0, 0 );
- if( res==-1 )
- {
- switch( errno )
- {
- case EINTR:
- case EAGAIN:
+ res = select(fd_max + 1, &fdset, 0, 0, 0);
+ if (res==-1)
{
- if( interrupt_handler )
- {
- int res = interrupt_handler();
- if( res )
+ switch (errno)
{
- return res;
- }
- if( lookahead_count )
+ case EINTR:
+ case EAGAIN:
{
- return lookahead_arr[--lookahead_count];
- }
+ if (interrupt_handler)
+ {
+ int res = interrupt_handler();
+ if (res)
+ {
+ return res;
+ }
+ if (lookahead_count)
+ {
+ return lookahead_arr[--lookahead_count];
+ }
- }
+ }
- do_loop = true;
- break;
+ do_loop = true;
+ break;
+ }
+ default:
+ {
+ /*
+ The terminal has been closed. Save and exit.
+ */
+ return R_EOF;
+ }
+ }
}
- default:
+ else
{
- /*
- The terminal has been closed. Save and exit.
- */
- return R_EOF;
- }
- }
- }
- else
- {
/* Assume we loop unless we see a character in stdin */
do_loop = true;
- if( env_universal_server.fd > 0 && FD_ISSET( env_universal_server.fd, &fdset ) )
+ if (env_universal_server.fd > 0 && FD_ISSET(env_universal_server.fd, &fdset))
{
- debug( 3, L"Wake up on universal variable event" );
+ debug(3, L"Wake up on universal variable event");
env_universal_read_all();
- if( lookahead_count )
+ if (lookahead_count)
{
return lookahead_arr[--lookahead_count];
}
}
- if ( ioport > 0 && FD_ISSET(ioport, &fdset))
- {
+ if (ioport > 0 && FD_ISSET(ioport, &fdset))
+ {
iothread_service_completion();
- if( lookahead_count )
+ if (lookahead_count)
{
return lookahead_arr[--lookahead_count];
}
- }
+ }
- if( FD_ISSET( STDIN_FILENO, &fdset ) )
- {
- if( read_blocked( 0, arr, 1 ) != 1 )
- {
- /* The teminal has been closed. Save and exit. */
- return R_EOF;
- }
+ if (FD_ISSET(STDIN_FILENO, &fdset))
+ {
+ if (read_blocked(0, arr, 1) != 1)
+ {
+ /* The teminal has been closed. Save and exit. */
+ return R_EOF;
+ }
/* We read from stdin, so don't loop */
- do_loop = false;
- }
+ do_loop = false;
+ }
+ }
}
- }
- while( do_loop );
+ while (do_loop);
- return arr[0];
+ return arr[0];
}
-wchar_t input_common_readch( int timed )
+wchar_t input_common_readch(int timed)
{
- if( lookahead_count == 0 )
- {
- if( timed )
+ if (lookahead_count == 0)
{
- int count;
- fd_set fds;
- struct timeval tm=
+ if (timed)
{
- 0,
- 1000 * WAIT_ON_ESCAPE
- }
- ;
-
- FD_ZERO( &fds );
- FD_SET( 0, &fds );
- count = select(1, &fds, 0, 0, &tm);
+ int count;
+ fd_set fds;
+ struct timeval tm=
+ {
+ 0,
+ 1000 * WAIT_ON_ESCAPE
+ }
+ ;
- switch( count )
- {
- case 0:
- return WEOF;
+ FD_ZERO(&fds);
+ FD_SET(0, &fds);
+ count = select(1, &fds, 0, 0, &tm);
- case -1:
- return WEOF;
- break;
- default:
- break;
+ switch (count)
+ {
+ case 0:
+ return WEOF;
- }
- }
+ case -1:
+ return WEOF;
+ break;
+ default:
+ break;
- wchar_t res;
- static mbstate_t state;
+ }
+ }
- while(1)
- {
- wint_t b = readb();
- char bb;
+ wchar_t res;
+ static mbstate_t state;
- size_t sz;
+ while (1)
+ {
+ wint_t b = readb();
+ char bb;
- if( (b >= R_NULL) && (b < R_NULL + 1000) )
- return b;
+ size_t sz;
- bb=b;
+ if ((b >= R_NULL) && (b < R_NULL + 1000))
+ return b;
- sz = mbrtowc( &res, &bb, 1, &state );
+ bb=b;
- switch( sz )
- {
- case (size_t)(-1):
- memset (&state, '\0', sizeof (state));
- debug( 2, L"Illegal input" );
- return R_NULL;
- case (size_t)(-2):
- break;
- case 0:
- return 0;
- default:
+ sz = mbrtowc(&res, &bb, 1, &state);
- return res;
- }
+ switch (sz)
+ {
+ case (size_t)(-1):
+ memset(&state, '\0', sizeof(state));
+ debug(2, L"Illegal input");
+ return R_NULL;
+ case (size_t)(-2):
+ break;
+ case 0:
+ return 0;
+ default:
+
+ return res;
+ }
+ }
}
- }
- else
- {
- if( !timed )
+ else
{
- while( (lookahead_count >= 0) && (lookahead_arr[lookahead_count-1] == WEOF) )
- lookahead_count--;
- if( lookahead_count == 0 )
- return input_common_readch(0);
- }
+ if (!timed)
+ {
+ while ((lookahead_count >= 0) && (lookahead_arr[lookahead_count-1] == WEOF))
+ lookahead_count--;
+ if (lookahead_count == 0)
+ return input_common_readch(0);
+ }
- return lookahead_arr[--lookahead_count];
- }
+ return lookahead_arr[--lookahead_count];
+ }
}
-void input_common_unreadch( wint_t ch )
+void input_common_unreadch(wint_t ch)
{
- lookahead_arr[lookahead_count++] = ch;
+ lookahead_arr[lookahead_count++] = ch;
}