diff options
author | Łukasz Niemier <lukasz@niemier.pl> | 2012-11-18 11:23:22 +0100 |
---|---|---|
committer | Łukasz Niemier <lukasz@niemier.pl> | 2012-11-18 11:23:22 +0100 |
commit | 47df1ae40adecd0a02fc7dd06ab0745cb18c3fe0 (patch) | |
tree | 13bf3e8fdcae60fdfb5fa5e26c95818dc7a49790 /key_reader.cpp | |
parent | b79854ad1aa814d9d35d76a1929b4726fa4bffa5 (diff) |
Remove trailing whitespaces and change tabs to spaces
Diffstat (limited to 'key_reader.cpp')
-rw-r--r-- | key_reader.cpp | 140 |
1 files changed, 70 insertions, 70 deletions
diff --git a/key_reader.cpp b/key_reader.cpp index c61e80b7..d126af7b 100644 --- a/key_reader.cpp +++ b/key_reader.cpp @@ -1,9 +1,9 @@ /* A small utility to print the resulting key codes from pressing a - key. Servers the same function as hitting ^V in bash, but I prefer - the way key_reader works. + key. Servers the same function as hitting ^V in bash, but I prefer + the way key_reader works. - Type ^C to exit the program. + Type ^C to exit the program. */ #include "config.h" @@ -22,76 +22,76 @@ int writestr( char *str ) { - write( 1, str, strlen(str) ); - return 0; + write( 1, str, strlen(str) ); + return 0; } int main( int argc, char **argv) { - set_main_thread(); + set_main_thread(); setup_fork_guards(); - setlocale( LC_ALL, "" ); - - - if( argc == 2 ) - { - static char term_buffer[2048]; - char *termtype = getenv ("TERM"); - char *tbuff = new char[9999]; - char *res; - - tgetent( term_buffer, termtype ); - res = tgetstr( argv[1], &tbuff ); - if( res != 0 ) - { - while( *res != 0 ) - { - printf("%d ", *res ); - - - res++; - } - printf( "\n" ); - } - else - { - printf("Undefined sequence\n"); - } - } - else - { - char scratch[1024]; - unsigned int c; - - struct termios modes, /* so we can change the modes */ - savemodes; /* so we can reset the modes when we're done */ - - input_common_init(0); - - - tcgetattr(0,&modes); /* get the current terminal modes */ - savemodes = modes; /* save a copy so we can reset them */ - - modes.c_lflag &= ~ICANON; /* turn off canonical mode */ - modes.c_lflag &= ~ECHO; /* turn off echo mode */ - modes.c_cc[VMIN]=1; - modes.c_cc[VTIME]=0; - tcsetattr(0,TCSANOW,&modes); /* set the new modes */ - while(1) - { - if( (c=input_common_readch(0)) == EOF ) - break; - if( (c > 31) && (c != 127) ) - sprintf( scratch, "dec: %d hex: %x char: %c\n", c, c, c ); - else - sprintf( scratch, "dec: %d hex: %x\n", c, c ); - writestr( scratch ); - } - /* reset the terminal to the saved mode */ - tcsetattr(0,TCSANOW,&savemodes); - - input_common_destroy(); - } - - return 0; + setlocale( LC_ALL, "" ); + + + if( argc == 2 ) + { + static char term_buffer[2048]; + char *termtype = getenv ("TERM"); + char *tbuff = new char[9999]; + char *res; + + tgetent( term_buffer, termtype ); + res = tgetstr( argv[1], &tbuff ); + if( res != 0 ) + { + while( *res != 0 ) + { + printf("%d ", *res ); + + + res++; + } + printf( "\n" ); + } + else + { + printf("Undefined sequence\n"); + } + } + else + { + char scratch[1024]; + unsigned int c; + + struct termios modes, /* so we can change the modes */ + savemodes; /* so we can reset the modes when we're done */ + + input_common_init(0); + + + tcgetattr(0,&modes); /* get the current terminal modes */ + savemodes = modes; /* save a copy so we can reset them */ + + modes.c_lflag &= ~ICANON; /* turn off canonical mode */ + modes.c_lflag &= ~ECHO; /* turn off echo mode */ + modes.c_cc[VMIN]=1; + modes.c_cc[VTIME]=0; + tcsetattr(0,TCSANOW,&modes); /* set the new modes */ + while(1) + { + if( (c=input_common_readch(0)) == EOF ) + break; + if( (c > 31) && (c != 127) ) + sprintf( scratch, "dec: %d hex: %x char: %c\n", c, c, c ); + else + sprintf( scratch, "dec: %d hex: %x\n", c, c ); + writestr( scratch ); + } + /* reset the terminal to the saved mode */ + tcsetattr(0,TCSANOW,&savemodes); + + input_common_destroy(); + } + + return 0; } |