From 109b8dda11f48662a07603bc0e775b83895eec59 Mon Sep 17 00:00:00 2001 From: kawi Date: Thu, 8 Jan 2015 17:07:27 +0100 Subject: [PATCH] windows adaptions, test code --- base/ReByteBuffer.cpp | 6 +++--- base/ReException.cpp | 10 +++++----- base/ReLogger.cpp | 10 +++++----- base/ReTestUnit.cpp | 4 ++-- base/ReVarArgs.cpp | 8 ++++---- base/rebase.hpp | 1 + cunit/cuReTraverser.cpp | 9 ++++++++- cunit/testall.cpp | 2 +- os/ReDirTools.cpp | 11 ++++++----- 9 files changed, 35 insertions(+), 26 deletions(-) diff --git a/base/ReByteBuffer.cpp b/base/ReByteBuffer.cpp index 7cc9b5b..3525de7 100644 --- a/base/ReByteBuffer.cpp +++ b/base/ReByteBuffer.cpp @@ -11,7 +11,7 @@ extern void* memcpy (void* dest, const void* src, size_t n); extern void* memmove (void* dest, const void* src, size_t n); extern int _memcmp (const void* s1, const void* s2, size_t n); -extern int snprintf (char* s, size_t maxlen, const char* format, ...); +extern int _snprintf (char* s, size_t maxlen, const char* format, ...); #endif /** @brief Constructor. @@ -138,7 +138,7 @@ ReByteBuffer& ReByteBuffer::append(const Byte* source, size_t length){ ReByteBuffer& ReByteBuffer::appendInt(int number, const char* format){ char buffer [128]; - snprintf(buffer, sizeof buffer, format, number); + _snprintf(buffer, sizeof buffer, format, number); size_t length = strlen(buffer); ensureSize(m_length + length); @@ -277,7 +277,7 @@ int ReByteBuffer::firstDifference(const Byte* source, size_t length, int start, int rc = -1; if (start < 0) rc = 0; - else if (start < m_length){ + else if (start < (int) m_length){ if (length == -1) length = strlen(source); int count = length > m_length - start ? m_length - start : length; diff --git a/base/ReException.cpp b/base/ReException.cpp index cf8581a..4f2da16 100644 --- a/base/ReException.cpp +++ b/base/ReException.cpp @@ -38,7 +38,7 @@ ReException::ReException(const char* message, const char* file, int lineNo) m_message(NULL) { char buffer[512]; - snprintf(buffer, sizeof buffer, "%s [%.100s-%d]", message, file, lineNo); + _snprintf(buffer, sizeof buffer, "%s [%.100s-%d]", message, file, lineNo); m_message = _strdup(buffer); } /** @brief Destructor. @@ -71,7 +71,7 @@ ReFormatException::ReFormatException(const char* message, const char* format) ReException() { char buffer[512]; - snprintf(buffer, sizeof buffer, "%s%s", message, format == NULL ? "" : format); + _snprintf(buffer, sizeof buffer, "%s%s", message, format == NULL ? "" : format); m_message = _strdup(buffer); } @@ -88,7 +88,7 @@ ReFormatException::ReFormatException(const char* message, const char* format, ReException() { char buffer[512]; - snprintf(buffer, sizeof buffer, "%s%s [%.100s-%d]", + _snprintf(buffer, sizeof buffer, "%s%s [%.100s-%d]", message, format == NULL ? "" : format, file, lineNo); m_message = _strdup(buffer); } @@ -104,7 +104,7 @@ ReBoundsException::ReBoundsException(const char* name, int index, int bound) char buffer[256]; const char* format = index < bound ? i18n("%s: index underflow: %d / %d") : i18n("%s: index overflow: %d / %d"); - snprintf(buffer, sizeof buffer, format, name, index, bound); + _snprintf(buffer, sizeof buffer, format, name, index, bound); m_message = _strdup(buffer); } /** @brief Constructor. @@ -122,7 +122,7 @@ ReBoundsException::ReBoundsException(const char* name, int index, int bound, con char buffer[256]; const char* format = index < bound ? i18n("%s: index underflow: %d / %d [%s-%d]") : i18n("%s: index overflow: %d / %d [%s-%d]"); - snprintf(buffer, sizeof buffer, format, name, index, bound, file, line); + _snprintf(buffer, sizeof buffer, format, name, index, bound, file, line); m_message = _strdup(buffer); } diff --git a/base/ReLogger.cpp b/base/ReLogger.cpp index dd159f7..37488ef 100644 --- a/base/ReLogger.cpp +++ b/base/ReLogger.cpp @@ -169,7 +169,7 @@ void ReFileAppender::setConfig(const char* pattern, int maxFiles, int maxSize){ const char* first = strchr(pattern, '*'); size_t len; if (first == NULL){ - snprintf(m_filePattern, sizeof m_filePattern, "%s.%s.log", pattern, placeholder); + _snprintf(m_filePattern, sizeof m_filePattern, "%s.%s.log", pattern, placeholder); } else { len = first - pattern; memcpy(m_filePattern, pattern, len); @@ -236,7 +236,7 @@ void ReFileAppender::changeFile(){ // Delete some of the oldest files to make room for the new: for (int ii = 0; ii < int(FILENO_UBOUND - m_maxFiles); ii++){ int fileNo = (FILENO_UBOUND + m_currentFileNo - m_maxFiles - ii) % m_maxFiles; - snprintf(filename, sizeof filename, m_filePattern, fileNo); + _snprintf(filename, sizeof filename, m_filePattern, fileNo); struct stat info; if (lstat(filename, &info) == 0) _unlink(filename); @@ -245,7 +245,7 @@ void ReFileAppender::changeFile(){ } if (++m_currentFileNo >= FILENO_UBOUND) m_currentFileNo = 0; - snprintf(filename, sizeof filename, m_filePattern, m_currentFileNo); + _snprintf(filename, sizeof filename, m_filePattern, m_currentFileNo); m_stream = fopen(filename, "w"); m_currentSize = 0; } @@ -324,7 +324,7 @@ ReVarArgs& ReLogger::sayF(ReClassCategoryGranularity mode, ReLogLocation locatio const char* format){ if (m_locationOfOpenSayF != 0){ char message[128]; - snprintf(message, sizeof message, "missing ReLogger::end(): Location: %d", + _snprintf(message, sizeof message, "missing ReLogger::end(): Location: %d", m_locationOfOpenSayF); say(LOG_ERROR|GRAN_USER|CAT_LIB, LC_LOGGER_SAYF_OPEN, message); } @@ -404,7 +404,7 @@ const char* ReLogger::getStandardPrefix(void){ "%Y.%m.%d %H:%M:%S", now1); size_t len = strlen(m_standardPrefix); char* ptr = m_standardPrefix + len; - snprintf (ptr, sizeof m_standardPrefix - len, " %ld: ", + _snprintf (ptr, sizeof m_standardPrefix - len, " %ld: ", (long) m_location); } return m_standardPrefix; diff --git a/base/ReTestUnit.cpp b/base/ReTestUnit.cpp index 3edadbc..012bd02 100644 --- a/base/ReTestUnit.cpp +++ b/base/ReTestUnit.cpp @@ -154,7 +154,7 @@ void ReTestUnit::assertEqualFiles(const char* name1, const char* name2, int line if (ix < 0){ ReByteBuffer line1(list1.strOf(ix), list1.strLengthOf(ix)); int ixLine = line1.firstDifference(list2.strOf(ix), list2.strLengthOf(ix)); - logF(true, i18n("%s-%d: Files differ in line %d-%d\%s\n%s\n%s"), + logF(true, i18n("%s-%d: Files differ in line %d-%d\n%s\n%s\n%s"), m_sourceFile, lineNo, ix, ixLine, list1.strOf(ix), list2.strOf(ix), colMarker(ixLine)); } @@ -203,7 +203,7 @@ void ReTestUnit::createTestDir(){ _mkdir(name); else{ char cmd[512 + 128]; - snprintf(cmd, sizeof cmd, "rm -Rf %s*", name); + _snprintf(cmd, sizeof cmd, "rm -Rf %s*", name); system(cmd); } strcpy(m_tempDir, name); diff --git a/base/ReVarArgs.cpp b/base/ReVarArgs.cpp index 262bc5d..a0b9151 100644 --- a/base/ReVarArgs.cpp +++ b/base/ReVarArgs.cpp @@ -97,7 +97,7 @@ ReVarArgs& ReVarArgs::reset(const char* format){ for (int ii = 1; ii < m_maxArgNo; ii++) if (m_args[ii] == 0){ char msg[128]; - snprintf(msg, sizeof msg, i18n("missing $%d in format: "), ii); + _snprintf(msg, sizeof msg, i18n("missing $%d in format: "), ii); throw ReFormatException(msg, format); } @@ -174,7 +174,7 @@ void ReVarArgs::store(const char* value, int length){ */ ReVarArgs& ReVarArgs::arg(int value, const char* format){ char number[256]; - snprintf(number, sizeof number, format, value); + _snprintf(number, sizeof number, format, value); store(number); return *this; } @@ -188,7 +188,7 @@ ReVarArgs& ReVarArgs::arg(int value, const char* format){ */ ReVarArgs& ReVarArgs::arg(long value, const char* format){ char number[256]; - snprintf(number, sizeof number, format, value); + _snprintf(number, sizeof number, format, value); store(number); return *this; } @@ -231,7 +231,7 @@ ReVarArgs& ReVarArgs::arg(const char* value, int minWidth, int maxWidth, bool al */ ReVarArgs& ReVarArgs::arg(double value, const char* format){ char number[256]; - snprintf(number, sizeof number, format, value); + _snprintf(number, sizeof number, format, value); store(number); return *this; } diff --git a/base/rebase.hpp b/base/rebase.hpp index 262b0a5..d7a9fca 100644 --- a/base/rebase.hpp +++ b/base/rebase.hpp @@ -37,6 +37,7 @@ #elif defined __WIN32__ # include # include +# define _memcmp(t,s,n) memcmp(t,s,n) typedef _int64 int64_t; # define S_ISDIR(mode) (((mode) & _S_IFDIR) != 0) #endif diff --git a/cunit/cuReTraverser.cpp b/cunit/cuReTraverser.cpp index 29af15f..de0ccab 100644 --- a/cunit/cuReTraverser.cpp +++ b/cunit/cuReTraverser.cpp @@ -60,7 +60,13 @@ private: testDirStatistic(); testBasic(); testCopyFile(); + testList(); } + void testList(){ + ReDirTools tools; + const char* argv[] = { "list", m_base.str(), NULL }; + tools.list(2, argv); + } void testCopyFile(){ ReByteBuffer src(m_base); src.append("dir1/dir1_2/dir1_2_1/x1.txt"); @@ -69,8 +75,9 @@ private: ReByteBuffer buffer; buffer.ensureSize(5); ReDirSync::copyFile(src.str(), 0, -1ll, trg.str(), buffer, ReLogger::globalLogger()); - //checkFile(); + checkFileEqu(src.str(), trg.str()); } + void checkRelDate(time_t absTime, int relTime){ int diff = int(time(NULL) - relTime - absTime); if (diff < 0) diff --git a/cunit/testall.cpp b/cunit/testall.cpp index c990847..9b3bf09 100644 --- a/cunit/testall.cpp +++ b/cunit/testall.cpp @@ -12,7 +12,7 @@ void testBase(){ extern void testReTestUnit(); - testReTestUnit(); + //testReTestUnit(); extern void testReByteBuffer(); testReByteBuffer(); extern void testReSeqList(void); diff --git a/os/ReDirTools.cpp b/os/ReDirTools.cpp index 5dc5f8e..6ac14d4 100644 --- a/os/ReDirTools.cpp +++ b/os/ReDirTools.cpp @@ -721,7 +721,7 @@ void formatWithSizeFilesAndDirs(const ReDirStatisticData& data, line.setLength(0); // Round up to the next KiByte: char buffer[256]; - snprintf(buffer, sizeof buffer, "%14.6f MB %7d %7d\t", + _snprintf(buffer, sizeof buffer, "%14.6f MB %7d %7d\t", data.m_sizes / 1E6, data.m_files, data.m_dirs); line.append(buffer, -1).append(data.m_path); } @@ -784,15 +784,16 @@ void ReDirList::list(int argc, const char* argv[]){ bool verbose = ! m_programArgs.getBool("quiet"); bool shortOutput = m_programArgs.getBool("short"); setFilterFromProgramArgs(filter); - if (m_programArgs.getArgCount() == 0) - help(i18n("no arguments given (missing path)")); + bool noPath = m_programArgs.getArgCount() == 0; ReByteBuffer bufferRights; ReByteBuffer bufferTime; int64_t sumSizes = 0; int files = 0; int dirs = 0; - for (int ix = 0; ix < m_programArgs.getArgCount(); ix++){ - ReTraverser traverser(m_programArgs.getArg(ix)); + + 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); int level; -- 2.39.5