Removing the termcap library from the header files so that FINAL CUT programs are not affected by the preprocessor #define macros

This commit is contained in:
Markus Gans 2021-02-28 13:21:21 +01:00
parent 59917ed126
commit 73faadd852
12 changed files with 112 additions and 133 deletions

View File

@ -1,3 +1,9 @@
2021-02-28 Markus Gans <guru.mail@muenster.de>
* Removing the termcap library from the header files so
that FINAL CUT programs are not affected by the preprocessor
#define macros.
Many thanks to Zhenyu Zhang for this optimization suggestion
2021-02-24 Markus Gans <guru.mail@muenster.de>
* Fixed the incorrect display on terminals without
UTF-8 character encoding

View File

@ -1385,13 +1385,13 @@ inline void FOptiAttr::change_current_color ( const FChar& term
if ( term.fg_color != fg || frev )
{
const auto& color_str = FTermcap::encodeParameter(AF, uInt16(ansi_fg), 0, 0, 0, 0, 0, 0, 0, 0);
const auto& color_str = FTermcap::encodeParameter(AF, uInt16(ansi_fg));
append_sequence (color_str.data());
}
if ( term.bg_color != bg || frev )
{
const auto& color_str = FTermcap::encodeParameter(AB, uInt16(ansi_bg), 0, 0, 0, 0, 0, 0, 0, 0);
const auto& color_str = FTermcap::encodeParameter(AB, uInt16(ansi_bg));
append_sequence (color_str.data());
}
}
@ -1399,13 +1399,13 @@ inline void FOptiAttr::change_current_color ( const FChar& term
{
if ( term.fg_color != fg || frev )
{
const auto& color_str = FTermcap::encodeParameter(Sf, uInt16(fg), 0, 0, 0, 0, 0, 0, 0, 0);
const auto& color_str = FTermcap::encodeParameter(Sf, uInt16(fg));
append_sequence (color_str.data());
}
if ( term.bg_color != bg || frev )
{
const auto& color_str = FTermcap::encodeParameter(Sb, uInt16(bg), 0, 0, 0, 0, 0, 0, 0, 0);
const auto& color_str = FTermcap::encodeParameter(Sb, uInt16(bg));
append_sequence (color_str.data());
}
}
@ -1413,7 +1413,7 @@ inline void FOptiAttr::change_current_color ( const FChar& term
{
fg = vga2ansi(fg);
bg = vga2ansi(bg);
const auto& color_str = FTermcap::encodeParameter(sp, uInt16(fg), uInt16(bg), 0, 0, 0, 0, 0, 0, 0);
const auto& color_str = FTermcap::encodeParameter(sp, uInt16(fg), uInt16(bg));
append_sequence (color_str.data());
}
}

View File

@ -284,7 +284,7 @@ void FOptiMove::set_column_address (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_column_address.cap = cap;
F_column_address.duration = capDuration (temp.data(), 1);
F_column_address.length = capDurationToLength (F_column_address.duration);
@ -302,7 +302,7 @@ void FOptiMove::set_row_address (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_row_address.cap = cap;
F_row_address.duration = capDuration (temp.data(), 1);
F_row_address.length = capDurationToLength (F_row_address.duration);
@ -320,7 +320,7 @@ void FOptiMove::set_parm_up_cursor (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_parm_up_cursor.cap = cap;
F_parm_up_cursor.duration = capDuration (temp.data(), 1);
F_parm_up_cursor.length = capDurationToLength (F_parm_up_cursor.duration);
@ -338,7 +338,7 @@ void FOptiMove::set_parm_down_cursor (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_parm_down_cursor.cap = cap;
F_parm_down_cursor.duration = capDuration (temp.data(), 1);
F_parm_down_cursor.length = capDurationToLength (F_parm_down_cursor.duration);
@ -356,7 +356,7 @@ void FOptiMove::set_parm_left_cursor (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_parm_left_cursor.cap = cap;
F_parm_left_cursor.duration = capDuration (temp.data(), 1);
F_parm_left_cursor.length = capDurationToLength (F_parm_left_cursor.duration);
@ -374,7 +374,7 @@ void FOptiMove::set_parm_right_cursor (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_parm_right_cursor.cap = cap;
F_parm_right_cursor.duration = capDuration (temp.data(), 1);
F_parm_right_cursor.length = capDurationToLength (F_parm_right_cursor.duration);
@ -392,7 +392,7 @@ void FOptiMove::set_erase_chars (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, 23, 0, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, 23);
F_erase_chars.cap = cap;
F_erase_chars.duration = capDuration (temp.data(), 1);
F_erase_chars.length = capDurationToLength (F_erase_chars.duration);
@ -410,7 +410,7 @@ void FOptiMove::set_repeat_char (const char cap[])
{
if ( cap && FTermcap::isInitialized() )
{
const auto& temp = FTermcap::encodeParameter(cap, ' ', 23, 0, 0, 0, 0, 0, 0, 0);
const auto& temp = FTermcap::encodeParameter(cap, ' ');
F_repeat_char.cap = cap;
F_repeat_char.duration = capDuration (temp.data(), 1);
F_repeat_char.length = capDurationToLength (F_repeat_char.duration);
@ -686,7 +686,7 @@ inline int FOptiMove::verticalMove (char move[], int from_y, int to_y) const
if ( move )
{
std::strncpy ( move
, FTermcap::encodeParameter(F_row_address.cap, to_y, 0, 0, 0, 0, 0, 0, 0, 0).data()
, FTermcap::encodeParameter(F_row_address.cap, to_y).data()
, BUF_SIZE );
move[BUF_SIZE - 1] = '\0';
}
@ -713,7 +713,7 @@ inline void FOptiMove::downMove ( char move[], int& vtime
if ( move )
{
std::strncpy ( move
, FTermcap::encodeParameter(F_parm_down_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0).data()
, FTermcap::encodeParameter(F_parm_down_cursor.cap, num).data()
, BUF_SIZE );
move[BUF_SIZE - 1] = '\0';
}
@ -741,7 +741,7 @@ inline void FOptiMove::upMove ( char move[], int& vtime
if ( move )
{
std::strncpy ( move
, FTermcap::encodeParameter(F_parm_up_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0).data()
, FTermcap::encodeParameter(F_parm_up_cursor.cap, num).data()
, BUF_SIZE );
move[BUF_SIZE - 1] = '\0';
}
@ -767,7 +767,7 @@ inline int FOptiMove::horizontalMove (char hmove[], int from_x, int to_x) const
{
// Move to fixed column position1
std::strncat ( hmove
, FTermcap::encodeParameter(F_column_address.cap, to_x, 0, 0, 0, 0, 0, 0, 0, 0).data()
, FTermcap::encodeParameter(F_column_address.cap, to_x).data()
, BUF_SIZE - std::strlen(hmove) - 1 );
hmove[BUF_SIZE - 1] = '\0';
htime = F_column_address.duration;
@ -790,7 +790,7 @@ inline void FOptiMove::rightMove ( char hmove[], int& htime
if ( F_parm_right_cursor.cap && F_parm_right_cursor.duration < htime )
{
std::strncpy ( hmove
, FTermcap::encodeParameter(F_parm_right_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0).data()
, FTermcap::encodeParameter(F_parm_right_cursor.cap, num).data()
, BUF_SIZE - 1);
hmove[BUF_SIZE - 1] = '\0';
htime = F_parm_right_cursor.duration;
@ -845,7 +845,7 @@ inline void FOptiMove::leftMove ( char hmove[], int& htime
if ( F_parm_left_cursor.cap && F_parm_left_cursor.duration < htime )
{
std::strncpy ( hmove
, FTermcap::encodeParameter(F_parm_left_cursor.cap, num, 0, 0, 0, 0, 0, 0, 0, 0).data()
, FTermcap::encodeParameter(F_parm_left_cursor.cap, num).data()
, BUF_SIZE - 1);
hmove[BUF_SIZE - 1] = '\0';
htime = F_parm_left_cursor.duration;

View File

@ -906,9 +906,9 @@ void FTerm::setPalette (FColor index, int r, int g, int b)
const int bb = (b * 1001) / 256;
if ( Ic )
color_str = FTermcap::encodeParameter(Ic, uInt16(index), rr, gg, bb, 0, 0, 0, 0, 0);
color_str = FTermcap::encodeParameter(Ic, uInt16(index), rr, gg, bb);
else if ( Ip )
color_str = FTermcap::encodeParameter(Ip, uInt16(index), 0, 0, 0, rr, gg, bb, 0, 0);
color_str = FTermcap::encodeParameter(Ip, uInt16(index), 0, 0, 0, rr, gg, bb);
if ( ! color_str.empty() )
{

View File

@ -20,6 +20,26 @@
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#if defined(__sun) && defined(__SVR4)
#include <termio.h>
typedef struct termio SGTTY;
typedef struct termios SGTTYS;
#ifdef _LP64
typedef unsigned int chtype;
#else
typedef unsigned long chtype;
#endif // _LP64
#include <term.h> // termcap
#else
#include <term.h> // termcap
#endif // defined(__sun) && defined(__SVR4)
#ifdef F_HAVE_LIBGPM
#undef buttons // from term.h
#endif
#include <algorithm>
#include <string>
#include <vector>
@ -67,6 +87,31 @@ char FTermcap::string_buf[2048] {};
*/
// public methods of FTermcap
//----------------------------------------------------------------------
bool FTermcap::getFlag (const std::string& cap)
{
return ::tgetflag(C_STR(cap.data()));
}
//----------------------------------------------------------------------
int FTermcap::getNumber (const std::string& cap)
{
return ::tgetnum(C_STR(cap.data()));
}
//----------------------------------------------------------------------
char* FTermcap::getString (const std::string& cap)
{
return ::tgetstr(C_STR(cap.data()), reinterpret_cast<char**>(&string_buf));
}
//----------------------------------------------------------------------
std::string FTermcap::encodeMotionParameter (const std::string& cap, int col, int row)
{
auto str = ::tgoto(C_STR(cap.data()), col, row);
return ( str ) ? str : std::string();
}
//----------------------------------------------------------------------
void FTermcap::init()
{
@ -253,11 +298,27 @@ void FTermcap::termcapKeys()
}
}
//----------------------------------------------------------------------
std::string FTermcap::encodeParams ( const std::string& cap
, const std::vector<int>& param_vec )
{
std::array<int, 9> params{{ 0, 0, 0, 0, 0, 0, 0, 0, 0 }};
std::copy (param_vec.begin(), param_vec.end(), params.begin());
auto str = ::tparm ( C_STR(cap.data()), params[0], params[1]
, params[2], params[3], params[4], params[5]
, params[6], params[7], params[8] );
return ( str ) ? str : std::string();
}
//----------------------------------------------------------------------
int FTermcap::_tputs (const char* str, int affcnt, fn_putc putc)
{
const auto& fsystem = FTerm::getFSystem();
return fsystem->tputs (str, affcnt, putc);
#if defined(__sun) && defined(__SVR4)
return ::tputs ( C_STR(str)
, affcnt, reinterpret_cast<int (*)(char)>(putc) );
#else
return ::tputs (str, affcnt, putc);
#endif
}

View File

@ -2424,7 +2424,7 @@ void FVTerm::printFullWidthPaddingCharacter ( uInt& x, uInt y
if ( le )
appendOutputBuffer (FTermControl{le});
else if ( LE )
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(LE, 1, 0, 0, 0, 0, 0, 0, 0, 0)});
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(LE, 1)});
else
{
skipPaddingCharacter (x, y, prev_char);
@ -2464,7 +2464,7 @@ void FVTerm::printHalfCovertFullWidthCharacter ( uInt& x, uInt y
if ( le )
appendOutputBuffer (FTermControl{le});
else if ( LE )
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(LE, 1, 0, 0, 0, 0, 0, 0, 0, 0)});
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(LE, 1)});
if ( le || LE )
{
@ -2536,7 +2536,7 @@ FVTerm::PrintState FVTerm::eraseCharacters ( uInt& x, uInt xmax, uInt y
&& (ut || normal) )
{
appendAttributes (print_char);
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(ec, whitespace, 0, 0, 0, 0, 0, 0, 0, 0)});
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(ec, whitespace)});
if ( x + whitespace - 1 < xmax || draw_trailing_ws )
setTermXY (int(x + whitespace), int(y));
@ -2601,7 +2601,7 @@ FVTerm::PrintState FVTerm::repeatCharacter (uInt& x, uInt xmax, uInt y) const
newFontChanges (print_char);
charsetChanges (print_char);
appendAttributes (print_char);
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(rp, print_char.ch[0], repetitions, 0, 0, 0, 0, 0, 0, 0)});
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(rp, print_char.ch[0], repetitions)});
term_pos->x_ref() += int(repetitions);
x = x + repetitions - 1;
}
@ -3063,7 +3063,7 @@ void FVTerm::appendLowerRight (FChar& last_char) const
if ( IC )
{
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(IC, 1, 0, 0, 0, 0, 0, 0, 0, 0)});
appendOutputBuffer (FTermControl{FTermcap::encodeParameter(IC, 1)});
appendChar (second_last);
}
else if ( im && ei )

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2020 Markus Gans *
* Copyright 2019-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -67,7 +67,6 @@ class FSystem
virtual FILE* fopen (const char*, const char*) = 0;
virtual int fclose (FILE*) = 0;
virtual int putchar (int) = 0;
virtual int tputs (const char*, int, fn_putc) = 0;
virtual uid_t getuid() = 0;
virtual uid_t geteuid() = 0;
virtual int getpwuid_r ( uid_t, struct passwd*, char*

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2020 Markus Gans *
* Copyright 2019-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -56,25 +56,6 @@
#endif // defined(__linux__)
#if defined(__sun) && defined(__SVR4)
#include <termio.h>
typedef struct termio SGTTY;
typedef struct termios SGTTYS;
#ifdef _LP64
typedef unsigned int chtype;
#else
typedef unsigned long chtype;
#endif // _LP64
#include <term.h> // termcap
#else
#include <term.h> // termcap
#endif // defined(__sun) && defined(__SVR4)
#ifdef F_HAVE_LIBGPM
#undef buttons // from term.h
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
@ -175,16 +156,6 @@ class FSystemImpl : public FSystem
#endif
}
int tputs (const char* str, int affcnt, fn_putc putc) override
{
#if defined(__sun) && defined(__SVR4)
return ::tputs ( C_STR(str)
, affcnt, reinterpret_cast<int (*)(char)>(putc) );
#else
return ::tputs (str, affcnt, putc);
#endif
}
uid_t getuid() override
{
return ::getuid();

View File

@ -35,26 +35,6 @@
#error "Only <final/final.h> can be included directly."
#endif
#if defined(__sun) && defined(__SVR4)
#include <termio.h>
typedef struct termio SGTTY;
typedef struct termios SGTTYS;
#ifdef _LP64
typedef unsigned int chtype;
#else
typedef unsigned long chtype;
#endif // _LP64
#include <term.h> // termcap
#else
#include <term.h> // termcap
#endif // defined(__sun) && defined(__SVR4)
#ifdef F_HAVE_LIBGPM
#undef buttons // from term.h
#endif
#include <array>
#include <string>
#include <utility>
@ -132,6 +112,8 @@ class FTermcap final
static void termcapNumerics();
static void termcapStrings();
static void termcapKeys();
static std::string encodeParams ( const std::string&
, const std::vector<int>& );
static int _tputs (const char*, int, fn_putc);
// Data member
@ -139,43 +121,16 @@ class FTermcap final
static bool initialized;
};
// FTermcap inline functions
//----------------------------------------------------------------------
inline FString FTermcap::getClassName() const
{ return "FTermcap"; }
//----------------------------------------------------------------------
inline bool FTermcap::getFlag (const std::string& cap)
{
return ::tgetflag(C_STR(cap.data()));
}
//----------------------------------------------------------------------
inline int FTermcap::getNumber (const std::string& cap)
{
return ::tgetnum(C_STR(cap.data()));
}
//----------------------------------------------------------------------
inline char* FTermcap::getString (const std::string& cap)
{
return ::tgetstr(C_STR(cap.data()), reinterpret_cast<char**>(&string_buf));
}
//----------------------------------------------------------------------
inline std::string FTermcap::encodeMotionParameter (const std::string& cap, int col, int row)
{
auto str = ::tgoto(C_STR(cap.data()), col, row);
return ( str ) ? str : std::string();
}
//----------------------------------------------------------------------
template <typename... Args>
inline std::string FTermcap::encodeParameter (const std::string& cap, Args&&... args)
std::string FTermcap::encodeParameter (const std::string& cap, Args&&... args)
{
auto str = ::tparm (C_STR(cap.data()), std::forward<Args>(args)...);
return ( str ) ? str : std::string();
return encodeParams(cap, {static_cast<int>(args)...});
}
//----------------------------------------------------------------------

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2020 Markus Gans *
* Copyright 2019-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -20,6 +20,8 @@
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <term.h>
#undef buttons // from term.h
#include <unistd.h>
#include <limits>
@ -62,7 +64,6 @@ class FSystemTest : public finalcut::FSystem
FILE* fopen (const char*, const char*) override;
int fclose (FILE*) override;
int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override;
uid_t geteuid() override;
int getpwuid_r (uid_t, struct passwd*, char*
@ -524,12 +525,6 @@ int FSystemTest::putchar (int c)
return 1;
}
//----------------------------------------------------------------------
int FSystemTest::tputs (const char* str, int affcnt, int (*putc)(int))
{
return ::tputs (str, affcnt, putc);
}
//----------------------------------------------------------------------
uid_t FSystemTest::getuid()
{

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2020 Markus Gans *
* Copyright 2019-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -20,6 +20,9 @@
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <term.h>
#undef buttons // from term.h
#include <limits>
#include <string>
@ -111,7 +114,6 @@ class FSystemTest : public finalcut::FSystem
FILE* fopen (const char*, const char*) override;
int fclose (FILE*) override;
int putchar (int) override;
int tputs (const char*, int, fn_putc) override;
uid_t getuid() override;
uid_t geteuid() override;
int getpwuid_r ( uid_t, struct passwd*, char*
@ -1377,12 +1379,6 @@ int FSystemTest::putchar (int c)
return 1;
}
//----------------------------------------------------------------------
int FSystemTest::tputs (const char* str, int affcnt, fn_putc putc)
{
return ::tputs (str, affcnt, putc);
}
//----------------------------------------------------------------------
uid_t FSystemTest::getuid()
{

View File

@ -3,7 +3,7 @@
* *
* This file is part of the FINAL CUT widget toolkit *
* *
* Copyright 2019-2020 Markus Gans *
* Copyright 2019-2021 Markus Gans *
* *
* FINAL CUT is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
@ -20,6 +20,9 @@
* <http://www.gnu.org/licenses/>. *
***********************************************************************/
#include <term.h>
#undef buttons // from term.h
#include <limits>
#include <string>
@ -79,7 +82,6 @@ class FSystemTest : public finalcut::FSystem
FILE* fopen (const char*, const char*) override;
int fclose (FILE*) override;
int putchar (int) override;
int tputs (const char*, int, int (*)(int)) override;
uid_t getuid() override;
uid_t geteuid() override;
int getpwuid_r (uid_t, struct passwd*, char*
@ -262,12 +264,6 @@ int FSystemTest::putchar (int c)
#endif
}
//----------------------------------------------------------------------
int FSystemTest::tputs (const char* str, int affcnt, int (*putc)(int))
{
return ::tputs (str, affcnt, putc);
}
//----------------------------------------------------------------------
uid_t FSystemTest::getuid()
{