diff --git a/parse.cpp b/parse.cpp index d43c19f..f4513b8 100644 --- a/parse.cpp +++ b/parse.cpp @@ -159,8 +159,8 @@ int vt_parser( int fd, Parser::UTF8Parser *parser ) /* feed to parser */ for ( int i = 0; i < bytes_read; i++ ) { - std::vector actions = parser->input( buf[ i ] ); - for ( std::vector::iterator j = actions.begin(); + std::list actions = parser->input( buf[ i ] ); + for ( std::list::iterator j = actions.begin(); j != actions.end(); j++ ) { diff --git a/parser.cpp b/parser.cpp index 994ca18..bb3acd5 100644 --- a/parser.cpp +++ b/parser.cpp @@ -5,7 +5,7 @@ #include "parser.hpp" static void append_or_delete( Parser::Action *act, - std::vector&vec ) + std::list&vec ) { assert( act ); @@ -16,9 +16,9 @@ static void append_or_delete( Parser::Action *act, } } -std::vector Parser::Parser::input( wchar_t ch ) +std::list Parser::Parser::input( wchar_t ch ) { - std::vector ret; + std::list ret; Transition tx = state->input( ch ); @@ -47,7 +47,7 @@ Parser::UTF8Parser::UTF8Parser() assert( BUF_SIZE >= MB_CUR_MAX ); } -std::vector Parser::UTF8Parser::input( char c ) +std::list Parser::UTF8Parser::input( char c ) { assert( buf_len < BUF_SIZE ); @@ -62,7 +62,7 @@ std::vector Parser::UTF8Parser::input( char c ) size_t total_bytes_parsed = 0; size_t orig_buf_len = buf_len; - std::vector ret; + std::list ret; /* this routine is somewhat complicated in order to comply with Unicode 6.0, section 3.9, "Best Practices for using U+FFFD" */ @@ -112,12 +112,8 @@ std::vector Parser::UTF8Parser::input( char c ) pwc = (wchar_t) 0xFFFD; } - std::vector vec = parser.input( pwc ); - for ( std::vector::iterator i = vec.begin(); - i != vec.end(); - i++ ) { - ret.push_back( *i ); - } + std::list vec = parser.input( pwc ); + ret.insert( ret.end(), vec.begin(), vec.end() ); total_bytes_parsed += bytes_parsed; } diff --git a/parser.hpp b/parser.hpp index 0726445..62804c4 100644 --- a/parser.hpp +++ b/parser.hpp @@ -5,7 +5,7 @@ http://www.vt100.net/emu/dec_ansi_parser */ #include -#include +#include #include #include "parsertransition.hpp" @@ -30,7 +30,7 @@ namespace Parser { Parser & operator=( const Parser & ); ~Parser() {} - std::vector input( wchar_t ch ); + std::list input( wchar_t ch ); }; static const size_t BUF_SIZE = 8; @@ -45,7 +45,7 @@ namespace Parser { public: UTF8Parser(); - std::vector input( char c ); + std::list input( char c ); }; } diff --git a/templates.cpp b/templates.cpp index 4cf6b79..ff66ccd 100644 --- a/templates.cpp +++ b/templates.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -9,11 +10,15 @@ namespace Parser { class Action; } -template class std::vector; -template class std::vector; -template class std::deque; -template class std::vector; -template class std::vector; -template class std::vector; -template class std::map; -template class std::vector; +using namespace std; +using namespace Terminal; + +template class list; +template class vector; +template class deque; +template class vector; +template class vector; +template class vector; +template class map; +template class vector; + diff --git a/termemu.cpp b/termemu.cpp index e325fa3..6a39b67 100644 --- a/termemu.cpp +++ b/termemu.cpp @@ -23,7 +23,8 @@ const size_t buf_size = 1024; void emulate_terminal( int fd, int debug_fd ); int copy( int src, int dest ); -int termemu( int fd, Terminal::Emulator *terminal, int debug_fd ); +int termemu( int fd, Parser::UTF8Parser *parser, + Terminal::Emulator *terminal, int debug_fd ); int main( int argc, char *argv[], @@ -107,11 +108,14 @@ int main( int argc, } } + printf( "[rtm is exiting.]\n" ); + return 0; } void emulate_terminal( int fd, int debug_fd ) { + Parser::UTF8Parser parser; Terminal::Emulator terminal( 80, 24 ); struct pollfd pollfds[ 2 ]; @@ -133,7 +137,7 @@ void emulate_terminal( int fd, int debug_fd ) return; } } else if ( pollfds[ 1 ].revents & POLLIN ) { - if ( termemu( fd, &terminal, debug_fd ) < 0 ) { + if ( termemu( fd, &parser, &terminal, debug_fd ) < 0 ) { return; } } else if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents) @@ -160,7 +164,8 @@ int copy( int src, int dest ) return swrite( dest, buf, bytes_read ); } -int termemu( int fd, Terminal::Emulator *terminal, int debug_fd ) +int termemu( int fd, Parser::UTF8Parser *parser, + Terminal::Emulator *terminal, int debug_fd ) { char buf[ buf_size ]; @@ -173,15 +178,21 @@ int termemu( int fd, Terminal::Emulator *terminal, int debug_fd ) return -1; } - std::string terminal_to_host; - - /* feed to terminal */ + /* feed bytes to parser, and actions to terminal */ for ( int i = 0; i < bytes_read; i++ ) { - terminal_to_host.append( terminal->input( buf[ i ], debug_fd ) ); + std::list actions = parser->input( buf[ i ] ); + for ( std::list::iterator i = actions.begin(); + i != actions.end(); + i++ ) { + (*i)->act_on_terminal( terminal ); + } } terminal->debug_printout( STDOUT_FILENO ); + debug_fd = debug_fd; + /* write writeback */ + std::string terminal_to_host = terminal->read_octets_to_host(); return swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() ); } diff --git a/terminal.cpp b/terminal.cpp index 3be9ec8..b2b8998 100644 --- a/terminal.cpp +++ b/terminal.cpp @@ -10,38 +10,14 @@ using namespace Terminal; Emulator::Emulator( size_t s_width, size_t s_height ) - : parser(), fb( s_width, s_height ), dispatch() + : fb( s_width, s_height ), dispatch() {} -std::string Emulator::input( char c, int actfd ) +std::string Emulator::read_octets_to_host( void ) { + std::string ret = dispatch.terminal_to_host; dispatch.terminal_to_host.clear(); - - std::vector vec = parser.input( c ); - - for ( std::vector::iterator i = vec.begin(); - i != vec.end(); - i++ ) { - Parser::Action *act = *i; - - act->act_on_terminal( this ); - - /* print out debugging information */ - if ( (actfd > 0) && ( !act->handled ) ) { - char actsum[ 64 ]; - if ( (typeid( *act ) == typeid( Parser::CSI_Dispatch )) - || (typeid( *act ) == typeid( Parser::Esc_Dispatch )) ) { - snprintf( actsum, 64, "%s%s ", act->str().c_str(), dispatch.str().c_str() ); - } else { - snprintf( actsum, 64, "%s ", act->str().c_str() ); - } - swrite( actfd, actsum ); - } - delete act; - } - - /* the user is supposed to send this string to the host, as if typed */ - return dispatch.terminal_to_host; + return ret; } void Emulator::execute( Parser::Execute *act ) diff --git a/terminal.hpp b/terminal.hpp index 20f8c8f..2880844 100644 --- a/terminal.hpp +++ b/terminal.hpp @@ -24,7 +24,6 @@ namespace Terminal { friend void Parser::OSC_End::act_on_terminal( Emulator * ); private: - Parser::UTF8Parser parser; Framebuffer fb; Dispatcher dispatch; @@ -38,7 +37,7 @@ namespace Terminal { public: Emulator( size_t s_width, size_t s_height ); - std::string input( char c, int debug_fd ); + std::string read_octets_to_host( void ); void debug_printout( int fd ); };