Duplicate key sequences detection added
This commit is contained in:
parent
5398ccbd5e
commit
775d6611b2
@ -262,7 +262,7 @@ bool ZRCola::DBSource::SelectKeySequences(ATL::CComPtr<ADORecordset> &rs) const
|
|||||||
wxCHECK(SUCCEEDED(::CoCreateInstance(CLSID_CADORecordset, NULL, CLSCTX_ALL, IID_IADORecordset, (LPVOID*)&rs)), false);
|
wxCHECK(SUCCEEDED(::CoCreateInstance(CLSID_CADORecordset, NULL, CLSCTX_ALL, IID_IADORecordset, (LPVOID*)&rs)), false);
|
||||||
|
|
||||||
// Open it.
|
// Open it.
|
||||||
if (FAILED(rs->Open(ATL::CComVariant(L"SELECT [Znak], [tipka] FROM [wrd_KeyCodes]"), ATL::CComVariant(m_db), adOpenStatic, adLockReadOnly, adCmdText))) {
|
if (FAILED(rs->Open(ATL::CComVariant(L"SELECT DISTINCT [Znak], [tipka] FROM [wrd_KeyCodes]"), ATL::CComVariant(m_db), adOpenStatic, adLockReadOnly, adCmdText))) {
|
||||||
_ftprintf(stderr, wxT("%s: error ZCC0050: Error loading key sequences from database. Please make sure the file is ZRCola.zrc compatible.\n"), m_filename.c_str());
|
_ftprintf(stderr, wxT("%s: error ZCC0050: Error loading key sequences from database. Please make sure the file is ZRCola.zrc compatible.\n"), m_filename.c_str());
|
||||||
LogErrors();
|
LogErrors();
|
||||||
return false;
|
return false;
|
||||||
|
@ -464,6 +464,19 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
qsort_s(db.idxChr.data(), count, sizeof(unsigned __int32), CompareKeySequenceChar, db.data.data());
|
qsort_s(db.idxChr.data(), count, sizeof(unsigned __int32), CompareKeySequenceChar, db.data.data());
|
||||||
qsort_s(db.idxKey.data(), count, sizeof(unsigned __int32), CompareKeySequenceKey , db.data.data());
|
qsort_s(db.idxKey.data(), count, sizeof(unsigned __int32), CompareKeySequenceKey , db.data.data());
|
||||||
|
|
||||||
|
// Check key sequences.
|
||||||
|
for (std::vector<unsigned __int32>::size_type i = 1, n = db.idxKey.size(); i < n; i++) {
|
||||||
|
const ZRCola::keyseq_db::keyseq
|
||||||
|
&ks1 = (const ZRCola::keyseq_db::keyseq&)db.data[db.idxKey[i - 1]],
|
||||||
|
&ks2 = (const ZRCola::keyseq_db::keyseq&)db.data[db.idxKey[i ]];
|
||||||
|
|
||||||
|
if (CompareSequence(ks1.seq, ks1.seq_len, ks2.seq, ks2.seq_len) == 0) {
|
||||||
|
std::wstring seq_str;
|
||||||
|
ZRCola::keyseq_db::GetSequenceAsText(ks1.seq, ks1.seq_len, seq_str);
|
||||||
|
_ftprintf(stderr, wxT("%s: warning ZCC0007: Duplicate key sequence (%ls => %04X or %04X). The keyboard behaviour will be unpredictable.\n"), (LPCTSTR)filenameIn.c_str(), seq_str.c_str(), ks1.chr, ks2.chr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Write translations to file.
|
// Write translations to file.
|
||||||
dst << ZRCola::keyseq_rec(db);
|
dst << ZRCola::keyseq_rec(db);
|
||||||
} else {
|
} else {
|
||||||
@ -479,7 +492,7 @@ int _tmain(int argc, _TCHAR *argv[])
|
|||||||
stdex::idrec::close<ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dst, dst_start);
|
stdex::idrec::close<ZRCola::recordid_t, ZRCola::recordsize_t, ZRCOLA_RECORD_ALIGN>(dst, dst_start);
|
||||||
|
|
||||||
if (dst.fail()) {
|
if (dst.fail()) {
|
||||||
_ftprintf(stderr, wxT("%s: error ZCC0007: Writing to output file failed.\n"), (LPCTSTR)filenameOut.c_str());
|
_ftprintf(stderr, wxT("%s: error ZCC1000: Writing to output file failed.\n"), (LPCTSTR)filenameOut.c_str());
|
||||||
has_errors = true;
|
has_errors = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,31 @@ namespace ZRCola {
|
|||||||
std::vector<unsigned __int32> idxChr; ///< Character index
|
std::vector<unsigned __int32> idxChr; ///< Character index
|
||||||
std::vector<unsigned __int32> idxKey; ///< Key index
|
std::vector<unsigned __int32> idxKey; ///< Key index
|
||||||
std::vector<unsigned __int16> data; ///< Key sequences data
|
std::vector<unsigned __int16> data; ///< Key sequences data
|
||||||
|
|
||||||
|
public:
|
||||||
|
///
|
||||||
|
/// Get text representation of a given key sequence
|
||||||
|
///
|
||||||
|
/// \param[in] seq Key sequence
|
||||||
|
/// \param[in] seq_len Number of elements in \p seq
|
||||||
|
/// \param[out] str Text representation of a \p seq key sequence
|
||||||
|
///
|
||||||
|
static void GetSequenceAsText(_In_count_(seq_len) const keyseq::key_t *seq, _In_ size_t seq_len, _Out_ std::wstring& str);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Get text representation of a given key sequence
|
||||||
|
///
|
||||||
|
/// \param[in] seq Key sequence
|
||||||
|
/// \param[in] seq_len Number of elements in \p seq
|
||||||
|
///
|
||||||
|
/// \returns Text representation of a \p seq key sequence
|
||||||
|
///
|
||||||
|
static inline std::wstring GetSequenceAsText(_In_count_(seq_len) const keyseq::key_t *seq, _In_ size_t seq_len)
|
||||||
|
{
|
||||||
|
std::wstring str;
|
||||||
|
GetSequenceAsText(seq, seq_len, str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,3 +18,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
|
|
||||||
|
|
||||||
|
void ZRCola::keyseq_db::GetSequenceAsText(_In_count_(seq_len) const ZRCola::keyseq_db::keyseq::key_t *seq, _In_ size_t seq_len, _Out_ std::wstring& str)
|
||||||
|
{
|
||||||
|
assert(seq || !seq_len);
|
||||||
|
|
||||||
|
str.clear();
|
||||||
|
for (size_t i = 0; i < seq_len; i++) {
|
||||||
|
if (i) str += L", ";
|
||||||
|
if (seq[i].modifiers & keyseq::CTRL ) str += L"Ctrl+";
|
||||||
|
if (seq[i].modifiers & keyseq::ALT ) str += L"Alt+";
|
||||||
|
if (seq[i].modifiers & keyseq::SHIFT) str += L"Shift+";
|
||||||
|
str += seq[i].key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,3 +21,5 @@
|
|||||||
|
|
||||||
#include "../../../include/zrcola.h"
|
#include "../../../include/zrcola.h"
|
||||||
#include "../include/zrcolaui/keyboard.h"
|
#include "../include/zrcolaui/keyboard.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user