Minor changes

This commit is contained in:
Markus Gans 2020-10-08 12:09:48 +02:00
parent e74dccf481
commit 9f1bd87151
7 changed files with 176 additions and 172 deletions

View File

@ -96,12 +96,14 @@ RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l)
{ {
for (std::size_t i{0}; i < 8; i++) for (std::size_t i{0}; i < 8; i++)
{ {
data[h++] = L' '; data[h] = L' ';
h++;
} }
for (std::size_t i{0}; i < 8; i++) for (std::size_t i{0}; i < 8; i++)
{ {
data[h++] = L'+'; data[h] = L'+';
h++;
} }
} }
@ -109,12 +111,14 @@ RotoZoomer::RotoZoomer (finalcut::FWidget* parent, bool b, int l)
{ {
for (std::size_t i{0}; i < 8; i++) for (std::size_t i{0}; i < 8; i++)
{ {
data[h++] = L'x'; data[h] = L'x';
h++;
} }
for (std::size_t i{0}; i < 8; i++) for (std::size_t i{0}; i < 8; i++)
{ {
data[h++] = L' '; data[h] = L' ';
h++;
} }
} }
} }

View File

@ -97,9 +97,9 @@ FApplication::FApplication (const int& _argc, char* _argv[])
if ( ! (_argc && _argv) ) if ( ! (_argc && _argv) )
{ {
typedef char* CString; typedef char* CString;
static CString empty[1]{CString("")}; static std::array<CString, 1> empty{CString("")};
app_argc = 0; app_argc = 0;
app_argv = empty; app_argv = empty.data();
} }
init(); init();

View File

@ -25,6 +25,7 @@
#include <strings.h> // need for strcasecmp #include <strings.h> // need for strcasecmp
#endif #endif
#include <array>
#include <vector> #include <vector>
#include "final/fevent.h" #include "final/fevent.h"
@ -427,7 +428,7 @@ inline bool FFileDialog::patternMatch ( const char* const pattern
std::strncat(search.data(), pattern, search.size() - std::strlen(search.data()) - 1); std::strncat(search.data(), pattern, search.size() - std::strlen(search.data()) - 1);
} }
else else
std::strncpy(search.data(), pattern, search.size()); std::strncpy(search.data(), pattern, search.size() - 1);
search[search.size() - 1] = '\0'; search[search.size() - 1] = '\0';
@ -602,7 +603,7 @@ void FFileDialog::followSymLink (const char* const dir, FDirEntry& entry) const
if ( ! fsystem ) if ( ! fsystem )
fsystem = FTerm::getFSystem(); fsystem = FTerm::getFSystem();
std::strncpy (symLink.data(), dir, symLink.size()); std::strncpy (symLink.data(), dir, symLink.size() - 1);
symLink[symLink.size() - 1] = '\0'; symLink[symLink.size() - 1] = '\0';
std::strncat ( symLink.data() std::strncat ( symLink.data()
, entry.name.c_str() , entry.name.c_str()

View File

@ -545,39 +545,37 @@ FPoint readCursorPos()
constexpr auto& DECXCPR{ESC "[6n"}; constexpr auto& DECXCPR{ESC "[6n"};
// Report Cursor Position (DECXCPR) // Report Cursor Position (DECXCPR)
const ssize_t ret = write(stdout_no, DECXCPR, std::strlen(DECXCPR)); if ( write(stdout_no, DECXCPR, std::strlen(DECXCPR)) < 1 )
return FPoint{x, y};
if ( ret > 0 ) std::fflush(stdout);
FD_ZERO(&ifds);
FD_SET(stdin_no, &ifds);
tv.tv_sec = 0;
tv.tv_usec = 100000; // 100 ms
// Read the answer
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) != 1 )
return FPoint{x, y};
constexpr auto parse = "\033[%4d;%4dR";
std::array<char, 20> temp{};
std::size_t pos{0};
do
{ {
std::fflush(stdout); std::size_t bytes_free = temp.size() - pos - 1;
FD_ZERO(&ifds); const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
FD_SET(stdin_no, &ifds);
tv.tv_sec = 0;
tv.tv_usec = 100000; // 100 ms
// Read the answer if ( bytes <= 0 )
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) == 1 ) break;
{
constexpr auto parse = "\033[%4d;%4dR";
std::array<char, 20> temp{};
std::size_t pos{0};
do pos += std::size_t(bytes);
{
std::size_t bytes_free = temp.size() - pos - 1;
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
if ( bytes <= 0 )
break;
pos += std::size_t(bytes);
}
while ( pos < temp.size() && std::strchr(temp.data(), 'R') == nullptr );
if ( pos > 4 )
std::sscanf(temp.data(), parse, &x, &y);
}
} }
while ( pos < temp.size() && std::strchr(temp.data(), 'R') == nullptr );
if ( pos > 4 )
std::sscanf(temp.data(), parse, &x, &y);
return FPoint{x, y}; return FPoint{x, y};
} }

