/*
* ReByteBuffer.cpp
*
- * Created on: 06.05.2010
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * @file ReByteBuffer.hpp
+ * ReByteBuffer.hpp
*
- * Created on: 06.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REBYTEBUFFER_H_
/*
- * ReString.cpp
+ * ReCString.cpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReString.h
+ * ReCString.hpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RESTRING_H_
/*
- * @file ReConfigFile.cpp
+ * ReConfigFile.cpp
*
- * @brief Configuration file handling for *.ini files.
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
* ReConfigFile.h
*
- * Created on: 18.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RECONFIGFILE_H_
/*
- * ReFileUtils.cpp
+ * ReDirectory.cpp
*
- * Created on: 16.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
m_dir = opendir(path);
m_valid = m_dir != NULL;
if (m_valid){
- if (m_path.at(m_path.length() - 1) != ReStringUtils::pathSeparator())
- m_path.append(ReStringUtils::pathSeparatorStr(), 1);
+ if (m_path.at(m_path.length() - 1) != OS_SEPARATOR_CHAR)
+ m_path.append(OS_SEPARATOR, 1);
}
#elif defined __WIN32__
struct stat info;
ReByteBuffer thePath(m_path);
- if (m_path.endsWith(ReStringUtils::pathSeparatorStr()))
+ if (m_path.endsWith(OS_SEPARATOR))
thePath.setLength(thePath.length() - 1);
m_valid = stat(thePath.str(), &info) == 0 && S_ISDIR(info.st_mode);
#endif
}
#elif defined __WIN32__
ReByteBuffer full(m_path);
- full.append(ReStringUtils::pathSeparatorStr(), -1).append(pattern, -1);
+ full.append(OS_SEPARATOR, -1).append(pattern, -1);
m_handle = FindFirstFileA(full.str(), &m_data);
rc = m_handle != INVALID_HANDLE_VALUE;
#endif
/*
- * ReFileUtils.h
+ * ReDirectory.hpp
*
- * Created on: 16.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REFILEFINDER_H_
/*
* ReException.cpp
*
- * Created on: 07.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReException.h
+ * ReException.hpp
*
- * Created on: 07.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REEXCEPTION_H_
/*
- * ReStringList.cpp
+ * ReHashList.cpp
*
- * Created on: 18.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReStringList.h
+ * ReHashList.hpp
*
- * Created on: 18.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REHASHLIST_H_
/*
* ReI18N.cpp
*
- * Created on: 22.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReI18N.h
+ * ReI18N.hpp
*
- * Created on: 22.05.2010
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
* Author: wk
*/
/*
* ReLogger.cpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReLogger.h
+ * ReLogger.hpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RELOGGER_H_
/*
* ReProgramArgs.cpp
*
- * Created on: 25.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReProgramArgs.h
+ * ReProgramArgs.hpp
*
- * Created on: 25.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REPROGRAMARGS_H_
/*
* ReSeqArray.cpp
*
- * Created on: 19.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReSeqArray.h
+ * ReSeqArray.hpp
*
- * Created on: 19.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RESEQLIST_H_
/*
* ReStringList.cpp
*
- * Created on: 20.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReStringList.h
+ * ReStringList.hpp
*
- * Created on: 20.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RESTRINGLIST_H_
/*
* ReStringUtils.cpp
*
- * Created on: 16.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
-#if defined __linux__
-char ReStringUtils::slash = '/';
-const char* ReStringUtils::slashStr = "/";
-#elif defined __WIN32__
-char ReStringUtils::slash = '\\';
-const char* ReStringUtils::slashStr = "\\";
-#endif
const char ReStringUtils::AUTO_SEPARATOR = '\0';
-
-/** @brief Initializes the os specific path separator (char and string).
- *
- * @return The path separator: '/' under unix and '\\' under windows.
- */
-char ReStringUtils::initPathSeparator(){
- slashStr = NULL;
- if (getenv("PATH") != NULL){
- if (strchr(getenv("PATH"), '\\') != NULL)
- slashStr = "\\";
- else if (strchr(getenv("PATH"), '/') == NULL)
- slashStr = "/";
- }
- if (slashStr != NULL && getenv("TMP") != NULL){
- if (strchr(getenv("TMP"), '\\') != NULL)
- slashStr = "\\";
- else if (strchr(getenv("TMP"), '/') == NULL)
- slashStr = "/";
- }
- if (slashStr == NULL && getenv("TEMP") != NULL){
- if (strchr(getenv("TEMP"), '\\') != NULL)
- slashStr = "\\";
- else if (strchr(getenv("TMP"), '/') == NULL)
- slashStr = "/";
- }
- if (slashStr == NULL)
- slashStr = "/";
- return slashStr[0];
-}
-
-
/** @brief Splits a filename into its parts.
*
* Example: file:/etc/samba/smb.conf
*/
void ReStringUtils::splitPath(const char* fullname,
ReByteBuffer* protocol, ReByteBuffer* path, ReByteBuffer* name, ReByteBuffer* ext){
- const char currentSlash = strchr(fullname, '/') != NULL ? '/' : slash;
+ const char currentSlash = strchr(fullname, '/') != NULL ? '/' : OS_SEPARATOR_CHAR;
const char* start = strchr(fullname, ':');
if (protocol != NULL){
protocol->setLength(0);
/*
- * ReStringUtils.h
+ * ReStringUtils.hpp
*
- * Created on: 16.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RESTRINGUTILS_H_
//@ If used in <code>isInList()</code> the first character of the list will be the separator.
static const char AUTO_SEPARATOR;
public:
- static char initPathSeparator();
- static char pathSeparator()
- { return slash; }
- static const char* pathSeparatorStr()
- { return slashStr; }
static void splitPath(const char* fullname,
ReByteBuffer* protocol, ReByteBuffer* path, ReByteBuffer* name, ReByteBuffer* ext);
static ReByteBuffer& joinPath(ReByteBuffer& result,
static int strnicmp(const char* string1, const char* string2, size_t length);
static bool isInList(const char* phrase, const char* list,
bool ignoreCase = true, char separator = AUTO_SEPARATOR);
-private:
- static char slash;
- static const char* slashStr;
};
#endif /* RESTRINGUTILS_H_ */
/*
* ReTestUnit.cpp
*
- * Created on: 04.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/** @brief Constructor.
strcpy(name, "/tmp/");
}
char* ptr = name + strlen(name) - 1;
- if (*ptr != ReStringUtils::pathSeparator())
- strcpy(ptr + 1, ReStringUtils::pathSeparatorStr());
+ if (*ptr != OS_SEPARATOR_CHAR)
+ strcpy(ptr + 1, OS_SEPARATOR);
strcat(ptr, "retestunit");
- strcat(ptr, ReStringUtils::pathSeparatorStr());
+ strcat(ptr, OS_SEPARATOR);
struct stat info;
#ifdef __WIN32__
#define ALLPERMS 0
* @return a time usable for for runtime measurement
*/
int ReTestUnit::milliSecSince(int64_t start){
-#if defined __linux__
+#if defined __linux__ || defined __WIN32__
int64_t diff = clock() - start;
- return diff * 1000 / CLOCKS_PER_SEC;
-#elif defined __WIN32__
- int64_t diff = clock() - start;
- return diff * 1000 / CLOCKS_PER_SEC;
+ return int(diff * 1000 / CLOCKS_PER_SEC);
#else
# error "timer not defined"
#endif
/*
- * ReTestUnit.h
+ * ReTestUnit.hpp
*
- * Created on: 04.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RETESTUNIT_H_
/*
* ReVarArgs.cpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
/**
* <pre><strong>Example:</strong>
/*
- * ReVarArgs.h
+ * ReVarArgs.hpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REVARARGS_H_
/*
* baselocations.hpp
*
- * Created on: 19.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef BASELOCATIONS_HPP_
/*
- * stdincludes.hpp
+ * rebase.hpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REBASE_HPP_
#define REBASE_HPP_
# define _snprintf snprintf
# define _memcmp(t,s,n) memcmp(t,s,n)
# define _mkdir(path) mkdir(path, ALLPERMS)
+# define OS_SEPARATOR_CHAR '/'
+# define OS_SEPARATOR "/"
#elif defined __WIN32__
# include <direct.h>
# include <windows.h>
# define _memcmp(t,s,n) memcmp(t,s,n)
# define lstat stat
+# define OS_SEPARATOR_CHAR '\\'
+# define OS_SEPARATOR "\\"
typedef _int64 int64_t;
typedef unsigned long long uint64_t;
typedef unsigned char uint8_t;
/*
* remath.hpp
*
- * Created on: 26.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REMATH_HPP_
/*
* renet.hpp
*
- * Created on: 26.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RENET_HPP_
/*
* restring.hpp
*
- * Created on: 15.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RESTRING_HPP_
/*
- * stdtest.cpp
+ * basetest.cpp
*
- * Created on: 05.05.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
#if defined RE_TESTUNIT
/*
* cuReByteBuffer.cpp
*
- * Created on: 27.11.2010
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
class TestReByteBuffer : public ReTestUnit {
/*
* cuReCString.cpp
*
- * Created on: 23.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
#include "string/restring.hpp"
+/*
+ * cuReDirectory.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReDirectory : public ReTestUnit {
+/*
+ * cuReException.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReException : public ReTestUnit, public ReVarArgTrigger {
+/*
+ * cuReHashList.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
#include "math/remath.hpp"
+/*
+ * cuReReI18N.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReI18N : public ReTestUnit {
+/*
+ * cuReLogger.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReLogger : public ReTestUnit {
/*
* cuReMatcher.cpp
*
- * Created on: 25.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
+/*
+ * cuReMatcher.hpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
+
#include "base/rebase.hpp"
#include "string/restring.hpp"
+/*
+ * cuReProgramArgs.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReProgramArgs : public ReTestUnit {
+/*
+ * cuReRandomizer.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
#include "math/remath.hpp"
+/*
+ * cuReSeqArray.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReSeqList : public ReTestUnit {
+/*
+ * cuReReStringList.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReStringList : public ReTestUnit {
+/*
+ * cuReStringUtils.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReStringUtils : public ReTestUnit {
+/*
+ * cuReTest.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestTestUnit : public ReTestUnit {
/*
* cuReTraverser.cpp
*
- * Created on: 23.12.2014
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
public:
TestReTraverser() : ReTestUnit("ReTraverser", __FILE__){
m_base = testDir();
- m_base.append("traverser").append(ReTraverser::m_separatorStr, -1);
+ m_base.append("traverser").append(OS_SEPARATOR, -1);
_mkdir(m_base.str());
run();
}
void makeDir(const char* relPath){
ReByteBuffer path(m_base);
path.append("/").append(relPath);
- path.replaceAll("/", 1, ReTraverser::m_separatorStr, -1);
+ path.replaceAll("/", 1, OS_SEPARATOR, -1);
_mkdir(path.str());
struct stat info;
if (stat(path.str(), &info) != 0){
void makeFile(const char* relPath){
ReByteBuffer path(m_base);
path.append("/").append(relPath);
- path.replaceAll("/", 1, ReTraverser::m_separatorStr, -1);
+ path.replaceAll("/", 1, OS_SEPARATOR, -1);
createFile(path.str(), relPath);
struct stat info;
if (stat(path.str(), &info) != 0){
ReByteBuffer path, expected;
checkT(hash.get(ReByteBuffer(node), path));
expected.set(parent, -1);
- if (! expected.endsWith(ReTraverser::m_separatorStr))
- expected.append(ReTraverser::m_separatorStr);
+ if (! expected.endsWith(OS_SEPARATOR))
+ expected.append(OS_SEPARATOR);
if (! path.endsWith(expected.str(), -1))
checkT(false);
}
RePatternList patterns;
// exclude */cache/*
ReByteBuffer buffer(";*;-*");
- buffer.append(ReTraverser::m_separatorStr).append("cache")
- .append(ReTraverser::m_separatorStr);
+ buffer.append(OS_SEPARATOR).append("cache")
+ .append(OS_SEPARATOR);
patterns.set(buffer.str());
traverser.setDirPattern(&patterns);
int level = 0;
buffer.set(list.strOf(0), list.strLengthOf(0));
checkT(buffer.startsWith("1\t"));
expected.set(m_base.str(), m_base.length()).append("dir1", -1)
- .append(ReTraverser::m_separatorStr);
- // .append(ReTraverser::m_separatorStr, -1)
+ .append(OS_SEPARATOR);
+ // .append(OS_SEPARATOR, -1)
checkT(buffer.endsWith(expected.str()));
buffer.setLength(0);
buffer.set(list.strOf(0), list.strLengthOf(0));
checkT(buffer.startsWith(" 0.000074 MB 3 4\t"));
expected.set(m_base.str(), m_base.length()).append("dir1", -1)
- .append(ReTraverser::m_separatorStr);
+ .append(OS_SEPARATOR);
checkT(buffer.endsWith(expected.str()));
buffer.set(list.strOf(1), list.strLengthOf(1));
checkT(buffer.startsWith(" 0.000008 MB 1 0\t"));
expected.set(m_base.str(), m_base.length()).append("dir2", -1)
- .append(ReTraverser::m_separatorStr);
+ .append(OS_SEPARATOR);
checkT(buffer.endsWith(expected.str()));
buffer.set(list.strOf(2), list.strLengthOf(2));
+/*
+ * cuReVarArgs.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReVarArgs : public ReTestUnit, public ReVarArgTrigger {
+/*
+ * cuReConfig.cpp
+ *
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
+ */
#include "base/rebase.hpp"
class TestReConfigFile : public ReTestUnit {
/*
* testall.cpp
*
- * Created on: 24.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
#include "os/reos.hpp"
/*
* ReObfuscator.cpp
*
- * Created on: 13.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
- * ReObfuscator.h
+ * ReObfuscator.hpp
*
- * Created on: 13.11.2010
- * Author: wk
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REOBFUSCATOR_H_
/*
* ReRandomizer.cpp
*
- * Created on: 01.11.2010
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
/*
- * ReRandomizer.h
+ * ReRandomizer.hpp
*
- * Created on: 01.11.2010
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef RANDOMIZER_H_
/*
* remath.hpp
*
- * Created on: 23.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef REMATH_HPP_
/*
- * DirTools.cpp
+ * ReDirTools.cpp
*
- * Created on: 30.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
close();
delete[] m_compoundUsage;
}
-/**
- * Initializes the compound usage message array.
- *
- * @param size the size of the array: size = (field1 + field2 + ...) * sizeof(const char*)
- */
-void ReDirOptions::initCompoundUsage(size_t size){
- delete[] m_compoundUsage;
- int count = size / sizeof m_compoundUsage[0];
- m_compoundUsage = new const char*[count];
- memset(m_compoundUsage, 0, size);
- m_countCompoundUsage = count;
-}
/**
* Adds a usage component to the compound usage message list.
* @param usage a string vector containing a part of the usage message
"units: m(inutes) h(hours), d(days). Default: m(inutes)\n"
"examples: -o25 --older-than=30d -o24h -o2009.3.2/12:00 -o1999.01.01"),
'o', "older-than", false, NULL);
-ReByteBuffer buffer;
-const char* ptr = m_programArgs.getString("older", buffer);
m_programArgs.addString("pathpattern",
i18n("a list of patterns for the path (without basename)\n"
"the separator is the first character of the list\n"
"and none of the 'not patterns' matches\n"
"examples: ';*;-*/.git/' ',*/cache/,*/temp/"),
'P', "path-pattern", false, NULL);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addString("nodepattern",
i18n("a list of patterns for the basename (name without path) separated by ';'\n"
"Each pattern can contain '*' as wildcard\n"
"of the 'not patterns' matches\n"
"examples: '*.cpp;*.hpp;Make*' '*;-*.bak;-*~"),
'p', "basename-pattern", false, NULL);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addBool("quiet",
i18n("no additional information like runtime"),
'q', "quiet", false);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addInt("trace",
i18n("all <number> seconds the current path will be traced\n"
"0: no trace"),
'T', "trace-interval", 0);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addString("type",
i18n("the file type\n"
"<string> is a list of <v> values:\n"
"<v>-sets: S(pecial)=bcspo N(ondir)=Slr\n"
"examples: -td --type=dr -tNi"),
't', "type", false, NULL);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addString("younger",
i18n("the modification date is younger than <string>\n"
"<string> is a date (e.g. 2015.02.17) or number followed by an unit\n"
"units: m(inutes) h(hours), d(days). Default: m(inutes)"),
'y', "younger-than", false, NULL);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addString("maxsize",
i18n("the filesize is greater or equal <string>\n"
"<string> is a number followed by an unit\n"
"units: b(yte) k(Byte) K(iByte) m(Byte), M(iByte), g(Byte) G(iByte)\n"
"examples: -Z50m --max-size=1G"),
'Z', "max-size", false, NULL);
-ptr = m_programArgs.getString("older", buffer);
m_programArgs.addString("minsize",
i18n("the filesize is greater or equal <string>\n"
"<string> is a number followed by an unit\n"
"units: b(yte) k(Byte) K(iByte) m(Byte), M(iByte), g(Byte) G(iByte)\n"
"examples: -z50m --min-size=1G"),
'z', "min-size", false, NULL);
-ptr = m_programArgs.getString("older", buffer);
}
/**
return (ReDirStatus_t::Type_t) rc;
}
-/**
- * Sets the standard filter options given by the program arguments.
- *
- * @param filter OUT: the filter to set
- */
-void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter_t& filter){
- ReByteBuffer buffer;
- if (m_programArgs.getString("younger", buffer)[0] != '\0')
- filter.m_maxAge = checkDate(buffer.str());
- if (m_programArgs.getString("older", buffer)[0] != '\0')
- filter.m_minAge = checkDate(buffer.str());
- if (m_programArgs.getString("maxsize", buffer)[0] != '\0')
- filter.m_maxSize = checkSize(buffer.str());
- if (m_programArgs.getString("minsize", buffer)[0] != '\0')
- filter.m_minSize = checkSize(buffer.str());
- if (m_programArgs.getString("type", buffer)[0] != '\0')
- filter.m_types = checkType(buffer.str());
- filter.m_minDepth = m_programArgs.getInt("mindepth");
- filter.m_maxDepth = m_programArgs.getInt("maxdepth");
- if (m_programArgs.getString("nodepattern", buffer)[0] != '\0'){
- checkPatternList(buffer.str());
- m_nodePatterns.set(buffer.str());
- filter.m_nodePatterns = &m_nodePatterns;
- }
- if (m_programArgs.getString("pathpattern", buffer)[0] != '\0'){
- checkPatternList(buffer.str());
- m_pathPatterns.set(buffer.str());
- filter.m_pathPatterns = &m_pathPatterns;
- }
- filter.m_traceInterval = m_programArgs.getInt("trace");
- if (m_programArgs.getString("output", buffer)[0] != '\0'){
- if ( (m_output = fopen(buffer.str(), "w")) == NULL){
- help("cannot open output file", buffer.str());
- m_output = stdout;
- }
- }
-}
/**
* Prints a help message, the error message and exits.
*
checkPatternList(m_programArgs.getString("pathpattern", buffer));
}
+/**
+ * Frees the resources.
+ */
void ReDirOptions::close(){
if (m_output != stdout){
fclose(m_output);
}
}
+/**
+ * Initializes the compound usage message array.
+ *
+ * @param size the size of the array: size = (field1 + field2 + ...) * sizeof(const char*)
+ */
+void ReDirOptions::initCompoundUsage(size_t size){
+ delete[] m_compoundUsage;
+ int count = size / sizeof m_compoundUsage[0];
+ m_compoundUsage = new const char*[count];
+ memset(m_compoundUsage, 0, size);
+ m_countCompoundUsage = count;
+}
+/**
+ * Sets the standard filter options given by the program arguments.
+ *
+ * @param filter OUT: the filter to set
+ */
+void ReDirOptions::setFilterFromProgramArgs(ReDirEntryFilter_t& filter){
+ ReByteBuffer buffer;
+ if (m_programArgs.getString("younger", buffer)[0] != '\0')
+ filter.m_maxAge = checkDate(buffer.str());
+ if (m_programArgs.getString("older", buffer)[0] != '\0')
+ filter.m_minAge = checkDate(buffer.str());
+ if (m_programArgs.getString("maxsize", buffer)[0] != '\0')
+ filter.m_maxSize = checkSize(buffer.str());
+ if (m_programArgs.getString("minsize", buffer)[0] != '\0')
+ filter.m_minSize = checkSize(buffer.str());
+ if (m_programArgs.getString("type", buffer)[0] != '\0')
+ filter.m_types = checkType(buffer.str());
+ filter.m_minDepth = m_programArgs.getInt("mindepth");
+ filter.m_maxDepth = m_programArgs.getInt("maxdepth");
+ if (m_programArgs.getString("nodepattern", buffer)[0] != '\0'){
+ checkPatternList(buffer.str());
+ m_nodePatterns.set(buffer.str());
+ filter.m_nodePatterns = &m_nodePatterns;
+ }
+ if (m_programArgs.getString("pathpattern", buffer)[0] != '\0'){
+ checkPatternList(buffer.str());
+ m_pathPatterns.set(buffer.str());
+ filter.m_pathPatterns = &m_pathPatterns;
+ }
+ filter.m_traceInterval = m_programArgs.getInt("trace");
+ if (m_programArgs.getString("output", buffer)[0] != '\0'){
+ if ( (m_output = fopen(buffer.str(), "w")) == NULL){
+ help("cannot open output file", buffer.str());
+ m_output = stdout;
+ }
+ }
+}
/**
* Constructor.
*/
m_path = source.m_path;
return *this;
}
-/**
- * Initializes the data of the instance.
- */
-void ReDirStatisticData::clear(){
- m_sizes = 0;
- m_files = 0;
- m_dirs = 0;
- m_path.setLength(0);
-}
-
-/**
- * Adds the data from another instance.
- *
- * @param source the other instance
- * @return the instance itself
- */
-ReDirStatisticData& ReDirStatisticData::add(const ReDirStatisticData& source){
- m_sizes += source.m_sizes;
- m_files += source.m_files;
- m_dirs += source.m_dirs;
- return *this;
-}
/**
* Constructor.
i18n("trace the current path every <number> seconds.\n"
"0: no trace"),
't', "trace-interval", 60);
+ addStandardFilterOptions();
}
/**
* Destructor.
}
/**
- * Build the statistic and print the results.
+ * Adds the data from another instance.
*
- * @param arc count of arguments in <code>argv</code>
- * @param argv the program arguments.
+ * @param source the other instance
+ * @return the instance itself
*/
-void ReDirStatistic::run(int argc, const char* argv[]){
- time_t start = time(NULL);
- try {
- m_programArgs.init(argc, argv);
- if (m_programArgs.getArgCount() < 1)
- m_programArgs.help("statistic: missing path", false, stdout);
- int depth = 1;
- if (m_programArgs.getArgCount() > 1)
- depth = atol(m_programArgs.getArg(1));
- ReDirStatistic statistic;
- statistic.setTraceInterval(m_programArgs.getInt("trace"));
- void (*proc) (const ReDirStatisticData& data,
- ReDirStatistic& parent, ReByteBuffer& line) = &formatWithSizeFilesAndDirs;
- if (m_programArgs.getBool("kbyte"))
- proc = &formatLikeDu;
- const ReStringList& list = statistic.calculate(m_programArgs.getArg(0), depth, proc);
- ReByteBuffer buffer;
- for (size_t ix = 0; ix < list.count(); ix++){
- buffer.set(list.strOf(ix), list.strLengthOf(ix));
- fprintf(m_output, "%s\n", buffer.str());
- }
- if (! m_programArgs.getBool("quiet")){
- int duration = int(time(NULL) - start);
- fprintf(m_output, "Duration: ");
- if (duration >= 3600)
- fprintf(m_output, "%d:", duration / 3600);
- fprintf(m_output, "%02d:%02d\n", duration % 3600 / 60, duration % 60);
- }
- } catch (ReOptionException& exc) {
- m_programArgs.help(exc.getMessage(), false, stdout);
- }
+ReDirStatisticData& ReDirStatisticData::add(const ReDirStatisticData& source){
+ m_sizes += source.m_sizes;
+ m_files += source.m_files;
+ m_dirs += source.m_dirs;
+ return *this;
+}
+/**
+ * Initializes the data of the instance.
+ */
+void ReDirStatisticData::clear(){
+ m_sizes = 0;
+ m_files = 0;
+ m_dirs = 0;
+ m_path.setLength(0);
}
+
/**
* Calculates the statistic of a directory tree.
*
const ReStringList& ReDirStatistic::calculate(const char* base, int level,
void (*formatter)(const ReDirStatisticData& data, ReDirStatistic& parent,
ReByteBuffer& line)){
+ ReDirEntryFilter_t filter;
ReTraverser traverser(base);
+ setFilterFromProgramArgs(filter);
+ traverser.setPropertiesFromFilter(&filter);
if (level > 1024)
level = 1024;
else if (level < 0)
ReDirStatisticData* current = dataStack[0];
current->m_path.set(base, -1);
ReByteBuffer line;
- int traceCount = 0;
+ int traceCount = 0;
+ bool useFilter = filter.m_minSize > 0 || filter.m_maxSize != -1
+ || filter.m_minAge != 0 || filter.m_maxAge != 0
+ || m_nodePatterns.count() > 0;
while( (entry = traverser.rawNextFile(currentDepth))){
- //@todo
- ReByteBuffer dummy(entry->m_path); dummy.append(entry->node());
if (currentDepth <= level && ! entry->m_path.equals(current->m_path)){
if (currentDepth <= topOfStack){
// close the entries of the stack above the new top level:
}
if (entry->isDirectory()){
current->m_dirs++;
- } else {
+ } else if (! useFilter || filter.match(*entry)){
current->m_sizes += entry->fileSize();
current->m_files++;
if (++traceCount % 100 == 0 && m_traceInterval > 0){
return m_list;
}
+/**
+ * Build the statistic and print the results.
+ *
+ * @param arc count of arguments in <code>argv</code>
+ * @param argv the program arguments.
+ */
+void ReDirStatistic::run(int argc, const char* argv[]){
+ time_t start = time(NULL);
+ try {
+ m_programArgs.init(argc, argv);
+ if (m_programArgs.getArgCount() < 1)
+ m_programArgs.help("statistic: missing path", false, stdout);
+ int depth = 1;
+ if (m_programArgs.getArgCount() > 1)
+ depth = atol(m_programArgs.getArg(1));
+ ReDirStatistic statistic;
+ statistic.setTraceInterval(m_programArgs.getInt("trace"));
+ void (*proc) (const ReDirStatisticData& data,
+ ReDirStatistic& parent, ReByteBuffer& line) = &formatWithSizeFilesAndDirs;
+ if (m_programArgs.getBool("kbyte"))
+ proc = &formatLikeDu;
+ const ReStringList& list = statistic.calculate(m_programArgs.getArg(0), depth, proc);
+ ReByteBuffer buffer;
+ for (size_t ix = 0; ix < list.count(); ix++){
+ buffer.set(list.strOf(ix), list.strLengthOf(ix));
+ fprintf(m_output, "%s\n", buffer.str());
+ }
+ if (! m_programArgs.getBool("quiet")){
+ int duration = int(time(NULL) - start);
+ fprintf(m_output, "Duration: ");
+ if (duration >= 3600)
+ fprintf(m_output, "%d:", duration / 3600);
+ fprintf(m_output, "%02d:%02d\n", duration % 3600 / 60, duration % 60);
+ }
+ } catch (ReOptionException& exc) {
+ m_programArgs.help(exc.getMessage(), false, stdout);
+ }
+}
/**
* Formats a line like the du (disk usage) command.
*
data.m_sizes / 1E6, data.m_files, data.m_dirs);
line.append(buffer, -1).append(data.m_path);
}
-/**
- * Prints an message how to use the program and exits.
- *
- * @param msg an error message
- * @param msg2 an addition to the error message or NULL
- */
-void ReDirTools::usage(const char* msg, const char* msg2){
- printf ("Version: %s\n", m_version);
- printf ("usage: dirtool <command> <opt>\n");
- statisticUsage();
- if (msg != NULL)
- printf ("+++ %s%s\n", msg, msg2 == NULL ? "" : msg2);
- exit(1);
-}
-
/**
* Prints a vector of lines.
*
statistic.programArgs().help(NULL, false, stdout);
}
+/**
+ * Prints an message how to use the program and exits.
+ *
+ * @param msg an error message
+ * @param msg2 an addition to the error message or NULL
+ */
+void ReDirTools::usage(const char* msg, const char* msg2){
+ printf ("Version: %s\n", m_version);
+ printf ("usage: dirtool <command> <opt>\n");
+ statisticUsage();
+ if (msg != NULL)
+ printf ("+++ %s%s\n", msg, msg2 == NULL ? "" : msg2);
+ exit(1);
+}
+
/**
* Constructor.
*/
for (int ix = 0; noPath || ix < m_programArgs.getArgCount(); ix++){
ReTraverser traverser(noPath ? "." : m_programArgs.getArg(ix));
noPath = false;
- traverser.setMinLevel(filter.m_maxDepth);
- traverser.setMaxLevel(filter.m_maxDepth);
+ traverser.setPropertiesFromFilter(&filter);
int level;
ReDirStatus_t* entry;
while( (entry = traverser.nextFile(level, &filter)) != NULL){
#endif
for (int ix = 0; ix < m_programArgs.getArgCount(); ix++){
ReTraverser traverser(m_programArgs.getArg(ix));
- traverser.setMinLevel(filter.m_maxDepth);
- traverser.setMaxLevel(filter.m_maxDepth);
+ traverser.setPropertiesFromFilter(&filter);
int level;
ReDirStatus_t* entry;
ReByteBuffer line;
struct stat info;
do {
path2 = path;
- int ix = path.indexOf(ReTraverser::m_separatorStr, minWidth);
+ int ix = path.indexOf(OS_SEPARATOR, minWidth);
path2.setLength(minWidth);
} while(false);
*/
void ReDirSync::synchronize(int argc, const char* argv[]){
ReDirEntryFilter_t filter;
- const char* sep = ReTraverser::m_separatorStr;
+ const char* sep = OS_SEPARATOR;
struct stat info;
try {
time_t start = time(NULL);
size_t ixTargetRelative = target.length();
ReTraverser traverser(source.str());
- traverser.setMinLevel(filter.m_maxDepth);
- traverser.setMaxLevel(filter.m_maxDepth);
+ traverser.setPropertiesFromFilter(&filter);
int level;
ReDirStatus_t* entry;
ReByteBuffer line;
}
}
-/**
- * Gets the arguments for the "statistic" command and execute this.
- *
- * @param argc the number of arguments
- * @param argav the argument vector
- */
-void ReDirTools::list(int argc, const char* argv[]){
- ReDirList lister;
- lister.list(argc, argv);
-}
-
/**
* Gets the arguments for the "batch" command and execute this.
*
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirTools::statistic(int argc, const char* argv[]){
- ReDirStatistic statistic;
- statistic.run(argc, argv);
+void ReDirTools::list(int argc, const char* argv[]){
+ ReDirList lister;
+ lister.list(argc, argv);
}
/**
ReLogger::freeGlobalLogger();
return 0;
}
+
+/**
+ * Gets the arguments for the "statistic" command and execute this.
+ *
+ * @param argc the number of arguments
+ * @param argav the argument vector
+ */
+void ReDirTools::statistic(int argc, const char* argv[]){
+ ReDirStatistic statistic;
+ statistic.run(argc, argv);
+}
+
/*
* DirTools.hpp
*
- * Created on: 30.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef OS_DIRTOOLS_HPP_
const char* checkPatternList(const char* value);
int64_t checkSize(const char* value);
void checkStandardFilterOptions();
- void close();
ReDirStatus_t::Type_t checkType(const char* value);
/** Returns the compound usage message.
* @return the compound usage message
*/
+ void close();
const char** compoundUsage() const
{ return m_compoundUsage; }
void initCompoundUsage(size_t size);
/*\r
* ReTraverser.cpp\r
*\r
- * Created on: 23.12.2014\r
- * Author: hm\r
+ * License: Public domain\r
+ * Do what you want.\r
+ * No warranties and disclaimer of any damages.\r
+ * The latest sources: https://github.com/republib\r
*/\r
\r
#include "base/rebase.hpp"\r
#include "os/reos.hpp"\r
\r
-#ifdef __linux__\r
-const char ReTraverser::m_separator = '/';\r
-const char* const ReTraverser::m_separatorStr = "/";\r
-#elif defined __WIN32__\r
-const char ReTraverser::m_separator = '\\';\r
-const char* const ReTraverser::m_separatorStr = "\\";\r
-#endif\r
-\r
/**\r
* Constructor.\r
*/\r
if (0 == (entry.type() & m_types))\r
break;\r
int64_t size = entry.fileSize();\r
- if (strstr(entry.node(), ".exe"))\r
- ReByteBuffer breaker;\r
if (m_minSize > 0 && size < m_minSize)\r
break;\r
if (m_maxSize >= 0 && size > m_maxSize)\r
break;\r
if (m_nodePatterns != NULL && ! m_nodePatterns->match(entry.node()))\r
break;\r
- if (m_pathPatterns != NULL && ! m_pathPatterns->match(entry.m_path.str()))\r
- break;\r
rc = true;\r
} while(false);\r
return rc;\r
memset(m_dirs, 0, sizeof m_dirs);\r
m_dirs[0] = new ReDirStatus_t();\r
// remove a preceeding "./". This simplifies the pattern expressions:\r
- if (m_base.startsWith(ReByteBuffer(".").append(m_separatorStr, 1).str())){\r
+ if (m_base.startsWith(ReByteBuffer(".").append(OS_SEPARATOR, 1).str())){\r
m_base.remove(0, 2);\r
}\r
}\r
current->m_passNo = 1;\r
if (level >= 0){\r
current->m_path.set(parent.str(), parent.length());\r
- if (! parent.endsWith(m_separatorStr))\r
- current->m_path.append(m_separatorStr);\r
+ if (! parent.endsWith(OS_SEPARATOR))\r
+ current->m_path.append(OS_SEPARATOR);\r
if (node != NULL)\r
- current->m_path.append(node).append(m_separatorStr);\r
+ current->m_path.append(node).append(OS_SEPARATOR);\r
}\r
rc = current->findFirst();\r
}\r
return rc;\r
}\r
\r
+/**\r
+ * Sets some properties from a filter.\r
+ *\r
+ * @param filter the filter with the properties to set\r
+ */\r
+void ReTraverser::setPropertiesFromFilter(ReDirEntryFilter_t* filter){\r
+ m_minLevel = filter->m_minDepth;\r
+ m_maxLevel = filter->m_maxDepth;\r
+ m_dirPatterns = filter->m_pathPatterns;\r
+}\r
\r
/*
* RpTraverser.hpp
*
- * Created on: 23.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef OS_RETRAVERSER_HPP_
*/
void setMinLevel(int value)
{ m_minLevel = value; }
+ void setPropertiesFromFilter(ReDirEntryFilter_t* filter);
protected:
bool initEntry(const ReByteBuffer& parent, const char* node, int level);
void freeEntry(int level);
/// a subdirectory will be entered only if this pattern list matches
/// if NULL any directory will be entered
RePatternList* m_dirPatterns;
-public:
- static const char m_separator;
- static const char* const m_separatorStr;
};
#endif /* OS_RETRAVERSER_HPP_ */
/*
* reos.hpp
*
- * Created on: 23.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef OS_REOS_HPP_
/*
* ReMatcher.cpp
*
- * Created on: 25.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#include "base/rebase.hpp"
/*
* ReMatcher.hpp
*
- * Created on: 25.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef STRING_REMATCHER_HPP_
RePatternList();
~RePatternList();
public:
+ /** @brief Returns the number of entries in the list.
+ * @return the count of patterns in the list
+ */
+ inline int count() const {
+ return m_count;
+ }
void destroy();
bool match(const char* pattern);
+ /** Returns the original pattern string.
+ * @return the string describing the patterns.
+ */
+ const char* patternString() const
+ { return m_patternString.str(); }
void set(const char* patterns, bool ignoreCase = false,
const char* separator = NULL, const char* notPrefix = "-");
- /** Returns the original pattern string.
- * @return the string describing the patterns.
- */
- const char* patternString() const
- { return m_patternString.str(); }
private:
int setOne(int index, const char* pattern, size_t patternLength,
bool ignoreCase, const ReByteBuffer& notPrefix);
/*
* restring.hpp
*
- * Created on: 25.12.2014
- * Author: hm
+ * License: Public domain
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * The latest sources: https://github.com/republib
*/
#ifndef STRING_RESTRING_HPP_