+56
-41
@@ -44,6 +44,7 @@
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <limits.h>
|
||||
#include <exception>
|
||||
|
||||
#if HAVE_PTY_H
|
||||
#include <pty.h>
|
||||
@@ -64,49 +65,63 @@ using namespace Terminal;
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
int fbmod = 0;
|
||||
int width = 80, height = 24;
|
||||
int iterations = ITERATIONS;
|
||||
if (argc > 1) iterations = atoi(argv[1]);
|
||||
if (argc > 3) {
|
||||
width = atoi(argv[2]);
|
||||
height = atoi(argv[3]);
|
||||
}
|
||||
Framebuffer local_framebuffers[ 2 ] = { Framebuffer(width,height), Framebuffer(width,height) };
|
||||
Framebuffer *local_framebuffer = &(local_framebuffers[ fbmod ]);
|
||||
Framebuffer *new_state = &(local_framebuffers[ !fbmod ]);
|
||||
Overlay::OverlayManager overlays;
|
||||
Display display( true );
|
||||
Complete local_terminal( width, height );
|
||||
|
||||
/* Adopt native locale */
|
||||
set_native_locale();
|
||||
fatal_assert( is_utf8_locale() );
|
||||
|
||||
for ( int i = 0; i < iterations; i++ ) {
|
||||
/* type a character */
|
||||
overlays.get_prediction_engine().new_user_byte( i + 'x', *local_framebuffer );
|
||||
|
||||
/* fetch target state */
|
||||
*new_state = local_terminal.get_fb();
|
||||
|
||||
/* apply local overlays */
|
||||
overlays.apply( *new_state );
|
||||
|
||||
/* calculate minimal difference from where we are */
|
||||
const string diff( display.new_frame( false,
|
||||
*local_framebuffer,
|
||||
*new_state ) );
|
||||
|
||||
/* make sure to use diff */
|
||||
if ( diff.size() > INT_MAX ) {
|
||||
exit( 1 );
|
||||
try {
|
||||
int fbmod = 0;
|
||||
int width = 80, height = 24;
|
||||
int iterations = ITERATIONS;
|
||||
if (argc > 1) {
|
||||
iterations = atoi(argv[1]);
|
||||
if (iterations < 1 || iterations > 1000000000) {
|
||||
fprintf(stderr, "bogus iteration count\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (argc > 3) {
|
||||
width = atoi(argv[2]);
|
||||
height = atoi(argv[3]);
|
||||
if (width < 1 || width > 1000 || height < 1 || height > 1000) {
|
||||
fprintf(stderr, "bogus window size\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
Framebuffer local_framebuffers[ 2 ] = { Framebuffer(width,height), Framebuffer(width,height) };
|
||||
Framebuffer *local_framebuffer = &(local_framebuffers[ fbmod ]);
|
||||
Framebuffer *new_state = &(local_framebuffers[ !fbmod ]);
|
||||
Overlay::OverlayManager overlays;
|
||||
Display display( true );
|
||||
Complete local_terminal( width, height );
|
||||
|
||||
fbmod = !fbmod;
|
||||
local_framebuffer = &(local_framebuffers[ fbmod ]);
|
||||
new_state = &(local_framebuffers[ !fbmod ]);
|
||||
/* Adopt native locale */
|
||||
set_native_locale();
|
||||
fatal_assert( is_utf8_locale() );
|
||||
|
||||
for ( int i = 0; i < iterations; i++ ) {
|
||||
/* type a character */
|
||||
overlays.get_prediction_engine().new_user_byte( i + 'x', *local_framebuffer );
|
||||
|
||||
/* fetch target state */
|
||||
*new_state = local_terminal.get_fb();
|
||||
|
||||
/* apply local overlays */
|
||||
overlays.apply( *new_state );
|
||||
|
||||
/* calculate minimal difference from where we are */
|
||||
const string diff( display.new_frame( false,
|
||||
*local_framebuffer,
|
||||
*new_state ) );
|
||||
|
||||
/* make sure to use diff */
|
||||
if ( diff.size() > INT_MAX ) {
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
fbmod = !fbmod;
|
||||
local_framebuffer = &(local_framebuffers[ fbmod ]);
|
||||
new_state = &(local_framebuffers[ !fbmod ]);
|
||||
}
|
||||
} catch ( const std::exception &e ) {
|
||||
fprintf( stderr, "Exception caught: %s\n", e.what() );
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+7
-11
@@ -65,13 +65,12 @@ int main( int argc, char *argv[] )
|
||||
} else {
|
||||
n = new Transport<UserStream, UserStream>( me, remote, NULL, NULL );
|
||||
}
|
||||
} catch ( const CryptoException &e ) {
|
||||
fprintf( stderr, "Fatal error: %s\n", e.what() );
|
||||
fprintf( stderr, "Port bound is %s, key is %s\n", n->port().c_str(), n->get_key().c_str() );
|
||||
} catch ( const std::exception &e ) {
|
||||
fprintf( stderr, "Fatal startup error: %s\n", e.what() );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
fprintf( stderr, "Port bound is %s, key is %s\n", n->port().c_str(), n->get_key().c_str() );
|
||||
|
||||
if ( server ) {
|
||||
Select &sel = Select::get_instance();
|
||||
uint64_t last_num = n->get_remote_state_num();
|
||||
@@ -97,8 +96,8 @@ int main( int argc, char *argv[] )
|
||||
last_num = n->get_remote_state_num();
|
||||
}
|
||||
}
|
||||
} catch ( const CryptoException &e ) {
|
||||
fprintf( stderr, "Cryptographic error: %s\n", e.what() );
|
||||
} catch ( const std::exception &e ) {
|
||||
fprintf( stderr, "Server error: %s\n", e.what() );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -163,11 +162,8 @@ int main( int argc, char *argv[] )
|
||||
if ( network_ready_to_read ) {
|
||||
n->recv();
|
||||
}
|
||||
} catch ( const NetworkException &e ) {
|
||||
fprintf( stderr, "%s\n", e.what() );
|
||||
break;
|
||||
} catch ( const CryptoException &e ) {
|
||||
fprintf( stderr, "Cryptographic error: %s\n", e.what() );
|
||||
} catch ( const std::exception &e ) {
|
||||
fprintf( stderr, "Client error: %s\n", e.what() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/time.h>
|
||||
#include <exception>
|
||||
|
||||
#if HAVE_PTY_H
|
||||
#include <pty.h>
|
||||
@@ -123,7 +124,7 @@ int main( int argc, char *argv[] )
|
||||
} else {
|
||||
/* get shell name */
|
||||
my_argv[ 0 ] = getenv( "SHELL" );
|
||||
if ( my_argv[ 0 ] == NULL ) {
|
||||
if ( my_argv[ 0 ] == NULL || *my_argv[ 0 ] == '\0' ) {
|
||||
struct passwd *pw = getpwuid( geteuid() );
|
||||
if ( pw == NULL ) {
|
||||
perror( "getpwuid" );
|
||||
@@ -151,7 +152,11 @@ int main( int argc, char *argv[] )
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
emulate_terminal( master );
|
||||
try {
|
||||
emulate_terminal( master );
|
||||
} catch ( const std::exception &e ) {
|
||||
fprintf( stderr, "\r\nException caught: %s\r\n", e.what() );
|
||||
}
|
||||
|
||||
if ( tcsetattr( STDIN_FILENO, TCSANOW, &saved_termios ) < 0 ) {
|
||||
perror( "tcsetattr" );
|
||||
|
||||
Reference in New Issue
Block a user