Move parser outside of terminal emulator -- prepare for keyboard input
This commit is contained in:
@@ -159,8 +159,8 @@ int vt_parser( int fd, Parser::UTF8Parser *parser )
|
|||||||
|
|
||||||
/* feed to parser */
|
/* feed to parser */
|
||||||
for ( int i = 0; i < bytes_read; i++ ) {
|
for ( int i = 0; i < bytes_read; i++ ) {
|
||||||
std::vector<Parser::Action *> actions = parser->input( buf[ i ] );
|
std::list<Parser::Action *> actions = parser->input( buf[ i ] );
|
||||||
for ( std::vector<Parser::Action *>::iterator j = actions.begin();
|
for ( std::list<Parser::Action *>::iterator j = actions.begin();
|
||||||
j != actions.end();
|
j != actions.end();
|
||||||
j++ ) {
|
j++ ) {
|
||||||
|
|
||||||
|
|||||||
+7
-11
@@ -5,7 +5,7 @@
|
|||||||
#include "parser.hpp"
|
#include "parser.hpp"
|
||||||
|
|
||||||
static void append_or_delete( Parser::Action *act,
|
static void append_or_delete( Parser::Action *act,
|
||||||
std::vector<Parser::Action *>&vec )
|
std::list<Parser::Action *>&vec )
|
||||||
{
|
{
|
||||||
assert( act );
|
assert( act );
|
||||||
|
|
||||||
@@ -16,9 +16,9 @@ static void append_or_delete( Parser::Action *act,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Parser::Action *> Parser::Parser::input( wchar_t ch )
|
std::list<Parser::Action *> Parser::Parser::input( wchar_t ch )
|
||||||
{
|
{
|
||||||
std::vector<Action *> ret;
|
std::list<Action *> ret;
|
||||||
|
|
||||||
Transition tx = state->input( ch );
|
Transition tx = state->input( ch );
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ Parser::UTF8Parser::UTF8Parser()
|
|||||||
assert( BUF_SIZE >= MB_CUR_MAX );
|
assert( BUF_SIZE >= MB_CUR_MAX );
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Parser::Action *> Parser::UTF8Parser::input( char c )
|
std::list<Parser::Action *> Parser::UTF8Parser::input( char c )
|
||||||
{
|
{
|
||||||
assert( buf_len < BUF_SIZE );
|
assert( buf_len < BUF_SIZE );
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ std::vector<Parser::Action *> Parser::UTF8Parser::input( char c )
|
|||||||
|
|
||||||
size_t total_bytes_parsed = 0;
|
size_t total_bytes_parsed = 0;
|
||||||
size_t orig_buf_len = buf_len;
|
size_t orig_buf_len = buf_len;
|
||||||
std::vector<Action *> ret;
|
std::list<Action *> ret;
|
||||||
|
|
||||||
/* this routine is somewhat complicated in order to comply with
|
/* this routine is somewhat complicated in order to comply with
|
||||||
Unicode 6.0, section 3.9, "Best Practices for using U+FFFD" */
|
Unicode 6.0, section 3.9, "Best Practices for using U+FFFD" */
|
||||||
@@ -112,12 +112,8 @@ std::vector<Parser::Action *> Parser::UTF8Parser::input( char c )
|
|||||||
pwc = (wchar_t) 0xFFFD;
|
pwc = (wchar_t) 0xFFFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Action *> vec = parser.input( pwc );
|
std::list<Action *> vec = parser.input( pwc );
|
||||||
for ( std::vector<Action *>::iterator i = vec.begin();
|
ret.insert( ret.end(), vec.begin(), vec.end() );
|
||||||
i != vec.end();
|
|
||||||
i++ ) {
|
|
||||||
ret.push_back( *i );
|
|
||||||
}
|
|
||||||
|
|
||||||
total_bytes_parsed += bytes_parsed;
|
total_bytes_parsed += bytes_parsed;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -5,7 +5,7 @@
|
|||||||
http://www.vt100.net/emu/dec_ansi_parser */
|
http://www.vt100.net/emu/dec_ansi_parser */
|
||||||
|
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <vector>
|
#include <list>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "parsertransition.hpp"
|
#include "parsertransition.hpp"
|
||||||
@@ -30,7 +30,7 @@ namespace Parser {
|
|||||||
Parser & operator=( const Parser & );
|
Parser & operator=( const Parser & );
|
||||||
~Parser() {}
|
~Parser() {}
|
||||||
|
|
||||||
std::vector<Action *> input( wchar_t ch );
|
std::list<Action *> input( wchar_t ch );
|
||||||
};
|
};
|
||||||
|
|
||||||
static const size_t BUF_SIZE = 8;
|
static const size_t BUF_SIZE = 8;
|
||||||
@@ -45,7 +45,7 @@ namespace Parser {
|
|||||||
public:
|
public:
|
||||||
UTF8Parser();
|
UTF8Parser();
|
||||||
|
|
||||||
std::vector<Action *> input( char c );
|
std::list<Action *> input( char c );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-8
@@ -1,3 +1,4 @@
|
|||||||
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
@@ -9,11 +10,15 @@ namespace Parser {
|
|||||||
class Action;
|
class Action;
|
||||||
}
|
}
|
||||||
|
|
||||||
template class std::vector<Parser::Action *>;
|
using namespace std;
|
||||||
template class std::vector<Terminal::Cell>;
|
using namespace Terminal;
|
||||||
template class std::deque<Terminal::Row>;
|
|
||||||
template class std::vector<Terminal::Cell *>;
|
template class list<Parser::Action *>;
|
||||||
template class std::vector<wchar_t>;
|
template class vector<Cell>;
|
||||||
template class std::vector<int>;
|
template class deque<Row>;
|
||||||
template class std::map<std::string, Terminal::Function>;
|
template class vector<Cell *>;
|
||||||
template class std::vector<bool>;
|
template class vector<wchar_t>;
|
||||||
|
template class vector<int>;
|
||||||
|
template class map<string, Function>;
|
||||||
|
template class vector<bool>;
|
||||||
|
|
||||||
|
|||||||
+18
-7
@@ -23,7 +23,8 @@ const size_t buf_size = 1024;
|
|||||||
|
|
||||||
void emulate_terminal( int fd, int debug_fd );
|
void emulate_terminal( int fd, int debug_fd );
|
||||||
int copy( int src, int dest );
|
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,
|
int main( int argc,
|
||||||
char *argv[],
|
char *argv[],
|
||||||
@@ -107,11 +108,14 @@ int main( int argc,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf( "[rtm is exiting.]\n" );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void emulate_terminal( int fd, int debug_fd )
|
void emulate_terminal( int fd, int debug_fd )
|
||||||
{
|
{
|
||||||
|
Parser::UTF8Parser parser;
|
||||||
Terminal::Emulator terminal( 80, 24 );
|
Terminal::Emulator terminal( 80, 24 );
|
||||||
struct pollfd pollfds[ 2 ];
|
struct pollfd pollfds[ 2 ];
|
||||||
|
|
||||||
@@ -133,7 +137,7 @@ void emulate_terminal( int fd, int debug_fd )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if ( pollfds[ 1 ].revents & POLLIN ) {
|
} else if ( pollfds[ 1 ].revents & POLLIN ) {
|
||||||
if ( termemu( fd, &terminal, debug_fd ) < 0 ) {
|
if ( termemu( fd, &parser, &terminal, debug_fd ) < 0 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)
|
} else if ( (pollfds[ 0 ].revents | pollfds[ 1 ].revents)
|
||||||
@@ -160,7 +164,8 @@ int copy( int src, int dest )
|
|||||||
return swrite( dest, buf, bytes_read );
|
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 ];
|
char buf[ buf_size ];
|
||||||
|
|
||||||
@@ -173,15 +178,21 @@ int termemu( int fd, Terminal::Emulator *terminal, int debug_fd )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string terminal_to_host;
|
/* feed bytes to parser, and actions to terminal */
|
||||||
|
|
||||||
/* feed to terminal */
|
|
||||||
for ( int i = 0; i < bytes_read; i++ ) {
|
for ( int i = 0; i < bytes_read; i++ ) {
|
||||||
terminal_to_host.append( terminal->input( buf[ i ], debug_fd ) );
|
std::list<Parser::Action *> actions = parser->input( buf[ i ] );
|
||||||
|
for ( std::list<Parser::Action *>::iterator i = actions.begin();
|
||||||
|
i != actions.end();
|
||||||
|
i++ ) {
|
||||||
|
(*i)->act_on_terminal( terminal );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal->debug_printout( STDOUT_FILENO );
|
terminal->debug_printout( STDOUT_FILENO );
|
||||||
|
|
||||||
|
debug_fd = debug_fd;
|
||||||
|
|
||||||
/* write writeback */
|
/* write writeback */
|
||||||
|
std::string terminal_to_host = terminal->read_octets_to_host();
|
||||||
return swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() );
|
return swrite( fd, terminal_to_host.c_str(), terminal_to_host.length() );
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-28
@@ -10,38 +10,14 @@
|
|||||||
using namespace Terminal;
|
using namespace Terminal;
|
||||||
|
|
||||||
Emulator::Emulator( size_t s_width, size_t s_height )
|
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();
|
dispatch.terminal_to_host.clear();
|
||||||
|
return ret;
|
||||||
std::vector<Parser::Action *> vec = parser.input( c );
|
|
||||||
|
|
||||||
for ( std::vector<Parser::Action *>::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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Emulator::execute( Parser::Execute *act )
|
void Emulator::execute( Parser::Execute *act )
|
||||||
|
|||||||
+1
-2
@@ -24,7 +24,6 @@ namespace Terminal {
|
|||||||
friend void Parser::OSC_End::act_on_terminal( Emulator * );
|
friend void Parser::OSC_End::act_on_terminal( Emulator * );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Parser::UTF8Parser parser;
|
|
||||||
Framebuffer fb;
|
Framebuffer fb;
|
||||||
Dispatcher dispatch;
|
Dispatcher dispatch;
|
||||||
|
|
||||||
@@ -38,7 +37,7 @@ namespace Terminal {
|
|||||||
public:
|
public:
|
||||||
Emulator( size_t s_width, size_t s_height );
|
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 );
|
void debug_printout( int fd );
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user