+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+namespace MUtils
+{
+ namespace Internal
+ {
+ namespace NaturalSort
+ {
+ /* CUSTOMIZATION SECTION
+ *
+ * You can change this typedef, but must then also change the inline
+ * functions in strnatcmp.c */
+ typedef wchar_t nat_char;
+
+ int strnatcmp(nat_char const *a, nat_char const *b);
+ int strnatcasecmp(nat_char const *a, nat_char const *b);
+ }
+ }
+}
diff --git a/src/3rd_party/strnatcmp/readme.htm b/src/3rd_party/strnatcmp/readme.htm
new file mode 100644
index 0000000..c443f36
--- /dev/null
+++ b/src/3rd_party/strnatcmp/readme.htm
@@ -0,0 +1,196 @@
+
+
+
+ Natural Order String Comparison
+
+
+
+Natural Order String Comparison
+by Martin Pool
+
+
Computer string sorting algorithms generally don't order strings
+containing numbers in the same way that a human would do. Consider:
+
+
rfc1.txt
+rfc2086.txt
+rfc822.txt
+
+It would be more friendly if the program listed the files as
+
+
rfc1.txt
+rfc822.txt
+rfc2086.txt
+
+
+Filenames sort properly if people insert leading zeros, but they
+don't always do that.
+
+
I've written a subroutine that compares strings according to this
+natural ordering. You can use this routine in your own software, or
+download a patch to add it to your favourite Unix program.
+
+
+
Sorting
+
+Strings are sorted as usual, except that decimal integer substrings
+are compared on their numeric value. For example,
+
+
+ a < a0 < a1 < a1a < a1b < a2 < a10 < a20
+
+
+Strings can contain several number parts:
+
+
+ x2-g8 < x2-y7 < x2-y08 < x8-y8
+
+
+in which case numeric fields are separated by nonnumeric characters.
+Leading spaces are ignored. This works very well for IP addresses
+from log files, for example.
+
+
+Leading zeros are not ignored, which tends to give more
+reasonable results on decimal fractions.
+
+
+
+ 1.001 < 1.002 < 1.010 < 1.02 < 1.1 < 1.3
+
+
+Some applications may wish to change this by modifying the test
+ that calls isspace
.
+
+
+
+ Performance is linear: each character of the string is scanned
+ at most once, and only as many characters as necessary to decide
+ are considered.
+
+
+Longer example of the results
+
+
+
Licensing
+
+This software is copyright by Martin Pool, and made available under
+the same licence as zlib:
+
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+
Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+
1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
3. This notice may not be removed or altered from any source distribution.
+
+
+This licence applies only to the C implementation. You are free to
+reimplement the idea fom scratch in any language.
+
+
Related Work
+
+
+
+ POSIX sort(1) has the -n option to sort numbers, but this doesn't
+ work if there is a non-numeric prefix.
+
+
+
+ GNU ls(1) has the --sort=version option, which works
+ the same way.
+
+
+
+ The PHP scripting language now has a
+ strnatcmp
+ function based on this code.
+ The PHP wrapper was done by Andrei Zimievsky.
+
+
+
+ Stuart
+ Cheshire has a Macintosh system extension
to do natural ordering.
+ I indepdendently reinvented the algorithm, but Stuart had it
+ first. I borrowed the term natural sort
from him.
+
+
+
+
+ Sort::Versions
+ in Perl. "The code has some special magic to deal with common
+conventions in program version numbers, like the difference between
+'decimal' versions (eg perl 5.005) and the Unix kind (eg perl 5.6.1)."
+
+
Sort::Naturally
+ is also in Perl, by Sean M. Burke. It uses locale-sensitive character classes to sort words and numeric substrings
+ in a way similar to natsort.
+
+
+ Ed Avis wrote something similar in Haskell.
+
+
+
+ Pierre-Luc Paour wrote a NaturalOrderComparator
+ in Java
+
+
Kristof Coomans wrote a natural sort comparison in Javascript
+
+ Alan Davies wrote
+ natcmp.rb,
+ an implementation in Ruby.
+
+
Numacomp
+ - similar thing in Python.
+
+
as3natcompare
+ implementation in Flash ActionScript 3.
+
+
Get It!
+
+
+
+
+ To Do
+
+
+ Comparison of characters is purely numeric, without taking
+ character set or locale into account. So it is only correct for
+ ASCII. This should probably be a separate function because doing
+ the comparisons will probably introduce a dependency on the OS
+ mechanism for finding the locale and comparing characters.
+
+
+
+ It might be good to support multibyte character sets too.
+
+
+ If you fix either of these, please mail me. They should not be
+ very hard.
+
+
+
+
\ No newline at end of file
diff --git a/src/3rd_party/strnatcmp/src/strnatcmp.cpp b/src/3rd_party/strnatcmp/src/strnatcmp.cpp
new file mode 100644
index 0000000..60ca371
--- /dev/null
+++ b/src/3rd_party/strnatcmp/src/strnatcmp.cpp
@@ -0,0 +1,214 @@
+/* -*- mode: c; c-file-style: "k&r" -*-
+
+strnatcmp.c -- Perform 'natural order' comparisons of strings in C.
+Copyright (C) 2000, 2004 by Martin Pool
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not
+claim that you wrote the original software. If you use this software
+in a product, an acknowledgment in the product documentation would be
+appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be
+misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+
+/* partial change history:
+*
+* 2004-10-10 mbp: Lift out character type dependencies into macros.
+*
+* Eric Sosman pointed out that ctype functions take a parameter whose
+* value must be that of an unsigned int, even on platforms that have
+* negative chars in their default char type.
+*/
+
+/*
+* 2013-08-23: Skip leading zero's for any run of digits, except
+* when a decimal point was seen immediatley before.
+* Patch by LoRd_MuldeR
+*/
+
+#include
+#include
+#include
+#include
+
+#include "../include/strnatcmp.h"
+
+/* These are defined as macros to make it easier to adapt this code to
+* different characters types or comparison functions. */
+static inline int nat_isdigit(MUtils::Internal::NaturalSort::nat_char a)
+{
+ return iswdigit(a);
+}
+
+static inline int nat_isspace(MUtils::Internal::NaturalSort::nat_char a)
+{
+ return iswspace(a);
+}
+
+static inline MUtils::Internal::NaturalSort::nat_char nat_isdecpoint(MUtils::Internal::NaturalSort::nat_char a)
+{
+ return (a == L'.') || (a == L',');
+}
+
+static inline MUtils::Internal::NaturalSort::nat_char nat_toupper(MUtils::Internal::NaturalSort::nat_char a)
+{
+ return towupper(a);
+}
+
+static int compare_right(MUtils::Internal::NaturalSort::nat_char const *a, MUtils::Internal::NaturalSort::nat_char const *b)
+{
+ int bias = 0;
+
+ /* The longest run of digits wins. That aside, the greatest
+ value wins, but we can't know that it will until we've scanned
+ both numbers to know that they have the same magnitude, so we
+ remember it in BIAS. */
+ for (;; a++, b++)
+ {
+ if (!nat_isdigit(*a) && !nat_isdigit(*b))
+ return bias;
+ else if (!nat_isdigit(*a))
+ return -1;
+ else if (!nat_isdigit(*b))
+ return +1;
+ else if (*a < *b)
+ {
+ if (!bias)
+ bias = -1;
+ }
+ else if (*a > *b)
+ {
+ if (!bias)
+ bias = +1;
+ }
+ else if (!*a && !*b)
+ return bias;
+ }
+
+ return 0;
+}
+
+static int compare_left(MUtils::Internal::NaturalSort::nat_char const *a, MUtils::Internal::NaturalSort::nat_char const *b)
+{
+ /* Compare two left-aligned numbers: the first to have a
+ different value wins. */
+ for (;; a++, b++)
+ {
+ if (!nat_isdigit(*a) && !nat_isdigit(*b))
+ return 0;
+ else if (!nat_isdigit(*a))
+ return -1;
+ else if (!nat_isdigit(*b))
+ return +1;
+ else if (*a < *b)
+ return -1;
+ else if (*a > *b)
+ return +1;
+ }
+
+ return 0;
+}
+
+static int strnatcmp0(MUtils::Internal::NaturalSort::nat_char const *a, MUtils::Internal::NaturalSort::nat_char const *b, const bool fold_case)
+{
+ int ai, bi;
+ MUtils::Internal::NaturalSort::nat_char ca, cb;
+ int result;
+ bool fractional;
+ int sa, sb;
+
+ assert(a && b);
+ ai = bi = 0;
+ fractional = false;
+
+ while (1)
+ {
+ ca = a[ai]; cb = b[bi];
+
+ /* skip over leading spaces or zeros */
+ while (nat_isspace(ca))
+ ca = a[++ai];
+
+ while (nat_isspace(cb))
+ cb = b[++bi];
+
+ /* process run of digits */
+ if (nat_isdigit(ca) && nat_isdigit(cb))
+ {
+ sa = sb = 0;
+
+ if(!fractional)
+ {
+ while (ca == L'0')
+ {
+ ca = a[++ai]; sa++;
+ }
+ while (cb == L'0')
+ {
+ cb = b[++bi]; sb++;
+ }
+ }
+
+ if (fractional)
+ {
+ if ((result = compare_left(a+ai, b+bi)) != 0)
+ return result;
+ }
+ else
+ {
+ if ((result = compare_right(a+ai, b+bi)) != 0)
+ return result;
+ }
+
+ /* on tie, the string with the longer leading zero's sequence wins */
+ if(sa < sb)
+ return -1;
+ else if(sa > sb)
+ return +1;
+ }
+
+ if (!ca && !cb)
+ {
+ /* The strings compare the same. Perhaps the caller
+ will want to call strcmp to break the tie. */
+ return (fold_case) ? _wcsicmp(a, b) : wcscmp(a, b);
+ }
+
+ if (fold_case)
+ {
+ ca = nat_toupper(ca);
+ cb = nat_toupper(cb);
+ }
+
+ if (ca < cb)
+ return -1;
+ else if (ca > cb)
+ return +1;
+
+ /* skipp leading zero's, unless previously seen char was a decimal point */
+ fractional = nat_isdecpoint(ca) && nat_isdecpoint(cb);
+
+ ++ai; ++bi;
+ }
+}
+
+int MUtils::Internal::NaturalSort::strnatcmp(nat_char const *a, nat_char const *b)
+{
+ return strnatcmp0(a, b, false);
+}
+
+/* Compare, recognizing numeric string and ignoring case. */
+int MUtils::Internal::NaturalSort::strnatcasecmp(nat_char const *a, nat_char const *b)
+{
+ return strnatcmp0(a, b, true);
+}
diff --git a/src/Global.cpp b/src/Global.cpp
index e94c440..2676603 100644
--- a/src/Global.cpp
+++ b/src/Global.cpp
@@ -26,7 +26,10 @@
//MUtils
#include
#include
+
+//Internal
#include "DirLocker.h"
+#include "3rd_party/strnatcmp/include/strnatcmp.h"
//Qt
#include
@@ -301,6 +304,25 @@ void MUtils::init_process(QProcess &process, const QString &wokringDir, const bo
process.setProcessEnvironment(env);
}
+///////////////////////////////////////////////////////////////////////////////
+// NATURAL ORDER STRING COMPARISON
+///////////////////////////////////////////////////////////////////////////////
+
+static bool natural_string_sort_helper(const QString &str1, const QString &str2)
+{
+ return (MUtils::Internal::NaturalSort::strnatcmp(MUTILS_WCHR(str1), MUTILS_WCHR(str2)) < 0);
+}
+
+static bool natural_string_sort_helper_fold_case(const QString &str1, const QString &str2)
+{
+ return (MUtils::Internal::NaturalSort::strnatcasecmp(MUTILS_WCHR(str1), MUTILS_WCHR(str2)) < 0);
+}
+
+void MUtils::natural_string_sort(QStringList &list, const bool bIgnoreCase)
+{
+ qSort(list.begin(), list.end(), bIgnoreCase ? natural_string_sort_helper_fold_case : natural_string_sort_helper);
+}
+
///////////////////////////////////////////////////////////////////////////////
// SELF-TEST
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/KeccakHash.cpp b/src/KeccakHash.cpp
index 1023a05..ae88817 100644
--- a/src/KeccakHash.cpp
+++ b/src/KeccakHash.cpp
@@ -21,7 +21,7 @@
/***************************************************************************
** **
-** MUtils::KeccakHash, an API wrapper bringing the optimized implementation of **
+** QKeccakHash, an API wrapper bringing the optimized implementation of **
** Keccak (http://keccak.noekeon.org/) to Qt. **
** Copyright (C) 2013 Emanuel Eichhammer **
** **
@@ -47,17 +47,17 @@
#include
#include
-#include "3rd_party/keccak_impl.h"
+#include "3rd_party/keccak/include/keccak_impl.h"
MUtils::KeccakHash::KeccakHash()
{
m_initialized = false;
- m_state = (MUtils::KeccakImpl::hashState*) _aligned_malloc(sizeof(MUtils::KeccakImpl::hashState), 32);
+ m_state = (MUtils::Internal::KeccakImpl::hashState*) _aligned_malloc(sizeof(MUtils::Internal::KeccakImpl::hashState), 32);
if(!m_state)
{
throw "[MUtils::KeccakHash] Error: _aligned_malloc() has failed, probably out of heap space!";
}
- memset(m_state, 0, sizeof(MUtils::KeccakImpl::hashState));
+ memset(m_state, 0, sizeof(MUtils::Internal::KeccakImpl::hashState));
m_hashResult.clear();
}
@@ -81,7 +81,7 @@ bool MUtils::KeccakHash::init(HashBits hashBits)
}
m_hashResult.clear();
- memset(m_state, 0, sizeof(MUtils::KeccakImpl::hashState));
+ memset(m_state, 0, sizeof(MUtils::Internal::KeccakImpl::hashState));
int hashBitLength = 0;
switch (hashBits)
@@ -93,7 +93,7 @@ bool MUtils::KeccakHash::init(HashBits hashBits)
default: throw "Invalid hash length!!";
}
- if(MUtils::KeccakImpl::Init(m_state, hashBitLength) != MUtils::KeccakImpl::SUCCESS)
+ if(MUtils::Internal::KeccakImpl::Init(m_state, hashBitLength) != MUtils::Internal::KeccakImpl::SUCCESS)
{
qWarning("KeccakImpl::Init() has failed unexpectedly!");
return false;
@@ -118,7 +118,7 @@ bool MUtils::KeccakHash::addData(const char *data, int size)
return false;
}
- if(MUtils::KeccakImpl::Update(m_state, (MUtils::KeccakImpl::BitSequence*)data, size*8) != MUtils::KeccakImpl::SUCCESS)
+ if(MUtils::Internal::KeccakImpl::Update(m_state, (MUtils::Internal::KeccakImpl::BitSequence*)data, size*8) != MUtils::Internal::KeccakImpl::SUCCESS)
{
qWarning("KeccakImpl::Update() has failed unexpectedly!");
m_hashResult.clear();
@@ -138,7 +138,7 @@ const QByteArray &MUtils::KeccakHash::finalize()
return m_hashResult;
}
- if(MUtils::KeccakImpl::Final(m_state, (MUtils::KeccakImpl::BitSequence*)m_hashResult.data()) != MUtils::KeccakImpl::SUCCESS)
+ if(MUtils::Internal::KeccakImpl::Final(m_state, (MUtils::Internal::KeccakImpl::BitSequence*)m_hashResult.data()) != MUtils::Internal::KeccakImpl::SUCCESS)
{
qWarning("KeccakImpl::Final() has failed unexpectedly!");
m_hashResult.clear();
diff --git a/src/Startup.cpp b/src/Startup.cpp
index de8d6b3..3fe6dd1 100644
--- a/src/Startup.cpp
+++ b/src/Startup.cpp
@@ -94,7 +94,7 @@ static int startup_helper(int &argc, char **argv, MUtils::Startup::main_function
int MUtils::Startup::startup(int &argc, char **argv, main_function_t *const entry_point)
{
int iResult = -1;
-#if(MUTILS_DEBUG)
+#if 1||(MUTILS_DEBUG)
iResult = startup_main(argc, argv, entry_point);
#else //MUTILS_DEBUG
#ifdef _MSC_VER
diff --git a/src/Version.cpp b/src/Version.cpp
index 34a3061..2544bd7 100644
--- a/src/Version.cpp
+++ b/src/Version.cpp
@@ -26,6 +26,7 @@
//Internal
#include
#include
+#include
#include "Config.h"
#ifdef _MSC_VER