diff --git a/src/crypto/base64.cc b/src/crypto/base64.cc index 098785922..fb1c0aad3 100644 --- a/src/crypto/base64.cc +++ b/src/crypto/base64.cc @@ -62,21 +62,21 @@ static const unsigned char reverse[] = { /* Reverse maps from an ASCII char to a base64 sixbit value. Returns > 0x3f on * failure. */ -static unsigned char base64_char_to_sixbit( unsigned char c ) -{ +static unsigned char base64_char_to_sixbit( unsigned char c ) { return reverse[ c ]; } bool base64_decode( const char *b64, const size_t b64_len, uint8_t *raw, - size_t *raw_len ) -{ + size_t *raw_len ) { fatal_assert( b64_len == 24 ); /* only useful for Mosh keys */ fatal_assert( *raw_len == 16 ); uint32_t bytes = 0; for ( int i = 0; i < 22; i++ ) { unsigned char sixbit = base64_char_to_sixbit( *( b64++ ) ); - if ( sixbit > 0x3f ) { return false; } + if ( sixbit > 0x3f ) { + return false; + } bytes <<= 6; bytes |= sixbit; /* write groups of 3 */ @@ -90,13 +90,14 @@ bool base64_decode( const char *b64, const size_t b64_len, uint8_t *raw, } /* last byte of output */ *raw = bytes >> 4; - if ( b64[ 0 ] != '=' || b64[ 1 ] != '=' ) { return false; } + if ( b64[ 0 ] != '=' || b64[ 1 ] != '=' ) { + return false; + } return true; } void base64_encode( const uint8_t *raw, const size_t raw_len, char *b64, - const size_t b64_len ) -{ + const size_t b64_len ) { fatal_assert( b64_len == 24 ); /* only useful for Mosh keys */ fatal_assert( raw_len == 16 ); diff --git a/src/crypto/byteorder.h b/src/crypto/byteorder.h index c7056e792..4994edf6a 100644 --- a/src/crypto/byteorder.h +++ b/src/crypto/byteorder.h @@ -70,8 +70,7 @@ /* Use unions rather than casts, to comply with strict aliasing rules. */ -inline uint64_t htobe64( uint64_t x ) -{ +inline uint64_t htobe64( uint64_t x ) { uint8_t xs[ 8 ] = { static_cast( ( x >> 56 ) & 0xFF ), static_cast( ( x >> 48 ) & 0xFF ), static_cast( ( x >> 40 ) & 0xFF ), @@ -88,8 +87,7 @@ inline uint64_t htobe64( uint64_t x ) return *u.p64; } -inline uint64_t be64toh( uint64_t x ) -{ +inline uint64_t be64toh( uint64_t x ) { union { const uint8_t *p8; const uint64_t *p64; @@ -101,8 +99,7 @@ inline uint64_t be64toh( uint64_t x ) | ( uint64_t( u.p8[ 6 ] ) << 8 ) | ( uint64_t( u.p8[ 7 ] ) ); } -inline uint16_t htobe16( uint16_t x ) -{ +inline uint16_t htobe16( uint16_t x ) { uint8_t xs[ 2 ] = { static_cast( ( x >> 8 ) & 0xFF ), static_cast( (x)&0xFF ) }; union { @@ -113,8 +110,7 @@ inline uint16_t htobe16( uint16_t x ) return *u.p16; } -inline uint16_t be16toh( uint16_t x ) -{ +inline uint16_t be16toh( uint16_t x ) { union { const uint8_t *p8; const uint16_t *p16; diff --git a/src/crypto/crypto.cc b/src/crypto/crypto.cc index b02aaaa2e..c16d0b769 100644 --- a/src/crypto/crypto.cc +++ b/src/crypto/crypto.cc @@ -46,8 +46,7 @@ using namespace Crypto; -long int myatoi( const char *str ) -{ +long int myatoi( const char *str ) { char *end; errno = 0; @@ -60,17 +59,17 @@ long int myatoi( const char *str ) return ret; } -uint64_t Crypto::unique( void ) -{ +uint64_t Crypto::unique( void ) { static uint64_t counter = 0; uint64_t rv = counter++; - if ( counter == 0 ) { throw CryptoException( "Counter wrapped", true ); } + if ( counter == 0 ) { + throw CryptoException( "Counter wrapped", true ); + } return rv; } AlignedBuffer::AlignedBuffer( size_t len, const char *data ) - : m_len( len ), m_allocated( NULL ), m_data( NULL ) -{ + : m_len( len ), m_allocated( NULL ), m_data( NULL ) { size_t alloc_len = len ? len : 1; #if defined( HAVE_POSIX_MEMALIGN ) if ( ( 0 != posix_memalign( &m_allocated, 16, alloc_len ) ) @@ -83,10 +82,14 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data ) /* malloc() a region 15 bytes larger than we need, and find the aligned offset within. */ m_allocated = malloc( 15 + alloc_len ); - if ( m_allocated == NULL ) { throw std::bad_alloc(); } + if ( m_allocated == NULL ) { + throw std::bad_alloc(); + } uintptr_t iptr = (uintptr_t)m_allocated; - if ( iptr & 0xF ) { iptr += 16 - ( iptr & 0xF ); } + if ( iptr & 0xF ) { + iptr += 16 - ( iptr & 0xF ); + } assert( !( iptr & 0xF ) ); assert( iptr >= (uintptr_t)m_allocated ); assert( iptr <= ( 15 + (uintptr_t)m_allocated ) ); @@ -95,11 +98,12 @@ AlignedBuffer::AlignedBuffer( size_t len, const char *data ) #endif /* !defined(HAVE_POSIX_MEMALIGN) */ - if ( data ) { memcpy( m_data, data, len ); } + if ( data ) { + memcpy( m_data, data, len ); + } } -Base64Key::Base64Key( string printable_key ) -{ +Base64Key::Base64Key( string printable_key ) { if ( printable_key.length() != 22 ) { throw CryptoException( "Key must be 22 letters long." ); } @@ -111,7 +115,9 @@ Base64Key::Base64Key( string printable_key ) throw CryptoException( "Key must be well-formed base64." ); } - if ( len != 16 ) { throw CryptoException( "Key must represent 16 octets." ); } + if ( len != 16 ) { + throw CryptoException( "Key must represent 16 octets." ); + } /* to catch changes after the first 128 bits */ if ( printable_key != this->printable_key() ) { @@ -123,8 +129,7 @@ Base64Key::Base64Key() { PRNG().fill( key, sizeof( key ) ); } Base64Key::Base64Key( PRNG &prng ) { prng.fill( key, sizeof( key ) ); } -string Base64Key::printable_key( void ) const -{ +string Base64Key::printable_key( void ) const { char base64[ 24 ]; base64_encode( key, 16, base64, 24 ); @@ -139,14 +144,13 @@ string Base64Key::printable_key( void ) const } Session::Session( Base64Key s_key ) - : key( s_key ) - , ctx_buf( ae_ctx_sizeof() ) - , ctx( (ae_ctx *)ctx_buf.data() ) - , blocks_encrypted( 0 ) - , plaintext_buffer( RECEIVE_MTU ) - , ciphertext_buffer( RECEIVE_MTU ) - , nonce_buffer( Nonce::NONCE_LEN ) -{ + : key( s_key ), + ctx_buf( ae_ctx_sizeof() ), + ctx( (ae_ctx *)ctx_buf.data() ), + blocks_encrypted( 0 ), + plaintext_buffer( RECEIVE_MTU ), + ciphertext_buffer( RECEIVE_MTU ), + nonce_buffer( Nonce::NONCE_LEN ) { if ( AE_SUCCESS != ae_init( ctx, key.data(), 16, 12, 16 ) ) { throw CryptoException( "Could not initialize AES-OCB context." ); } @@ -154,23 +158,20 @@ Session::Session( Base64Key s_key ) Session::~Session() { fatal_assert( ae_clear( ctx ) == AE_SUCCESS ); } -Nonce::Nonce( uint64_t val ) -{ +Nonce::Nonce( uint64_t val ) { uint64_t val_net = htobe64( val ); memset( bytes, 0, 4 ); memcpy( bytes + 4, &val_net, 8 ); } -uint64_t Nonce::val( void ) const -{ +uint64_t Nonce::val( void ) const { uint64_t ret; memcpy( &ret, bytes + 4, 8 ); return be64toh( ret ); } -Nonce::Nonce( const char *s_bytes, size_t len ) -{ +Nonce::Nonce( const char *s_bytes, size_t len ) { if ( len != 8 ) { throw CryptoException( "Nonce representation must be 8 octets long." ); } @@ -179,8 +180,7 @@ Nonce::Nonce( const char *s_bytes, size_t len ) memcpy( bytes + 4, s_bytes, 8 ); } -const string Session::encrypt( const Message &plaintext ) -{ +const string Session::encrypt( const Message &plaintext ) { const size_t pt_len = plaintext.text.size(); const int ciphertext_len = pt_len + 16; @@ -230,8 +230,7 @@ const string Session::encrypt( const Message &plaintext ) return plaintext.nonce.cc_str() + text; } -const Message Session::decrypt( const char *str, size_t len ) -{ +const Message Session::decrypt( const char *str, size_t len ) { if ( len < 24 ) { throw CryptoException( "Ciphertext must contain nonce and tag." ); } @@ -274,8 +273,7 @@ static rlim_t saved_core_rlimit; /* Disable dumping core, as a precaution to avoid saving sensitive data to disk. */ -void Crypto::disable_dumping_core( void ) -{ +void Crypto::disable_dumping_core( void ) { struct rlimit limit; if ( 0 != getrlimit( RLIMIT_CORE, &limit ) ) { /* We don't throw CryptoException because this is called very early @@ -292,8 +290,7 @@ void Crypto::disable_dumping_core( void ) } } -void Crypto::reenable_dumping_core( void ) -{ +void Crypto::reenable_dumping_core( void ) { /* Silent failure is safe. */ struct rlimit limit; if ( 0 == getrlimit( RLIMIT_CORE, &limit ) ) { diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 40d0f40a1..c13655514 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -120,14 +120,10 @@ namespace Crypto { Message( const char *nonce_bytes, size_t nonce_len, const char *text_bytes, size_t text_len ) - : nonce( nonce_bytes, nonce_len ), text( text_bytes, text_len ) - { - } + : nonce( nonce_bytes, nonce_len ), text( text_bytes, text_len ) {} Message( const Nonce &s_nonce, const string &s_text ) - : nonce( s_nonce ), text( s_text ) - { - } + : nonce( s_nonce ), text( s_text ) {} }; class Session { @@ -152,8 +148,7 @@ namespace Crypto { const string encrypt( const Message &plaintext ); const Message decrypt( const char *str, size_t len ); - const Message decrypt( const string &ciphertext ) - { + const Message decrypt( const string &ciphertext ) { return decrypt( ciphertext.data(), ciphertext.size() ); } diff --git a/src/crypto/ocb_openssl.cc b/src/crypto/ocb_openssl.cc index 5f8b8cf6d..81cd1b9ee 100644 --- a/src/crypto/ocb_openssl.cc +++ b/src/crypto/ocb_openssl.cc @@ -11,8 +11,7 @@ struct _ae_ctx { int tag_len; }; -int ae_clear( ae_ctx *ctx ) -{ +int ae_clear( ae_ctx *ctx ) { EVP_CIPHER_CTX_free( ctx->enc_ctx ); EVP_CIPHER_CTX_free( ctx->dec_ctx ); OPENSSL_cleanse( ctx, sizeof( *ctx ) ); @@ -25,11 +24,12 @@ int ae_ctx_sizeof() { return sizeof( _ae_ctx ); } // decryption. See the documentation of EVP_CipherInit_ex static int ae_evp_cipher_init( EVP_CIPHER_CTX **in_ctx, int direction, const unsigned char *key, int nonce_len, - int tag_len ) -{ + int tag_len ) { // Create an OpenSSL EVP context. It does not yet have any specific // cipher associated with it. - if ( !( *in_ctx = EVP_CIPHER_CTX_new() ) ) { return -3; } + if ( !( *in_ctx = EVP_CIPHER_CTX_new() ) ) { + return -3; + } EVP_CIPHER_CTX *ctx = *in_ctx; // Although OCB-AES has the same initialization process between // encryption and decryption, an EVP_CIPHER_CTX must be initialized @@ -55,16 +55,19 @@ static int ae_evp_cipher_init( EVP_CIPHER_CTX **in_ctx, int direction, } int ae_init( ae_ctx *ctx, const void *key, int key_len, int nonce_len, - int tag_len ) -{ + int tag_len ) { // Pre-condition: Only nonces of length 12 are supported. The // documentation of `ae_init` in ae.h specifies that `ctx` is // untouched if an invalid configuration is requested. Delegating // this to OpenSSL would happen too late; `ctx` has already been // modified. - if ( nonce_len != 12 ) { return AE_NOT_SUPPORTED; } + if ( nonce_len != 12 ) { + return AE_NOT_SUPPORTED; + } // Pre-condition: Only AES-128 is supported. - if ( key_len != 16 ) { return AE_NOT_SUPPORTED; } + if ( key_len != 16 ) { + return AE_NOT_SUPPORTED; + } int r = AE_SUCCESS; if ( ( r = ae_evp_cipher_init( &ctx->enc_ctx, 1, reinterpret_cast( key ), @@ -84,16 +87,19 @@ int ae_init( ae_ctx *ctx, const void *key, int key_len, int nonce_len, int ae_encrypt( ae_ctx *ctx, const void *nonce_ptr, const void *pt_ptr, int pt_len, const void *ad_ptr, int ad_len, void *ct_ptr, - void *tag, int final ) -{ + void *tag, int final ) { const unsigned char *nonce = reinterpret_cast( nonce_ptr ); const unsigned char *pt = reinterpret_cast( pt_ptr ); const unsigned char *ad = reinterpret_cast( ad_ptr ); unsigned char *ct = reinterpret_cast( ct_ptr ); // Streaming mode is not supported; nonce must always be provided. - if ( final != AE_FINALIZE ) { return AE_NOT_SUPPORTED; } - if ( nonce == NULL ) { return AE_NOT_SUPPORTED; } + if ( final != AE_FINALIZE ) { + return AE_NOT_SUPPORTED; + } + if ( nonce == NULL ) { + return AE_NOT_SUPPORTED; + } if ( EVP_EncryptInit_ex( ctx->enc_ctx, /*type=*/NULL, /*impl=*/NULL, /*key=*/NULL, nonce ) != 1 ) { @@ -123,29 +129,38 @@ int ae_encrypt( ae_ctx *ctx, const void *nonce_ptr, const void *pt_ptr, != 1 ) { return -3; } - if ( tag == NULL ) { ciphertext_len += ctx->tag_len; } + if ( tag == NULL ) { + ciphertext_len += ctx->tag_len; + } return ciphertext_len; } int ae_decrypt( ae_ctx *ctx, const void *nonce_ptr, const void *ct_ptr, int ct_len, const void *ad_ptr, int ad_len, void *pt_ptr, - const void *tag, int final ) -{ + const void *tag, int final ) { const unsigned char *nonce = reinterpret_cast( nonce_ptr ); const unsigned char *ct = reinterpret_cast( ct_ptr ); const unsigned char *ad = reinterpret_cast( ad_ptr ); unsigned char *pt = reinterpret_cast( pt_ptr ); - if ( ct_len < ctx->tag_len ) { return AE_INVALID; } + if ( ct_len < ctx->tag_len ) { + return AE_INVALID; + } // If an external tag is not provided, then the tag is assumed to be // the final bytes of the cipher text. Subtract it off now so the // plaintext does not accidentally try to decrypt the AEAD tag (and // then cause an authentication failure). - if ( tag == NULL ) { ct_len -= ctx->tag_len; } + if ( tag == NULL ) { + ct_len -= ctx->tag_len; + } // Like encryption, nonce must always be provided and streaming is not // supported. - if ( final != AE_FINALIZE ) { return AE_NOT_SUPPORTED; } - if ( nonce == NULL ) { return AE_NOT_SUPPORTED; } + if ( final != AE_FINALIZE ) { + return AE_NOT_SUPPORTED; + } + if ( nonce == NULL ) { + return AE_NOT_SUPPORTED; + } if ( EVP_DecryptInit_ex( ctx->dec_ctx, /*type=*/NULL, /*impl=*/NULL, /*key=*/NULL, nonce ) != 1 ) { diff --git a/src/crypto/prng.h b/src/crypto/prng.h index 46a94b338..cb394552e 100644 --- a/src/crypto/prng.h +++ b/src/crypto/prng.h @@ -58,9 +58,10 @@ class PRNG { public: PRNG() : randfile( rdev, std::ifstream::in | std::ifstream::binary ) {} - void fill( void *dest, size_t size ) - { - if ( 0 == size ) { return; } + void fill( void *dest, size_t size ) { + if ( 0 == size ) { + return; + } randfile.read( static_cast( dest ), size ); if ( !randfile ) { @@ -68,22 +69,19 @@ class PRNG { } } - uint8_t uint8() - { + uint8_t uint8() { uint8_t x; fill( &x, 1 ); return x; } - uint32_t uint32() - { + uint32_t uint32() { uint32_t x; fill( &x, 4 ); return x; } - uint64_t uint64() - { + uint64_t uint64() { uint64_t x; fill( &x, 8 ); return x; diff --git a/src/examples/benchmark.cc b/src/examples/benchmark.cc index 29ac38a4f..a9bb6d601 100644 --- a/src/examples/benchmark.cc +++ b/src/examples/benchmark.cc @@ -63,8 +63,7 @@ const int ITERATIONS = 100000; using namespace Terminal; -int main( int argc, char **argv ) -{ +int main( int argc, char **argv ) { try { int fbmod = 0; int width = 80, height = 24; @@ -112,7 +111,9 @@ int main( int argc, char **argv ) display.new_frame( false, *local_framebuffer, *new_state ) ); /* make sure to use diff */ - if ( diff.size() > INT_MAX ) { exit( 1 ); } + if ( diff.size() > INT_MAX ) { + exit( 1 ); + } fbmod = !fbmod; local_framebuffer = &( local_framebuffers[ fbmod ] ); diff --git a/src/examples/decrypt.cc b/src/examples/decrypt.cc index 9bb7d6829..a086a6c31 100644 --- a/src/examples/decrypt.cc +++ b/src/examples/decrypt.cc @@ -38,8 +38,7 @@ using namespace Crypto; -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ) { if ( argc != 2 ) { fprintf( stderr, "Usage: %s KEY\n", argv[ 0 ] ); return 1; diff --git a/src/examples/encrypt.cc b/src/examples/encrypt.cc index da454bd3b..fd8e31016 100644 --- a/src/examples/encrypt.cc +++ b/src/examples/encrypt.cc @@ -38,8 +38,7 @@ using namespace Crypto; -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ) { if ( argc != 2 ) { fprintf( stderr, "Usage: %s NONCE\n", argv[ 0 ] ); return 1; diff --git a/src/examples/ntester.cc b/src/examples/ntester.cc index 82c23d8f1..7925ab167 100644 --- a/src/examples/ntester.cc +++ b/src/examples/ntester.cc @@ -42,8 +42,7 @@ using namespace Network; -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ) { bool server = true; char *key; char *ip; @@ -136,7 +135,9 @@ int main( int argc, char *argv[] ) } try { - if ( sel.select( n->wait_time() ) < 0 ) { perror( "select" ); } + if ( sel.select( n->wait_time() ) < 0 ) { + perror( "select" ); + } n->tick(); @@ -156,7 +157,9 @@ int main( int argc, char *argv[] ) } } - if ( network_ready_to_read ) { n->recv(); } + if ( network_ready_to_read ) { + n->recv(); + } } catch ( const std::exception &e ) { fprintf( stderr, "Client error: %s\n", e.what() ); } diff --git a/src/examples/parse.cc b/src/examples/parse.cc index 6d8fe0847..27d6afdab 100644 --- a/src/examples/parse.cc +++ b/src/examples/parse.cc @@ -67,8 +67,7 @@ static int copy( int src, int dest ); static int vt_parser( int fd, Parser::UTF8Parser *parser ); int main( int argc __attribute__( ( unused ) ), - char *argv[] __attribute__( ( unused ) ), char *envp[] ) -{ + char *argv[] __attribute__( ( unused ) ), char *envp[] ) { int master; struct termios saved_termios, raw_termios, child_termios; @@ -138,8 +137,7 @@ int main( int argc __attribute__( ( unused ) ), return 0; } -static void emulate_terminal( int fd ) -{ +static void emulate_terminal( int fd ) { Parser::UTF8Parser parser; Select &sel = Select::get_instance(); @@ -154,17 +152,20 @@ static void emulate_terminal( int fd ) } if ( sel.read( STDIN_FILENO ) ) { - if ( copy( STDIN_FILENO, fd ) < 0 ) { return; } + if ( copy( STDIN_FILENO, fd ) < 0 ) { + return; + } } else if ( sel.read( fd ) ) { - if ( vt_parser( fd, &parser ) < 0 ) { return; } + if ( vt_parser( fd, &parser ) < 0 ) { + return; + } } else { fprintf( stderr, "select mysteriously woken up\n" ); } } } -static int copy( int src, int dest ) -{ +static int copy( int src, int dest ) { char buf[ buf_size ]; ssize_t bytes_read = read( src, buf, buf_size ); @@ -178,8 +179,7 @@ static int copy( int src, int dest ) return swrite( dest, buf, bytes_read ); } -static int vt_parser( int fd, Parser::UTF8Parser *parser ) -{ +static int vt_parser( int fd, Parser::UTF8Parser *parser ) { char buf[ buf_size ]; /* fill buffer if possible */ diff --git a/src/examples/termemu.cc b/src/examples/termemu.cc index 8371b2ce1..80a637957 100644 --- a/src/examples/termemu.cc +++ b/src/examples/termemu.cc @@ -72,8 +72,7 @@ const size_t buf_size = 16384; static void emulate_terminal( int fd ); -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ) { int master; struct termios saved_termios, raw_termios, child_termios; @@ -176,14 +175,15 @@ int main( int argc, char *argv[] ) /* Print a frame if the last frame was more than 1/50 seconds ago */ static bool tick( Terminal::Framebuffer &state, Terminal::Framebuffer &new_frame, - const Terminal::Display &display ) -{ + const Terminal::Display &display ) { static bool initialized = false; static struct timeval last_time; struct timeval this_time; - if ( gettimeofday( &this_time, NULL ) < 0 ) { perror( "gettimeofday" ); } + if ( gettimeofday( &this_time, NULL ) < 0 ) { + perror( "gettimeofday" ); + } double diff = ( this_time.tv_sec - last_time.tv_sec ) + .000001 * ( this_time.tv_usec - last_time.tv_usec ); @@ -219,8 +219,7 @@ static bool tick( Terminal::Framebuffer &state, assume the previous frame was sent to the real terminal. */ -static void emulate_terminal( int fd ) -{ +static void emulate_terminal( int fd ) { /* get current window size */ struct winsize window_size; if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) { diff --git a/src/frontend/mosh-client.cc b/src/frontend/mosh-client.cc index 767dec89f..4a73f18f4 100644 --- a/src/frontend/mosh-client.cc +++ b/src/frontend/mosh-client.cc @@ -70,8 +70,7 @@ #error "SysV or X/Open-compatible Curses header file required" #endif -static void print_version( FILE *file ) -{ +static void print_version( FILE *file ) { fputs( "mosh-client (" PACKAGE_STRING ") [build " BUILD_VERSION "]\n" "Copyright 2012 Keith Winstein \n" @@ -82,8 +81,7 @@ static void print_version( FILE *file ) file ); } -static void print_usage( FILE *file, const char *argv0 ) -{ +static void print_usage( FILE *file, const char *argv0 ) { print_version( file ); fprintf( file, "\nUsage: %s [-# 'ARGS'] IP PORT\n" @@ -91,8 +89,7 @@ static void print_usage( FILE *file, const char *argv0 ) argv0, argv0 ); } -static void print_colorcount( void ) -{ +static void print_colorcount( void ) { /* check colors */ setupterm( (char *)0, 1, (int *)0 ); diff --git a/src/frontend/mosh-server.cc b/src/frontend/mosh-server.cc index 2e874ac6a..bed6b1251 100644 --- a/src/frontend/mosh-server.cc +++ b/src/frontend/mosh-server.cc @@ -105,8 +105,7 @@ static int run_server( const char *desired_ip, const char *desired_port, const string &command_path, char *command_argv[], const int colors, unsigned int verbose, bool with_motd ); -static void print_version( FILE *file ) -{ +static void print_version( FILE *file ) { fputs( "mosh-server (" PACKAGE_STRING ") [build " BUILD_VERSION "]\n" "Copyright 2012 Keith Winstein \n" @@ -117,8 +116,7 @@ static void print_version( FILE *file ) file ); } -static void print_usage( FILE *stream, const char *argv0 ) -{ +static void print_usage( FILE *stream, const char *argv0 ) { fprintf( stream, "Usage: %s new [-s] [-v] [-i LOCALADDR] [-p PORT[:PORT2]] [-c " "COLORS] [-l NAME=VALUE] [-- COMMAND...]\n", @@ -131,8 +129,7 @@ static bool motd_hushed( void ); static void warn_unattached( const string &ignore_entry ); /* Simple spinloop */ -static void spin( void ) -{ +static void spin( void ) { static unsigned int spincount = 0; spincount++; @@ -145,8 +142,7 @@ static void spin( void ) } } -static string get_SSH_IP( void ) -{ +static string get_SSH_IP( void ) { const char *SSH_CONNECTION = getenv( "SSH_CONNECTION" ); if ( !SSH_CONNECTION ) { /* Older sshds don't set this */ fputs( "Warning: SSH_CONNECTION not found; binding to any interface.\n", @@ -176,8 +172,7 @@ static string get_SSH_IP( void ) return local_interface_IP; } -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ) { /* For security, make sure we don't dump core */ Crypto::disable_dumping_core(); @@ -206,7 +201,9 @@ int main( int argc, char *argv[] ) exit( 0 ); } if ( 0 == strcmp( argv[ i ], "--" ) ) { /* -- is mandatory */ - if ( i != argc - 1 ) { command_argv = argv + i + 1; } + if ( i != argc - 1 ) { + command_argv = argv + i + 1; + } argc = i; /* rest of options before -- */ break; } @@ -320,7 +317,9 @@ int main( int argc, char *argv[] ) with_motd = true; } - if ( command_path.empty() ) { command_path = command_argv[ 0 ]; } + if ( command_path.empty() ) { + command_path = command_argv[ 0 ]; + } /* Adopt implementation locale */ set_native_locale(); @@ -335,7 +334,9 @@ int main( int argc, char *argv[] ) i != locale_vars.end(); i++ ) { char *env_string = strdup( i->c_str() ); fatal_assert( env_string ); - if ( 0 != putenv( env_string ) ) { perror( "putenv" ); } + if ( 0 != putenv( env_string ) ) { + perror( "putenv" ); + } } /* check again */ @@ -371,8 +372,8 @@ int main( int argc, char *argv[] ) static int run_server( const char *desired_ip, const char *desired_port, const string &command_path, char *command_argv[], - const int colors, unsigned int verbose, bool with_motd ) -{ + const int colors, unsigned int verbose, + bool with_motd ) { /* get network idle timeout */ long network_timeout = 0; char *timeout_envar = getenv( "MOSH_SERVER_NETWORK_TMOUT" ); @@ -432,7 +433,9 @@ static int run_server( const char *desired_ip, const char *desired_port, * detection of the MOSH CONNECT message. Print it on a new line to bodge * around that. */ - if ( isatty( STDIN_FILENO ) ) { puts( "\r\n" ); } + if ( isatty( STDIN_FILENO ) ) { + puts( "\r\n" ); + } printf( "MOSH CONNECT %s %s\n", network->port().c_str(), network->get_key().c_str() ); @@ -471,8 +474,12 @@ static int run_server( const char *desired_ip, const char *desired_port, #endif /* HAVE_IUTF8 */ fflush( NULL ); - if ( isatty( STDOUT_FILENO ) ) { tcdrain( STDOUT_FILENO ); } - if ( isatty( STDERR_FILENO ) ) { tcdrain( STDERR_FILENO ); } + if ( isatty( STDOUT_FILENO ) ) { + tcdrain( STDOUT_FILENO ); + } + if ( isatty( STDERR_FILENO ) ) { + tcdrain( STDERR_FILENO ); + } exit( 0 ); } @@ -645,8 +652,7 @@ static int run_server( const char *desired_ip, const char *desired_port, static void serve( int host_fd, Terminal::Complete &terminal, ServerConnection &network, long network_timeout, - long network_signaled_timeout ) -{ + long network_signaled_timeout ) { /* scale timeouts */ const uint64_t network_timeout_ms = static_cast( network_timeout ) * 1000; @@ -715,7 +721,9 @@ static void serve( int host_fd, Terminal::Complete &terminal, assert( fd_list.size() == 1 ); /* servers don't hop */ int network_fd = fd_list.back(); sel.add_fd( network_fd ); - if ( !network.shutdown_in_progress() ) { sel.add_fd( host_fd ); } + if ( !network.shutdown_in_progress() ) { + sel.add_fd( host_fd ); + } int active_fds = sel.select( timeout ); if ( active_fds < 0 ) { @@ -745,7 +753,9 @@ static void serve( int host_fd, Terminal::Complete &terminal, /* apply only the last consecutive Resize action */ if ( i < us.size() - 1 ) { const Parser::Action &next = us.get_action( i + 1 ); - if ( typeid( next ) == typeid( Parser::Resize ) ) { continue; } + if ( typeid( next ) == typeid( Parser::Resize ) ) { + continue; + } } /* tell child process of resize */ const Parser::Resize &res = @@ -827,7 +837,9 @@ static void serve( int host_fd, Terminal::Complete &terminal, /* Tell child to start login session. */ if ( !child_released ) { - if ( swrite( host_fd, "\n", 1 ) < 0 ) { err( 1, "child release" ); } + if ( swrite( host_fd, "\n", 1 ) < 0 ) { + err( 1, "child release" ); + } child_released = true; } } @@ -899,7 +911,9 @@ static void serve( int host_fd, Terminal::Complete &terminal, } /* quit if we received and acknowledged a shutdown request */ - if ( network.counterparty_shutdown_ack_sent() ) { break; } + if ( network.counterparty_shutdown_ack_sent() ) { + break; + } #ifdef HAVE_UTEMPTER /* update utmp if has been more than 30 seconds since heard from client */ @@ -945,27 +959,31 @@ static void serve( int host_fd, Terminal::Complete &terminal, } /* Print the motd from a given file, if available */ -static bool print_motd( const char *filename ) -{ +static bool print_motd( const char *filename ) { FILE *motd = fopen( filename, "r" ); - if ( !motd ) { return false; } + if ( !motd ) { + return false; + } const int BUFSIZE = 256; char buffer[ BUFSIZE ]; while ( 1 ) { size_t bytes_read = fread( buffer, 1, BUFSIZE, motd ); - if ( bytes_read == 0 ) { break; /* don't report error */ } + if ( bytes_read == 0 ) { + break; /* don't report error */ + } size_t bytes_written = fwrite( buffer, 1, bytes_read, stdout ); - if ( bytes_written == 0 ) { break; } + if ( bytes_written == 0 ) { + break; + } } fclose( motd ); return true; } -static void chdir_homedir( void ) -{ +static void chdir_homedir( void ) { const char *home = getenv( "HOME" ); if ( home == NULL ) { struct passwd *pw = getpwuid( getuid() ); @@ -976,29 +994,30 @@ static void chdir_homedir( void ) home = pw->pw_dir; } - if ( chdir( home ) < 0 ) { perror( "chdir" ); } + if ( chdir( home ) < 0 ) { + perror( "chdir" ); + } - if ( setenv( "PWD", home, 1 ) < 0 ) { perror( "setenv" ); } + if ( setenv( "PWD", home, 1 ) < 0 ) { + perror( "setenv" ); + } } -static bool motd_hushed( void ) -{ +static bool motd_hushed( void ) { /* must be in home directory already */ struct stat buf; return 0 == lstat( ".hushlogin", &buf ); } #ifdef HAVE_UTMPX_H -static bool device_exists( const char *ut_line ) -{ +static bool device_exists( const char *ut_line ) { string device_name = string( "/dev/" ) + string( ut_line ); struct stat buf; return 0 == lstat( device_name.c_str(), &buf ); } #endif -static void warn_unattached( const string &ignore_entry ) -{ +static void warn_unattached( const string &ignore_entry ) { #ifdef HAVE_UTMPX_H /* get username */ const struct passwd *pw = getpwuid( getuid() ); diff --git a/src/frontend/stmclient.cc b/src/frontend/stmclient.cc index 632c5ec1e..8eb44bc67 100644 --- a/src/frontend/stmclient.cc +++ b/src/frontend/stmclient.cc @@ -65,8 +65,7 @@ using std::wstring; -void STMClient::resume( void ) -{ +void STMClient::resume( void ) { /* Restore termios state */ if ( tcsetattr( STDIN_FILENO, TCSANOW, &raw_termios ) < 0 ) { perror( "tcsetattr" ); @@ -80,8 +79,7 @@ void STMClient::resume( void ) repaint_requested = true; } -void STMClient::init( void ) -{ +void STMClient::init( void ) { if ( !is_utf8_locale() ) { LocaleVar native_ctype = get_ctype(); string native_charset( locale_charset() ); @@ -209,8 +207,7 @@ void STMClient::init( void ) connecting_notification = wstring( tmp ); } -void STMClient::shutdown( void ) -{ +void STMClient::shutdown( void ) { /* Restore screen state */ overlays.get_notification_engine().set_notification_string( wstring( L"" ) ); overlays.get_notification_engine().server_heard( timestamp() ); @@ -242,8 +239,7 @@ void STMClient::shutdown( void ) } } -void STMClient::main_init( void ) -{ +void STMClient::main_init( void ) { Select &sel = Select::get_instance(); sel.add_signal( SIGWINCH ); sel.add_signal( SIGTERM ); @@ -285,8 +281,7 @@ void STMClient::main_init( void ) Select::set_verbose( verbose ); } -void STMClient::output_new_frame( void ) -{ +void STMClient::output_new_frame( void ) { if ( !network ) { /* clean shutdown even when not initialized */ return; } @@ -307,8 +302,7 @@ void STMClient::output_new_frame( void ) local_framebuffer = new_state; } -void STMClient::process_network_input( void ) -{ +void STMClient::process_network_input( void ) { network->recv(); /* Now give hints to the overlays */ @@ -325,8 +319,7 @@ void STMClient::process_network_input( void ) network->get_latest_remote_state().state.get_echo_ack() ); } -bool STMClient::process_user_input( int fd ) -{ +bool STMClient::process_user_input( int fd ) { const int buf_size = 16384; char buf[ buf_size ]; @@ -341,13 +334,17 @@ bool STMClient::process_user_input( int fd ) NetworkType &net = *network; - if ( net.shutdown_in_progress() ) { return true; } + if ( net.shutdown_in_progress() ) { + return true; + } overlays.get_prediction_engine().set_local_frame_sent( net.get_sent_state_last() ); /* Don't predict for bulk data. */ bool paste = bytes_read > 100; - if ( paste ) { overlays.get_prediction_engine().reset(); } + if ( paste ) { + overlays.get_prediction_engine().reset(); + } for ( int i = 0; i < bytes_read; i++ ) { char the_byte = buf[ i ]; @@ -429,8 +426,7 @@ bool STMClient::process_user_input( int fd ) return true; } -bool STMClient::process_resize( void ) -{ +bool STMClient::process_resize( void ) { /* get new size */ if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) { perror( "ioctl TIOCGWINSZ" ); @@ -453,8 +449,7 @@ bool STMClient::process_resize( void ) return true; } -bool STMClient::main( void ) -{ +bool STMClient::main( void ) { /* initialize signal handling and structures */ main_init(); @@ -477,7 +472,9 @@ bool STMClient::main( void ) int wait_time = std::min( network->wait_time(), overlays.wait_time() ); /* Handle startup "Connecting..." message */ - if ( still_connecting() ) { wait_time = std::min( 250, wait_time ); } + if ( still_connecting() ) { + wait_time = std::min( 250, wait_time ); + } /* poll for events */ /* network->fd() can in theory change over time */ @@ -506,7 +503,9 @@ bool STMClient::main( void ) } } - if ( network_ready_to_read ) { process_network_input(); } + if ( network_ready_to_read ) { + process_network_input(); + } if ( sel.read( STDIN_FILENO ) && !process_user_input( @@ -525,7 +524,9 @@ bool STMClient::main( void ) return false; } - if ( sel.signal( SIGCONT ) ) { resume(); } + if ( sel.signal( SIGCONT ) ) { + resume(); + } if ( sel.signal( SIGTERM ) || sel.signal( SIGINT ) || sel.signal( SIGHUP ) || sel.signal( SIGPIPE ) ) { diff --git a/src/frontend/stmclient.h b/src/frontend/stmclient.h index 328036f2d..7ad01ad06 100644 --- a/src/frontend/stmclient.h +++ b/src/frontend/stmclient.h @@ -79,8 +79,7 @@ class STMClient { void output_new_frame( void ); - bool still_connecting( void ) const - { + bool still_connecting( void ) const { /* Initially, network == NULL */ return network && ( network->get_remote_state_num() == 0 ); } @@ -91,30 +90,28 @@ class STMClient { STMClient( const char *s_ip, const char *s_port, const char *s_key, const char *predict_mode, unsigned int s_verbose, const char *predict_overwrite ) - : ip( s_ip ? s_ip : "" ) - , port( s_port ? s_port : "" ) - , key( s_key ? s_key : "" ) - , escape_key( 0x1E ) - , escape_pass_key( '^' ) - , escape_pass_key2( '^' ) - , escape_requires_lf( false ) - , escape_key_help( L"?" ) - , saved_termios() - , raw_termios() - , window_size() - , local_framebuffer( 1, 1 ) - , new_state( 1, 1 ) - , overlays() - , network() - , display( true ) - , /* use TERM environment var to initialize display */ - connecting_notification() - , repaint_requested( false ) - , lf_entered( false ) - , quit_sequence_started( false ) - , clean_shutdown( false ) - , verbose( s_verbose ) - { + : ip( s_ip ? s_ip : "" ), + port( s_port ? s_port : "" ), + key( s_key ? s_key : "" ), + escape_key( 0x1E ), + escape_pass_key( '^' ), + escape_pass_key2( '^' ), + escape_requires_lf( false ), + escape_key_help( L"?" ), + saved_termios(), + raw_termios(), + window_size(), + local_framebuffer( 1, 1 ), + new_state( 1, 1 ), + overlays(), + network(), + display( true ), /* use TERM environment var to initialize display */ + connecting_notification(), + repaint_requested( false ), + lf_entered( false ), + quit_sequence_started( false ), + clean_shutdown( false ), + verbose( s_verbose ) { if ( predict_mode ) { if ( !strcmp( predict_mode, "always" ) ) { overlays.get_prediction_engine().set_display_preference( diff --git a/src/frontend/terminaloverlay.cc b/src/frontend/terminaloverlay.cc index fac427f6f..b677d5bc5 100644 --- a/src/frontend/terminaloverlay.cc +++ b/src/frontend/terminaloverlay.cc @@ -41,14 +41,15 @@ using namespace Overlay; void ConditionalOverlayCell::apply( Framebuffer &fb, uint64_t confirmed_epoch, - int row, bool flag ) const -{ + int row, bool flag ) const { if ( ( !active ) || ( row >= fb.ds.get_height() ) || ( col >= fb.ds.get_width() ) ) { return; } - if ( tentative( confirmed_epoch ) ) { return; } + if ( tentative( confirmed_epoch ) ) { + return; + } if ( replacement.is_blank() && fb.get_cell( row, col )->is_blank() ) { flag = false; @@ -76,9 +77,10 @@ void ConditionalOverlayCell::apply( Framebuffer &fb, uint64_t confirmed_epoch, Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row, uint64_t early_ack __attribute__( ( unused ) ), - uint64_t late_ack ) const -{ - if ( !active ) { return Inactive; } + uint64_t late_ack ) const { + if ( !active ) { + return Inactive; + } if ( ( row >= fb.ds.get_height() ) || ( col >= fb.ds.get_width() ) ) { return IncorrectOrExpired; @@ -87,9 +89,13 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row, const Cell ¤t = *( fb.get_cell( row, col ) ); /* see if it hasn't been updated yet */ - if ( late_ack < expiration_frame ) { return Pending; } + if ( late_ack < expiration_frame ) { + return Pending; + } - if ( unknown ) { return CorrectNoCredit; } + if ( unknown ) { + return CorrectNoCredit; + } if ( replacement.is_blank() ) { /* too easy for this to trigger falsely */ return CorrectNoCredit; @@ -100,7 +106,9 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row, for ( ; it != original_contents.end(); it++ ) { if ( it->contents_match( replacement ) ) break; } - if ( it == original_contents.end() ) { return Correct; } + if ( it == original_contents.end() ) { + return Correct; + } return CorrectNoCredit; } return IncorrectOrExpired; @@ -109,9 +117,10 @@ Validity ConditionalOverlayCell::get_validity( const Framebuffer &fb, int row, Validity ConditionalCursorMove::get_validity( const Framebuffer &fb, uint64_t early_ack __attribute( ( unused ) ), - uint64_t late_ack ) const -{ - if ( !active ) { return Inactive; } + uint64_t late_ack ) const { + if ( !active ) { + return Inactive; + } if ( ( row >= fb.ds.get_height() ) || ( col >= fb.ds.get_width() ) ) { // fprintf( stderr, "Crazy cursor (%d,%d)!\n", row, col ); @@ -130,11 +139,14 @@ Validity ConditionalCursorMove::get_validity( const Framebuffer &fb, } void ConditionalCursorMove::apply( Framebuffer &fb, - uint64_t confirmed_epoch ) const -{ - if ( !active ) { return; } + uint64_t confirmed_epoch ) const { + if ( !active ) { + return; + } - if ( tentative( confirmed_epoch ) ) { return; } + if ( tentative( confirmed_epoch ) ) { + return; + } assert( row < fb.ds.get_height() ); assert( col < fb.ds.get_width() ); @@ -145,19 +157,16 @@ void ConditionalCursorMove::apply( Framebuffer &fb, } NotificationEngine::NotificationEngine() - : last_word_from_server( timestamp() ) - , last_acked_state( timestamp() ) - , escape_key_string() - , message() - , message_is_network_error( false ) - , message_expiration( -1 ) - , show_quit_keystroke( true ) -{ -} + : last_word_from_server( timestamp() ), + last_acked_state( timestamp() ), + escape_key_string(), + message(), + message_is_network_error( false ), + message_expiration( -1 ), + show_quit_keystroke( true ) {} static std::string human_readable_duration( int num_seconds, - const std::string &seconds_abbr ) -{ + const std::string &seconds_abbr ) { char tmp[ 128 ]; if ( num_seconds < 60 ) { snprintf( tmp, 128, "%d %s", num_seconds, seconds_abbr.c_str() ); @@ -170,19 +179,22 @@ static std::string human_readable_duration( int num_seconds, return tmp; } -void NotificationEngine::apply( Framebuffer &fb ) const -{ +void NotificationEngine::apply( Framebuffer &fb ) const { uint64_t now = timestamp(); bool time_expired = need_countup( now ); - if ( message.empty() && !time_expired ) { return; } + if ( message.empty() && !time_expired ) { + return; + } assert( fb.ds.get_width() > 0 ); assert( fb.ds.get_height() > 0 ); /* hide cursor if necessary */ - if ( fb.ds.get_cursor_row() == 0 ) { fb.ds.cursor_visible = false; } + if ( fb.ds.get_cursor_row() == 0 ) { + fb.ds.cursor_visible = false; + } /* draw bar across top of screen */ Cell notification_bar( 0 ); @@ -219,7 +231,9 @@ void NotificationEngine::apply( Framebuffer &fb ) const const char *keystroke_str = show_quit_keystroke ? escape_key_string.c_str() : blank; - if ( message.empty() && ( !time_expired ) ) { return; } + if ( message.empty() && ( !time_expired ) ) { + return; + } if ( message.empty() && time_expired ) { swprintf( tmp, 128, L"mosh: Last %s %s ago.%s", explanation, @@ -245,7 +259,9 @@ void NotificationEngine::apply( Framebuffer &fb ) const * sequence into graphemes */ for ( wstring::const_iterator i = string_to_draw.begin(); i != string_to_draw.end(); i++ ) { - if ( overlay_col >= fb.ds.get_width() ) { break; } + if ( overlay_col >= fb.ds.get_width() ) { + break; + } wchar_t ch = *i; int chwidth = ch == L'\0' ? -1 : wcwidth( ch ); @@ -267,7 +283,9 @@ void NotificationEngine::apply( Framebuffer &fb ) const overlay_col += chwidth; break; case 0: /* combining character */ - if ( !combining_cell ) { break; } + if ( !combining_cell ) { + break; + } if ( combining_cell->empty() ) { assert( !combining_cell->get_wide() ); @@ -275,7 +293,9 @@ void NotificationEngine::apply( Framebuffer &fb ) const overlay_col++; } - if ( !combining_cell->full() ) { combining_cell->append( ch ); } + if ( !combining_cell->full() ) { + combining_cell->append( ch ); + } break; case -1: /* unprintable character */ break; default: assert( !"unexpected character width from wcwidth()" ); @@ -283,13 +303,13 @@ void NotificationEngine::apply( Framebuffer &fb ) const } } -void NotificationEngine::adjust_message( void ) -{ - if ( timestamp() >= message_expiration ) { message.clear(); } +void NotificationEngine::adjust_message( void ) { + if ( timestamp() >= message_expiration ) { + message.clear(); + } } -int NotificationEngine::wait_time( void ) const -{ +int NotificationEngine::wait_time( void ) const { uint64_t next_expiry = INT_MAX; uint64_t now = timestamp(); @@ -309,8 +329,7 @@ int NotificationEngine::wait_time( void ) const return next_expiry; } -void OverlayManager::apply( Framebuffer &fb ) -{ +void OverlayManager::apply( Framebuffer &fb ) { predictions.cull( fb ); predictions.apply( fb ); notifications.adjust_message(); @@ -318,22 +337,19 @@ void OverlayManager::apply( Framebuffer &fb ) title.apply( fb ); } -void TitleEngine::set_prefix( const wstring &s ) -{ +void TitleEngine::set_prefix( const wstring &s ) { prefix = Terminal::Framebuffer::title_type( s.begin(), s.end() ); } void ConditionalOverlayRow::apply( Framebuffer &fb, uint64_t confirmed_epoch, - bool flag ) const -{ + bool flag ) const { for ( overlay_cells_type::const_iterator it = overlay_cells.begin(); it != overlay_cells.end(); it++ ) { it->apply( fb, confirmed_epoch, row_num, flag ); } } -void PredictionEngine::apply( Framebuffer &fb ) const -{ +void PredictionEngine::apply( Framebuffer &fb ) const { if ( ( display_preference == Never ) || !( srtt_trigger || glitch_trigger || ( display_preference == Always ) || ( display_preference == Experimental ) ) ) { @@ -351,12 +367,13 @@ void PredictionEngine::apply( Framebuffer &fb ) const } } -void PredictionEngine::kill_epoch( uint64_t epoch, const Framebuffer &fb ) -{ +void PredictionEngine::kill_epoch( uint64_t epoch, const Framebuffer &fb ) { for ( cursors_type::iterator it = cursors.begin(); it != cursors.end(); ) { cursors_type::iterator it_next = it; it_next++; - if ( it->tentative( epoch - 1 ) ) { cursors.erase( it ); } + if ( it->tentative( epoch - 1 ) ) { + cursors.erase( it ); + } it = it_next; } @@ -369,15 +386,16 @@ void PredictionEngine::kill_epoch( uint64_t epoch, const Framebuffer &fb ) i++ ) { for ( overlay_cells_type::iterator j = i->overlay_cells.begin(); j != i->overlay_cells.end(); j++ ) { - if ( j->tentative( epoch - 1 ) ) { j->reset(); } + if ( j->tentative( epoch - 1 ) ) { + j->reset(); + } } } become_tentative(); } -void PredictionEngine::reset( void ) -{ +void PredictionEngine::reset( void ) { cursors.clear(); overlays.clear(); become_tentative(); @@ -385,8 +403,7 @@ void PredictionEngine::reset( void ) // fprintf( stderr, "RESETTING\n" ); } -void PredictionEngine::init_cursor( const Framebuffer &fb ) -{ +void PredictionEngine::init_cursor( const Framebuffer &fb ) { if ( cursors.empty() ) { /* initialize new cursor prediction */ @@ -403,9 +420,10 @@ void PredictionEngine::init_cursor( const Framebuffer &fb ) } } -void PredictionEngine::cull( const Framebuffer &fb ) -{ - if ( display_preference == Never ) { return; } +void PredictionEngine::cull( const Framebuffer &fb ) { + if ( display_preference == Never ) { + return; + } if ( ( last_height != fb.ds.get_height() ) || ( last_width != fb.ds.get_width() ) ) { @@ -435,7 +453,9 @@ void PredictionEngine::cull( const Framebuffer &fb ) } /* really big glitches also activate underlining */ - if ( glitch_trigger > GLITCH_REPAIR_COUNT ) { flagging = true; } + if ( glitch_trigger > GLITCH_REPAIR_COUNT ) { + flagging = true; + } /* go through cell predictions */ @@ -590,15 +610,18 @@ void PredictionEngine::cull( const Framebuffer &fb ) } ConditionalOverlayRow &PredictionEngine::get_or_make_row( int row_num, - int num_cols ) -{ + int num_cols ) { overlays_type::iterator it; for ( it = overlays.begin(); it != overlays.end(); it++ ) { - if ( it->row_num == row_num ) { break; } + if ( it->row_num == row_num ) { + break; + } } - if ( it != overlays.end() ) { return *it; } + if ( it != overlays.end() ) { + return *it; + } /* make row */ ConditionalOverlayRow r( row_num ); r.overlay_cells.reserve( num_cols ); @@ -611,9 +634,10 @@ ConditionalOverlayRow &PredictionEngine::get_or_make_row( int row_num, return overlays.back(); } -void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) -{ - if ( display_preference == Never ) { return; } +void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) { + if ( display_preference == Never ) { + return; + } if ( display_preference == Experimental ) { prediction_epoch = confirmed_epoch; } @@ -624,7 +648,9 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) /* translate application-mode cursor control function to ANSI cursor control * sequence */ - if ( ( last_byte == 0x1b ) && ( the_byte == 'O' ) ) { the_byte = '['; } + if ( ( last_byte == 0x1b ) && ( the_byte == 'O' ) ) { + the_byte = '['; + } last_byte = the_byte; Parser::Actions actions; @@ -830,8 +856,7 @@ void PredictionEngine::new_user_byte( char the_byte, const Framebuffer &fb ) } } -void PredictionEngine::newline_carriage_return( const Framebuffer &fb ) -{ +void PredictionEngine::newline_carriage_return( const Framebuffer &fb ) { uint64_t now = timestamp(); init_cursor( fb ); cursor().col = 0; @@ -867,9 +892,10 @@ void PredictionEngine::newline_carriage_return( const Framebuffer &fb ) } } -void PredictionEngine::become_tentative( void ) -{ - if ( display_preference != Experimental ) { prediction_epoch++; } +void PredictionEngine::become_tentative( void ) { + if ( display_preference != Experimental ) { + prediction_epoch++; + } /* fprintf( stderr, "Now tentative in epoch %lu (confirmed=%lu)\n", @@ -877,15 +903,18 @@ void PredictionEngine::become_tentative( void ) */ } -bool PredictionEngine::active( void ) const -{ - if ( !cursors.empty() ) { return true; } +bool PredictionEngine::active( void ) const { + if ( !cursors.empty() ) { + return true; + } for ( overlays_type::const_iterator i = overlays.begin(); i != overlays.end(); i++ ) { for ( overlay_cells_type::const_iterator j = i->overlay_cells.begin(); j != i->overlay_cells.end(); j++ ) { - if ( j->active ) { return true; } + if ( j->active ) { + return true; + } } } diff --git a/src/frontend/terminaloverlay.h b/src/frontend/terminaloverlay.h index e18251674..359f48196 100644 --- a/src/frontend/terminaloverlay.h +++ b/src/frontend/terminaloverlay.h @@ -66,27 +66,22 @@ namespace Overlay { uint64_t prediction_time; /* used to find long-pending predictions */ ConditionalOverlay( uint64_t s_exp, int s_col, uint64_t s_tentative ) - : expiration_frame( s_exp ) - , col( s_col ) - , active( false ) - , tentative_until_epoch( s_tentative ) - , prediction_time( uint64_t( -1 ) ) - { - } + : expiration_frame( s_exp ), + col( s_col ), + active( false ), + tentative_until_epoch( s_tentative ), + prediction_time( uint64_t( -1 ) ) {} virtual ~ConditionalOverlay() {} - bool tentative( uint64_t confirmed_epoch ) const - { + bool tentative( uint64_t confirmed_epoch ) const { return tentative_until_epoch > confirmed_epoch; } - void reset( void ) - { + void reset( void ) { expiration_frame = tentative_until_epoch = -1; active = false; } - void expire( uint64_t s_exp, uint64_t now ) - { + void expire( uint64_t s_exp, uint64_t now ) { expiration_frame = s_exp; prediction_time = now; } @@ -103,9 +98,7 @@ namespace Overlay { ConditionalCursorMove( uint64_t s_exp, int s_row, int s_col, uint64_t s_tentative ) - : ConditionalOverlay( s_exp, s_col, s_tentative ), row( s_row ) - { - } + : ConditionalOverlay( s_exp, s_col, s_tentative ), row( s_row ) {} }; class ConditionalOverlayCell : public ConditionalOverlay { @@ -123,21 +116,17 @@ namespace Overlay { uint64_t late_ack ) const; ConditionalOverlayCell( uint64_t s_exp, int s_col, uint64_t s_tentative ) - : ConditionalOverlay( s_exp, s_col, s_tentative ) - , replacement( 0 ) - , unknown( false ) - , original_contents() - { - } + : ConditionalOverlay( s_exp, s_col, s_tentative ), + replacement( 0 ), + unknown( false ), + original_contents() {} - void reset( void ) - { + void reset( void ) { unknown = false; original_contents.clear(); ConditionalOverlay::reset(); } - void reset_with_orig( void ) - { + void reset_with_orig( void ) { if ( ( !active ) || unknown ) { reset(); return; @@ -158,9 +147,7 @@ namespace Overlay { void apply( Framebuffer &fb, uint64_t confirmed_epoch, bool flag ) const; ConditionalOverlayRow( int s_row_num ) - : row_num( s_row_num ), overlay_cells() - { - } + : row_num( s_row_num ), overlay_cells() {} }; /* the various overlays */ @@ -174,16 +161,13 @@ namespace Overlay { uint64_t message_expiration; bool show_quit_keystroke; - bool server_late( uint64_t ts ) const - { + bool server_late( uint64_t ts ) const { return ( ts - last_word_from_server ) > 6500; } - bool reply_late( uint64_t ts ) const - { + bool reply_late( uint64_t ts ) const { return ( ts - last_acked_state ) > 10000; } - bool need_countup( uint64_t ts ) const - { + bool need_countup( uint64_t ts ) const { return server_late( ts ) || reply_late( ts ); } @@ -191,20 +175,17 @@ namespace Overlay { void adjust_message( void ); void apply( Framebuffer &fb ) const; const wstring &get_notification_string( void ) const { return message; } - void server_heard( uint64_t s_last_word ) - { + void server_heard( uint64_t s_last_word ) { last_word_from_server = s_last_word; } - void server_acked( uint64_t s_last_acked ) - { + void server_acked( uint64_t s_last_acked ) { last_acked_state = s_last_acked; } int wait_time( void ) const; void set_notification_string( const wstring &s_message, bool permanent = false, - bool s_show_quit_keystroke = true ) - { + bool s_show_quit_keystroke = true ) { message = s_message; if ( permanent ) { message_expiration = -1; @@ -215,15 +196,13 @@ namespace Overlay { show_quit_keystroke = s_show_quit_keystroke; } - void set_escape_key_string( const string &s_name ) - { + void set_escape_key_string( const string &s_name ) { char tmp[ 128 ]; snprintf( tmp, sizeof tmp, " [To quit: %s .]", s_name.c_str() ); escape_key_string = tmp; } - void set_network_error( const std::string &s ) - { + void set_network_error( const std::string &s ) { wchar_t tmp[ 128 ]; swprintf( tmp, 128, L"%s", s.c_str() ); @@ -232,8 +211,7 @@ namespace Overlay { message_expiration = timestamp() + Network::ACK_INTERVAL + 100; } - void clear_network_error() - { + void clear_network_error() { if ( message_is_network_error ) { message_expiration = std::min( message_expiration, timestamp() + 1000 ); } @@ -289,8 +267,7 @@ namespace Overlay { long-pending prediction */ uint64_t last_quick_confirmation; - ConditionalCursorMove &cursor( void ) - { + ConditionalCursorMove &cursor( void ) { assert( !cursors.empty() ); return cursors.back(); } @@ -312,19 +289,16 @@ namespace Overlay { bool active( void ) const; - bool timing_tests_necessary( void ) const - { + bool timing_tests_necessary( void ) const { /* Are there any timing-based triggers that haven't fired yet? */ return !( glitch_trigger && flagging ); } public: - void set_display_preference( DisplayPreference s_pref ) - { + void set_display_preference( DisplayPreference s_pref ) { display_preference = s_pref; } - void set_predict_overwrite( bool overwrite ) - { + void set_predict_overwrite( bool overwrite ) { predict_overwrite = overwrite; } @@ -336,39 +310,35 @@ namespace Overlay { void set_local_frame_sent( uint64_t x ) { local_frame_sent = x; } void set_local_frame_acked( uint64_t x ) { local_frame_acked = x; } - void set_local_frame_late_acked( uint64_t x ) - { + void set_local_frame_late_acked( uint64_t x ) { local_frame_late_acked = x; } void set_send_interval( unsigned int x ) { send_interval = x; } - int wait_time( void ) const - { + int wait_time( void ) const { return ( timing_tests_necessary() && active() ) ? 50 : INT_MAX; } PredictionEngine( void ) - : last_byte( 0 ) - , parser() - , overlays() - , cursors() - , local_frame_sent( 0 ) - , local_frame_acked( 0 ) - , local_frame_late_acked( 0 ) - , prediction_epoch( 1 ) - , confirmed_epoch( 0 ) - , flagging( false ) - , srtt_trigger( false ) - , glitch_trigger( 0 ) - , last_quick_confirmation( 0 ) - , send_interval( 250 ) - , last_height( 0 ) - , last_width( 0 ) - , display_preference( Adaptive ) - , predict_overwrite( false ) - { - } + : last_byte( 0 ), + parser(), + overlays(), + cursors(), + local_frame_sent( 0 ), + local_frame_acked( 0 ), + local_frame_late_acked( 0 ), + prediction_epoch( 1 ), + confirmed_epoch( 0 ), + flagging( false ), + srtt_trigger( false ), + glitch_trigger( 0 ), + last_quick_confirmation( 0 ), + send_interval( 250 ), + last_height( 0 ), + last_width( 0 ), + display_preference( Adaptive ), + predict_overwrite( false ) {} }; class TitleEngine { @@ -391,8 +361,7 @@ namespace Overlay { public: void apply( Framebuffer &fb ); - NotificationEngine &get_notification_engine( void ) - { + NotificationEngine &get_notification_engine( void ) { return notifications; } PredictionEngine &get_prediction_engine( void ) { return predictions; } @@ -401,8 +370,7 @@ namespace Overlay { OverlayManager() : notifications(), predictions(), title() {} - int wait_time( void ) const - { + int wait_time( void ) const { return std::min( notifications.wait_time(), predictions.wait_time() ); } }; diff --git a/src/fuzz/terminal_fuzzer.cc b/src/fuzz/terminal_fuzzer.cc index ce573e8bd..c0184f63a 100644 --- a/src/fuzz/terminal_fuzzer.cc +++ b/src/fuzz/terminal_fuzzer.cc @@ -4,8 +4,7 @@ #include "completeterminal.h" #include "parser.h" -extern "C" int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) -{ +extern "C" int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) { Terminal::Display display( false ); Terminal::Complete complete( 80, 24 ); Terminal::Framebuffer state( 80, 24 ); diff --git a/src/fuzz/terminal_parser_fuzzer.cc b/src/fuzz/terminal_parser_fuzzer.cc index c645609e2..0747dc7d0 100644 --- a/src/fuzz/terminal_parser_fuzzer.cc +++ b/src/fuzz/terminal_parser_fuzzer.cc @@ -3,12 +3,13 @@ #include "parser.h" -extern "C" int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) -{ +extern "C" int LLVMFuzzerTestOneInput( const uint8_t *data, size_t size ) { Parser::UTF8Parser parser; Parser::Actions result; - for ( size_t i = 0; i < size; i++ ) { parser.input( data[ i ], result ); } + for ( size_t i = 0; i < size; i++ ) { + parser.input( data[ i ], result ); + } return 0; } diff --git a/src/network/compressor.cc b/src/network/compressor.cc index 151687f62..39ccdcc30 100644 --- a/src/network/compressor.cc +++ b/src/network/compressor.cc @@ -38,8 +38,7 @@ using namespace Network; using std::string; -string Compressor::compress_str( const string &input ) -{ +string Compressor::compress_str( const string &input ) { long unsigned int len = BUFFER_SIZE; dos_assert( Z_OK @@ -49,8 +48,7 @@ string Compressor::compress_str( const string &input ) return string( reinterpret_cast( buffer ), len ); } -string Compressor::uncompress_str( const string &input ) -{ +string Compressor::uncompress_str( const string &input ) { long unsigned int len = BUFFER_SIZE; dos_assert( Z_OK @@ -61,8 +59,7 @@ string Compressor::uncompress_str( const string &input ) } /* construct on first use */ -Compressor &Network::get_compressor( void ) -{ +Compressor &Network::get_compressor( void ) { static Compressor the_compressor; return the_compressor; } diff --git a/src/network/network.cc b/src/network/network.cc index fe127dc1c..1008589be 100644 --- a/src/network/network.cc +++ b/src/network/network.cc @@ -68,13 +68,12 @@ const uint64_t SEQUENCE_MASK = uint64_t( -1 ) ^ DIRECTION_MASK; /* Read in packet */ Packet::Packet( const Message &message ) - : seq( message.nonce.val() & SEQUENCE_MASK ) - , direction( ( message.nonce.val() & DIRECTION_MASK ) ? TO_CLIENT : - TO_SERVER ) - , timestamp( -1 ) - , timestamp_reply( -1 ) - , payload() -{ + : seq( message.nonce.val() & SEQUENCE_MASK ), + direction( ( message.nonce.val() & DIRECTION_MASK ) ? TO_CLIENT : + TO_SERVER ), + timestamp( -1 ), + timestamp_reply( -1 ), + payload() { dos_assert( message.text.size() >= 2 * sizeof( uint16_t ) ); const uint16_t *data = (uint16_t *)message.text.data(); @@ -86,8 +85,7 @@ Packet::Packet( const Message &message ) } /* Output from packet */ -Message Packet::toMessage( void ) -{ +Message Packet::toMessage( void ) { uint64_t direction_seq = ( uint64_t( direction == TO_CLIENT ) << 63 ) | ( seq & SEQUENCE_MASK ); @@ -100,8 +98,7 @@ Message Packet::toMessage( void ) return Message( Nonce( direction_seq ), timestamps + payload ); } -Packet Connection::new_packet( const string &s_payload ) -{ +Packet Connection::new_packet( const string &s_payload ) { uint16_t outgoing_timestamp_reply = -1; uint64_t now = timestamp(); @@ -120,8 +117,7 @@ Packet Connection::new_packet( const string &s_payload ) return p; } -void Connection::hop_port( void ) -{ +void Connection::hop_port( void ) { assert( !server ); setup(); @@ -131,14 +127,15 @@ void Connection::hop_port( void ) prune_sockets(); } -void Connection::prune_sockets( void ) -{ +void Connection::prune_sockets( void ) { /* don't keep old sockets if the new socket has been working for long enough */ if ( socks.size() > 1 ) { if ( timestamp() - last_port_choice > MAX_OLD_SOCKET_AGE ) { int num_to_kill = socks.size() - 1; - for ( int i = 0; i < num_to_kill; i++ ) { socks.pop_front(); } + for ( int i = 0; i < num_to_kill; i++ ) { + socks.pop_front(); + } } } else { return; @@ -147,14 +144,17 @@ void Connection::prune_sockets( void ) /* make sure we don't have too many receive sockets open */ if ( socks.size() > MAX_PORTS_OPEN ) { int num_to_kill = socks.size() - MAX_PORTS_OPEN; - for ( int i = 0; i < num_to_kill; i++ ) { socks.pop_front(); } + for ( int i = 0; i < num_to_kill; i++ ) { + socks.pop_front(); + } } } Connection::Socket::Socket( int family ) - : _fd( socket( family, SOCK_DGRAM, 0 ) ) -{ - if ( _fd < 0 ) { throw NetworkException( "socket", errno ); } + : _fd( socket( family, SOCK_DGRAM, 0 ) ) { + if ( _fd < 0 ) { + throw NetworkException( "socket", errno ); + } /* Disable path MTU discovery */ #ifdef HAVE_IP_MTU_DISCOVER @@ -184,8 +184,7 @@ Connection::Socket::Socket( int family ) void Connection::setup( void ) { last_port_choice = timestamp(); } -const std::vector Connection::fds( void ) const -{ +const std::vector Connection::fds( void ) const { std::vector ret; for ( std::deque::const_iterator it = socks.begin(); @@ -196,8 +195,7 @@ const std::vector Connection::fds( void ) const return ret; } -void Connection::set_MTU( int family ) -{ +void Connection::set_MTU( int family ) { switch ( family ) { case AF_INET: MTU = DEFAULT_IPV4_MTU - IPV4_HEADER_LEN; break; case AF_INET6: MTU = DEFAULT_IPV6_MTU - IPV6_HEADER_LEN; break; @@ -210,8 +208,7 @@ class AddrInfo { struct addrinfo *res; AddrInfo( const char *node, const char *service, const struct addrinfo *hints ) - : res( NULL ) - { + : res( NULL ) { int errcode = getaddrinfo( node, service, hints, &res ); if ( errcode != 0 ) { throw NetworkException( std::string( "Bad IP address (" ) @@ -229,26 +226,25 @@ class AddrInfo { Connection::Connection( const char *desired_ip, const char *desired_port ) /* server */ - : socks() - , has_remote_addr( false ) - , remote_addr() - , remote_addr_len( 0 ) - , server( true ) - , MTU( DEFAULT_SEND_MTU ) - , key() - , session( key ) - , direction( TO_CLIENT ) - , saved_timestamp( -1 ) - , saved_timestamp_received_at( 0 ) - , expected_receiver_seq( 0 ) - , last_heard( -1 ) - , last_port_choice( -1 ) - , last_roundtrip_success( -1 ) - , RTT_hit( false ) - , SRTT( 1000 ) - , RTTVAR( 500 ) - , send_error() -{ + : socks(), + has_remote_addr( false ), + remote_addr(), + remote_addr_len( 0 ), + server( true ), + MTU( DEFAULT_SEND_MTU ), + key(), + session( key ), + direction( TO_CLIENT ), + saved_timestamp( -1 ), + saved_timestamp_received_at( 0 ), + expected_receiver_seq( 0 ), + last_heard( -1 ), + last_port_choice( -1 ), + last_roundtrip_success( -1 ), + RTT_hit( false ), + SRTT( 1000 ), + RTTVAR( 500 ), + send_error() { setup(); /* The mosh wrapper always gives an IP request, in order @@ -280,7 +276,9 @@ Connection::Connection( const char *desired_ip, /* now try any local interface */ try { - if ( try_bind( NULL, desired_port_low, desired_port_high ) ) { return; } + if ( try_bind( NULL, desired_port_low, desired_port_high ) ) { + return; + } } catch ( const NetworkException &e ) { fprintf( stderr, "Error binding to any interface: %s\n", e.what() ); throw; /* this time it's fatal */ @@ -289,8 +287,7 @@ Connection::Connection( const char *desired_ip, throw NetworkException( "Could not bind", errno ); } -bool Connection::try_bind( const char *addr, int port_low, int port_high ) -{ +bool Connection::try_bind( const char *addr, int port_low, int port_high ) { struct addrinfo hints; memset( &hints, 0, sizeof( hints ) ); hints.ai_family = AF_UNSPEC; @@ -351,26 +348,25 @@ bool Connection::try_bind( const char *addr, int port_low, int port_high ) Connection::Connection( const char *key_str, const char *ip, const char *port ) /* client */ - : socks() - , has_remote_addr( false ) - , remote_addr() - , remote_addr_len( 0 ) - , server( false ) - , MTU( DEFAULT_SEND_MTU ) - , key( key_str ) - , session( key ) - , direction( TO_SERVER ) - , saved_timestamp( -1 ) - , saved_timestamp_received_at( 0 ) - , expected_receiver_seq( 0 ) - , last_heard( -1 ) - , last_port_choice( -1 ) - , last_roundtrip_success( -1 ) - , RTT_hit( false ) - , SRTT( 1000 ) - , RTTVAR( 500 ) - , send_error() -{ + : socks(), + has_remote_addr( false ), + remote_addr(), + remote_addr_len( 0 ), + server( false ), + MTU( DEFAULT_SEND_MTU ), + key( key_str ), + session( key ), + direction( TO_SERVER ), + saved_timestamp( -1 ), + saved_timestamp_received_at( 0 ), + expected_receiver_seq( 0 ), + last_heard( -1 ), + last_port_choice( -1 ), + last_roundtrip_success( -1 ), + RTT_hit( false ), + SRTT( 1000 ), + RTTVAR( 500 ), + send_error() { setup(); /* associate socket with remote host and port */ @@ -392,9 +388,10 @@ Connection::Connection( const char *key_str, const char *ip, set_MTU( remote_addr.sa.sa_family ); } -void Connection::send( const string &s ) -{ - if ( !has_remote_addr ) { return; } +void Connection::send( const string &s ) { + if ( !has_remote_addr ) { + return; + } Packet px = new_packet( s ); @@ -427,8 +424,7 @@ void Connection::send( const string &s ) } } -string Connection::recv( void ) -{ +string Connection::recv( void ) { assert( !socks.empty() ); for ( std::deque::const_iterator it = socks.begin(); it != socks.end(); it++ ) { @@ -450,8 +446,7 @@ string Connection::recv( void ) throw NetworkException( "No packet received" ); } -string Connection::recv_one( int sock_to_recv ) -{ +string Connection::recv_one( int sock_to_recv ) { /* receive source address, ECN, and payload in msghdr structure */ Addr packet_remote_addr; struct msghdr header; @@ -479,7 +474,9 @@ string Connection::recv_one( int sock_to_recv ) ssize_t received_len = recvmsg( sock_to_recv, &header, MSG_DONTWAIT ); - if ( received_len < 0 ) { throw NetworkException( "recvmsg", errno ); } + if ( received_len < 0 ) { + throw NetworkException( "recvmsg", errno ); + } if ( header.msg_flags & MSG_TRUNC ) { throw NetworkException( "Received oversize datagram", errno ); @@ -576,8 +573,7 @@ string Connection::recv_one( int sock_to_recv ) return p.payload; } -std::string Connection::port( void ) const -{ +std::string Connection::port( void ) const { Addr local_addr; socklen_t addrlen = sizeof( local_addr ); @@ -598,17 +594,19 @@ std::string Connection::port( void ) const uint64_t Network::timestamp( void ) { return frozen_timestamp(); } -uint16_t Network::timestamp16( void ) -{ +uint16_t Network::timestamp16( void ) { uint16_t ts = timestamp() % 65536; - if ( ts == uint16_t( -1 ) ) { ts++; } + if ( ts == uint16_t( -1 ) ) { + ts++; + } return ts; } -uint16_t Network::timestamp_diff( uint16_t tsnew, uint16_t tsold ) -{ +uint16_t Network::timestamp_diff( uint16_t tsnew, uint16_t tsold ) { int diff = tsnew - tsold; - if ( diff < 0 ) { diff += 65536; } + if ( diff < 0 ) { + diff += 65536; + } assert( diff >= 0 ); assert( diff <= 65535 ); @@ -616,8 +614,7 @@ uint16_t Network::timestamp_diff( uint16_t tsnew, uint16_t tsold ) return diff; } -uint64_t Connection::timeout( void ) const -{ +uint64_t Connection::timeout( void ) const { uint64_t RTO = lrint( ceil( SRTT + 4 * RTTVAR ) ); if ( RTO < MIN_RTO ) { RTO = MIN_RTO; @@ -629,13 +626,13 @@ uint64_t Connection::timeout( void ) const Connection::Socket::~Socket() { fatal_assert( close( _fd ) == 0 ); } -Connection::Socket::Socket( const Socket &other ) : _fd( dup( other._fd ) ) -{ - if ( _fd < 0 ) { throw NetworkException( "socket", errno ); } +Connection::Socket::Socket( const Socket &other ) : _fd( dup( other._fd ) ) { + if ( _fd < 0 ) { + throw NetworkException( "socket", errno ); + } } -Connection::Socket &Connection::Socket::operator=( const Socket &other ) -{ +Connection::Socket &Connection::Socket::operator=( const Socket &other ) { if ( dup2( other._fd, _fd ) < 0 ) { throw NetworkException( "socket", errno ); } @@ -645,8 +642,7 @@ Connection::Socket &Connection::Socket::operator=( const Socket &other ) bool Connection::parse_portrange( const char *desired_port, int &desired_port_low, - int &desired_port_high ) -{ + int &desired_port_high ) { /* parse "port" or "portlow:porthigh" */ desired_port_low = desired_port_high = 0; char *end; diff --git a/src/network/network.h b/src/network/network.h index 4fbf41934..024938c9d 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -65,11 +65,9 @@ namespace Network { public: NetworkException( string s_function = "", int s_errno = 0 ) - : function( s_function ) - , the_errno( s_errno ) - , my_what( function + ": " + strerror( the_errno ) ) - { - } + : function( s_function ), + the_errno( s_errno ), + my_what( function + ": " + strerror( the_errno ) ) {} const char *what() const throw() { return my_what.c_str(); } ~NetworkException() throw() {} }; @@ -85,13 +83,11 @@ namespace Network { Packet( Direction s_direction, uint16_t s_timestamp, uint16_t s_timestamp_reply, const string &s_payload ) - : seq( Crypto::unique() ) - , direction( s_direction ) - , timestamp( s_timestamp ) - , timestamp_reply( s_timestamp_reply ) - , payload( s_payload ) - { - } + : seq( Crypto::unique() ), + direction( s_direction ), + timestamp( s_timestamp ), + timestamp_reply( s_timestamp_reply ), + payload( s_payload ) {} Packet( const Message &message ); @@ -200,8 +196,7 @@ namespace Network { void hop_port( void ); - int sock( void ) const - { + int sock( void ) const { assert( !socks.empty() ); return socks.back().fd(); } @@ -237,8 +232,7 @@ namespace Network { string &get_send_error( void ) { return send_error; } - void set_last_roundtrip_success( uint64_t s_success ) - { + void set_last_roundtrip_success( uint64_t s_success ) { last_roundtrip_success = s_success; } diff --git a/src/network/networktransport-impl.h b/src/network/networktransport-impl.h index a2ce305e5..59c1f6a8d 100644 --- a/src/network/networktransport-impl.h +++ b/src/network/networktransport-impl.h @@ -44,15 +44,14 @@ Transport::Transport( MyState &initial_state, RemoteState &initial_remote, const char *desired_ip, const char *desired_port ) - : connection( desired_ip, desired_port ) - , sender( &connection, initial_state ) - , received_states( - 1, TimestampedState( timestamp(), 0, initial_remote ) ) - , receiver_quench_timer( 0 ) - , last_receiver_state( initial_remote ) - , fragments() - , verbose( 0 ) -{ + : connection( desired_ip, desired_port ), + sender( &connection, initial_state ), + received_states( + 1, TimestampedState( timestamp(), 0, initial_remote ) ), + receiver_quench_timer( 0 ), + last_receiver_state( initial_remote ), + fragments(), + verbose( 0 ) { /* server */ } @@ -61,21 +60,19 @@ Transport::Transport( MyState &initial_state, RemoteState &initial_remote, const char *key_str, const char *ip, const char *port ) - : connection( key_str, ip, port ) - , sender( &connection, initial_state ) - , received_states( - 1, TimestampedState( timestamp(), 0, initial_remote ) ) - , receiver_quench_timer( 0 ) - , last_receiver_state( initial_remote ) - , fragments() - , verbose( 0 ) -{ + : connection( key_str, ip, port ), + sender( &connection, initial_state ), + received_states( + 1, TimestampedState( timestamp(), 0, initial_remote ) ), + receiver_quench_timer( 0 ), + last_receiver_state( initial_remote ), + fragments(), + verbose( 0 ) { /* client */ } template -void Transport::recv( void ) -{ +void Transport::recv( void ) { string s( connection.recv() ); Fragment frag( s ); @@ -96,7 +93,9 @@ void Transport::recv( void ) for ( typename list >::iterator i = received_states.begin(); i != received_states.end(); i++ ) { - if ( inst.new_num() == i->num ) { return; } + if ( inst.new_num() == i->num ) { + return; + } } /* now, make sure we do have the old state */ @@ -147,7 +146,9 @@ void Transport::recv( void ) new_state.timestamp = timestamp(); new_state.num = inst.new_num(); - if ( !inst.diff().empty() ) { new_state.state.apply_string( inst.diff() ); } + if ( !inst.diff().empty() ) { + new_state.state.apply_string( inst.diff() ); + } /* Insert new state in sorted place */ for ( typename list >::iterator i = @@ -172,7 +173,9 @@ void Transport::recv( void ) sender.set_ack_num( received_states.back().num ); sender.remote_heard( new_state.timestamp ); - if ( !inst.diff().empty() ) { sender.set_data_ack(); } + if ( !inst.diff().empty() ) { + sender.set_data_ack(); + } } } @@ -180,14 +183,15 @@ void Transport::recv( void ) * need to keep around */ template void Transport::process_throwaway_until( - uint64_t throwaway_num ) -{ + uint64_t throwaway_num ) { typename list >::iterator i = received_states.begin(); while ( i != received_states.end() ) { typename list >::iterator inext = i; inext++; - if ( i->num < throwaway_num ) { received_states.erase( i ); } + if ( i->num < throwaway_num ) { + received_states.erase( i ); + } i = inext; } @@ -195,8 +199,7 @@ void Transport::process_throwaway_until( } template -string Transport::get_remote_diff( void ) -{ +string Transport::get_remote_diff( void ) { /* find diff between last receiver state and current remote state, then * rationalize states */ diff --git a/src/network/networktransport.h b/src/network/networktransport.h index c58e6e758..e363679ae 100644 --- a/src/network/networktransport.h +++ b/src/network/networktransport.h @@ -86,26 +86,21 @@ namespace Network { /* Shut down other side of connection. */ /* Illegal to change current_state after this. */ void start_shutdown( void ) { sender.start_shutdown(); } - bool shutdown_in_progress( void ) const - { + bool shutdown_in_progress( void ) const { return sender.get_shutdown_in_progress(); } - bool shutdown_acknowledged( void ) const - { + bool shutdown_acknowledged( void ) const { return sender.get_shutdown_acknowledged(); } - bool shutdown_ack_timed_out( void ) const - { + bool shutdown_ack_timed_out( void ) const { return sender.shutdown_ack_timed_out(); } - bool has_remote_addr( void ) const - { + bool has_remote_addr( void ) const { return connection.get_has_remote_addr(); } /* Other side has requested shutdown and we have sent one ACK */ - bool counterparty_shutdown_ack_sent( void ) const - { + bool counterparty_shutdown_ack_sent( void ) const { return sender.get_counterparty_shutdown_acknowledged(); } @@ -113,52 +108,43 @@ namespace Network { string get_key( void ) const { return connection.get_key(); } MyState &get_current_state( void ) { return sender.get_current_state(); } - void set_current_state( const MyState &x ) - { + void set_current_state( const MyState &x ) { sender.set_current_state( x ); } - uint64_t get_remote_state_num( void ) const - { + uint64_t get_remote_state_num( void ) const { return received_states.back().num; } - const TimestampedState &get_latest_remote_state( void ) const - { + const TimestampedState &get_latest_remote_state( void ) const { return received_states.back(); } const std::vector fds( void ) const { return connection.fds(); } - void set_verbose( unsigned int s_verbose ) - { + void set_verbose( unsigned int s_verbose ) { sender.set_verbose( s_verbose ); verbose = s_verbose; } void set_send_delay( int new_delay ) { sender.set_send_delay( new_delay ); } - uint64_t get_sent_state_acked_timestamp( void ) const - { + uint64_t get_sent_state_acked_timestamp( void ) const { return sender.get_sent_state_acked_timestamp(); } - uint64_t get_sent_state_acked( void ) const - { + uint64_t get_sent_state_acked( void ) const { return sender.get_sent_state_acked(); } - uint64_t get_sent_state_last( void ) const - { + uint64_t get_sent_state_last( void ) const { return sender.get_sent_state_last(); } unsigned int send_interval( void ) const { return sender.send_interval(); } - const Addr &get_remote_addr( void ) const - { + const Addr &get_remote_addr( void ) const { return connection.get_remote_addr(); } - socklen_t get_remote_addr_len( void ) const - { + socklen_t get_remote_addr_len( void ) const { return connection.get_remote_addr_len(); } diff --git a/src/network/transportfragment.cc b/src/network/transportfragment.cc index 95209f5b7..840a324c7 100644 --- a/src/network/transportfragment.cc +++ b/src/network/transportfragment.cc @@ -41,20 +41,17 @@ using namespace Network; using namespace TransportBuffers; -static string network_order_string( uint16_t host_order ) -{ +static string network_order_string( uint16_t host_order ) { uint16_t net_int = htobe16( host_order ); return string( (char *)&net_int, sizeof( net_int ) ); } -static string network_order_string( uint64_t host_order ) -{ +static string network_order_string( uint64_t host_order ) { uint64_t net_int = htobe64( host_order ); return string( (char *)&net_int, sizeof( net_int ) ); } -string Fragment::tostring( void ) -{ +string Fragment::tostring( void ) { assert( initialized ); string ret; @@ -75,12 +72,11 @@ string Fragment::tostring( void ) } Fragment::Fragment( const string &x ) - : id( -1 ) - , fragment_num( -1 ) - , final( false ) - , initialized( true ) - , contents() -{ + : id( -1 ), + fragment_num( -1 ), + final( false ), + initialized( true ), + contents() { fatal_assert( x.size() >= frag_header_len ); contents = string( x.begin() + frag_header_len, x.end() ); @@ -93,8 +89,7 @@ Fragment::Fragment( const string &x ) fragment_num &= 0x7FFF; } -bool FragmentAssembly::add_fragment( Fragment &frag ) -{ +bool FragmentAssembly::add_fragment( Fragment &frag ) { /* see if this is a totally new packet */ if ( current_id != frag.id ) { fragments.clear(); @@ -132,8 +127,7 @@ bool FragmentAssembly::add_fragment( Fragment &frag ) return fragments_arrived == fragments_total; } -Instruction FragmentAssembly::get_assembly( void ) -{ +Instruction FragmentAssembly::get_assembly( void ) { assert( fragments_arrived == fragments_total ); string encoded; @@ -154,16 +148,14 @@ Instruction FragmentAssembly::get_assembly( void ) return ret; } -bool Fragment::operator==( const Fragment &x ) const -{ +bool Fragment::operator==( const Fragment &x ) const { return ( id == x.id ) && ( fragment_num == x.fragment_num ) && ( final == x.final ) && ( initialized == x.initialized ) && ( contents == x.contents ); } vector Fragmenter::make_fragments( const Instruction &inst, - size_t MTU ) -{ + size_t MTU ) { MTU -= Fragment::frag_header_len; if ( ( inst.old_num() != last_instruction.old_num() ) || ( inst.new_num() != last_instruction.new_num() ) diff --git a/src/network/transportfragment.h b/src/network/transportfragment.h index cc1bdc049..96f3c44d7 100644 --- a/src/network/transportfragment.h +++ b/src/network/transportfragment.h @@ -58,23 +58,19 @@ namespace Network { string contents; Fragment() - : id( -1 ) - , fragment_num( -1 ) - , final( false ) - , initialized( false ) - , contents() - { - } + : id( -1 ), + fragment_num( -1 ), + final( false ), + initialized( false ), + contents() {} Fragment( uint64_t s_id, uint16_t s_fragment_num, bool s_final, const string &s_contents ) - : id( s_id ) - , fragment_num( s_fragment_num ) - , final( s_final ) - , initialized( true ) - , contents( s_contents ) - { - } + : id( s_id ), + fragment_num( s_fragment_num ), + final( s_final ), + initialized( true ), + contents( s_contents ) {} Fragment( const string &x ); @@ -91,12 +87,10 @@ namespace Network { public: FragmentAssembly() - : fragments() - , current_id( -1 ) - , fragments_arrived( 0 ) - , fragments_total( -1 ) - { - } + : fragments(), + current_id( -1 ), + fragments_arrived( 0 ), + fragments_total( -1 ) {} bool add_fragment( Fragment &inst ); Instruction get_assembly( void ); }; @@ -108,8 +102,8 @@ namespace Network { size_t last_MTU; public: - Fragmenter() : next_instruction_id( 0 ), last_instruction(), last_MTU( -1 ) - { + Fragmenter() + : next_instruction_id( 0 ), last_instruction(), last_MTU( -1 ) { last_instruction.set_old_num( -1 ); last_instruction.set_new_num( -1 ); } diff --git a/src/network/transportsender-impl.h b/src/network/transportsender-impl.h index fbee1fb89..ffe405402 100644 --- a/src/network/transportsender-impl.h +++ b/src/network/transportsender-impl.h @@ -49,30 +49,28 @@ using namespace Network; template TransportSender::TransportSender( Connection *s_connection, MyState &initial_state ) - : connection( s_connection ) - , current_state( initial_state ) - , sent_states( 1, TimestampedState( timestamp(), 0, initial_state ) ) - , assumed_receiver_state( sent_states.begin() ) - , fragmenter() - , next_ack_time( timestamp() ) - , next_send_time( timestamp() ) - , verbose( 0 ) - , shutdown_in_progress( false ) - , shutdown_tries( 0 ) - , shutdown_start( -1 ) - , ack_num( 0 ) - , pending_data_ack( false ) - , SEND_MINDELAY( 8 ) - , last_heard( 0 ) - , prng() - , mindelay_clock( -1 ) -{ -} + : connection( s_connection ), + current_state( initial_state ), + sent_states( 1, + TimestampedState( timestamp(), 0, initial_state ) ), + assumed_receiver_state( sent_states.begin() ), + fragmenter(), + next_ack_time( timestamp() ), + next_send_time( timestamp() ), + verbose( 0 ), + shutdown_in_progress( false ), + shutdown_tries( 0 ), + shutdown_start( -1 ), + ack_num( 0 ), + pending_data_ack( false ), + SEND_MINDELAY( 8 ), + last_heard( 0 ), + prng(), + mindelay_clock( -1 ) {} /* Try to send roughly two frames per RTT, bounded by limits on frame rate */ template -unsigned int TransportSender::send_interval( void ) const -{ +unsigned int TransportSender::send_interval( void ) const { int SEND_INTERVAL = lrint( ceil( connection->get_SRTT() / 2.0 ) ); if ( SEND_INTERVAL < SEND_INTERVAL_MIN ) { SEND_INTERVAL = SEND_INTERVAL_MIN; @@ -85,8 +83,7 @@ unsigned int TransportSender::send_interval( void ) const /* Housekeeping routine to calculate next send and ack times */ template -void TransportSender::calculate_timers( void ) -{ +void TransportSender::calculate_timers( void ) { uint64_t now = timestamp(); /* Update assumed receiver state */ @@ -100,7 +97,9 @@ void TransportSender::calculate_timers( void ) } if ( !( current_state == sent_states.back().state ) ) { - if ( mindelay_clock == uint64_t( -1 ) ) { mindelay_clock = now; } + if ( mindelay_clock == uint64_t( -1 ) ) { + mindelay_clock = now; + } next_send_time = std::max( mindelay_clock + SEND_MINDELAY, sent_states.back().timestamp + send_interval() ); @@ -127,16 +126,19 @@ void TransportSender::calculate_timers( void ) /* How many ms to wait until next event */ template -int TransportSender::wait_time( void ) -{ +int TransportSender::wait_time( void ) { calculate_timers(); uint64_t next_wakeup = next_ack_time; - if ( next_send_time < next_wakeup ) { next_wakeup = next_send_time; } + if ( next_send_time < next_wakeup ) { + next_wakeup = next_send_time; + } uint64_t now = timestamp(); - if ( !connection->get_has_remote_addr() ) { return INT_MAX; } + if ( !connection->get_has_remote_addr() ) { + return INT_MAX; + } if ( next_wakeup > now ) { return next_wakeup - now; @@ -147,15 +149,18 @@ int TransportSender::wait_time( void ) /* Send data or an empty ack if necessary */ template -void TransportSender::tick( void ) -{ +void TransportSender::tick( void ) { calculate_timers(); /* updates assumed receiver state and rationalizes */ - if ( !connection->get_has_remote_addr() ) { return; } + if ( !connection->get_has_remote_addr() ) { + return; + } uint64_t now = timestamp(); - if ( ( now < next_ack_time ) && ( now < next_send_time ) ) { return; } + if ( ( now < next_ack_time ) && ( now < next_send_time ) ) { + return; + } /* Determine if a new diff or empty ack needs to be sent */ @@ -199,8 +204,7 @@ void TransportSender::tick( void ) } template -void TransportSender::send_empty_ack( void ) -{ +void TransportSender::send_empty_ack( void ) { uint64_t now = timestamp(); assert( now >= next_ack_time ); @@ -208,7 +212,9 @@ void TransportSender::send_empty_ack( void ) uint64_t new_num = sent_states.back().num + 1; /* special case for shutdown sequence */ - if ( shutdown_in_progress ) { new_num = uint64_t( -1 ); } + if ( shutdown_in_progress ) { + new_num = uint64_t( -1 ); + } // sent_states.push_back( TimestampedState( // sent_states.back().timestamp, new_num, current_state ) ); @@ -221,20 +227,20 @@ void TransportSender::send_empty_ack( void ) template void TransportSender::add_sent_state( uint64_t the_timestamp, - uint64_t num, MyState &state ) -{ + uint64_t num, MyState &state ) { sent_states.push_back( TimestampedState( the_timestamp, num, state ) ); if ( sent_states.size() > 32 ) { /* limit on state queue */ typename sent_states_type::iterator last = sent_states.end(); - for ( int i = 0; i < 16; i++ ) { last--; } + for ( int i = 0; i < 16; i++ ) { + last--; + } sent_states.erase( last ); /* erase state from middle of queue */ } } template -void TransportSender::send_to_receiver( const string &diff ) -{ +void TransportSender::send_to_receiver( const string &diff ) { uint64_t new_num; if ( current_state == sent_states.back().state ) { /* previously sent */ new_num = sent_states.back().num; @@ -243,7 +249,9 @@ void TransportSender::send_to_receiver( const string &diff ) } /* special case for shutdown sequence */ - if ( shutdown_in_progress ) { new_num = uint64_t( -1 ); } + if ( shutdown_in_progress ) { + new_num = uint64_t( -1 ); + } if ( new_num == sent_states.back().num ) { sent_states.back().timestamp = timestamp(); @@ -263,8 +271,7 @@ void TransportSender::send_to_receiver( const string &diff ) } template -void TransportSender::update_assumed_receiver_state( void ) -{ +void TransportSender::update_assumed_receiver_state( void ) { uint64_t now = timestamp(); /* start from what is known and give benefit of the doubt to unacknowledged @@ -288,8 +295,7 @@ void TransportSender::update_assumed_receiver_state( void ) } template -void TransportSender::rationalize_states( void ) -{ +void TransportSender::rationalize_states( void ) { const MyState *known_receiver_state = &sent_states.front().state; current_state.subtract( known_receiver_state ); @@ -302,8 +308,7 @@ void TransportSender::rationalize_states( void ) } template -const string TransportSender::make_chaff( void ) -{ +const string TransportSender::make_chaff( void ) { const size_t CHAFF_MAX = 16; const size_t chaff_len = prng.uint8() % ( CHAFF_MAX + 1 ); @@ -314,8 +319,7 @@ const string TransportSender::make_chaff( void ) template void TransportSender::send_in_fragments( const string &diff, - uint64_t new_num ) -{ + uint64_t new_num ) { Instruction inst; inst.set_protocol_version( MOSH_PROTOCOL_VERSION ); @@ -326,7 +330,9 @@ void TransportSender::send_in_fragments( const string &diff, inst.set_diff( diff ); inst.set_chaff( make_chaff() ); - if ( new_num == uint64_t( -1 ) ) { shutdown_tries++; } + if ( new_num == uint64_t( -1 ) ) { + shutdown_tries++; + } vector fragments = fragmenter.make_fragments( inst, connection->get_MTU() - Network::Connection::ADDED_BYTES @@ -352,20 +358,23 @@ void TransportSender::send_in_fragments( const string &diff, template void TransportSender::process_acknowledgment_through( - uint64_t ack_num ) -{ + uint64_t ack_num ) { /* Ignore ack if we have culled the state it's acknowledging */ typename sent_states_type::iterator i; for ( i = sent_states.begin(); i != sent_states.end(); i++ ) { - if ( i->num == ack_num ) { break; } + if ( i->num == ack_num ) { + break; + } } if ( i != sent_states.end() ) { for ( i = sent_states.begin(); i != sent_states.end(); ) { typename sent_states_type::iterator i_next = i; i_next++; - if ( i->num < ack_num ) { sent_states.erase( i ); } + if ( i->num < ack_num ) { + sent_states.erase( i ); + } i = i_next; } } @@ -374,8 +383,7 @@ void TransportSender::process_acknowledgment_through( /* give up on getting acknowledgement for shutdown */ template -bool TransportSender::shutdown_ack_timed_out( void ) const -{ +bool TransportSender::shutdown_ack_timed_out( void ) const { if ( shutdown_in_progress ) { if ( shutdown_tries >= SHUTDOWN_RETRIES ) { return true; @@ -390,8 +398,7 @@ bool TransportSender::shutdown_ack_timed_out( void ) const /* Executed upon entry to new receiver state */ template -void TransportSender::set_ack_num( uint64_t s_ack_num ) -{ +void TransportSender::set_ack_num( uint64_t s_ack_num ) { ack_num = s_ack_num; } @@ -399,9 +406,10 @@ void TransportSender::set_ack_num( uint64_t s_ack_num ) /* Mutates proposed_diff */ template void TransportSender::attempt_prospective_resend_optimization( - string &proposed_diff ) -{ - if ( assumed_receiver_state == sent_states.begin() ) { return; } + string &proposed_diff ) { + if ( assumed_receiver_state == sent_states.begin() ) { + return; + } string resend_diff = current_state.diff_from( sent_states.front().state ); diff --git a/src/network/transportsender.h b/src/network/transportsender.h index 1080a02a0..6c1fcdaec 100644 --- a/src/network/transportsender.h +++ b/src/network/transportsender.h @@ -132,8 +132,7 @@ namespace Network { void remote_heard( uint64_t ts ) { last_heard = ts; } /* Starts shutdown sequence */ - void start_shutdown( void ) - { + void start_shutdown( void ) { if ( !shutdown_in_progress ) { shutdown_start = timestamp(); shutdown_in_progress = true; @@ -142,13 +141,11 @@ namespace Network { /* Misc. getters and setters */ /* Cannot modify current_state while shutdown in progress */ - MyState &get_current_state( void ) - { + MyState &get_current_state( void ) { assert( !shutdown_in_progress ); return current_state; } - void set_current_state( const MyState &x ) - { + void set_current_state( const MyState &x ) { assert( !shutdown_in_progress ); current_state = x; current_state.reset_input(); @@ -156,24 +153,19 @@ namespace Network { void set_verbose( unsigned int s_verbose ) { verbose = s_verbose; } bool get_shutdown_in_progress( void ) const { return shutdown_in_progress; } - bool get_shutdown_acknowledged( void ) const - { + bool get_shutdown_acknowledged( void ) const { return sent_states.front().num == uint64_t( -1 ); } - bool get_counterparty_shutdown_acknowledged( void ) const - { + bool get_counterparty_shutdown_acknowledged( void ) const { return fragmenter.last_ack_sent() == uint64_t( -1 ); } - uint64_t get_sent_state_acked_timestamp( void ) const - { + uint64_t get_sent_state_acked_timestamp( void ) const { return sent_states.front().timestamp; } - uint64_t get_sent_state_acked( void ) const - { + uint64_t get_sent_state_acked( void ) const { return sent_states.front().num; } - uint64_t get_sent_state_last( void ) const - { + uint64_t get_sent_state_last( void ) const { return sent_states.back().num; } diff --git a/src/network/transportstate.h b/src/network/transportstate.h index b8d708a5a..001b1c3b4 100644 --- a/src/network/transportstate.h +++ b/src/network/transportstate.h @@ -43,9 +43,7 @@ namespace Network { TimestampedState( uint64_t s_timestamp, uint64_t s_num, const State &s_state ) - : timestamp( s_timestamp ), num( s_num ), state( s_state ) - { - } + : timestamp( s_timestamp ), num( s_num ), state( s_state ) {} }; } diff --git a/src/statesync/completeterminal.cc b/src/statesync/completeterminal.cc index c99cbe3e9..544b72cdd 100644 --- a/src/statesync/completeterminal.cc +++ b/src/statesync/completeterminal.cc @@ -42,8 +42,7 @@ using namespace Parser; using namespace Terminal; using namespace HostBuffers; -string Complete::act( const string &str ) -{ +string Complete::act( const string &str ) { for ( unsigned int i = 0; i < str.size(); i++ ) { /* parse octet into up to three actions */ parser.input( str[ i ], actions ); @@ -59,16 +58,14 @@ string Complete::act( const string &str ) return terminal.read_octets_to_host(); } -string Complete::act( const Action &act ) -{ +string Complete::act( const Action &act ) { /* apply action to terminal */ act.act_on_terminal( &terminal ); return terminal.read_octets_to_host(); } /* interface for Network::Transport */ -string Complete::diff_from( const Complete &existing ) const -{ +string Complete::diff_from( const Complete &existing ) const { HostBuffers::HostMessage output; if ( existing.get_echo_ack() != get_echo_ack() ) { @@ -99,14 +96,12 @@ string Complete::diff_from( const Complete &existing ) const return output.SerializeAsString(); } -string Complete::init_diff( void ) const -{ +string Complete::init_diff( void ) const { return diff_from( Complete( get_fb().ds.get_width(), get_fb().ds.get_height() ) ); } -void Complete::apply_string( const string &diff ) -{ +void Complete::apply_string( const string &diff ) { HostBuffers::HostMessage input; fatal_assert( input.ParseFromString( diff ) ); @@ -128,56 +123,61 @@ void Complete::apply_string( const string &diff ) } } -bool Complete::operator==( Complete const &x ) const -{ +bool Complete::operator==( Complete const &x ) const { // assert( parser == x.parser ); /* parser state is irrelevant for us */ return ( terminal == x.terminal ) && ( echo_ack == x.echo_ack ); } -bool Complete::set_echo_ack( uint64_t now ) -{ +bool Complete::set_echo_ack( uint64_t now ) { bool ret = false; uint64_t newest_echo_ack = 0; for ( input_history_type::const_iterator i = input_history.begin(); i != input_history.end(); i++ ) { - if ( i->second <= now - ECHO_TIMEOUT ) { newest_echo_ack = i->first; } + if ( i->second <= now - ECHO_TIMEOUT ) { + newest_echo_ack = i->first; + } } for ( input_history_type::iterator i = input_history.begin(); i != input_history.end(); ) { input_history_type::iterator i_next = i; i_next++; - if ( i->first < newest_echo_ack ) { input_history.erase( i ); } + if ( i->first < newest_echo_ack ) { + input_history.erase( i ); + } i = i_next; } - if ( echo_ack != newest_echo_ack ) { ret = true; } + if ( echo_ack != newest_echo_ack ) { + ret = true; + } echo_ack = newest_echo_ack; return ret; } -void Complete::register_input_frame( uint64_t n, uint64_t now ) -{ +void Complete::register_input_frame( uint64_t n, uint64_t now ) { input_history.push_back( std::make_pair( n, now ) ); } -int Complete::wait_time( uint64_t now ) const -{ - if ( input_history.size() < 2 ) { return INT_MAX; } +int Complete::wait_time( uint64_t now ) const { + if ( input_history.size() < 2 ) { + return INT_MAX; + } input_history_type::const_iterator it = input_history.begin(); it++; uint64_t next_echo_ack_time = it->second + ECHO_TIMEOUT; - if ( next_echo_ack_time <= now ) { return 0; } + if ( next_echo_ack_time <= now ) { + return 0; + } return next_echo_ack_time - now; } -bool Complete::compare( const Complete &other ) const -{ +bool Complete::compare( const Complete &other ) const { bool ret = false; const Framebuffer &fb = terminal.get_fb(); const Framebuffer &other_fb = other.terminal.get_fb(); diff --git a/src/statesync/completeterminal.h b/src/statesync/completeterminal.h index 506d8652c..312d12d34 100644 --- a/src/statesync/completeterminal.h +++ b/src/statesync/completeterminal.h @@ -62,14 +62,12 @@ namespace Terminal { public: Complete( size_t width, size_t height ) - : parser() - , terminal( width, height ) - , display( false ) - , actions() - , input_history() - , echo_ack( 0 ) - { - } + : parser(), + terminal( width, height ), + display( false ), + actions(), + input_history(), + echo_ack( 0 ) {} std::string act( const std::string &str ); std::string act( const Parser::Action &act ); diff --git a/src/statesync/user.cc b/src/statesync/user.cc index ff6e99a72..9e95ce196 100644 --- a/src/statesync/user.cc +++ b/src/statesync/user.cc @@ -41,8 +41,7 @@ using namespace Parser; using namespace Network; using namespace ClientBuffers; -void UserStream::subtract( const UserStream *prefix ) -{ +void UserStream::subtract( const UserStream *prefix ) { // if we are subtracting ourself from ourself, just clear the deque if ( this == prefix ) { actions.clear(); @@ -57,8 +56,7 @@ void UserStream::subtract( const UserStream *prefix ) } } -string UserStream::diff_from( const UserStream &existing ) const -{ +string UserStream::diff_from( const UserStream &existing ) const { deque::const_iterator my_it = actions.begin(); for ( deque::const_iterator i = existing.actions.begin(); @@ -106,8 +104,7 @@ string UserStream::diff_from( const UserStream &existing ) const return output.SerializeAsString(); } -void UserStream::apply_string( const string &diff ) -{ +void UserStream::apply_string( const string &diff ) { ClientBuffers::UserMessage input; fatal_assert( input.ParseFromString( diff ) ); @@ -126,8 +123,7 @@ void UserStream::apply_string( const string &diff ) } } -const Parser::Action &UserStream::get_action( unsigned int i ) const -{ +const Parser::Action &UserStream::get_action( unsigned int i ) const { switch ( actions[ i ].type ) { case UserByteType: return actions[ i ].userbyte; case ResizeType: return actions[ i ].resize; diff --git a/src/statesync/user.h b/src/statesync/user.h index 0db795216..11f2a4497 100644 --- a/src/statesync/user.h +++ b/src/statesync/user.h @@ -54,20 +54,15 @@ namespace Network { Parser::Resize resize; UserEvent( const Parser::UserByte &s_userbyte ) - : type( UserByteType ), userbyte( s_userbyte ), resize( -1, -1 ) - { - } + : type( UserByteType ), userbyte( s_userbyte ), resize( -1, -1 ) {} UserEvent( const Parser::Resize &s_resize ) - : type( ResizeType ), userbyte( 0 ), resize( s_resize ) - { - } + : type( ResizeType ), userbyte( 0 ), resize( s_resize ) {} private: UserEvent(); public: - bool operator==( const UserEvent &x ) const - { + bool operator==( const UserEvent &x ) const { return ( type == x.type ) && ( userbyte == x.userbyte ) && ( resize == x.resize ); } @@ -80,12 +75,10 @@ namespace Network { public: UserStream() : actions() {} - void push_back( const Parser::UserByte &s_userbyte ) - { + void push_back( const Parser::UserByte &s_userbyte ) { actions.push_back( UserEvent( s_userbyte ) ); } - void push_back( const Parser::Resize &s_resize ) - { + void push_back( const Parser::Resize &s_resize ) { actions.push_back( UserEvent( s_resize ) ); } @@ -98,8 +91,7 @@ namespace Network { string diff_from( const UserStream &existing ) const; string init_diff( void ) const { return diff_from( UserStream() ); }; void apply_string( const string &diff ); - bool operator==( const UserStream &x ) const - { + bool operator==( const UserStream &x ) const { return actions == x.actions; } diff --git a/src/terminal/parser.cc b/src/terminal/parser.cc index 65403b465..5c3d70b26 100644 --- a/src/terminal/parser.cc +++ b/src/terminal/parser.cc @@ -40,18 +40,21 @@ const Parser::StateFamily Parser::family; -static void append_or_delete( Parser::ActionPointer act, Parser::Actions &vec ) -{ +static void append_or_delete( Parser::ActionPointer act, + Parser::Actions &vec ) { assert( act ); - if ( !act->ignore() ) { vec.push_back( act ); } + if ( !act->ignore() ) { + vec.push_back( act ); + } } -void Parser::Parser::input( wchar_t ch, Actions &ret ) -{ +void Parser::Parser::input( wchar_t ch, Actions &ret ) { Transition tx = state->input( ch ); - if ( tx.next_state != NULL ) { append_or_delete( state->exit(), ret ); } + if ( tx.next_state != NULL ) { + append_or_delete( state->exit(), ret ); + } append_or_delete( tx.action, ret ); @@ -61,14 +64,12 @@ void Parser::Parser::input( wchar_t ch, Actions &ret ) } } -Parser::UTF8Parser::UTF8Parser() : parser(), buf_len( 0 ) -{ +Parser::UTF8Parser::UTF8Parser() : parser(), buf_len( 0 ) { assert( BUF_SIZE >= (size_t)MB_CUR_MAX ); buf[ 0 ] = '\0'; } -void Parser::UTF8Parser::input( char c, Actions &ret ) -{ +void Parser::UTF8Parser::input( char c, Actions &ret ) { assert( buf_len < BUF_SIZE ); /* 1-byte UTF-8 character, aka ASCII? Cheat. */ @@ -153,8 +154,7 @@ void Parser::UTF8Parser::input( char c, Actions &ret ) Parser::Parser::Parser( const Parser &other ) : state( other.state ) {} -Parser::Parser &Parser::Parser::operator=( const Parser &other ) -{ +Parser::Parser &Parser::Parser::operator=( const Parser &other ) { state = other.state; return *this; } diff --git a/src/terminal/parser.h b/src/terminal/parser.h index f16d9797c..8de07027a 100644 --- a/src/terminal/parser.h +++ b/src/terminal/parser.h @@ -77,8 +77,7 @@ namespace Parser { void input( char c, Actions &actions ); - void reset_input( void ) - { + void reset_input( void ) { parser.reset_input(); buf[ 0 ] = '\0'; buf_len = 0; diff --git a/src/terminal/parseraction.cc b/src/terminal/parseraction.cc index 9ef322dc8..c49631774 100644 --- a/src/terminal/parseraction.cc +++ b/src/terminal/parseraction.cc @@ -38,63 +38,51 @@ using namespace Parser; -void Print::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Print::act_on_terminal( Terminal::Emulator *emu ) const { emu->print( this ); } -void Execute::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Execute::act_on_terminal( Terminal::Emulator *emu ) const { emu->execute( this ); } -void Clear::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Clear::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.clear( this ); } -void Param::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Param::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.newparamchar( this ); } -void Collect::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Collect::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.collect( this ); } -void CSI_Dispatch::act_on_terminal( Terminal::Emulator *emu ) const -{ +void CSI_Dispatch::act_on_terminal( Terminal::Emulator *emu ) const { emu->CSI_dispatch( this ); } -void Esc_Dispatch::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Esc_Dispatch::act_on_terminal( Terminal::Emulator *emu ) const { emu->Esc_dispatch( this ); } -void OSC_Put::act_on_terminal( Terminal::Emulator *emu ) const -{ +void OSC_Put::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.OSC_put( this ); } -void OSC_Start::act_on_terminal( Terminal::Emulator *emu ) const -{ +void OSC_Start::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.OSC_start( this ); } -void OSC_End::act_on_terminal( Terminal::Emulator *emu ) const -{ +void OSC_End::act_on_terminal( Terminal::Emulator *emu ) const { emu->OSC_end( this ); } -void UserByte::act_on_terminal( Terminal::Emulator *emu ) const -{ +void UserByte::act_on_terminal( Terminal::Emulator *emu ) const { emu->dispatch.terminal_to_host.append( emu->user.input( this, emu->fb.ds.application_mode_cursor_keys ) ); } -void Resize::act_on_terminal( Terminal::Emulator *emu ) const -{ +void Resize::act_on_terminal( Terminal::Emulator *emu ) const { emu->resize( width, height ); } diff --git a/src/terminal/parseraction.h b/src/terminal/parseraction.h index bc9f663fc..cedfe120f 100644 --- a/src/terminal/parseraction.h +++ b/src/terminal/parseraction.h @@ -151,12 +151,9 @@ namespace Parser { void act_on_terminal( Terminal::Emulator *emu ) const; Resize( size_t s_width, size_t s_height ) - : width( s_width ), height( s_height ) - { - } + : width( s_width ), height( s_height ) {} - bool operator==( const Resize &other ) const - { + bool operator==( const Resize &other ) const { return ( width == other.width ) && ( height == other.height ); } }; diff --git a/src/terminal/parserstate.cc b/src/terminal/parserstate.cc index 28ecf9c4e..7e3b19a65 100644 --- a/src/terminal/parserstate.cc +++ b/src/terminal/parserstate.cc @@ -36,8 +36,7 @@ using namespace Parser; -Transition State::anywhere_rule( wchar_t ch ) const -{ +Transition State::anywhere_rule( wchar_t ch ) const { if ( ( ch == 0x18 ) || ( ch == 0x1A ) || ( ( 0x80 <= ch ) && ( ch <= 0x8F ) ) || ( ( 0x91 <= ch ) && ( ch <= 0x97 ) ) || ( ch == 0x99 ) || ( ch == 0x9A ) ) { @@ -60,8 +59,7 @@ Transition State::anywhere_rule( wchar_t ch ) const ActionPointer() ); /* don't allocate an Ignore action */ } -Transition State::input( wchar_t ch ) const -{ +Transition State::input( wchar_t ch ) const { /* Check for immediate transitions. */ Transition anywhere = anywhere_rule( ch ); if ( anywhere.next_state ) { @@ -77,35 +75,36 @@ Transition State::input( wchar_t ch ) const return ret; } -static bool C0_prime( wchar_t ch ) -{ +static bool C0_prime( wchar_t ch ) { return ( ch <= 0x17 ) || ( ch == 0x19 ) || ( ( 0x1C <= ch ) && ( ch <= 0x1F ) ); } -static bool GLGR( wchar_t ch ) -{ +static bool GLGR( wchar_t ch ) { return ( ( 0x20 <= ch ) && ( ch <= 0x7F ) ) /* GL area */ || ( ( 0xA0 <= ch ) && ( ch <= 0xFF ) ); /* GR area */ } -Transition Ground::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition Ground::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } - if ( GLGR( ch ) ) { return Transition( shared::make_shared() ); } + if ( GLGR( ch ) ) { + return Transition( shared::make_shared() ); + } return Transition(); } -ActionPointer Escape::enter( void ) const -{ +ActionPointer Escape::enter( void ) const { return shared::make_shared(); } -Transition Escape::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition Escape::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } if ( ( 0x20 <= ch ) && ( ch <= 0x2F ) ) { return Transition( shared::make_shared(), @@ -119,11 +118,17 @@ Transition Escape::input_state_rule( wchar_t ch ) const return Transition( shared::make_shared(), &family->s_Ground ); } - if ( ch == 0x5B ) { return Transition( &family->s_CSI_Entry ); } + if ( ch == 0x5B ) { + return Transition( &family->s_CSI_Entry ); + } - if ( ch == 0x5D ) { return Transition( &family->s_OSC_String ); } + if ( ch == 0x5D ) { + return Transition( &family->s_OSC_String ); + } - if ( ch == 0x50 ) { return Transition( &family->s_DCS_Entry ); } + if ( ch == 0x50 ) { + return Transition( &family->s_DCS_Entry ); + } if ( ( ch == 0x58 ) || ( ch == 0x5E ) || ( ch == 0x5F ) ) { return Transition( &family->s_SOS_PM_APC_String ); @@ -132,9 +137,10 @@ Transition Escape::input_state_rule( wchar_t ch ) const return Transition(); } -Transition Escape_Intermediate::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition Escape_Intermediate::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } if ( ( 0x20 <= ch ) && ( ch <= 0x2F ) ) { return Transition( shared::make_shared() ); @@ -147,14 +153,14 @@ Transition Escape_Intermediate::input_state_rule( wchar_t ch ) const return Transition(); } -ActionPointer CSI_Entry::enter( void ) const -{ +ActionPointer CSI_Entry::enter( void ) const { return shared::make_shared(); } -Transition CSI_Entry::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition CSI_Entry::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } if ( ( 0x40 <= ch ) && ( ch <= 0x7E ) ) { return Transition( shared::make_shared(), &family->s_Ground ); @@ -168,7 +174,9 @@ Transition CSI_Entry::input_state_rule( wchar_t ch ) const return Transition( shared::make_shared(), &family->s_CSI_Param ); } - if ( ch == 0x3A ) { return Transition( &family->s_CSI_Ignore ); } + if ( ch == 0x3A ) { + return Transition( &family->s_CSI_Ignore ); + } if ( ( 0x20 <= ch ) && ( ch <= 0x2F ) ) { return Transition( shared::make_shared(), @@ -178,9 +186,10 @@ Transition CSI_Entry::input_state_rule( wchar_t ch ) const return Transition(); } -Transition CSI_Param::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition CSI_Param::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } if ( ( ( 0x30 <= ch ) && ( ch <= 0x39 ) ) || ( ch == 0x3B ) ) { return Transition( shared::make_shared() ); @@ -202,9 +211,10 @@ Transition CSI_Param::input_state_rule( wchar_t ch ) const return Transition(); } -Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } if ( ( 0x20 <= ch ) && ( ch <= 0x2F ) ) { return Transition( shared::make_shared() ); @@ -221,9 +231,10 @@ Transition CSI_Intermediate::input_state_rule( wchar_t ch ) const return Transition(); } -Transition CSI_Ignore::input_state_rule( wchar_t ch ) const -{ - if ( C0_prime( ch ) ) { return Transition( shared::make_shared() ); } +Transition CSI_Ignore::input_state_rule( wchar_t ch ) const { + if ( C0_prime( ch ) ) { + return Transition( shared::make_shared() ); + } if ( ( 0x40 <= ch ) && ( ch <= 0x7E ) ) { return Transition( &family->s_Ground ); @@ -232,19 +243,19 @@ Transition CSI_Ignore::input_state_rule( wchar_t ch ) const return Transition(); } -ActionPointer DCS_Entry::enter( void ) const -{ +ActionPointer DCS_Entry::enter( void ) const { return shared::make_shared(); } -Transition DCS_Entry::input_state_rule( wchar_t ch ) const -{ +Transition DCS_Entry::input_state_rule( wchar_t ch ) const { if ( ( 0x20 <= ch ) && ( ch <= 0x2F ) ) { return Transition( shared::make_shared(), &family->s_DCS_Intermediate ); } - if ( ch == 0x3A ) { return Transition( &family->s_DCS_Ignore ); } + if ( ch == 0x3A ) { + return Transition( &family->s_DCS_Ignore ); + } if ( ( ( 0x30 <= ch ) && ( ch <= 0x39 ) ) || ( ch == 0x3B ) ) { return Transition( shared::make_shared(), &family->s_DCS_Param ); @@ -261,8 +272,7 @@ Transition DCS_Entry::input_state_rule( wchar_t ch ) const return Transition(); } -Transition DCS_Param::input_state_rule( wchar_t ch ) const -{ +Transition DCS_Param::input_state_rule( wchar_t ch ) const { if ( ( ( 0x30 <= ch ) && ( ch <= 0x39 ) ) || ( ch == 0x3B ) ) { return Transition( shared::make_shared() ); } @@ -283,8 +293,7 @@ Transition DCS_Param::input_state_rule( wchar_t ch ) const return Transition(); } -Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const -{ +Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const { if ( ( 0x20 <= ch ) && ( ch <= 0x2F ) ) { return Transition( shared::make_shared() ); } @@ -300,46 +309,43 @@ Transition DCS_Intermediate::input_state_rule( wchar_t ch ) const return Transition(); } -ActionPointer DCS_Passthrough::enter( void ) const -{ +ActionPointer DCS_Passthrough::enter( void ) const { return shared::make_shared(); } -ActionPointer DCS_Passthrough::exit( void ) const -{ +ActionPointer DCS_Passthrough::exit( void ) const { return shared::make_shared(); } -Transition DCS_Passthrough::input_state_rule( wchar_t ch ) const -{ +Transition DCS_Passthrough::input_state_rule( wchar_t ch ) const { if ( C0_prime( ch ) || ( ( 0x20 <= ch ) && ( ch <= 0x7E ) ) ) { return Transition( shared::make_shared() ); } - if ( ch == 0x9C ) { return Transition( &family->s_Ground ); } + if ( ch == 0x9C ) { + return Transition( &family->s_Ground ); + } return Transition(); } -Transition DCS_Ignore::input_state_rule( wchar_t ch ) const -{ - if ( ch == 0x9C ) { return Transition( &family->s_Ground ); } +Transition DCS_Ignore::input_state_rule( wchar_t ch ) const { + if ( ch == 0x9C ) { + return Transition( &family->s_Ground ); + } return Transition(); } -ActionPointer OSC_String::enter( void ) const -{ +ActionPointer OSC_String::enter( void ) const { return shared::make_shared(); } -ActionPointer OSC_String::exit( void ) const -{ +ActionPointer OSC_String::exit( void ) const { return shared::make_shared(); } -Transition OSC_String::input_state_rule( wchar_t ch ) const -{ +Transition OSC_String::input_state_rule( wchar_t ch ) const { if ( ( 0x20 <= ch ) && ( ch <= 0x7F ) ) { return Transition( shared::make_shared() ); } @@ -351,9 +357,10 @@ Transition OSC_String::input_state_rule( wchar_t ch ) const return Transition(); } -Transition SOS_PM_APC_String::input_state_rule( wchar_t ch ) const -{ - if ( ch == 0x9C ) { return Transition( &family->s_Ground ); } +Transition SOS_PM_APC_String::input_state_rule( wchar_t ch ) const { + if ( ch == 0x9C ) { + return Transition( &family->s_Ground ); + } return Transition(); } diff --git a/src/terminal/parserstate.h b/src/terminal/parserstate.h index 20ce60cc3..e9ea2ee9b 100644 --- a/src/terminal/parserstate.h +++ b/src/terminal/parserstate.h @@ -49,12 +49,10 @@ namespace Parser { public: void setfamily( StateFamily *s_family ) { family = s_family; } Transition input( wchar_t ch ) const; - virtual ActionPointer enter( void ) const - { + virtual ActionPointer enter( void ) const { return shared::make_shared(); } - virtual ActionPointer exit( void ) const - { + virtual ActionPointer exit( void ) const { return shared::make_shared(); } diff --git a/src/terminal/parserstatefamily.h b/src/terminal/parserstatefamily.h index b432206f7..8e5e63a90 100644 --- a/src/terminal/parserstatefamily.h +++ b/src/terminal/parserstatefamily.h @@ -58,21 +58,20 @@ namespace Parser { SOS_PM_APC_String s_SOS_PM_APC_String; StateFamily() - : s_Ground() - , s_Escape() - , s_Escape_Intermediate() - , s_CSI_Entry() - , s_CSI_Param() - , s_CSI_Intermediate() - , s_CSI_Ignore() - , s_DCS_Entry() - , s_DCS_Param() - , s_DCS_Intermediate() - , s_DCS_Passthrough() - , s_DCS_Ignore() - , s_OSC_String() - , s_SOS_PM_APC_String() - { + : s_Ground(), + s_Escape(), + s_Escape_Intermediate(), + s_CSI_Entry(), + s_CSI_Param(), + s_CSI_Intermediate(), + s_CSI_Ignore(), + s_DCS_Entry(), + s_DCS_Param(), + s_DCS_Intermediate(), + s_DCS_Passthrough(), + s_DCS_Ignore(), + s_OSC_String(), + s_SOS_PM_APC_String() { s_Ground.setfamily( this ); s_Escape.setfamily( this ); s_Escape_Intermediate.setfamily( this ); diff --git a/src/terminal/parsertransition.h b/src/terminal/parsertransition.h index fa01a7c4b..5a31f017f 100644 --- a/src/terminal/parsertransition.h +++ b/src/terminal/parsertransition.h @@ -48,11 +48,8 @@ namespace Parser { State *next_state; Transition( const Transition &x ) - : action( x.action ), next_state( x.next_state ) - { - } - Transition &operator=( const Transition &t ) - { + : action( x.action ), next_state( x.next_state ) {} + Transition &operator=( const Transition &t ) { action = t.action; next_state = t.next_state; @@ -60,18 +57,14 @@ namespace Parser { } Transition( ActionPointer s_action = shared::make_shared(), State *s_next_state = NULL ) - : action( s_action ), next_state( s_next_state ) - { - } + : action( s_action ), next_state( s_next_state ) {} // This is only ever used in the 1-argument form; // we use this instead of an initializer to // tell Coverity the object never owns *action. Transition( State *s_next_state, ActionPointer s_action = shared::make_shared() ) - : action( s_action ), next_state( s_next_state ) - { - } + : action( s_action ), next_state( s_next_state ) {} }; } diff --git a/src/terminal/terminal.cc b/src/terminal/terminal.cc index 6c64a40d8..f7dd15876 100644 --- a/src/terminal/terminal.cc +++ b/src/terminal/terminal.cc @@ -41,24 +41,19 @@ using namespace Terminal; Emulator::Emulator( size_t s_width, size_t s_height ) - : fb( s_width, s_height ), dispatch(), user() -{ -} + : fb( s_width, s_height ), dispatch(), user() {} -std::string Emulator::read_octets_to_host( void ) -{ +std::string Emulator::read_octets_to_host( void ) { std::string ret = dispatch.terminal_to_host; dispatch.terminal_to_host.clear(); return ret; } -void Emulator::execute( const Parser::Execute *act ) -{ +void Emulator::execute( const Parser::Execute *act ) { dispatch.dispatch( CONTROL, act, &fb ); } -void Emulator::print( const Parser::Print *act ) -{ +void Emulator::print( const Parser::Print *act ) { assert( act->char_present ); const wchar_t ch = act->ch; @@ -101,7 +96,9 @@ void Emulator::print( const Parser::Print *act ) this_cell = NULL; } - if ( !this_cell ) { this_cell = fb.get_mutable_cell(); } + if ( !this_cell ) { + this_cell = fb.get_mutable_cell(); + } fb.reset_cell( this_cell ); this_cell->append( ch ); @@ -136,7 +133,9 @@ void Emulator::print( const Parser::Print *act ) combining_cell->set_fallback( true ); fb.ds.move_col( 1, true, true ); } - if ( !combining_cell->full() ) { combining_cell->append( ch ); } + if ( !combining_cell->full() ) { + combining_cell->append( ch ); + } } break; case -1: /* unprintable character */ break; @@ -144,18 +143,15 @@ void Emulator::print( const Parser::Print *act ) } } -void Emulator::CSI_dispatch( const Parser::CSI_Dispatch *act ) -{ +void Emulator::CSI_dispatch( const Parser::CSI_Dispatch *act ) { dispatch.dispatch( CSI, act, &fb ); } -void Emulator::OSC_end( const Parser::OSC_End *act ) -{ +void Emulator::OSC_end( const Parser::OSC_End *act ) { dispatch.OSC_dispatch( act, &fb ); } -void Emulator::Esc_dispatch( const Parser::Esc_Dispatch *act ) -{ +void Emulator::Esc_dispatch( const Parser::Esc_Dispatch *act ) { /* handle 7-bit ESC-encoding of C1 control characters */ if ( ( dispatch.get_dispatch_chars().size() == 0 ) && ( 0x40 <= act->ch ) && ( act->ch <= 0x5F ) ) { @@ -167,13 +163,11 @@ void Emulator::Esc_dispatch( const Parser::Esc_Dispatch *act ) } } -void Emulator::resize( size_t s_width, size_t s_height ) -{ +void Emulator::resize( size_t s_width, size_t s_height ) { fb.resize( s_width, s_height ); } -bool Emulator::operator==( Emulator const &x ) const -{ +bool Emulator::operator==( Emulator const &x ) const { /* dispatcher and user are irrelevant for us */ return fb == x.fb; } diff --git a/src/terminal/terminaldispatcher.cc b/src/terminal/terminaldispatcher.cc index 6af580b0c..7225b79e6 100644 --- a/src/terminal/terminaldispatcher.cc +++ b/src/terminal/terminaldispatcher.cc @@ -45,17 +45,14 @@ using namespace Terminal; static const size_t MAXIMUM_CLIPBOARD_SIZE = 16 * 1024; Dispatcher::Dispatcher() - : params() - , parsed_params() - , parsed( false ) - , dispatch_chars() - , OSC_string() - , terminal_to_host() -{ -} - -void Dispatcher::newparamchar( const Parser::Param *act ) -{ + : params(), + parsed_params(), + parsed( false ), + dispatch_chars(), + OSC_string(), + terminal_to_host() {} + +void Dispatcher::newparamchar( const Parser::Param *act ) { assert( act->char_present ); assert( ( act->ch == ';' ) || ( ( act->ch >= '0' ) && ( act->ch <= '9' ) ) ); if ( params.length() < 100 ) { @@ -65,8 +62,7 @@ void Dispatcher::newparamchar( const Parser::Param *act ) parsed = false; } -void Dispatcher::collect( const Parser::Collect *act ) -{ +void Dispatcher::collect( const Parser::Collect *act ) { assert( act->char_present ); if ( ( dispatch_chars.length() < 8 ) /* never should need more than 2 */ && ( act->ch <= 255 ) ) { /* ignore non-8-bit */ @@ -74,16 +70,16 @@ void Dispatcher::collect( const Parser::Collect *act ) } } -void Dispatcher::clear( const Parser::Clear *act __attribute( ( unused ) ) ) -{ +void Dispatcher::clear( const Parser::Clear *act __attribute( ( unused ) ) ) { params.clear(); dispatch_chars.clear(); parsed = false; } -void Dispatcher::parse_params( void ) -{ - if ( parsed ) { return; } +void Dispatcher::parse_params( void ) { + if ( parsed ) { + return; + } parsed_params.clear(); const char *str = params.c_str(); @@ -91,12 +87,16 @@ void Dispatcher::parse_params( void ) while ( 1 ) { const char *segment_end = strchr( segment_begin, ';' ); - if ( segment_end == NULL ) { break; } + if ( segment_end == NULL ) { + break; + } errno = 0; char *endptr; long val = strtol( segment_begin, &endptr, 10 ); - if ( endptr == segment_begin ) { val = -1; } + if ( endptr == segment_begin ) { + val = -1; + } if ( val > PARAM_MAX || errno == ERANGE ) { val = -1; @@ -114,7 +114,9 @@ void Dispatcher::parse_params( void ) errno = 0; char *endptr; long val = strtol( segment_begin, &endptr, 10 ); - if ( endptr == segment_begin ) { val = -1; } + if ( endptr == segment_begin ) { + val = -1; + } if ( val > PARAM_MAX || errno == ERANGE ) { val = -1; @@ -128,27 +130,30 @@ void Dispatcher::parse_params( void ) parsed = true; } -int Dispatcher::getparam( size_t N, int defaultval ) -{ +int Dispatcher::getparam( size_t N, int defaultval ) { int ret = defaultval; - if ( !parsed ) { parse_params(); } + if ( !parsed ) { + parse_params(); + } - if ( parsed_params.size() > N ) { ret = parsed_params[ N ]; } + if ( parsed_params.size() > N ) { + ret = parsed_params[ N ]; + } if ( ret < 1 ) ret = defaultval; return ret; } -int Dispatcher::param_count( void ) -{ - if ( !parsed ) { parse_params(); } +int Dispatcher::param_count( void ) { + if ( !parsed ) { + parse_params(); + } return parsed_params.size(); } -std::string Dispatcher::str( void ) -{ +std::string Dispatcher::str( void ) { char assum[ 64 ]; snprintf( assum, 64, "[dispatch=\"%s\" params=\"%s\"]", dispatch_chars.c_str(), params.c_str() ); @@ -156,15 +161,13 @@ std::string Dispatcher::str( void ) } /* construct on first use to avoid static initialization order crash */ -DispatchRegistry &Terminal::get_global_dispatch_registry( void ) -{ +DispatchRegistry &Terminal::get_global_dispatch_registry( void ) { static DispatchRegistry global_dispatch_registry; return global_dispatch_registry; } static void register_function( Function_Type type, - const std::string &dispatch_chars, Function f ) -{ + const std::string &dispatch_chars, Function f ) { switch ( type ) { case ESCAPE: get_global_dispatch_registry().escape.insert( @@ -184,14 +187,12 @@ static void register_function( Function_Type type, Function::Function( Function_Type type, const std::string &dispatch_chars, void ( *s_function )( Framebuffer *, Dispatcher * ), bool s_clears_wrap_state ) - : function( s_function ), clears_wrap_state( s_clears_wrap_state ) -{ + : function( s_function ), clears_wrap_state( s_clears_wrap_state ) { register_function( type, dispatch_chars, *this ); } void Dispatcher::dispatch( Function_Type type, const Parser::Action *act, - Framebuffer *fb ) -{ + Framebuffer *fb ) { /* add final char to dispatch key */ if ( ( type == ESCAPE ) || ( type == CSI ) ) { assert( act->char_present ); @@ -221,12 +222,13 @@ void Dispatcher::dispatch( Function_Type type, const Parser::Action *act, fb->ds.next_print_will_wrap = false; return; } - if ( i->second.clears_wrap_state ) { fb->ds.next_print_will_wrap = false; } + if ( i->second.clears_wrap_state ) { + fb->ds.next_print_will_wrap = false; + } i->second.function( fb, this ); } -void Dispatcher::OSC_put( const Parser::OSC_Put *act ) -{ +void Dispatcher::OSC_put( const Parser::OSC_Put *act ) { assert( act->char_present ); if ( OSC_string.size() < MAXIMUM_CLIPBOARD_SIZE ) { OSC_string.push_back( act->ch ); @@ -234,13 +236,11 @@ void Dispatcher::OSC_put( const Parser::OSC_Put *act ) } void Dispatcher::OSC_start( const Parser::OSC_Start *act - __attribute( ( unused ) ) ) -{ + __attribute( ( unused ) ) ) { OSC_string.clear(); } -bool Dispatcher::operator==( const Dispatcher &x ) const -{ +bool Dispatcher::operator==( const Dispatcher &x ) const { return ( params == x.params ) && ( parsed_params == x.parsed_params ) && ( parsed == x.parsed ) && ( dispatch_chars == x.dispatch_chars ) && ( OSC_string == x.OSC_string ) diff --git a/src/terminal/terminaldisplay.cc b/src/terminal/terminaldisplay.cc index d85307029..a09600ed0 100644 --- a/src/terminal/terminaldisplay.cc +++ b/src/terminal/terminaldisplay.cc @@ -39,19 +39,16 @@ using namespace Terminal; /* Print a new "frame" to the terminal, using ANSI/ECMA-48 escape codes. */ -static const Renditions &initial_rendition( void ) -{ +static const Renditions &initial_rendition( void ) { const static Renditions blank = Renditions( 0 ); return blank; } -std::string Display::open() const -{ +std::string Display::open() const { return std::string( smcup ? smcup : "" ) + std::string( "\033[?1h" ); } -std::string Display::close() const -{ +std::string Display::close() const { return std::string( "\033[?1l\033[0m\033[?25h" "\033[?1003l\033[?1002l\033[?1001l\033[?1000l" @@ -60,8 +57,7 @@ std::string Display::close() const } std::string Display::new_frame( bool initialized, const Framebuffer &last, - const Framebuffer &f ) const -{ + const Framebuffer &f ) const { FrameState frame( last ); char tmp[ 64 ]; @@ -181,9 +177,13 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, for ( int row = 0; row < f.ds.get_height(); row++ ) { const Row *new_row = f.get_row( 0 ); const Row *old_row = &*rows.at( row ); - if ( !( new_row == old_row || *new_row == *old_row ) ) { continue; } + if ( !( new_row == old_row || *new_row == *old_row ) ) { + continue; + } /* if row 0, we're looking at ourselves and probably didn't scroll */ - if ( row == 0 ) { break; } + if ( row == 0 ) { + break; + } /* found a scroll */ lines_scrolled = row; scroll_height = 1; @@ -341,8 +341,7 @@ std::string Display::new_frame( bool initialized, const Framebuffer &last, bool Display::put_row( bool initialized, FrameState &frame, const Framebuffer &f, int frame_y, const Row &old_row, - bool wrap ) const -{ + bool wrap ) const { char tmp[ 64 ]; int frame_x = 0; @@ -361,7 +360,9 @@ bool Display::put_row( bool initialized, FrameState &frame, } /* If rows are the same object, we don't need to do anything at all. */ - if ( initialized && &row == &old_row ) { return false; } + if ( initialized && &row == &old_row ) { + return false; + } const bool wrap_this = row.get_wrap(); const int row_width = f.ds.get_width(); @@ -382,7 +383,9 @@ bool Display::put_row( bool initialized, FrameState &frame, /* Slurp up all the empty cells */ if ( cell.empty() ) { - if ( !clear_count ) { blank_renditions = cell.get_renditions(); } + if ( !clear_count ) { + blank_renditions = cell.get_renditions(); + } if ( cell.get_renditions() == blank_renditions ) { /* Remember run of blank cells */ clear_count++; @@ -434,7 +437,9 @@ bool Display::put_row( bool initialized, FrameState &frame, frame.append_cell( cell ); frame_x += cell_width; frame.cursor_x += cell_width; - if ( frame_x >= row_width ) { wrote_last_cell = true; } + if ( frame_x >= row_width ) { + wrote_last_cell = true; + } } /* End of line. */ @@ -476,20 +481,18 @@ bool Display::put_row( bool initialized, FrameState &frame, } FrameState::FrameState( const Framebuffer &s_last ) - : str() - , cursor_x( 0 ) - , cursor_y( 0 ) - , current_rendition( 0 ) - , cursor_visible( s_last.ds.cursor_visible ) - , last_frame( s_last ) -{ + : str(), + cursor_x( 0 ), + cursor_y( 0 ), + current_rendition( 0 ), + cursor_visible( s_last.ds.cursor_visible ), + last_frame( s_last ) { /* Preallocate for better performance. Make a guess-- doesn't matter for * correctness */ str.reserve( last_frame.ds.get_width() * last_frame.ds.get_height() * 4 ); } -void FrameState::append_silent_move( int y, int x ) -{ +void FrameState::append_silent_move( int y, int x ) { if ( cursor_x == x && cursor_y == y ) return; /* turn off cursor if necessary before moving cursor */ if ( cursor_visible ) { @@ -499,8 +502,7 @@ void FrameState::append_silent_move( int y, int x ) append_move( y, x ); } -void FrameState::append_move( int y, int x ) -{ +void FrameState::append_move( int y, int x ) { const int last_x = cursor_x; const int last_y = cursor_y; cursor_x = x; @@ -509,7 +511,9 @@ void FrameState::append_move( int y, int x ) if ( last_x != -1 && last_y != -1 ) { // Can we use CR and/or LF? They're cheap and easier to trace. if ( x == 0 && y - last_y >= 0 && y - last_y < 5 ) { - if ( last_x != 0 ) { append( '\r' ); } + if ( last_x != 0 ) { + append( '\r' ); + } append( y - last_y, '\n' ); return; } @@ -525,8 +529,7 @@ void FrameState::append_move( int y, int x ) append( tmp ); } -void FrameState::update_rendition( const Renditions &r, bool force ) -{ +void FrameState::update_rendition( const Renditions &r, bool force ) { if ( force || !( current_rendition == r ) ) { /* print renditions */ append_string( r.sgr() ); diff --git a/src/terminal/terminaldisplayinit.cc b/src/terminal/terminaldisplayinit.cc index f98169f92..f98e8715f 100644 --- a/src/terminal/terminaldisplayinit.cc +++ b/src/terminal/terminaldisplayinit.cc @@ -62,8 +62,7 @@ using namespace Terminal; -static bool ti_flag( const char *capname ) -{ +static bool ti_flag( const char *capname ) { int val = tigetflag( const_cast( capname ) ); if ( val == -1 ) { throw std::invalid_argument( @@ -72,8 +71,7 @@ static bool ti_flag( const char *capname ) return val; } -static const char *ti_str( const char *capname ) -{ +static const char *ti_str( const char *capname ) { const char *val = tigetstr( const_cast( capname ) ); if ( val == (const char *)-1 ) { throw std::invalid_argument( @@ -83,12 +81,11 @@ static const char *ti_str( const char *capname ) } Display::Display( bool use_environment ) - : has_ech( true ) - , has_bce( true ) - , has_title( true ) - , smcup( NULL ) - , rmcup( NULL ) -{ + : has_ech( true ), + has_bce( true ), + has_title( true ), + smcup( NULL ), + rmcup( NULL ) { if ( use_environment ) { int errret = -2; int ret = setupterm( (char *)0, 1, &errret ); diff --git a/src/terminal/terminalframebuffer.cc b/src/terminal/terminalframebuffer.cc index 765fe91f5..2084eed18 100644 --- a/src/terminal/terminalframebuffer.cc +++ b/src/terminal/terminalframebuffer.cc @@ -39,16 +39,13 @@ using namespace Terminal; Cell::Cell( color_type background_color ) - : contents() - , renditions( background_color ) - , wide( false ) - , fallback( false ) - , wrap( false ) -{ -} + : contents(), + renditions( background_color ), + wide( false ), + fallback( false ), + wrap( false ) {} -void Cell::reset( color_type background_color ) -{ +void Cell::reset( color_type background_color ) { contents.clear(); renditions = Renditions( background_color ); wide = false; @@ -56,8 +53,7 @@ void Cell::reset( color_type background_color ) wrap = false; } -void DrawState::reinitialize_tabs( unsigned int start ) -{ +void DrawState::reinitialize_tabs( unsigned int start ) { assert( default_tabs ); for ( unsigned int i = start; i < tabs.size(); i++ ) { tabs[ i ] = ( ( i % 8 ) == 0 ); @@ -65,43 +61,41 @@ void DrawState::reinitialize_tabs( unsigned int start ) } DrawState::DrawState( int s_width, int s_height ) - : width( s_width ) - , height( s_height ) - , cursor_col( 0 ) - , cursor_row( 0 ) - , combining_char_col( 0 ) - , combining_char_row( 0 ) - , default_tabs( true ) - , tabs( s_width ) - , scrolling_region_top_row( 0 ) - , scrolling_region_bottom_row( height - 1 ) - , renditions( 0 ) - , save() - , next_print_will_wrap( false ) - , origin_mode( false ) - , auto_wrap_mode( true ) - , insert_mode( false ) - , cursor_visible( true ) - , reverse_video( false ) - , bracketed_paste( false ) - , mouse_reporting_mode( MOUSE_REPORTING_NONE ) - , mouse_focus_event( false ) - , mouse_alternate_scroll( false ) - , mouse_encoding_mode( MOUSE_ENCODING_DEFAULT ) - , application_mode_cursor_keys( false ) -{ + : width( s_width ), + height( s_height ), + cursor_col( 0 ), + cursor_row( 0 ), + combining_char_col( 0 ), + combining_char_row( 0 ), + default_tabs( true ), + tabs( s_width ), + scrolling_region_top_row( 0 ), + scrolling_region_bottom_row( height - 1 ), + renditions( 0 ), + save(), + next_print_will_wrap( false ), + origin_mode( false ), + auto_wrap_mode( true ), + insert_mode( false ), + cursor_visible( true ), + reverse_video( false ), + bracketed_paste( false ), + mouse_reporting_mode( MOUSE_REPORTING_NONE ), + mouse_focus_event( false ), + mouse_alternate_scroll( false ), + mouse_encoding_mode( MOUSE_ENCODING_DEFAULT ), + application_mode_cursor_keys( false ) { reinitialize_tabs( 0 ); } Framebuffer::Framebuffer( int s_width, int s_height ) - : rows() - , icon_name() - , window_title() - , clipboard() - , bell_count( 0 ) - , title_initialized( false ) - , ds( s_width, s_height ) -{ + : rows(), + icon_name(), + window_title(), + clipboard(), + bell_count( 0 ), + title_initialized( false ), + ds( s_width, s_height ) { assert( s_height > 0 ); assert( s_width > 0 ); const size_t w = s_width; @@ -110,18 +104,15 @@ Framebuffer::Framebuffer( int s_width, int s_height ) } Framebuffer::Framebuffer( const Framebuffer &other ) - : rows( other.rows ) - , icon_name( other.icon_name ) - , window_title( other.window_title ) - , clipboard( other.clipboard ) - , bell_count( other.bell_count ) - , title_initialized( other.title_initialized ) - , ds( other.ds ) -{ -} - -Framebuffer &Framebuffer::operator=( const Framebuffer &other ) -{ + : rows( other.rows ), + icon_name( other.icon_name ), + window_title( other.window_title ), + clipboard( other.clipboard ), + bell_count( other.bell_count ), + title_initialized( other.title_initialized ), + ds( other.ds ) {} + +Framebuffer &Framebuffer::operator=( const Framebuffer &other ) { if ( this != &other ) { rows = other.rows; icon_name = other.icon_name; @@ -134,8 +125,7 @@ Framebuffer &Framebuffer::operator=( const Framebuffer &other ) return *this; } -void Framebuffer::scroll( int N ) -{ +void Framebuffer::scroll( int N ) { if ( N >= 0 ) { delete_line( ds.get_scrolling_region_top_row(), N ); } else { @@ -143,22 +133,19 @@ void Framebuffer::scroll( int N ) } } -void DrawState::new_grapheme( void ) -{ +void DrawState::new_grapheme( void ) { combining_char_col = cursor_col; combining_char_row = cursor_row; } -void DrawState::snap_cursor_to_border( void ) -{ +void DrawState::snap_cursor_to_border( void ) { if ( cursor_row < limit_top() ) cursor_row = limit_top(); if ( cursor_row > limit_bottom() ) cursor_row = limit_bottom(); if ( cursor_col < 0 ) cursor_col = 0; if ( cursor_col >= width ) cursor_col = width - 1; } -void DrawState::move_row( int N, bool relative ) -{ +void DrawState::move_row( int N, bool relative ) { if ( relative ) { cursor_row += N; } else { @@ -170,9 +157,10 @@ void DrawState::move_row( int N, bool relative ) next_print_will_wrap = false; } -void DrawState::move_col( int N, bool relative, bool implicit ) -{ - if ( implicit ) { new_grapheme(); } +void DrawState::move_col( int N, bool relative, bool implicit ) { + if ( implicit ) { + new_grapheme(); + } if ( relative ) { cursor_col += N; @@ -180,7 +168,9 @@ void DrawState::move_col( int N, bool relative, bool implicit ) cursor_col = N; } - if ( implicit ) { next_print_will_wrap = ( cursor_col >= width ); } + if ( implicit ) { + next_print_will_wrap = ( cursor_col >= width ); + } snap_cursor_to_border(); if ( !implicit ) { @@ -189,8 +179,7 @@ void DrawState::move_col( int N, bool relative, bool implicit ) } } -void Framebuffer::move_rows_autoscroll( int rows ) -{ +void Framebuffer::move_rows_autoscroll( int rows ) { /* don't scroll if outside the scrolling region */ if ( ( ds.get_cursor_row() < ds.get_scrolling_region_top_row() ) || ( ds.get_cursor_row() > ds.get_scrolling_region_bottom_row() ) ) { @@ -211,8 +200,7 @@ void Framebuffer::move_rows_autoscroll( int rows ) ds.move_row( rows, true ); } -Cell *Framebuffer::get_combining_cell( void ) -{ +Cell *Framebuffer::get_combining_cell( void ) { if ( ( ds.get_combining_char_col() < 0 ) || ( ds.get_combining_char_row() < 0 ) || ( ds.get_combining_char_col() >= ds.get_width() ) @@ -228,23 +216,27 @@ void DrawState::set_tab( void ) { tabs[ cursor_col ] = true; } void DrawState::clear_tab( int col ) { tabs[ col ] = false; } -int DrawState::get_next_tab( int count ) const -{ +int DrawState::get_next_tab( int count ) const { if ( count >= 0 ) { for ( int i = cursor_col + 1; i < width; i++ ) { - if ( tabs[ i ] && --count == 0 ) { return i; } + if ( tabs[ i ] && --count == 0 ) { + return i; + } } return -1; } for ( int i = cursor_col - 1; i > 0; i-- ) { - if ( tabs[ i ] && ++count == 0 ) { return i; } + if ( tabs[ i ] && ++count == 0 ) { + return i; + } } return 0; } -void DrawState::set_scrolling_region( int top, int bottom ) -{ - if ( height < 1 ) { return; } +void DrawState::set_scrolling_region( int top, int bottom ) { + if ( height < 1 ) { + return; + } scrolling_region_top_row = top; scrolling_region_bottom_row = bottom; @@ -263,33 +255,29 @@ void DrawState::set_scrolling_region( int top, int bottom ) } } -int DrawState::limit_top( void ) const -{ +int DrawState::limit_top( void ) const { return origin_mode ? scrolling_region_top_row : 0; } -int DrawState::limit_bottom( void ) const -{ +int DrawState::limit_bottom( void ) const { return origin_mode ? scrolling_region_bottom_row : height - 1; } -void Framebuffer::apply_renditions_to_cell( Cell *cell ) -{ - if ( !cell ) { cell = get_mutable_cell(); } +void Framebuffer::apply_renditions_to_cell( Cell *cell ) { + if ( !cell ) { + cell = get_mutable_cell(); + } cell->set_renditions( ds.get_renditions() ); } SavedCursor::SavedCursor() - : cursor_col( 0 ) - , cursor_row( 0 ) - , renditions( 0 ) - , auto_wrap_mode( true ) - , origin_mode( false ) -{ -} + : cursor_col( 0 ), + cursor_row( 0 ), + renditions( 0 ), + auto_wrap_mode( true ), + origin_mode( false ) {} -void DrawState::save_cursor( void ) -{ +void DrawState::save_cursor( void ) { save.cursor_col = cursor_col; save.cursor_row = cursor_row; save.renditions = renditions; @@ -297,8 +285,7 @@ void DrawState::save_cursor( void ) save.origin_mode = origin_mode; } -void DrawState::restore_cursor( void ) -{ +void DrawState::restore_cursor( void ) { cursor_col = save.cursor_col; cursor_row = save.cursor_row; renditions = save.renditions; @@ -309,17 +296,20 @@ void DrawState::restore_cursor( void ) new_grapheme(); } -void Framebuffer::insert_line( int before_row, int count ) -{ +void Framebuffer::insert_line( int before_row, int count ) { if ( ( before_row < ds.get_scrolling_region_top_row() ) || ( before_row > ds.get_scrolling_region_bottom_row() + 1 ) ) { return; } int scroll = ds.get_scrolling_region_bottom_row() + 1 - before_row; - if ( count < scroll ) { scroll = count; } + if ( count < scroll ) { + scroll = count; + } - if ( scroll == 0 ) { return; } + if ( scroll == 0 ) { + return; + } // delete old rows rows_type::iterator start = @@ -330,17 +320,20 @@ void Framebuffer::insert_line( int before_row, int count ) rows.insert( start, scroll, newrow() ); } -void Framebuffer::delete_line( int row, int count ) -{ +void Framebuffer::delete_line( int row, int count ) { if ( ( row < ds.get_scrolling_region_top_row() ) || ( row > ds.get_scrolling_region_bottom_row() ) ) { return; } int scroll = ds.get_scrolling_region_bottom_row() + 1 - row; - if ( count < scroll ) { scroll = count; } + if ( count < scroll ) { + scroll = count; + } - if ( scroll == 0 ) { return; } + if ( scroll == 0 ) { + return; + } // delete old rows rows_type::iterator start = rows.begin() + row; @@ -351,40 +344,32 @@ void Framebuffer::delete_line( int row, int count ) } Row::Row( const size_t s_width, const color_type background_color ) - : cells( s_width, Cell( background_color ) ), gen( get_gen() ) -{ -} + : cells( s_width, Cell( background_color ) ), gen( get_gen() ) {} -uint64_t Row::get_gen() const -{ +uint64_t Row::get_gen() const { static uint64_t gen_counter = 0; return gen_counter++; } -void Row::insert_cell( int col, color_type background_color ) -{ +void Row::insert_cell( int col, color_type background_color ) { cells.insert( cells.begin() + col, Cell( background_color ) ); cells.pop_back(); } -void Row::delete_cell( int col, color_type background_color ) -{ +void Row::delete_cell( int col, color_type background_color ) { cells.push_back( Cell( background_color ) ); cells.erase( cells.begin() + col ); } -void Framebuffer::insert_cell( int row, int col ) -{ +void Framebuffer::insert_cell( int row, int col ) { get_mutable_row( row )->insert_cell( col, ds.get_background_rendition() ); } -void Framebuffer::delete_cell( int row, int col ) -{ +void Framebuffer::delete_cell( int row, int col ) { get_mutable_row( row )->delete_cell( col, ds.get_background_rendition() ); } -void Framebuffer::reset( void ) -{ +void Framebuffer::reset( void ) { int width = ds.get_width(), height = ds.get_height(); ds = DrawState( width, height ); rows = rows_type( height, newrow() ); @@ -393,8 +378,7 @@ void Framebuffer::reset( void ) /* do not reset bell_count */ } -void Framebuffer::soft_reset( void ) -{ +void Framebuffer::soft_reset( void ) { ds.insert_mode = false; ds.origin_mode = false; ds.cursor_visible = true; /* per xterm and gnome-terminal */ @@ -404,8 +388,7 @@ void Framebuffer::soft_reset( void ) ds.clear_saved_cursor(); } -void Framebuffer::resize( int s_width, int s_height ) -{ +void Framebuffer::resize( int s_width, int s_height ) { assert( s_width > 0 ); assert( s_height > 0 ); @@ -414,8 +397,12 @@ void Framebuffer::resize( int s_width, int s_height ) ds.resize( s_width, s_height ); row_pointer blankrow( newrow() ); - if ( oldheight != s_height ) { rows.resize( s_height, blankrow ); } - if ( oldwidth == s_width ) { return; } + if ( oldheight != s_height ) { + rows.resize( s_height, blankrow ); + } + if ( oldwidth == s_width ) { + return; + } for ( rows_type::iterator i = rows.begin(); i != rows.end() && *i != blankrow; i++ ) { *i = make_shared( **i ); @@ -424,8 +411,7 @@ void Framebuffer::resize( int s_width, int s_height ) } } -void DrawState::resize( int s_width, int s_height ) -{ +void DrawState::resize( int s_width, int s_height ) { if ( ( width != s_width ) || ( height != s_height ) ) { /* reset entire scrolling region on any resize */ /* xterm and rxvt-unicode do this. gnome-terminal only @@ -435,7 +421,9 @@ void DrawState::resize( int s_width, int s_height ) } tabs.resize( s_width ); - if ( default_tabs ) { reinitialize_tabs( width ); } + if ( default_tabs ) { + reinitialize_tabs( width ); + } width = s_width; height = s_height; @@ -451,13 +439,10 @@ void DrawState::resize( int s_width, int s_height ) } Renditions::Renditions( color_type s_background ) - : foreground_color( 0 ), background_color( s_background ), attributes( 0 ) -{ -} + : foreground_color( 0 ), background_color( s_background ), attributes( 0 ) {} /* This routine cannot be used to set a color beyond the 16-color set. */ -void Renditions::set_rendition( color_type num ) -{ +void Renditions::set_rendition( color_type num ) { if ( num == 0 ) { clear_attributes(); foreground_color = background_color = 0; @@ -507,8 +492,7 @@ void Renditions::set_rendition( color_type num ) } } -void Renditions::set_foreground_color( int num ) -{ +void Renditions::set_foreground_color( int num ) { if ( ( 0 <= num ) && ( num <= 255 ) ) { foreground_color = 30 + num; } else if ( is_true_color( num ) ) { @@ -516,8 +500,7 @@ void Renditions::set_foreground_color( int num ) } } -void Renditions::set_background_color( int num ) -{ +void Renditions::set_background_color( int num ) { if ( ( 0 <= num ) && ( num <= 255 ) ) { background_color = 40 + num; } else if ( is_true_color( num ) ) { @@ -525,8 +508,7 @@ void Renditions::set_background_color( int num ) } } -std::string Renditions::sgr( void ) const -{ +std::string Renditions::sgr( void ) const { std::string ret; char col[ 64 ]; @@ -579,16 +561,14 @@ std::string Renditions::sgr( void ) const return ret; } -void Row::reset( color_type background_color ) -{ +void Row::reset( color_type background_color ) { gen = get_gen(); for ( cells_type::iterator i = cells.begin(); i != cells.end(); i++ ) { i->reset( background_color ); } } -void Framebuffer::prefix_window_title( const title_type &s ) -{ +void Framebuffer::prefix_window_title( const title_type &s ) { if ( icon_name == window_title ) { /* preserve equivalence */ icon_name.insert( icon_name.begin(), s.begin(), s.end() ); @@ -596,9 +576,10 @@ void Framebuffer::prefix_window_title( const title_type &s ) window_title.insert( window_title.begin(), s.begin(), s.end() ); } -std::string Cell::debug_contents( void ) const -{ - if ( contents.empty() ) { return "'_' ()"; } +std::string Cell::debug_contents( void ) const { + if ( contents.empty() ) { + return "'_' ()"; + } std::string chars( 1, '\'' ); print_grapheme( chars ); chars.append( "' [" ); @@ -616,8 +597,7 @@ std::string Cell::debug_contents( void ) const return chars; } -bool Cell::compare( const Cell &other ) const -{ +bool Cell::compare( const Cell &other ) const { bool ret = false; std::string grapheme, other_grapheme; diff --git a/src/terminal/terminalframebuffer.h b/src/terminal/terminalframebuffer.h index 526552ac0..783911660 100644 --- a/src/terminal/terminalframebuffer.h +++ b/src/terminal/terminalframebuffer.h @@ -78,13 +78,11 @@ namespace Terminal { std::string sgr( void ) const; static unsigned int make_true_color( unsigned int r, unsigned int g, - unsigned int b ) - { + unsigned int b ) { return true_color_mask | ( r << 16 ) | ( g << 8 ) | b; } - static bool is_true_color( unsigned int color ) - { + static bool is_true_color( unsigned int color ) { return ( color & true_color_mask ) != 0; } @@ -92,19 +90,16 @@ namespace Terminal { // } unsigned int get_background_rendition() const { return background_color; } - bool operator==( const Renditions &x ) const - { + bool operator==( const Renditions &x ) const { return ( attributes == x.attributes ) && ( foreground_color == x.foreground_color ) && ( background_color == x.background_color ); } - void set_attribute( attribute_type attr, bool val ) - { + void set_attribute( attribute_type attr, bool val ) { attributes = val ? ( attributes | ( 1 << attr ) ) : ( attributes & ~( 1 << attr ) ); } - bool get_attribute( attribute_type attr ) const - { + bool get_attribute( attribute_type attr ) const { return attributes & ( 1 << attr ); } void clear_attributes() { attributes = 0; } @@ -129,8 +124,7 @@ namespace Terminal { void reset( color_type background_color ); - bool operator==( const Cell &x ) const - { + bool operator==( const Cell &x ) const { return ( ( contents == x.contents ) && ( fallback == x.fallback ) && ( wide == x.wide ) && ( renditions == x.renditions ) && ( wrap == x.wrap ) ); @@ -146,14 +140,12 @@ namespace Terminal { bool full( void ) const { return contents.size() >= 32; } void clear( void ) { contents.clear(); } - bool is_blank( void ) const - { + bool is_blank( void ) const { // XXX fix. return ( contents.empty() || contents == " " || contents == "\xC2\xA0" ); } - bool contents_match( const Cell &other ) const - { + bool contents_match( const Cell &other ) const { return ( is_blank() && other.is_blank() ) || ( contents == other.contents ); } @@ -161,13 +153,11 @@ namespace Terminal { bool compare( const Cell &other ) const; // Is this a printing ISO 8859-1 character? - static bool isprint_iso8859_1( const wchar_t c ) - { + static bool isprint_iso8859_1( const wchar_t c ) { return ( c <= 0xff && c >= 0xa0 ) || ( c <= 0x7e && c >= 0x20 ); } - static void append_to_str( std::string &dest, const wchar_t c ) - { + static void append_to_str( std::string &dest, const wchar_t c ) { /* ASCII? Cheat. */ if ( static_cast( c ) <= 0x7f ) { dest.push_back( static_cast( c ) ); @@ -181,8 +171,7 @@ namespace Terminal { dest.append( tmp, len ); } - void append( const wchar_t c ) - { + void append( const wchar_t c ) { /* ASCII? Cheat. */ if ( static_cast( c ) <= 0x7f ) { contents.push_back( static_cast( c ) ); @@ -196,8 +185,7 @@ namespace Terminal { contents.insert( contents.end(), tmp, tmp + len ); } - void print_grapheme( std::string &output ) const - { + void print_grapheme( std::string &output ) const { if ( contents.empty() ) { output.append( 1, ' ' ); return; @@ -206,7 +194,9 @@ namespace Terminal { * cells that begin with combining character get combiner * attached to no-break space */ - if ( fallback ) { output.append( "\xC2\xA0" ); } + if ( fallback ) { + output.append( "\xC2\xA0" ); + } output.append( contents ); } @@ -243,8 +233,7 @@ namespace Terminal { void reset( color_type background_color ); - bool operator==( const Row &x ) const - { + bool operator==( const Row &x ) const { return ( gen == x.gen && cells == x.cells ); } @@ -337,12 +326,10 @@ namespace Terminal { void set_scrolling_region( int top, int bottom ); - int get_scrolling_region_top_row( void ) const - { + int get_scrolling_region_top_row( void ) const { return scrolling_region_top_row; } - int get_scrolling_region_bottom_row( void ) const - { + int get_scrolling_region_bottom_row( void ) const { return scrolling_region_bottom_row; } @@ -354,8 +341,7 @@ namespace Terminal { void add_rendition( color_type x ) { renditions.set_rendition( x ); } const Renditions &get_renditions( void ) const { return renditions; } Renditions &get_renditions( void ) { return renditions; } - int get_background_rendition( void ) const - { + int get_background_rendition( void ) const { return renditions.get_background_rendition(); } @@ -367,8 +353,7 @@ namespace Terminal { DrawState( int s_width, int s_height ); - bool operator==( const DrawState &x ) const - { + bool operator==( const DrawState &x ) const { /* only compare fields that affect display */ return ( width == x.width ) && ( height == x.height ) && ( cursor_col == x.cursor_col ) && ( cursor_row == x.cursor_row ) @@ -411,8 +396,7 @@ namespace Terminal { bool title_initialized; /* true if the window title has been set via an OSC */ - row_pointer newrow( void ) - { + row_pointer newrow( void ) { const size_t w = ds.get_width(); const color_type c = ds.get_background_rendition(); return make_shared( w, c ); @@ -429,23 +413,20 @@ namespace Terminal { void scroll( int N ); void move_rows_autoscroll( int rows ); - inline const Row *get_row( int row ) const - { + inline const Row *get_row( int row ) const { if ( row == -1 ) row = ds.get_cursor_row(); return rows.at( row ).get(); } - inline const Cell *get_cell( int row = -1, int col = -1 ) const - { + inline const Cell *get_cell( int row = -1, int col = -1 ) const { if ( row == -1 ) row = ds.get_cursor_row(); if ( col == -1 ) col = ds.get_cursor_col(); return &rows.at( row )->cells.at( col ); } - Row *get_mutable_row( int row ) - { + Row *get_mutable_row( int row ) { if ( row == -1 ) row = ds.get_cursor_row(); row_pointer &mutable_row = rows.at( row ); // If the row is shared, copy it. @@ -455,8 +436,7 @@ namespace Terminal { return mutable_row.get(); } - Cell *get_mutable_cell( int row = -1, int col = -1 ) - { + Cell *get_mutable_cell( int row = -1, int col = -1 ) { if ( row == -1 ) row = ds.get_cursor_row(); if ( col == -1 ) col = ds.get_cursor_col(); @@ -495,8 +475,7 @@ namespace Terminal { void ring_bell( void ) { bell_count++; } unsigned int get_bell_count( void ) const { return bell_count; } - bool operator==( const Framebuffer &x ) const - { + bool operator==( const Framebuffer &x ) const { return ( rows == x.rows ) && ( window_title == x.window_title ) && ( clipboard == x.clipboard ) && ( bell_count == x.bell_count ) && ( ds == x.ds ); diff --git a/src/terminal/terminalfunctions.cc b/src/terminal/terminalfunctions.cc index d2014a862..44a7424ee 100644 --- a/src/terminal/terminalfunctions.cc +++ b/src/terminal/terminalfunctions.cc @@ -43,16 +43,14 @@ using namespace Terminal; /* Terminal functions -- routines activated by CSI, escape or a control char */ -static void clearline( Framebuffer *fb, int row, int start, int end ) -{ +static void clearline( Framebuffer *fb, int row, int start, int end ) { for ( int col = start; col <= end; col++ ) { fb->reset_cell( fb->get_mutable_cell( row, col ) ); } } /* erase in line */ -static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) { switch ( dispatch->getparam( 0, 0 ) ) { case 0: /* default: active position to end of line, inclusive */ clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 ); @@ -68,8 +66,7 @@ static void CSI_EL( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_EL( CSI, "K", CSI_EL ); /* erase in display */ -static void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) { switch ( dispatch->getparam( 0, 0 ) ) { case 0: /* active position to end of screen, inclusive */ clearline( fb, -1, fb->ds.get_cursor_col(), fb->ds.get_width() - 1 ); @@ -95,8 +92,7 @@ static void CSI_ED( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_ED( CSI, "J", CSI_ED ); /* cursor movement -- relative and absolute */ -static void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_cursormove( Framebuffer *fb, Dispatcher *dispatch ) { int num = dispatch->getparam( 0, 1 ); switch ( dispatch->get_dispatch_chars()[ 0 ] ) { @@ -122,8 +118,7 @@ static Function func_CSI_cursormove_f( CSI, "f", CSI_cursormove ); /* device attributes */ static void CSI_DA( Framebuffer *fb __attribute( ( unused ) ), - Dispatcher *dispatch ) -{ + Dispatcher *dispatch ) { dispatch->terminal_to_host.append( "\033[?62c" ); /* plain vt220 */ } @@ -131,8 +126,7 @@ static Function func_CSI_DA( CSI, "c", CSI_DA ); /* secondary device attributes */ static void CSI_SDA( Framebuffer *fb __attribute( ( unused ) ), - Dispatcher *dispatch ) -{ + Dispatcher *dispatch ) { dispatch->terminal_to_host.append( "\033[>1;10;0c" ); /* plain vt220 */ } @@ -140,8 +134,7 @@ static Function func_CSI_SDA( CSI, ">c", CSI_SDA ); /* screen alignment diagnostic */ static void Esc_DECALN( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { for ( int y = 0; y < fb->ds.get_height(); y++ ) { for ( int x = 0; x < fb->ds.get_width(); x++ ) { fb->reset_cell( fb->get_mutable_cell( y, x ) ); @@ -154,8 +147,7 @@ static Function func_Esc_DECALN( ESCAPE, "#8", Esc_DECALN ); /* line feed */ static void Ctrl_LF( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->move_rows_autoscroll( 1 ); } @@ -167,8 +159,7 @@ static Function func_Ctrl_FF( CONTROL, "\x0c", Ctrl_LF ); /* carriage return */ static void Ctrl_CR( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ds.move_col( 0 ); } @@ -176,8 +167,7 @@ static Function func_Ctrl_CR( CONTROL, "\x0d", Ctrl_CR ); /* backspace */ static void Ctrl_BS( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ds.move_col( -1, true ); } @@ -185,8 +175,7 @@ static Function func_Ctrl_BS( CONTROL, "\x08", Ctrl_BS ); /* reverse index -- like a backwards line feed */ static void Ctrl_RI( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->move_rows_autoscroll( -1 ); } @@ -194,8 +183,7 @@ static Function func_Ctrl_RI( CONTROL, "\x8D", Ctrl_RI ); /* newline */ static void Ctrl_NEL( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ds.move_col( 0 ); fb->move_rows_autoscroll( 1 ); } @@ -203,8 +191,7 @@ static void Ctrl_NEL( Framebuffer *fb, static Function func_Ctrl_NEL( CONTROL, "\x85", Ctrl_NEL ); /* horizontal tab */ -static void HT_n( Framebuffer *fb, size_t count ) -{ +static void HT_n( Framebuffer *fb, size_t count ) { int col = fb->ds.get_next_tab( count ); if ( col == -1 ) { /* no tabs, go to end of line */ col = fb->ds.get_width() - 1; @@ -219,17 +206,19 @@ static void HT_n( Framebuffer *fb, size_t count ) } static void Ctrl_HT( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { HT_n( fb, 1 ); } static Function func_Ctrl_HT( CONTROL, "\x09", Ctrl_HT, false ); -static void CSI_CxT( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_CxT( Framebuffer *fb, Dispatcher *dispatch ) { int param = dispatch->getparam( 0, 1 ); - if ( dispatch->get_dispatch_chars()[ 0 ] == 'Z' ) { param = -param; } - if ( param == 0 ) { return; } + if ( dispatch->get_dispatch_chars()[ 0 ] == 'Z' ) { + param = -param; + } + if ( param == 0 ) { + return; + } HT_n( fb, param ); } @@ -238,16 +227,14 @@ static Function func_CSI_CBT( CSI, "Z", CSI_CxT, false ); /* horizontal tab set */ static void Ctrl_HTS( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ds.set_tab(); } static Function func_Ctrl_HTS( CONTROL, "\x88", Ctrl_HTS ); /* tabulation clear */ -static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) { int param = dispatch->getparam( 0, 0 ); switch ( param ) { case 0: /* clear this tab stop */ @@ -255,7 +242,9 @@ static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) break; case 3: /* clear all tab stops */ fb->ds.clear_default_tabs(); - for ( int x = 0; x < fb->ds.get_width(); x++ ) { fb->ds.clear_tab( x ); } + for ( int x = 0; x < fb->ds.get_width(); x++ ) { + fb->ds.clear_tab( x ); + } break; default: break; } @@ -264,8 +253,7 @@ static void CSI_TBC( Framebuffer *fb, Dispatcher *dispatch ) /* TBC preserves wrap state */ static Function func_CSI_TBC( CSI, "g", CSI_TBC, false ); -static bool *get_DEC_mode( int param, Framebuffer *fb ) -{ +static bool *get_DEC_mode( int param, Framebuffer *fb ) { switch ( param ) { case 1: /* cursor key mode */ return &( fb->ds.application_mode_cursor_keys ); case 3: /* 80/132. Ignore but clear screen. */ @@ -293,14 +281,14 @@ static bool *get_DEC_mode( int param, Framebuffer *fb ) } /* helper for CSI_DECSM and CSI_DECRM */ -static void set_if_available( bool *mode, bool value ) -{ - if ( mode ) { *mode = value; } +static void set_if_available( bool *mode, bool value ) { + if ( mode ) { + *mode = value; + } } /* set private mode */ -static void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { int param = dispatch->getparam( i, 0 ); if ( param == 9 || ( param >= 1000 && param <= 1003 ) ) { @@ -316,8 +304,7 @@ static void CSI_DECSM( Framebuffer *fb, Dispatcher *dispatch ) } /* clear private mode */ -static void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { int param = dispatch->getparam( i, 0 ); if ( param == 9 || ( param >= 1000 && param <= 1003 ) ) { @@ -334,8 +321,7 @@ static void CSI_DECRM( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DECSM( CSI, "?h", CSI_DECSM, false ); static Function func_CSI_DECRM( CSI, "?l", CSI_DECRM, false ); -static bool *get_ANSI_mode( int param, Framebuffer *fb ) -{ +static bool *get_ANSI_mode( int param, Framebuffer *fb ) { if ( param == 4 ) { /* insert/replace mode */ return &( fb->ds.insert_mode ); } @@ -343,20 +329,22 @@ static bool *get_ANSI_mode( int param, Framebuffer *fb ) } /* set mode */ -static void CSI_SM( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_SM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb ); - if ( mode ) { *mode = true; } + if ( mode ) { + *mode = true; + } } } /* clear mode */ -static void CSI_RM( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_RM( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { bool *mode = get_ANSI_mode( dispatch->getparam( i, 0 ), fb ); - if ( mode ) { *mode = false; } + if ( mode ) { + *mode = false; + } } } @@ -364,8 +352,7 @@ static Function func_CSI_SM( CSI, "h", CSI_SM ); static Function func_CSI_RM( CSI, "l", CSI_RM ); /* set top and bottom margins */ -static void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_DECSTBM( Framebuffer *fb, Dispatcher *dispatch ) { int top = dispatch->getparam( 0, 1 ); int bottom = dispatch->getparam( 1, fb->ds.get_height() ); @@ -383,16 +370,14 @@ static Function func_CSI_DECSTMB( CSI, "r", CSI_DECSTBM ); /* terminal bell */ static void Ctrl_BEL( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ring_bell(); } static Function func_Ctrl_BEL( CONTROL, "\x07", Ctrl_BEL ); /* select graphics rendition -- e.g., bold, blinking, etc. */ -static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_SGR( Framebuffer *fb, Dispatcher *dispatch ) { for ( int i = 0; i < dispatch->param_count(); i++ ) { int rendition = dispatch->getparam( i, 0 ); /* We need to special-case the handling of [34]8 ; 5 ; Ps, @@ -439,14 +424,12 @@ static Function func_CSI_SGR( /* save and restore cursor */ static void Esc_DECSC( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ds.save_cursor(); } static void Esc_DECRC( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->ds.restore_cursor(); } @@ -454,8 +437,7 @@ static Function func_Esc_DECSC( ESCAPE, "7", Esc_DECSC ); static Function func_Esc_DECRC( ESCAPE, "8", Esc_DECRC ); /* device status report -- e.g., cursor position (used by resize) */ -static void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) { int param = dispatch->getparam( 0, 0 ); switch ( param ) { @@ -475,8 +457,7 @@ static void CSI_DSR( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DSR( CSI, "n", CSI_DSR ); /* insert line */ -static void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) { int lines = dispatch->getparam( 0, 1 ); fb->insert_line( fb->ds.get_cursor_row(), lines ); @@ -489,8 +470,7 @@ static void CSI_IL( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_IL( CSI, "L", CSI_IL ); /* delete line */ -static void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) { int lines = dispatch->getparam( 0, 1 ); fb->delete_line( fb->ds.get_cursor_row(), lines ); @@ -503,8 +483,7 @@ static void CSI_DL( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DL( CSI, "M", CSI_DL ); /* insert characters */ -static void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) { int cells = dispatch->getparam( 0, 1 ); for ( int i = 0; i < cells; i++ ) { @@ -515,8 +494,7 @@ static void CSI_ICH( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_ICH( CSI, "@", CSI_ICH ); /* delete character */ -static void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) { int cells = dispatch->getparam( 0, 1 ); for ( int i = 0; i < cells; i++ ) { @@ -527,8 +505,7 @@ static void CSI_DCH( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_DCH( CSI, "P", CSI_DCH ); /* line position absolute */ -static void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) { int row = dispatch->getparam( 0, 1 ); fb->ds.move_row( row - 1 ); } @@ -536,8 +513,7 @@ static void CSI_VPA( Framebuffer *fb, Dispatcher *dispatch ) static Function func_CSI_VPA( CSI, "d", CSI_VPA ); /* character position absolute */ -static void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_HPA( Framebuffer *fb, Dispatcher *dispatch ) { int col = dispatch->getparam( 0, 1 ); fb->ds.move_col( col - 1 ); } @@ -546,11 +522,12 @@ static Function func_CSI_CHA( CSI, "G", CSI_HPA ); /* ECMA-48 name: CHA */ static Function func_CSI_HPA( CSI, "\x60", CSI_HPA ); /* ECMA-48 name: HPA */ /* erase character */ -static void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_ECH( Framebuffer *fb, Dispatcher *dispatch ) { int num = dispatch->getparam( 0, 1 ); int limit = fb->ds.get_cursor_col() + num - 1; - if ( limit >= fb->ds.get_width() ) { limit = fb->ds.get_width() - 1; } + if ( limit >= fb->ds.get_width() ) { + limit = fb->ds.get_width() - 1; + } clearline( fb, -1, fb->ds.get_cursor_col(), limit ); } @@ -559,8 +536,7 @@ static Function func_CSI_ECH( CSI, "X", CSI_ECH ); /* reset to initial state */ static void Esc_RIS( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->reset(); } @@ -568,8 +544,7 @@ static Function func_Esc_RIS( ESCAPE, "c", Esc_RIS ); /* soft reset */ static void CSI_DECSTR( Framebuffer *fb, - Dispatcher *dispatch __attribute( ( unused ) ) ) -{ + Dispatcher *dispatch __attribute( ( unused ) ) ) { fb->soft_reset(); } @@ -578,8 +553,7 @@ static Function func_CSI_DECSTR( CSI, "!p", CSI_DECSTR ); /* xterm uses an Operating System Command to set the window title */ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act __attribute( ( unused ) ), - Framebuffer *fb ) -{ + Framebuffer *fb ) { /* handle osc copy clipboard sequence 52;c; */ if ( OSC_string.size() >= 5 && OSC_string[ 0 ] == L'5' && OSC_string[ 1 ] == L'2' && OSC_string[ 2 ] == L';' @@ -610,23 +584,25 @@ void Dispatcher::OSC_dispatch( const Parser::OSC_End *act int title_length = std::min( OSC_string.size(), (size_t)256 ); Terminal::Framebuffer::title_type newtitle( OSC_string.begin() + offset, OSC_string.begin() + title_length ); - if ( set_icon ) { fb->set_icon_name( newtitle ); } - if ( set_title ) { fb->set_window_title( newtitle ); } + if ( set_icon ) { + fb->set_icon_name( newtitle ); + } + if ( set_title ) { + fb->set_window_title( newtitle ); + } } } } /* scroll down or terminfo indn */ -static void CSI_SD( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_SD( Framebuffer *fb, Dispatcher *dispatch ) { fb->scroll( dispatch->getparam( 0, 1 ) ); } static Function func_CSI_SD( CSI, "S", CSI_SD ); /* scroll up or terminfo rin */ -static void CSI_SU( Framebuffer *fb, Dispatcher *dispatch ) -{ +static void CSI_SU( Framebuffer *fb, Dispatcher *dispatch ) { fb->scroll( -dispatch->getparam( 0, 1 ) ); } diff --git a/src/terminal/terminaluserinput.cc b/src/terminal/terminaluserinput.cc index ce7850e4a..545373c6d 100644 --- a/src/terminal/terminaluserinput.cc +++ b/src/terminal/terminaluserinput.cc @@ -37,8 +37,7 @@ using namespace Terminal; using std::string; string UserInput::input( const Parser::UserByte *act, - bool application_mode_cursor_keys ) -{ + bool application_mode_cursor_keys ) { /* The user will always be in application mode. If stm is not in application mode, convert user's cursor control function to an ANSI cursor control sequence */ diff --git a/src/tests/base64.cc b/src/tests/base64.cc index d8004f5eb..5ef4c2409 100644 --- a/src/tests/base64.cc +++ b/src/tests/base64.cc @@ -54,8 +54,7 @@ bool verbose = false; -static void test_base64( void ) -{ +static void test_base64( void ) { /* run through a test vector */ char encoded[ 25 ]; uint8_t decoded[ 16 ]; @@ -75,7 +74,9 @@ static void test_base64( void ) fatal_assert( raw_len == 16 ); fatal_assert( !memcmp( row->native, decoded, sizeof decoded ) ); } - if ( verbose ) { printf( "validation PASSED\n" ); } + if ( verbose ) { + printf( "validation PASSED\n" ); + } /* try 0..255 in the last byte; make sure the final two characters are output * properly */ uint8_t source[ 16 ]; @@ -89,7 +90,9 @@ static void test_base64( void ) fatal_assert( raw_len == 16 ); fatal_assert( !memcmp( source, decoded, sizeof decoded ) ); } - if ( verbose ) { printf( "last-byte PASSED\n" ); } + if ( verbose ) { + printf( "last-byte PASSED\n" ); + } /* randomly try keys */ PRNG prng; @@ -99,7 +102,9 @@ static void test_base64( void ) fatal_assert( key1.printable_key() == key2.printable_key() && !memcmp( key1.data(), key2.data(), 16 ) ); } - if ( verbose ) { printf( "random PASSED\n" ); } + if ( verbose ) { + printf( "random PASSED\n" ); + } /* test bad keys */ const char *bad_keys[] = { @@ -123,12 +128,15 @@ static void test_base64( void ) raw_len = 16; fatal_assert( !base64_decode( *key, b64_len, decoded, &raw_len ) ); } - if ( verbose ) { printf( "bad-keys PASSED\n" ); } + if ( verbose ) { + printf( "bad-keys PASSED\n" ); + } } -int main( int argc, char *argv[] ) -{ - if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { verbose = true; } +int main( int argc, char *argv[] ) { + if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { + verbose = true; + } try { test_base64(); diff --git a/src/tests/encrypt-decrypt.cc b/src/tests/encrypt-decrypt.cc index ea66eba00..8a2a8756d 100644 --- a/src/tests/encrypt-decrypt.cc +++ b/src/tests/encrypt-decrypt.cc @@ -56,8 +56,7 @@ bool verbose = false; #define NONCE_FMT "%016" PRIx64 -static std::string random_payload( void ) -{ +static std::string random_payload( void ) { const size_t len = prng.uint32() % MESSAGE_SIZE_MAX; char buf[ MESSAGE_SIZE_MAX ]; prng.fill( buf, len ); @@ -66,8 +65,7 @@ static std::string random_payload( void ) return payload; } -static void test_bad_decrypt( Session &decryption_session ) -{ +static void test_bad_decrypt( Session &decryption_session ) { std::string bad_ct = random_payload(); bool got_exn = false; @@ -81,20 +79,23 @@ static void test_bad_decrypt( Session &decryption_session ) fatal_assert( !e.fatal ); } - if ( verbose ) { hexdump( bad_ct, "bad ct" ); } + if ( verbose ) { + hexdump( bad_ct, "bad ct" ); + } fatal_assert( got_exn ); } /* Generate a single key and initial nonce, then perform some encryptions. */ -static void test_one_session( void ) -{ +static void test_one_session( void ) { Base64Key key; Session encryption_session( key ); Session decryption_session( key ); uint64_t nonce_int = prng.uint64(); - if ( verbose ) { hexdump( key.data(), 16, "key" ); } + if ( verbose ) { + hexdump( key.data(), 16, "key" ); + } for ( size_t i = 0; i < MESSAGES_PER_SESSION; i++ ) { Nonce nonce( nonce_int ); @@ -108,7 +109,9 @@ static void test_one_session( void ) std::string ciphertext = encryption_session.encrypt( Message( nonce, plaintext ) ); - if ( verbose ) { hexdump( ciphertext, "ct" ); } + if ( verbose ) { + hexdump( ciphertext, "ct" ); + } Message decrypted = decryption_session.decrypt( ciphertext ); if ( verbose ) { @@ -122,15 +125,20 @@ static void test_one_session( void ) nonce_int++; - if ( !( prng.uint8() % 16 ) ) { test_bad_decrypt( decryption_session ); } + if ( !( prng.uint8() % 16 ) ) { + test_bad_decrypt( decryption_session ); + } - if ( verbose ) { printf( "\n" ); } + if ( verbose ) { + printf( "\n" ); + } } } -int main( int argc, char *argv[] ) -{ - if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { verbose = true; } +int main( int argc, char *argv[] ) { + if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { + verbose = true; + } for ( size_t i = 0; i < NUM_SESSIONS; i++ ) { try { diff --git a/src/tests/inpty.cc b/src/tests/inpty.cc index cd1e856c3..57928d964 100644 --- a/src/tests/inpty.cc +++ b/src/tests/inpty.cc @@ -55,8 +55,7 @@ #include "pty_compat.h" #include "swrite.h" -int main( int argc, char *argv[] ) -{ +int main( int argc, char *argv[] ) { if ( argc < 2 ) { fprintf( stderr, "usage: inpty COMMAND [ARGS...]\n" ); return 1; diff --git a/src/tests/is-utf8-locale.cc b/src/tests/is-utf8-locale.cc index 7c7a85b27..57b0122ee 100644 --- a/src/tests/is-utf8-locale.cc +++ b/src/tests/is-utf8-locale.cc @@ -35,8 +35,7 @@ #include "locale_utils.h" int main( int argc __attribute__( ( unused ) ), - char **argv __attribute__( ( unused ) ) ) -{ + char **argv __attribute__( ( unused ) ) ) { set_native_locale(); if ( !is_utf8_locale() ) { fprintf( stderr, "not a UTF-8 locale\n" ); diff --git a/src/tests/nonce-incr.cc b/src/tests/nonce-incr.cc index a579c9b62..47902354d 100644 --- a/src/tests/nonce-incr.cc +++ b/src/tests/nonce-incr.cc @@ -38,8 +38,7 @@ #include "network.h" -int main() -{ +int main() { std::set nonces; const unsigned int NUM_EXAMPLES = 1000000; @@ -65,7 +64,9 @@ int main() } } - if ( nonces.size() == 4 * NUM_EXAMPLES ) { return EXIT_SUCCESS; } + if ( nonces.size() == 4 * NUM_EXAMPLES ) { + return EXIT_SUCCESS; + } return EXIT_FAILURE; } diff --git a/src/tests/ocb-aes.cc b/src/tests/ocb-aes.cc index 261b2afb3..aa60249b1 100644 --- a/src/tests/ocb-aes.cc +++ b/src/tests/ocb-aes.cc @@ -56,15 +56,13 @@ using Crypto::AlignedBuffer; bool verbose = false; -static bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) -{ +static bool equal( const AlignedBuffer &a, const AlignedBuffer &b ) { return ( a.len() == b.len() ) && !memcmp( a.data(), b.data(), a.len() ); } typedef shared::shared_ptr AlignedPointer; -static AlignedBuffer *get_ctx( const AlignedBuffer &key ) -{ +static AlignedBuffer *get_ctx( const AlignedBuffer &key ) { AlignedBuffer *ctx_buf = new AlignedBuffer( ae_ctx_sizeof() ); fatal_assert( ctx_buf ); fatal_assert( AE_SUCCESS @@ -73,16 +71,14 @@ static AlignedBuffer *get_ctx( const AlignedBuffer &key ) return ctx_buf; } -static void scrap_ctx( AlignedBuffer &ctx_buf ) -{ +static void scrap_ctx( AlignedBuffer &ctx_buf ) { fatal_assert( AE_SUCCESS == ae_clear( (ae_ctx *)ctx_buf.data() ) ); } static void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, const AlignedBuffer &plaintext, const AlignedBuffer &assoc, - const AlignedBuffer &expected_ciphertext ) -{ + const AlignedBuffer &expected_ciphertext ) { AlignedPointer ctx_buf( get_ctx( key ) ); ae_ctx *ctx = (ae_ctx *)ctx_buf->data(); @@ -106,8 +102,8 @@ static void test_encrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, static void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, const AlignedBuffer &ciphertext, const AlignedBuffer &assoc, - const AlignedBuffer &expected_plaintext, bool valid ) -{ + const AlignedBuffer &expected_plaintext, + bool valid ) { AlignedPointer ctx_buf( get_ctx( key ) ); ae_ctx *ctx = (ae_ctx *)ctx_buf->data(); @@ -117,10 +113,14 @@ static void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, ciphertext.len(), assoc.data(), assoc.len(), observed_plaintext.data(), NULL, AE_FINALIZE ); - if ( verbose ) { printf( "ret %d\n", ret ); } + if ( verbose ) { + printf( "ret %d\n", ret ); + } if ( valid ) { - if ( verbose ) { hexdump( observed_plaintext, "obs pt" ); } + if ( verbose ) { + hexdump( observed_plaintext, "obs pt" ); + } fatal_assert( ret == int( expected_plaintext.len() ) ); fatal_assert( equal( expected_plaintext, observed_plaintext ) ); } else { @@ -133,8 +133,7 @@ static void test_decrypt( const AlignedBuffer &key, const AlignedBuffer &nonce, static void test_vector( const char *key_p, const char *nonce_p, size_t assoc_len, const char *assoc_p, size_t plaintext_len, const char *plaintext_p, - size_t ciphertext_len, const char *ciphertext_p ) -{ + size_t ciphertext_len, const char *ciphertext_p ) { AlignedBuffer key( KEY_LEN, key_p ); AlignedBuffer nonce( NONCE_LEN, nonce_p ); @@ -163,15 +162,16 @@ static void test_vector( const char *key_p, const char *nonce_p, test_decrypt( key, nonce, bad_ct, assoc, plaintext, false ); } - if ( verbose ) { printf( "PASSED\n\n" ); } + if ( verbose ) { + printf( "PASSED\n\n" ); + } } #define TEST_VECTOR( _key, _nonce, _assoc, _pt, _ct ) \ test_vector( _key, _nonce, sizeof( _assoc ) - 1, _assoc, sizeof( _pt ) - 1, \ _pt, sizeof( _ct ) - 1, _ct ) -static void test_all_vectors( void ) -{ +static void test_all_vectors( void ) { /* Test vectors from * http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A */ @@ -467,8 +467,7 @@ static void test_all_vectors( void ) /* http://tools.ietf.org/html/draft-krovetz-ocb-03#appendix-A also specifies an iterative test algorithm, which we implement here. */ -static void test_iterative( void ) -{ +static void test_iterative( void ) { /* Key is always all zeros */ AlignedBuffer key( KEY_LEN ); memset( key.data(), 0, KEY_LEN ); @@ -528,13 +527,16 @@ static void test_iterative( void ) "\xB2\xB4\x1C\xBF\x9B\x05\x03\x7D\xA7\xF1\x6C\x24\xA3\x5C\x1C\x94" ); fatal_assert( equal( out, correct ) ); - if ( verbose ) { printf( "iterative PASSED\n\n" ); } + if ( verbose ) { + printf( "iterative PASSED\n\n" ); + } scrap_ctx( *ctx_buf ); } -int main( int argc, char *argv[] ) -{ - if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { verbose = true; } +int main( int argc, char *argv[] ) { + if ( argc >= 2 && strcmp( argv[ 1 ], "-v" ) == 0 ) { + verbose = true; + } try { test_all_vectors(); diff --git a/src/tests/test_utils.cc b/src/tests/test_utils.cc index 3b5fd920a..95c3bf64e 100644 --- a/src/tests/test_utils.cc +++ b/src/tests/test_utils.cc @@ -34,8 +34,7 @@ #include "test_utils.h" -void hexdump( const void *buf, size_t len, const char *name ) -{ +void hexdump( const void *buf, size_t len, const char *name ) { const unsigned char *data = (const unsigned char *)buf; printf( DUMP_NAME_FMT, name ); for ( size_t i = 0; i < len; i++ ) { @@ -47,12 +46,10 @@ void hexdump( const void *buf, size_t len, const char *name ) printf( "\n" ); } -void hexdump( const Crypto::AlignedBuffer &buf, const char *name ) -{ +void hexdump( const Crypto::AlignedBuffer &buf, const char *name ) { hexdump( buf.data(), buf.len(), name ); } -void hexdump( const std::string &buf, const char *name ) -{ +void hexdump( const std::string &buf, const char *name ) { hexdump( buf.data(), buf.size(), name ); } diff --git a/src/util/dos_assert.h b/src/util/dos_assert.h index 79e17966f..418a3d74f 100644 --- a/src/util/dos_assert.h +++ b/src/util/dos_assert.h @@ -39,8 +39,7 @@ #include "crypto.h" static void dos_detected( const char *expression, const char *file, int line, - const char *function ) -{ + const char *function ) { char buffer[ 2048 ]; snprintf( buffer, 2048, "Illegal counterparty input (possible denial of service) in " diff --git a/src/util/fatal_assert.h b/src/util/fatal_assert.h index cadaf00c0..441c4e35e 100644 --- a/src/util/fatal_assert.h +++ b/src/util/fatal_assert.h @@ -37,8 +37,7 @@ #include static void fatal_error( const char *expression, const char *file, int line, - const char *function ) -{ + const char *function ) { fprintf( stderr, "Fatal assertion failure in function %s at %s:%d\nFailed test: %s\n", function, file, line, expression ); diff --git a/src/util/locale_utils.cc b/src/util/locale_utils.cc index c919684bc..b341d884e 100644 --- a/src/util/locale_utils.cc +++ b/src/util/locale_utils.cc @@ -45,14 +45,14 @@ #include "locale_utils.h" -const std::string LocaleVar::str( void ) const -{ - if ( name.empty() ) { return std::string( "[no charset variables]" ); } +const std::string LocaleVar::str( void ) const { + if ( name.empty() ) { + return std::string( "[no charset variables]" ); + } return name + "=" + value; } -const LocaleVar get_ctype( void ) -{ +const LocaleVar get_ctype( void ) { /* Reimplement the search logic, just for diagnostics */ if ( const char *all = getenv( "LC_ALL" ) ) { return LocaleVar( "LC_ALL", all ); @@ -64,20 +64,20 @@ const LocaleVar get_ctype( void ) return LocaleVar( "", "" ); } -const char *locale_charset( void ) -{ +const char *locale_charset( void ) { static const char ASCII_name[] = "US-ASCII"; /* Produce more pleasant name of US-ASCII */ const char *ret = nl_langinfo( CODESET ); - if ( strcmp( ret, "ANSI_X3.4-1968" ) == 0 ) { ret = ASCII_name; } + if ( strcmp( ret, "ANSI_X3.4-1968" ) == 0 ) { + ret = ASCII_name; + } return ret; } -bool is_utf8_locale( void ) -{ +bool is_utf8_locale( void ) { /* Verify locale calls for UTF-8 */ if ( strcmp( locale_charset(), "UTF-8" ) != 0 && strcmp( locale_charset(), "utf-8" ) != 0 ) { @@ -86,8 +86,7 @@ bool is_utf8_locale( void ) return true; } -void set_native_locale( void ) -{ +void set_native_locale( void ) { /* Adopt native locale */ if ( NULL == setlocale( LC_ALL, "" ) ) { int saved_errno = errno; @@ -106,8 +105,7 @@ void set_native_locale( void ) } } -void clear_locale_variables( void ) -{ +void clear_locale_variables( void ) { unsetenv( "LANG" ); unsetenv( "LANGUAGE" ); unsetenv( "LC_CTYPE" ); diff --git a/src/util/locale_utils.h b/src/util/locale_utils.h index 1d4f0810c..761f887f1 100644 --- a/src/util/locale_utils.h +++ b/src/util/locale_utils.h @@ -39,9 +39,7 @@ class LocaleVar { public: const std::string name, value; LocaleVar( const char *s_name, const char *s_value ) - : name( s_name ), value( s_value ) - { - } + : name( s_name ), value( s_value ) {} const std::string str( void ) const; }; diff --git a/src/util/pty_compat.cc b/src/util/pty_compat.cc index 160b17973..42b92168f 100644 --- a/src/util/pty_compat.cc +++ b/src/util/pty_compat.cc @@ -46,8 +46,7 @@ #ifndef HAVE_FORKPTY pid_t my_forkpty( int *amaster, char *name, const struct termios *termp, - const struct winsize *winp ) -{ + const struct winsize *winp ) { /* For Solaris and AIX */ int master, slave; char *slave_name; @@ -161,8 +160,7 @@ pid_t my_forkpty( int *amaster, char *name, const struct termios *termp, #endif #ifndef HAVE_CFMAKERAW -void my_cfmakeraw( struct termios *termios_p ) -{ +void my_cfmakeraw( struct termios *termios_p ) { termios_p->c_iflag &= ~( IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON ); termios_p->c_oflag &= ~OPOST; diff --git a/src/util/select.cc b/src/util/select.cc index 8fae0c243..278f3b5b2 100644 --- a/src/util/select.cc +++ b/src/util/select.cc @@ -38,8 +38,7 @@ sigset_t Select::dummy_sigset; unsigned int Select::verbose = 0; -void Select::handle_signal( int signum ) -{ +void Select::handle_signal( int signum ) { fatal_assert( signum >= 0 ); fatal_assert( signum <= MAX_SIGNAL_NUMBER ); diff --git a/src/util/select.h b/src/util/select.h index a758f97fc..f02d0cb39 100644 --- a/src/util/select.h +++ b/src/util/select.h @@ -49,8 +49,7 @@ class Select { public: - static Select &get_instance( void ) - { + static Select &get_instance( void ) { /* COFU may or may not be thread-safe, depending on compiler */ static Select instance; return instance; @@ -59,13 +58,13 @@ class Select { private: Select() : max_fd( -1 ) - /* These initializations are not used; they are just - here to appease -Weffc++. */ - , all_fds( dummy_fd_set ) - , read_fds( dummy_fd_set ) - , empty_sigset( dummy_sigset ) - , consecutive_polls( 0 ) - { + /* These initializations are not used; they are just + here to appease -Weffc++. */ + , + all_fds( dummy_fd_set ), + read_fds( dummy_fd_set ), + empty_sigset( dummy_sigset ), + consecutive_polls( 0 ) { FD_ZERO( &all_fds ); FD_ZERO( &read_fds ); @@ -73,8 +72,7 @@ class Select { fatal_assert( 0 == sigemptyset( &empty_sigset ) ); } - void clear_got_signal( void ) - { + void clear_got_signal( void ) { for ( volatile sig_atomic_t *p = got_signal; p < got_signal + sizeof( got_signal ) / sizeof( *got_signal ); p++ ) { *p = 0; @@ -86,16 +84,16 @@ class Select { Select &operator=( const Select & ); public: - void add_fd( int fd ) - { - if ( fd > max_fd ) { max_fd = fd; } + void add_fd( int fd ) { + if ( fd > max_fd ) { + max_fd = fd; + } FD_SET( fd, &all_fds ); } void clear_fds( void ) { FD_ZERO( &all_fds ); } - static void add_signal( int signum ) - { + static void add_signal( int signum ) { fatal_assert( signum >= 0 ); fatal_assert( signum <= MAX_SIGNAL_NUMBER ); @@ -115,8 +113,7 @@ class Select { } /* timeout unit: milliseconds; negative timeout means wait forever */ - int select( int timeout ) - { + int select( int timeout ) { memcpy( &read_fds, &all_fds, sizeof( read_fds ) ); clear_got_signal(); @@ -197,8 +194,7 @@ class Select { } /* This method consumes a signal notification. */ - bool signal( int signum ) - { + bool signal( int signum ) { fatal_assert( signum >= 0 ); fatal_assert( signum <= MAX_SIGNAL_NUMBER ); /* XXX This requires a guard against concurrent signals. */ @@ -208,10 +204,11 @@ class Select { } /* This method does not consume signal notifications. */ - bool any_signal( void ) const - { + bool any_signal( void ) const { bool rv = false; - for ( int i = 0; i < MAX_SIGNAL_NUMBER; i++ ) { rv |= got_signal[ i ]; } + for ( int i = 0; i < MAX_SIGNAL_NUMBER; i++ ) { + rv |= got_signal[ i ]; + } return rv; } diff --git a/src/util/shared.h b/src/util/shared.h index 057ffb650..6e90d469a 100644 --- a/src/util/shared.h +++ b/src/util/shared.h @@ -53,29 +53,25 @@ namespace shared { // make_shared emulation. template - inline shared_ptr make_shared() - { + inline shared_ptr make_shared() { return shared_ptr( new Tp() ); } template - inline shared_ptr make_shared( const A1 &a1 ) - { + inline shared_ptr make_shared( const A1 &a1 ) { return shared_ptr( new Tp( a1 ) ); } template - inline shared_ptr make_shared( const A1 &a1, const A2 &a2 ) - { + inline shared_ptr make_shared( const A1 &a1, const A2 &a2 ) { return shared_ptr( new Tp( a1, a2 ) ); } template - inline shared_ptr make_shared( const A1 &a1, const A2 &a2, const A3 &a3 ) - { + inline shared_ptr make_shared( const A1 &a1, const A2 &a2, + const A3 &a3 ) { return shared_ptr( new Tp( a1, a2, a3 ) ); } template inline shared_ptr make_shared( const A1 &a1, const A2 &a2, const A3 &a3, - const A4 &a4 ) - { + const A4 &a4 ) { return shared_ptr( new Tp( a1, a2, a3, a4 ) ); } #else diff --git a/src/util/swrite.cc b/src/util/swrite.cc index be4eee88b..b59e99888 100644 --- a/src/util/swrite.cc +++ b/src/util/swrite.cc @@ -36,8 +36,7 @@ #include "swrite.h" -int swrite( int fd, const char *str, ssize_t len ) -{ +int swrite( int fd, const char *str, ssize_t len ) { ssize_t total_bytes_written = 0; ssize_t bytes_to_write = ( len >= 0 ) ? len : (ssize_t)strlen( str ); while ( total_bytes_written < bytes_to_write ) { diff --git a/src/util/timestamp.cc b/src/util/timestamp.cc index ab6cc54cc..1ffd3b328 100644 --- a/src/util/timestamp.cc +++ b/src/util/timestamp.cc @@ -60,15 +60,15 @@ static uint64_t millis_cache = -1; -uint64_t frozen_timestamp( void ) -{ - if ( millis_cache == uint64_t( -1 ) ) { freeze_timestamp(); } +uint64_t frozen_timestamp( void ) { + if ( millis_cache == uint64_t( -1 ) ) { + freeze_timestamp(); + } return millis_cache; } -void freeze_timestamp( void ) -{ +void freeze_timestamp( void ) { // Try all our clock sources till we get something. This could // break if a source only sometimes works in a given process. #if HAVE_CLOCK_GETTIME