From: hama Date: Wed, 28 Jan 2015 23:49:41 +0000 (+0100) Subject: bug fixing X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=128e829e549c5a9a4c29d1e985f85c550e94a77b;p=crepublib bug fixing --- diff --git a/base/ReByteBuffer.cpp b/base/ReByteBuffer.cpp index c61d1eb..0e25832 100644 --- a/base/ReByteBuffer.cpp +++ b/base/ReByteBuffer.cpp @@ -562,7 +562,7 @@ bool ReByteBuffer::splice(size_t ix, size_t replacedLength, Byte* start = m_buffer + ix; Byte* tail = start + replacedLength; - size_t lengthTail = m_length - ix; + size_t lengthTail = m_length - ix - replacedLength; if (length <= replacedLength){ // The sequence will not be longer: diff --git a/base/ReProgramArgs.cpp b/base/ReProgramArgs.cpp index e00ff47..7a2c2e7 100644 --- a/base/ReProgramArgs.cpp +++ b/base/ReProgramArgs.cpp @@ -55,8 +55,12 @@ ReProgramArgs::ReProgramArgs(const char* usageList[], const char* examples[]) m_lastError() { m_properties.setCapacity(64, 64*8, 64*1024); + ReByteBuffer line; for (const char** argv = usageList; *argv != NULL; argv++){ - m_usage.add(-1, *argv, -1); + line.set(*argv); + if (line.endsWith("\n")) + line.setLength(line.length() - 1); + m_usage.append(line.str()); } if (examples != NULL){ for (const char** argv = examples; *argv != NULL; argv++){ @@ -91,7 +95,7 @@ ReProgramArgs::ReProgramArgs(const char* usageString, const char* examples) { m_usage.split(usageString, '\n'); if (examples != NULL){ - if (strstr(examples, "$0") != NULL) + if (strstr(examples, "$0") == NULL) m_examples.split(examples, '\n'); else{ ReByteBuffer line; diff --git a/base/ReStringList.cpp b/base/ReStringList.cpp index f13a5ea..acd9d7c 100644 --- a/base/ReStringList.cpp +++ b/base/ReStringList.cpp @@ -55,7 +55,7 @@ ReStringList& ReStringList::append(const ReByteBuffer& source, Tag tagOf){ */ ReStringList& ReStringList::append(const ReStringList& source){ for (size_t ii = 0; ii < source.count(); ii++) - add(-1, source.strOf(ii), source.strLengthOf(ii), source.tagOf(ii)); + add(-1, source.strOf(ii), source.sizeOf(ii), source.tagOf(ii)); return *this; } /** @brief Inserts a string at a given index. diff --git a/cunit/cuReProgramArgs.cpp b/cunit/cuReProgramArgs.cpp index 327bbe1..692d4ca 100644 --- a/cunit/cuReProgramArgs.cpp +++ b/cunit/cuReProgramArgs.cpp @@ -36,8 +36,8 @@ private: } void createExpectedShortHelp(const char* filename){ createFile(filename, -"test This tests the usage of ReProgramArg\n" -"This tests the usage of ReProgramArg\n" +"test \n" +"This tests the usage of ReProgramArgs\n" "\n" ":\n" "-B or --boolval2\n" @@ -59,8 +59,8 @@ private: "-u or --string2= Default value: 'undef'\n" " This 2nd string must be non empty\n" "Example(s):\n" -"$0 -b+ -B- file dir\ttest of an exampl+++ Not really an error!\n" -"\ttest of an exampl+++ Not really an error!\n" +"? -b+ -B- file dir\n" +"\ttest of an example\n" "+++ Not really an error!\n" ); } @@ -132,8 +132,8 @@ private: } void createExpectedLongHelp(const char* filename){ createFile(filename, -"test \n" +"This tests the usage of ReProgramArgs\n" "\n" ":\n" "--boolval2\n" diff --git a/cunit/testall.cpp b/cunit/testall.cpp index 2d9cb08..277bd6e 100644 --- a/cunit/testall.cpp +++ b/cunit/testall.cpp @@ -13,6 +13,9 @@ #endif void testBase(){ + extern void testReProgramArgs(void); + testReProgramArgs(); + extern void testReTestUnit(); //testReTestUnit(); extern void testReByteBuffer(); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 7f4c6a1..f85e111 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -173,7 +173,9 @@ void ReDirOptions::addStandardFilterOptions(){ "If the first character is '-' the pattern is a 'not pattern':\n" "A directory will be entered if at least one of the positive patterns\n" "and none of the 'not patterns' matches\n" - "examples: ';*;-*/.git/' ',*/cache/,*/temp/"), + "examples:\n" + "';*/music/;pic*' enters music and xy/Music and PIC and pictures but not xy/pic and img\n" + "';*;-*/.git;.hg' ignores .git and xy/z/.git and .ht, but enters xy/.hg"), 'P', "path-pattern", false, NULL); m_programArgs.addString("nodepattern", i18n("a list of patterns for the basename (name without path) separated by ';'\n" @@ -430,6 +432,7 @@ void ReDirOptions::help(const char* errorMessage, const char* message2) const{ m_programArgs.help(msg.str(), false, stdout); exit(1); } + /** * Checks the correctness of the standard filter options. * @@ -468,6 +471,43 @@ void ReDirOptions::initCompoundUsage(size_t size){ memset(m_compoundUsage, 0, size); m_countCompoundUsage = count; } + +/** + * Optimizes the path patterns. + * + * For all patterns of the list: + *
  • remove a trailing "\" and "\*"
  • + *
  • change "*\xy" to "*\xy" and "xy" (finds xy in the root directory)
  • + *
  • replaces "/" with the os specific path separator
  • + *
+ * + * @param buffer the pattern list as string, e.g. ";*;-cache" + */ +void ReDirOptions::optimizePathPattern(ReByteBuffer& buffer){ + ReStringList list; + ReStringList rootList; + list.split(buffer.str() + 1, buffer.str()[0]); + buffer.replaceAll(OS_SEPARATOR, 1, "/", 1); + ReByteBuffer item; + for (int ix = 0; ix < list.count(); ix++){ + item.set(list.strOf(ix), -1); + if (item.endsWith("/*")) + item.setLength(item.length() - 2); + if (item.endsWith("/")) + item.setLength(item.length() - 1); + bool notAnchored = item.startsWith("*/") || item.startsWith("-*/"); + item.replaceAll("/", 1, OS_SEPARATOR, 1); + list.replace(ix, item.str()); + if (notAnchored){ + item.remove(item.str()[0] == '-' ? 1 : 0, 2); + rootList.append(item.str(), 0); + } + } + if (rootList.count() > 0) + list.append(rootList); + item.set(buffer.str(), 1); + list.join(item.str(), buffer); +} /** * Sets the standard filter options given by the program arguments. * @@ -494,6 +534,7 @@ void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter_t& filter){ } if (m_programArgs.getString("pathpattern", buffer)[0] != '\0'){ checkPatternList(buffer.str()); + optimizePathPattern(buffer); m_pathPatterns.set(buffer.str()); filter.m_pathPatterns = &m_pathPatterns; } diff --git a/os/ReDirTools.hpp b/os/ReDirTools.hpp index a9ea3e9..1532aa8 100644 --- a/os/ReDirTools.hpp +++ b/os/ReDirTools.hpp @@ -41,6 +41,8 @@ public: ReProgramArgs& programArgsChangeable() { return m_programArgs; } void setFilterFromProgramArgs(ReDirEntryFilter_t& filter); +protected: + void optimizePathPattern(ReByteBuffer& buffer); protected: ReProgramArgs m_programArgs; RePatternList m_nodePatterns; diff --git a/os/ReTraverser.hpp b/os/ReTraverser.hpp index 90f562f..9c4244b 100644 --- a/os/ReTraverser.hpp +++ b/os/ReTraverser.hpp @@ -155,8 +155,10 @@ protected: * @return true: the subdir will be processed
* false: do not enter this subdir */ - inline bool isAllowedDir(const ReByteBuffer& path, const char* node){ - bool rc = m_dirPatterns->match(ReByteBuffer(path).append(node).str()); + inline bool isAllowedDir(ReByteBuffer& path, const char* node){ + int ix = path.length(); + bool rc = m_dirPatterns->match(path.append(node)); + path.setLength(ix); return rc; } protected: