const char* rc = NULL;
if (index < count()){
Sequence* seq = getInfo(index);
- rc = m_content.buffer() + seq->m_index;
+ rc = m_content.str() + seq->m_index;
}
return rc;
}
* @param filename the name of the file
* @param separator this string was put between the substrings. May be NULL
* @param mode the file open mode: "w" for truncate and write, "a" for append
+ * @param endOfFile NULL or a string written at the end of line
*
* @return true: the file could be opened. false: otherwise
*/
bool ReStringList::writeToFile(const char* filename,
- const char* separator, const char* mode){
+ const char* separator, const char* mode, const char* endOfFile){
bool rc = false;
FILE* fp = fopen(filename, mode);
if (fp){
if (ix != aCount - 1 && separator != NULL)
fputs(separator, fp);
}
+ if (endOfFile != NULL)
+ fputs(endOfFile, fp);
fclose(fp);
rc = true;
}
size_t sumOfStrLengths() const;
Tag tagOf(Index index) const;
bool writeToFile(const char* filename, const char* separator = "\n",
- const char* mode = "w");
+ const char* mode = "w", const char* endOfFile = "\n");
};
#endif /* RESTRINGLIST_H_ */
m_sourceFile(sourceFile),
m_buffer()
{
+ int ix = m_sourceFile.rindexOf(OS_SEPARATOR, 1);
+ if (ix >= 0)
+ m_sourceFile.remove(0, ix + 1);
logF(false, i18n("Start %s"), name);
createTestDir();
}
line.append("!", -1);
list.append(line, -5);
checkEqu(2u, list.count());
+
checkEqu(99ll, list.tagOf(0));
checkEqu("Hi", list.strOf(0));
checkEqu(-5ll, list.tagOf(1));
checkEqu("Hi!", list.strOf(1));
+
+ checkN(list.strOf(2));
}
void testReplace(){
ReStringList list;
checkEqu("99", list2.strOf(5));
list2.clear();
list2.readFromFile(file.str(), false);
- checkEqu("1", list2.strOf(0));
- checkEqu("abc", list2.strOf(1));
- checkEqu("xyz", list2.strOf(2));
- checkEqu("4", list2.strOf(3));
- checkEqu("", list2.strOf(4));
- checkEqu("99", list2.strOf(5));
+ checkEqu("1\n", list2.strOf(0));
+ checkEqu("abc\n", list2.strOf(1));
+ checkEqu("xyz\n", list2.strOf(2));
+ checkEqu("4\n", list2.strOf(3));
+ checkEqu("\n", list2.strOf(4));
+ checkEqu("99\n", list2.strOf(5));
checkEqu(-1, list2.firstDiff(list2));
}
}
private:
void run(){
+ testLengthOfUnsigned();
testStrnicmp();
testIsInList();
testSplitPath();
}
+ void testLengthOfUnsigned(){
+ unsigned int value;
+ checkEqu(3, (int) ReStringUtils::lengthOfUnsigned("123.4", -1, &value));
+ checkEqu(123, (int) value);
+ value = 0x47112011;
+ checkEqu(0, (int)ReStringUtils::lengthOfUnsigned("", 0, &value));
+ checkEqu(0x47112011, (int) value);
+ checkEqu(2, (int) ReStringUtils::lengthOfUnsigned("235", 2, &value));
+ checkEqu(23, (int) value);
+ }
void testStrnicmp(){
checkT(ReStringUtils::strnicmp("abc", "abc", 3) == 0);
checkT(ReStringUtils::strnicmp("abc", "ab", 3) > 0);
void run(){
initTree();
- testToolSync();
- testToolStatistic();
testBasic();
testDirOptions();
checkSetFilterFromProgramArgs();
- testDirStatistic();
- testCopyFile();
testList();
}
void testList(){
checkOneFile("dir1_2", "dir1", hash);
checkF(hash.get("cache.txt", buffer));
}
- void testDirStatistic(){
- ReDirStatistic stat;
- const ReStringList& list = stat.calculate(m_base.str(), 1);
- ReByteBuffer buffer;
- ReByteBuffer expected;
- log(false, list.join("\n", buffer).str());
- checkEqu(4u, list.count());
- // "1 t:\temp\winfried\2\retestunit\dir1\n"
- 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(OS_SEPARATOR);
- // .append(OS_SEPARATOR, -1)
- checkT(buffer.endsWith(expected.str()));
-
- buffer.setLength(0);
- const ReStringList& list2 = stat.calculate(m_base.str(), 1, formatWithSizeFilesAndDirs);
- log(false, list2.join("\n", buffer).str());
-
- 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(OS_SEPARATOR);
- checkT(buffer.endsWith(expected.str()));
-
- buffer.set(list.strOf(1), list.strLengthOf(1));
- checkT(buffer.startsWith(" 0.000054 MB 2 3\t"));
- expected.set(m_base.str(), m_base.length()).append("dir2", -1)
- .append(OS_SEPARATOR);
- checkT(buffer.endsWith(expected.str()));
-
- buffer.set(list.strOf(2), list.strLengthOf(2));
- checkT(buffer.startsWith(" 0.000087 MB 5 6\t"));
- expected.set(m_base.str(), m_base.length());
- }
- void testToolStatistic(){
- ReDirTools tools;
- const char* argv[] = { "dt", "stat", "-P;*;-*/cache/*", m_base.str(), "2" };
- tools.main(5, (char**) argv);
- }
- void testToolSync(){
- ReDirTools tools;
- ReByteBuffer source(m_base);
- source.append("dir1");
- ReByteBuffer target(makeDir("synctest"));
- const char* argv[] = { "dt", "sync", "-P;*;-*/cache/*", "-p;*.txt",
- source.str(), target.str() };
- tools.main(6, (char**) argv);
- }
};
extern void testReTraverser(void);
m_traceInterval(0),
m_lastTrace(0)
{
- m_programArgs.addBool("quiet",
- i18n("does not show additional information, e.g. runtime"),
- 'q', "quiet", false);
m_programArgs.addBool("kbyte",
i18n("output is '<kbyte> <path>' (like unix 'du' command)"),
'k', "kbyte", false);
- m_programArgs.addInt("trace",
- i18n("trace the current path every <number> seconds.\n"
- "0: no trace"),
- 't', "trace-interval", 60);
addStandardFilterOptions();
}
/**
buffer.set(list.strOf(ix), list.strLengthOf(ix));
fprintf(m_output, "%s\n", buffer.str());
}
- if (! m_programArgs.getBool("quiet")){
+ if (m_verboseLevel >= V_SUMMARY){
int duration = int(time(NULL) - start);
fprintf(m_output, "Duration: ");
if (duration >= 3600)
try {
time_t start = time(NULL);
m_programArgs.init(argc, argv);
- bool verbose = ! m_programArgs.getBool("quiet");
bool shortOutput = m_programArgs.getBool("short");
setFilterFromProgramArgs(filter);
bool noPath = m_programArgs.getArgCount() == 0;
}
}
}
- if (verbose){
+ if (m_verboseLevel >= V_SUMMARY){
int duration = int(time(NULL) - start);
fprintf(m_output, "+++ %d dirs and %d file(s) with %.6f MByte in %02d:%02d sec\n",
dirs, files, sumSizes / 1E6, duration / 60, duration % 60);
ReByteBuffer script(m_programArgs.getString("script", buffer), -1);
if (arguments.length() + script.length() == 0)
help(i18n("one of the option must be set: -a (--arguments) or -c (--script)"));
- bool verbose = ! m_programArgs.getBool("quiet");
#if defined __WIN32__
bool isExe = m_programArgs.getBool("isexe");
#endif
fprintf(m_output, "%s\n", line.str());
}
}
- if (verbose){
+ if (m_verboseLevel >= V_SUMMARY){
int duration = int(time(NULL) - start);
#if defined __linux__
const char* prefix = "#";