Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1. Переход к колонке по Alt-F8 во вьювере не работал, если первый пар…
…аметр был указан в процентах (пример из справки).

2. Мелкий рефакторинг. %очередная мантра о том, что однобуквенные переменные плохо влияют на вашу карму%.
3. Warnings.
  • Loading branch information
alabuzhev committed Feb 7, 2016
1 parent 866f531 commit 5db0916
Show file tree
Hide file tree
Showing 18 changed files with 106 additions and 88 deletions.
2 changes: 1 addition & 1 deletion far/FarDlgBuilder.cpp
Expand Up @@ -237,7 +237,7 @@ DialogBuilder::DialogBuilder(LNGID TitleMessageId, const wchar_t *HelpTopic, Dia
}

DialogBuilder::DialogBuilder():
m_HelpTopic(L""), m_Mode(0), m_IdExist(false)
m_HelpTopic(L""), m_Mode(0), m_Id(GUID_NULL), m_IdExist(false)
{
AddBorder(L"");
}
Expand Down
3 changes: 2 additions & 1 deletion far/RegExp.cpp
Expand Up @@ -215,10 +215,11 @@ struct RegExp::UniSet
Setter(UniSet& s,wchar_t chr):set(s),idx(chr)
{
}
void operator=(int val)
Setter& operator=(int val)
{
if (val)set.SetBit(idx);
else set.ClearBit(idx);
return *this;
}
bool operator!()const
{
Expand Down
10 changes: 9 additions & 1 deletion far/changelog
@@ -1,4 +1,12 @@
drkns 06.02.2016 04:01:40 +0200 - build 4542
drkns 07.02.2016 18:30:10 +0200 - build 4543

1. Переход к колонке по Alt-F8 во вьювере не работал, если первый параметр был указан в процентах (пример из справки).

2. Мелкий рефакторинг. %очередная мантра о том, что однобуквенные переменные плохо влияют на вашу карму%.

3. Warnings.

drkns 06.02.2016 04:01:40 +0200 - build 4542

1. 0003169: исчезают панели при запуске внешнего редактора

Expand Down
2 changes: 1 addition & 1 deletion far/common.hpp
Expand Up @@ -196,7 +196,7 @@ class writable_blob: public blob
delete[] static_cast<const char*>(m_Data);
}

