Refactoring FTerm::init_termcaps

This commit is contained in:
Markus Gans 2018-02-19 01:36:38 +01:00
parent 4322e957c9
commit 9426657c43
4 changed files with 73 additions and 62 deletions

View File

@ -1,3 +1,6 @@
2017-02-19 Markus Gans <guru.mail@muenster.de>
* Refactoring FTerm::init_termcaps
2017-02-18 Markus Gans <guru.mail@muenster.de> 2017-02-18 Markus Gans <guru.mail@muenster.de>
* Avoid scroll bar overshooting * Avoid scroll bar overshooting
* Refactoring FListView::onMouseMove * Refactoring FListView::onMouseMove

View File

@ -31,7 +31,7 @@
static FVTerm* terminal; static FVTerm* terminal;
// Function prototype // Function prototype
void tcapBooleans (const std::string&, bool); void tcapBoolean (const std::string&, bool);
void tcapNumeric (const std::string&, int); void tcapNumeric (const std::string&, int);
void tcapString (const std::string&, const char[]); void tcapString (const std::string&, const char[]);
void debug (FApplication&); void debug (FApplication&);
@ -142,7 +142,7 @@ const int last_item = int ( sizeof(strings) / sizeof(strings[0]) ) - 1;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Functions // Functions
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void tcapBooleans (const std::string& name, bool cap_bool) void tcapBoolean (const std::string& name, bool cap_bool)
{ {
std::cout << "FTermcap::" << name << ": "; std::cout << "FTermcap::" << name << ": ";
@ -232,19 +232,19 @@ void debug (FApplication& TermApp)
void booleans() void booleans()
{ {
std::cout << "\r\n[Booleans]\r\n"; std::cout << "\r\n[Booleans]\r\n";
tcapBooleans ( "background_color_erase" tcapBoolean ( "background_color_erase"
, FTermcap::background_color_erase ); , FTermcap::background_color_erase );
tcapBooleans ( "automatic_left_margin" tcapBoolean ( "automatic_left_margin"
, FTermcap::automatic_left_margin ); , FTermcap::automatic_left_margin );
tcapBooleans ( "automatic_right_margin" tcapBoolean ( "automatic_right_margin"
, FTermcap::automatic_right_margin ); , FTermcap::automatic_right_margin );
tcapBooleans ( "eat_nl_glitch" tcapBoolean ( "eat_nl_glitch"
, FTermcap::eat_nl_glitch ); , FTermcap::eat_nl_glitch );
tcapBooleans ( "ansi_default_color" tcapBoolean ( "ansi_default_color"
, FTermcap::ansi_default_color ); , FTermcap::ansi_default_color );
tcapBooleans ( "osc_support" tcapBoolean ( "osc_support"
, FTermcap::osc_support ); , FTermcap::osc_support );
tcapBooleans ( "no_utf8_acs_chars" tcapBoolean ( "no_utf8_acs_chars"
, FTermcap::no_utf8_acs_chars ); , FTermcap::no_utf8_acs_chars );
} }

View File

@ -495,8 +495,10 @@ class FTerm
static void init_cygwin_charmap(); static void init_cygwin_charmap();
static void init_teraterm_charmap(); static void init_teraterm_charmap();
static void init_termcaps(); static void init_termcaps();
static void init_termcaps_error (int);
static void init_termcaps_variables(char*&);
static void init_termcaps_booleans(); static void init_termcaps_booleans();
static void init_termcaps_numeric(); static void init_termcaps_numerics();
static void init_termcaps_strings (char*&); static void init_termcaps_strings (char*&);
static void init_termcaps_quirks(); static void init_termcaps_quirks();
#if defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__FreeBSD__) || defined(__DragonFly__)

View File

@ -3366,9 +3366,7 @@ void FTerm::init_teraterm_charmap()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::init_termcaps() /* Terminal capability data base
{
/* Terminal capability data base
* ----------------------------- * -----------------------------
* Info under: man 5 terminfo * Info under: man 5 terminfo
* *
@ -3376,11 +3374,12 @@ void FTerm::init_termcaps()
* captoinfo - convert all termcap descriptions into terminfo descriptions * captoinfo - convert all termcap descriptions into terminfo descriptions
* infocmp - print out terminfo description from the current terminal * infocmp - print out terminfo description from the current terminal
*/ */
static const int void FTerm::init_termcaps()
success = 1 {
, no_entry = 0 std::vector<std::string> terminals;
, db_not_found = -1 std::vector<std::string>::iterator iter;
, uninitialized = -2; static const int success = 1;
static const int uninitialized = -2;
static char term_buffer[2048]; static char term_buffer[2048];
static char string_buf[2048]; static char string_buf[2048];
char* buffer = string_buf; char* buffer = string_buf;
@ -3389,43 +3388,46 @@ void FTerm::init_termcaps()
// share the terminal capabilities // share the terminal capabilities
FTermcap().setTermcapMap(tcap); FTermcap().setTermcapMap(tcap);
if ( termtype[0] ) // open termcap file
terminals.push_back(termtype); // available terminal type
if ( color256 ) // 1st fallback if not found
terminals.push_back("xterm-256color");
terminals.push_back("xterm"); // 2nd fallback if not found
terminals.push_back("ansi"); // 3rd fallback if not found
terminals.push_back("vt100"); // 4th fallback if not found
iter = terminals.begin();
while ( iter != terminals.end() )
{ {
// open the termcap file + load entry for termtype // Copy c-string + terminating null-character ('\0')
std::strncpy (termtype, (*iter).c_str(), (*iter).length() + 1);
// Open the termcap file + load entry for termtype
status = tgetent(term_buffer, termtype); status = tgetent(term_buffer, termtype);
if ( status == success || ! terminal_detection )
break;
++iter;
} }
if ( status != success && color256 ) if ( std::strncmp(termtype, "ansi", 4) == 0 )
{
// use "xterm-256color" as fallback if not found
std::strncpy (termtype, C_STR("xterm-256color"), 15);
status = tgetent(term_buffer, termtype);
}
if ( status != success )
{
// use "xterm" as fallback if not found
std::strncpy (termtype, C_STR("xterm"), 6);
status = tgetent(term_buffer, termtype);
if ( status != success )
{
// use "ansi" as fallback if not found
std::strncpy (termtype, C_STR("ansi"), 5);
status = tgetent(term_buffer, termtype);
ansi_terminal = true; ansi_terminal = true;
if ( status != success ) init_termcaps_error (status);
{ init_termcaps_variables (buffer);
// use "vt100" as fallback if not found }
std::strncpy (termtype, C_STR("vt100"), 6);
status = tgetent(term_buffer, termtype);
ansi_terminal = false;
}
}
}
if ( status == no_entry ) //----------------------------------------------------------------------
void FTerm::init_termcaps_error (int status)
{
static const int no_entry = 0;
static const int db_not_found = -1;
static const int uninitialized = -2;
if ( status == no_entry || status == uninitialized )
{ {
std::cerr << "Unknown terminal: " << termtype << "\n" std::cerr << "Unknown terminal: " << termtype << "\n"
<< "Check the TERM environment variable\n" << "Check the TERM environment variable\n"
@ -3438,12 +3440,16 @@ void FTerm::init_termcaps()
std::cerr << "The termcap/terminfo database could not be found.\n"; std::cerr << "The termcap/terminfo database could not be found.\n";
std::abort(); std::abort();
} }
}
//----------------------------------------------------------------------
void FTerm::init_termcaps_variables (char*& buffer)
{
// Get termcap booleans // Get termcap booleans
init_termcaps_booleans(); init_termcaps_booleans();
// Get termcap numeric // Get termcap numerics
init_termcaps_numeric(); init_termcaps_numerics();
// Get termcap strings // Get termcap strings
init_termcaps_strings(buffer); init_termcaps_strings(buffer);
@ -3490,7 +3496,7 @@ void FTerm::init_termcaps_booleans()
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FTerm::init_termcaps_numeric() void FTerm::init_termcaps_numerics()
{ {
// Get termcap numeric // Get termcap numeric