diff --git a/ChangeLog b/ChangeLog index 0ac7f5b3..05a93c5e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2021-02-28 Markus Gans + * 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 * Fixed the incorrect display on terminals without UTF-8 character encoding diff --git a/src/foptiattr.cpp b/src/foptiattr.cpp index 8356f916..071418bd 100644 --- a/src/foptiattr.cpp +++ b/src/foptiattr.cpp @@ -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()); } } diff --git a/src/foptimove.cpp b/src/foptimove.cpp index aea7e4c0..59ce75a3 100644 --- a/src/foptimove.cpp +++ b/src/foptimove.cpp @@ -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; diff --git a/src/fterm.cpp b/src/fterm.cpp index 5e59c226..2469a428 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -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() ) { diff --git a/src/ftermcap.cpp b/src/ftermcap.cpp index a7d4d46a..da4c6227 100644 --- a/src/ftermcap.cpp +++ b/src/ftermcap.cpp @@ -20,6 +20,26 @@ * . * ***********************************************************************/ +#if defined(__sun) && defined(__SVR4) + #include + typedef struct termio SGTTY; + typedef struct termios SGTTYS; + + #ifdef _LP64 + typedef unsigned int chtype; + #else + typedef unsigned long chtype; + #endif // _LP64 + + #include // termcap +#else + #include // termcap +#endif // defined(__sun) && defined(__SVR4) + +#ifdef F_HAVE_LIBGPM + #undef buttons // from term.h +#endif + #include #include #include @@ -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(&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& param_vec ) +{ + std::array 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(putc) ); +#else + return ::tputs (str, affcnt, putc); +#endif } diff --git a/src/fvterm.cpp b/src/fvterm.cpp index fbcb5e01..b224c2be 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -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 ) diff --git a/src/include/final/fsystem.h b/src/include/final/fsystem.h index 8ac8723a..f3183db6 100644 --- a/src/include/final/fsystem.h +++ b/src/include/final/fsystem.h @@ -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* diff --git a/src/include/final/fsystemimpl.h b/src/include/final/fsystemimpl.h index aa9bad91..9e33aec5 100644 --- a/src/include/final/fsystemimpl.h +++ b/src/include/final/fsystemimpl.h @@ -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 - typedef struct termio SGTTY; - typedef struct termios SGTTYS; - - #ifdef _LP64 - typedef unsigned int chtype; - #else - typedef unsigned long chtype; - #endif // _LP64 - - #include // termcap -#else - #include // termcap -#endif // defined(__sun) && defined(__SVR4) - -#ifdef F_HAVE_LIBGPM - #undef buttons // from term.h -#endif #include #include @@ -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(putc) ); -#else - return ::tputs (str, affcnt, putc); -#endif - } - uid_t getuid() override { return ::getuid(); diff --git a/src/include/final/ftermcap.h b/src/include/final/ftermcap.h index 42baa9dc..652e725a 100644 --- a/src/include/final/ftermcap.h +++ b/src/include/final/ftermcap.h @@ -35,26 +35,6 @@ #error "Only can be included directly." #endif -#if defined(__sun) && defined(__SVR4) - #include - typedef struct termio SGTTY; - typedef struct termios SGTTYS; - - #ifdef _LP64 - typedef unsigned int chtype; - #else - typedef unsigned long chtype; - #endif // _LP64 - - #include // termcap -#else - #include // termcap -#endif // defined(__sun) && defined(__SVR4) - -#ifdef F_HAVE_LIBGPM - #undef buttons // from term.h -#endif - #include #include #include @@ -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& ); 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(&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 -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)...); - return ( str ) ? str : std::string(); + return encodeParams(cap, {static_cast(args)...}); } //---------------------------------------------------------------------- diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index 7f1b80a3..aff7cd2c 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -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 @@ * . * ***********************************************************************/ +#include +#undef buttons // from term.h #include #include @@ -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() { diff --git a/test/ftermlinux-test.cpp b/test/ftermlinux-test.cpp index fdecbd3a..4c34d4c9 100644 --- a/test/ftermlinux-test.cpp +++ b/test/ftermlinux-test.cpp @@ -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 @@ * . * ***********************************************************************/ +#include +#undef buttons // from term.h + #include #include @@ -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() { diff --git a/test/ftermopenbsd-test.cpp b/test/ftermopenbsd-test.cpp index 671a2c4a..cabe96b1 100644 --- a/test/ftermopenbsd-test.cpp +++ b/test/ftermopenbsd-test.cpp @@ -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 @@ * . * ***********************************************************************/ +#include +#undef buttons // from term.h + #include #include @@ -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() {