blob& operator=(const blob& rhs)
writable_blob& operator=(const blob& rhs)
{
if (m_Data)
{
Expand Down
2 changes: 1 addition & 1 deletion far/dialog.cpp
Expand Up @@ -153,7 +153,7 @@ bool IsKeyHighlighted(const string& str,int Key,int Translate,int AmpPos)

if (AltKey < 0xFFFF)
{
if ((unsigned int)AltKey >= L'0' && (unsigned int)AltKey <= L'9')
if (std::iswdigit(AltKey))
return AltKey==UpperStrKey;

if ((unsigned int)AltKey > L' ' && AltKey <= 0xFFFF)
Expand Down
38 changes: 15 additions & 23 deletions far/editor.cpp
Expand Up @@ -4990,45 +4990,37 @@ bool Editor::IsFileModified() const
// используется в FileEditor
int64_t Editor::GetCurPos(bool file_pos, bool add_bom) const
{
auto CurPtr = Lines.begin();
uint64_t TotalSize = 0;
int mult = 1, bom = 0;
const int Unknown = -1;
int Multiplier = 1;
uint64_t bom = 0;

if (file_pos)
{
if (m_codepage == CP_UNICODE || m_codepage == CP_REVERSEBOM)
{
mult = 2;
Multiplier = sizeof(wchar_t);
if (add_bom)
bom += 2;
bom = 1;
}
else if (m_codepage == CP_UTF8)
{
mult = -1;
Multiplier = Unknown;
if (add_bom)
bom += 3;
bom = 3;
}
else
else if (GetCodePageInfo(m_codepage).first > 1)
{
string cp_name;
UINT cp_maxlen = 0;
std::tie(cp_maxlen, cp_name) = GetCodePageInfo(m_codepage);
if (cp_maxlen > 1)
mult = -1;
Multiplier = Unknown;
}
}

while (CurPtr!=m_it_TopScreen)
const auto TotalSize = std::accumulate(Lines.cbegin(), m_it_TopScreen.cbase(), bom, [&](uint64_t Value, CONST_REFERENCE(Lines) line) -> uint64_t
{
const auto& SaveStr = CurPtr->GetString();
const auto EndSeq = CurPtr->GetEOL();
if (mult > 0)
TotalSize += SaveStr.size() + wcslen(EndSeq);
else
TotalSize -= unicode::to(m_codepage, SaveStr.data(), SaveStr.size(), nullptr, 0) + wcslen(EndSeq);
++CurPtr;
}
const auto& Str = line.GetString();
return Value + (Multiplier != Unknown? Str.size() : unicode::to(m_codepage, Str.data(), Str.size(), nullptr, 0)) + wcslen(line.GetEOL());
});

return TotalSize*mult + bom;
return Multiplier != Unknown? TotalSize * Multiplier : TotalSize;
}


Expand Down
11 changes: 6 additions & 5 deletions far/editor.hpp
Expand Up @@ -158,7 +158,7 @@ class Editor: public SimpleScreenObject

struct InternalEditorBookmark;

template<class T>
template<class T, class ConstT = T>
class numbered_iterator_t: public T
{
public:
Expand Down Expand Up @@ -190,12 +190,13 @@ class Editor: public SimpleScreenObject
numbered_iterator_t& operator--() { --base(); --m_Number; return *this; }

bool operator==(const numbered_iterator_t& rhs) const { return base() == rhs.base(); }
bool operator==(const T& rhs) const { return base() == rhs; }
bool operator==(const T& rhs) const { return rhs == *this; }
template<class Y>
bool operator !=(const Y& rhs) const { return !(*this == rhs); }

T& base() { return static_cast<T&>(*this); }
const T& base() const { return static_cast<const T&>(*this); }
T& base() { return *this; }
const typename std::conditional<std::is_base_of<ConstT, T>::value, ConstT, T>::type& base() const { return *this; }
typename std::conditional<std::is_base_of<ConstT, T>::value, const ConstT&, ConstT>::type cbase() const { return *this; }

private:
// Intentionally not implemented, use prefix forms.
Expand All @@ -205,7 +206,7 @@ class Editor: public SimpleScreenObject
size_t m_Number;
};

typedef numbered_iterator_t<iterator> numbered_iterator;
typedef numbered_iterator_t<iterator, const_iterator> numbered_iterator;
typedef numbered_iterator_t<const_iterator> numbered_const_iterator;

virtual void DisplayObject() override;
Expand Down
12 changes: 7 additions & 5 deletions far/filelist.cpp
Expand Up @@ -6225,6 +6225,8 @@ int FileList::ProcessOneHostFile(const FileListItem* Item)

void FileList::SetPluginMode(PluginHandle* hPlugin,const string& PluginFile,bool SendOnFocus)
{
const auto ParentWindow = Parent();

if (m_PanelMode != panel_mode::PLUGIN_PANEL)
{
Global->CtrlObject->FolderHistory->AddToHistory(m_CurDir);
Expand All @@ -6234,8 +6236,8 @@ void FileList::SetPluginMode(PluginHandle* hPlugin,const string& PluginFile,bool
m_hPlugin=hPlugin;
m_PanelMode = panel_mode::PLUGIN_PANEL;

if (SendOnFocus)
Parent()->SetActivePanel(shared_from_this());
if (SendOnFocus && ParentWindow)
ParentWindow->SetActivePanel(shared_from_this());

OpenPanelInfo Info;
Global->CtrlObject->Plugins->GetOpenPanelInfo(hPlugin,&Info);
Expand All @@ -6249,13 +6251,13 @@ void FileList::SetPluginMode(PluginHandle* hPlugin,const string& PluginFile,bool
m_ReverseSortOrder = Info.StartSortOrder != 0;
}

if (Parent())
if (ParentWindow)
{
// BUGBUG, redraw logic shouldn't be here

Parent()->RedrawKeyBar();
ParentWindow->RedrawKeyBar();

const auto AnotherPanel = Parent()->GetAnotherPanel(this);
const auto AnotherPanel = ParentWindow->GetAnotherPanel(this);

if (AnotherPanel->GetType() != panel_type::FILE_PANEL)
{
Expand Down
4 changes: 4 additions & 0 deletions far/fileview.cpp
Expand Up @@ -57,9 +57,13 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "keybar.hpp"

FileViewer::FileViewer(private_tag, int DisableEdit, const wchar_t *Title):
RedrawTitle(),
F3KeyOnly(),
m_bClosing(),
FullScreen(true),
DisableEdit(DisableEdit),
DisableHistory(),
SaveToSaveAs(),
delete_on_close(),
str_title(NullToEmpty(Title))
{
Expand Down
1 change: 1 addition & 0 deletions far/findfile.cpp
Expand Up @@ -3206,6 +3206,7 @@ background_searcher::background_searcher(
bool UseFilter):

m_Owner(Owner),
findString(),
InFileSearchInited(),
m_Autodetection(),
strFindStr(FindString),
Expand Down
35 changes: 15 additions & 20 deletions far/language.cpp
Expand Up @@ -339,7 +339,7 @@ static void parse_lng_line(const string& str, string& label, string& data, bool&
{
have_data = true;
data = str.substr(1);
if (data.size() > 0 && data.back() == L'"')
if (!data.empty() && data.back() == L'"')
data.pop_back();
return;
}
Expand All @@ -362,7 +362,6 @@ static void parse_lng_line(const string& str, string& label, string& data, bool&
}
}
}
return;
}

void Language::init(const string& Path, int CountNeed)
Expand All @@ -385,7 +384,7 @@ void Language::init(const string& Path, int CountNeed)
reserve(CountNeed);
}

std::map<string, int> id_map;
std::unordered_map<string, size_t> id_map;
string label, Buffer, text;
while (GetStr.GetString(Buffer))
{
Expand All @@ -394,7 +393,7 @@ void Language::init(const string& Path, int CountNeed)
parse_lng_line(Buffer, label, text, have_text);
if (have_text)
{
int idx = static_cast<int>(m_Messages.size());
auto idx = m_Messages.size();
add(ConvertString(text.data(), text.size()));
if (!label.empty())
{
Expand All @@ -412,20 +411,12 @@ void Language::init(const string& Path, int CountNeed)

// try to load Far<LNG>.lng.custom file(s)
//
if (id_map.size() > 0) // if string IDs available
if (!id_map.empty())
{
for (int j = 0; j < 2; ++j)
const auto LoadStrings = [&](const string& FileName)
{
string custom_lng_file_path = m_FileName + L".custom";
if (j) {
auto tmp = Global->Opt->ProfilePath + L"\\" + ExtractFileName(custom_lng_file_path);
if (tmp == custom_lng_file_path)
continue;
else
std::swap(tmp, custom_lng_file_path);
}
os::fs::file lang_file;
if (lang_file.Open(custom_lng_file_path, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING))
if (lang_file.Open(FileName, FILE_READ_DATA, FILE_SHARE_READ, nullptr, OPEN_EXISTING))
{
GetFileFormat(lang_file, nCodePage, nullptr, false);
GetFileString get_str(lang_file, nCodePage);
Expand All @@ -437,18 +428,22 @@ void Language::init(const string& Path, int CountNeed)
parse_lng_line(Buffer, label, text, have_text);
if (have_text && !label.empty())
{
auto found = id_map.find(label);
const auto found = id_map.find(label);
if (found != id_map.end())
{
auto idx = found->second;
m_Messages[idx] = ConvertString(text.data(), text.size());
m_Messages[found->second] = ConvertString(text.data(), text.size());
}
label.clear();
}
}
lang_file.Close();
}
}
};

const auto CustomLngInSameDir = m_FileName + L".custom";
const auto CustomLngInProfileDir = Global->Opt->ProfilePath + L"\\" + ExtractFileName(CustomLngInSameDir);

LoadStrings(CustomLngInSameDir);
LoadStrings(CustomLngInProfileDir);
}
}

Expand Down
1 change: 1 addition & 0 deletions far/makefile_gcc_common
Expand Up @@ -71,6 +71,7 @@ CFLAGS += \
-Wno-missing-field-initializers \

CCFLAGS = $(CFLAGS) -std=c++14 \
-Wnon-virtual-dtor \
-Woverloaded-virtual \
-Wzero-as-null-pointer-constant \

Expand Down
1 change: 1 addition & 0 deletions far/modal.cpp
Expand Up @@ -42,6 +42,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "keyboard.hpp"

SimpleModal::SimpleModal():
m_ReadRec(INPUT_RECORD()),
m_EndLoop(false),
m_ReadKey(-1),
m_WriteKey(-1)
Expand Down
3 changes: 2 additions & 1 deletion far/notification.cpp
Expand Up @@ -48,7 +48,8 @@ static const wchar_t* EventNames[] =
static_assert(ARRAYSIZE(EventNames) == event_id_count, "Incomplete EventNames array");

message_manager::message_manager():
m_Window(std::make_unique<wm_listener>())
m_Window(std::make_unique<wm_listener>()),
m_suppressions()
{
}

Expand Down
1 change: 1 addition & 0 deletions far/nsUniversalDetectorEx.cpp
Expand Up @@ -43,6 +43,7 @@ WARNING_PUSH(1)
WARNING_DISABLE_GCC("-Wcast-qual")
WARNING_DISABLE_GCC("-Wuseless-cast")
WARNING_DISABLE_GCC("-Wzero-as-null-pointer-constant")
WARNING_DISABLE_GCC("-Wnon-virtual-dtor")


#include "thirdparty/ucd/nsCore.h"
Expand Down
26 changes: 12 additions & 14 deletions far/strmix.cpp
Expand Up @@ -128,15 +128,14 @@ wchar_t* QuoteSpace(wchar_t *Str)
{
if (wcspbrk(Str, Global->Opt->strQuotedSymbols.data()))
{
auto l = wcslen(Str);
if (Str[l - 1] == L'\\')
InsertQuote(Str);

// forward slash can't harm the quotation mark, but consistency is preferable
const auto Size = wcslen(Str);
if (IsSlash(Str[Size - 2]))
{
Str[l - 1] = L'\0';
InsertQuote(Str);
wcscat(Str + l, L"\\");
std::swap(Str[Size - 2], Str[Size - 1]);
}
else
InsertQuote(Str);
}
return Str;
}
Expand All @@ -163,14 +162,13 @@ string &QuoteSpace(string &strStr)
{
if (strStr.find_first_of(Global->Opt->strQuotedSymbols) != string::npos)
{
if (strStr.back() == L'\\')
InsertQuote(strStr);

// forward slash can't harm the quotation mark, but consistency is preferable
if (IsSlash(*(strStr.end() - 2)))
{
strStr.pop_back();
InsertQuote(strStr);
strStr.push_back(L'\\');
std::iter_swap(strStr.end() - 2, strStr.end() - 1);
}
else
InsertQuote(strStr);
}
return strStr;
}
Expand Down Expand Up @@ -1470,7 +1468,7 @@ int HexToInt(int h)
if (h >= 'A' && h <= 'F')
return h - 'A' + 10;

if (h >= '0' && h <= '9')
if (std::iswdigit(h))
return h - '0';

return 0;
Expand Down

0 comments on commit 5db0916

Please sign in to comment.