View File

@ -580,39 +580,38 @@ FString FTermDetection::getXTermColorName (FColor color)
tv.tv_usec = 150000; // 150 ms tv.tv_usec = 150000; // 150 ms
// read the terminal answer // read the terminal answer
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 ) if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 )
return color_str;
constexpr auto parse = "\033]4;%10hu;%509[^\n]s";
std::array<char, 35> temp{};
std::size_t pos{0};
do
{ {
constexpr auto parse = "\033]4;%10hu;%509[^\n]s"; std::size_t bytes_free = temp.size() - pos - 1;
std::array<char, 35> temp{}; const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
std::size_t pos{0};
do if ( bytes <= 0 )
{ break;
std::size_t bytes_free = temp.size() - pos - 1;
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
if ( bytes <= 0 ) pos += std::size_t(bytes);
break; }
while ( pos < temp.size() );
pos += std::size_t(bytes); if ( pos > 4 && std::sscanf(temp.data(), parse, &color, buf.data()) == 2 )
} {
while ( pos < temp.size() ); std::size_t n = std::strlen(buf.data());
if ( pos > 4 // BEL + '\0' = string terminator
&& std::sscanf(temp.data(), parse, &color, buf.data()) == 2 ) if ( n >= 6 && buf[n - 1] == BEL[0] && buf[n] == '\0' )
{ buf[n - 1] = '\0';
std::size_t n = std::strlen(buf.data());
// BEL + '\0' = string terminator // Esc + \ = OSC string terminator (mintty)
if ( n >= 6 && buf[n - 1] == BEL[0] && buf[n] == '\0' ) if ( n >= 6 && buf[n - 2] == ESC[0] && buf[n - 1] == '\\' )
buf[n - 1] = '\0'; buf[n - 2] = '\0';
// Esc + \ = OSC string terminator (mintty) color_str = buf.data();
if ( n >= 6 && buf[n - 2] == ESC[0] && buf[n - 1] == '\\' )
buf[n - 2] = '\0';
color_str = buf.data();
}
} }
return color_str; return color_str;
@ -647,8 +646,8 @@ const char* FTermDetection::parseAnswerbackMsg (const char current_termtype[])
new_termtype = "putty"; new_termtype = "putty";
} }
// Some terminal like cygwin or the windows terminal // Some terminals like cygwin or the Windows terminal
// needs to delete the '♣' char // have to delete the printed character '♣'
std::fprintf (stdout, "\r " BS); std::fprintf (stdout, "\r " BS);
std::fflush (stdout); std::fflush (stdout);
@ -681,26 +680,26 @@ FString FTermDetection::getAnswerbackMsg()
tv.tv_usec = 150000; // 150 ms tv.tv_usec = 150000; // 150 ms
// Read the answerback message // Read the answerback message
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 ) if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 )
return answerback;
std::array<char, 10> temp{};
std::size_t pos{0};
do
{ {
std::array<char, 10> temp{}; std::size_t bytes_free = temp.size() - pos - 1;
std::size_t pos{0}; const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
do if ( bytes <= 0 )
{ break;
std::size_t bytes_free = temp.size() - pos - 1;
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
if ( bytes <= 0 ) pos += std::size_t(bytes);
break;
pos += std::size_t(bytes);
}
while ( pos < temp.size() );
if ( pos > 0 )
answerback = temp.data();
} }
while ( pos < temp.size() );
if ( pos > 0 )
answerback = temp.data();
return answerback; return answerback;
} }
@ -815,9 +814,7 @@ FString FTermDetection::getSecDA()
constexpr auto& SECDA{ESC "[>c"}; constexpr auto& SECDA{ESC "[>c"};
// Get the secondary device attributes // Get the secondary device attributes
const ssize_t ret = write(stdout_no, SECDA, std::strlen(SECDA)); if ( write(stdout_no, SECDA, std::strlen(SECDA)) == -1 )
if ( ret == -1 )
return sec_da_str; return sec_da_str;
std::fflush(stdout); std::fflush(stdout);
@ -827,28 +824,27 @@ FString FTermDetection::getSecDA()
tv.tv_usec = 600000; // 600 ms tv.tv_usec = 600000; // 600 ms
// Read the answer // Read the answer
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) == 1 ) if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 )
return sec_da_str;
constexpr auto parse = "\033[>%10d;%10d;%10dc";
std::array<char, 40> temp{};
std::size_t pos{0};
do
{ {
constexpr auto parse = "\033[>%10d;%10d;%10dc"; std::size_t bytes_free = temp.size() - pos - 1;
std::array<char, 40> temp{}; const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
std::size_t pos{0};
do if ( bytes <= 0 )
{ break;
std::size_t bytes_free = temp.size() - pos - 1;
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
if ( bytes <= 0 ) pos += std::size_t(bytes);
break;
pos += std::size_t(bytes);
}
while ( pos < temp.size() && std::strchr(temp.data(), 'c') == nullptr );
if ( pos > 3
&& std::sscanf(temp.data(), parse, &a, &b, &c) == 3 )
sec_da_str.sprintf("\033[>%d;%d;%dc", a, b, c);
} }
while ( pos < temp.size() && std::strchr(temp.data(), 'c') == nullptr );
if ( pos > 3 && std::sscanf(temp.data(), parse, &a, &b, &c) == 3 )
sec_da_str.sprintf("\033[>%d;%d;%dc", a, b, c);
return sec_da_str; return sec_da_str;
} }

View File

@ -765,56 +765,58 @@ FString FTermXTerminal::captureXTermFont() const
{ {
initCheck(FString{}); initCheck(FString{});
if ( term_detection->isXTerminal() if ( ! term_detection->isXTerminal()
|| term_detection->isScreenTerm() && ! term_detection->isScreenTerm()
|| FTermcap::osc_support ) && ! FTermcap::osc_support )
{ {
fd_set ifds{}; return FString{};
struct timeval tv{}; }
const int stdin_no = FTermios::getStdIn();
// Querying the terminal font fd_set ifds{};
oscPrefix(); struct timeval tv{};
FTerm::putstring (OSC "50;?" BEL); const int stdin_no = FTermios::getStdIn();
oscPostfix();
std::fflush(stdout);
FD_ZERO(&ifds);
FD_SET(stdin_no, &ifds);
tv.tv_sec = 0;
tv.tv_usec = 150000; // 150 ms
// Read the terminal answer // Querying the terminal font
if ( select(stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 ) oscPrefix();
{ FTerm::putstring (OSC "50;?" BEL);
std::array<char, 150> temp{}; oscPostfix();
std::size_t pos{0}; std::fflush(stdout);
FD_ZERO(&ifds);
FD_SET(stdin_no, &ifds);
tv.tv_sec = 0;
tv.tv_usec = 150000; // 150 ms
do // Read the terminal answer
{ if ( select(stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 )
std::size_t bytes_free = temp.size() - pos - 1; return FString{};
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
if ( bytes <= 0 ) std::array<char, 150> temp{};
break; std::size_t pos{0};
pos += std::size_t(bytes); do
} {
while ( pos < temp.size() && std::strchr(temp.data(), '\a') == nullptr ); std::size_t bytes_free = temp.size() - pos - 1;
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
if ( pos > 5 && temp[0] == ESC[0] && temp[1] == ']' if ( bytes <= 0 )
&& temp[2] == '5' && temp[3] == '0' && temp[4] == ';' ) break;
{
// Skip leading Esc ] 5 0 ;
char* str = &temp[5];
const std::size_t n = std::strlen(str);
// BEL + '\0' = string terminator pos += std::size_t(bytes);
if ( n >= 5 && str[n - 1] == BEL[0] && str[n] == '\0' ) }
str[n - 1] = '\0'; while ( pos < temp.size() && std::strchr(temp.data(), '\a') == nullptr );
return FString{str}; if ( pos > 5 && temp[0] == ESC[0] && temp[1] == ']' && temp[2] == '5'
} && temp[3] == '0' && temp[4] == ';' )
} {
// Skip leading Esc ] 5 0 ;
char* str = &temp[5];
const std::size_t n = std::strlen(str);
// BEL + '\0' = string terminator
if ( n >= 5 && str[n - 1] == BEL[0] && str[n] == '\0' )
str[n - 1] = '\0';
return FString{str};
} }
return FString{}; return FString{};
@ -841,38 +843,38 @@ FString FTermXTerminal::captureXTermTitle() const
tv.tv_usec = 150000; // 150 ms tv.tv_usec = 150000; // 150 ms
// read the terminal answer // read the terminal answer
if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) > 0 ) if ( select (stdin_no + 1, &ifds, nullptr, nullptr, &tv) < 1 )
return FString{};
std::array<char, 512> temp{};
std::size_t pos{0};
do
{ {
std::array<char, 512> temp{}; std::size_t bytes_free = temp.size() - pos - 1;
std::size_t pos{0}; const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free);
do if ( bytes <= 0 )
break;
pos += std::size_t(bytes);
}
while ( pos < temp.size() && std::strstr(temp.data(), ESC "\\") == nullptr );
if ( pos > 6 && temp[0] == ESC[0] && temp[1] == ']' && temp[2] == 'l' )
{
// Skip leading Esc + ] + l = OSC l
char* str = &temp[3];
const std::size_t n = std::strlen(str);
// Esc + \ = OSC string terminator
if ( n >= 2 && str[n - 2] == ESC[0] && str[n - 1] == '\\' )
{ {
std::size_t bytes_free = temp.size() - pos - 1; if ( n < 4 )
const ssize_t bytes = read(stdin_no, &temp[pos], bytes_free); return FString{};
if ( bytes <= 0 ) str[n - 2] = '\0';
break; return FString{str};
pos += std::size_t(bytes);
}
while ( pos < temp.size() && std::strstr(temp.data(), ESC "\\") == nullptr );
if ( pos > 6 && temp[0] == ESC[0] && temp[1] == ']' && temp[2] == 'l' )
{
// Skip leading Esc + ] + l = OSC l
char* str = &temp[3];
const std::size_t n = std::strlen(str);
// Esc + \ = OSC string terminator
if ( n >= 2 && str[n - 2] == ESC[0] && str[n - 1] == '\\' )
{
if ( n < 4 )
return FString{};
str[n - 2] = '\0';
return FString{str};
}
} }
} }

View File

@ -153,6 +153,8 @@ template <typename T>
class FData : public FDataAccess class FData : public FDataAccess
{ {
public: public:
typedef typename std::remove_cv<T>::type T_nocv;
// Constructors // Constructors
explicit FData (T& v) // constructor explicit FData (T& v) // constructor
: value_ref{v} : value_ref{v}
@ -244,8 +246,9 @@ class FData : public FDataAccess
// Inquiries // Inquiries
bool isInitializedCopy() const bool isInitializedCopy() const
{ {
return bool( reinterpret_cast<void*>(&value) const auto& v = reinterpret_cast<void*>(const_cast<T_nocv*>(&value));
== reinterpret_cast<void*>(&value_ref.get()) ); const auto& r = reinterpret_cast<void*>(const_cast<T_nocv*>(&value_ref.get()));
return bool( v == r );
} }
bool isInitializedReference() const bool isInitializedReference() const