if (start >= 0 && start <= int(m_length - toFindLength)
&& end >= (int) toFindLength && end <= (int) m_length){
while(rc < 0 && start <= int(end - toFindLength)){
- if (ignoreCase ? memicmp(toFind, m_buffer + start, toFindLength) == 0
+ if (ignoreCase ? memicmp((void*) toFind, (void*) (m_buffer + start),
+ toFindLength) == 0
: memcmp(toFind, m_buffer + start, toFindLength) == 0)
rc = start;
else
inline ReByteBuffer& set(const Byte* source, size_t length){
return setLength(0).append(source, length);
}
+ /** @brief Sets the content of the buffer by copying a byte sequence.
+ * @param source the source to copy.
+ * @return *this (for chaining).
+ */
+ inline ReByteBuffer& set(const ReByteBuffer& source){
+ return setLength(0).append(source);
+ }
ReByteBuffer& setLength(size_t length);
ReByteBuffer& setLengthAndFill(size_t length, Byte filler = 0);
* < 0: region1 is alphabetically less than region2<br>
* > 0: region1 is alphabetically greater than region2
*/
-int memicmp(void* region1, void* region2, int size)
+int memicmp(const void* region1, const void* region2, int size)
{
unsigned char* ptr1 = (unsigned char*) region1;
unsigned char* ptr2 = (unsigned char*) region2;
void replaceSubstring(char* start, size_t bufferSize, size_t lengthReplaced,
const char* newString);
#if defined __linux__
-int memicmp(void* region1, void* region2, int size);
+int memicmp(const void* region1, const void* region2, int size);
#endif
#endif /* RESTRING_H_ */
*
* @throws ReException
*/
-void ReProgramArgs::init(int argc, char* argv[]){
+void ReProgramArgs::init(int argc, const char* argv[]){
m_program = argv[0];
argv++;
argc--;
const char* getArg(size_t index) const;
const char* getProgramName() const;
- void init(int argc, char* argv[]);
+ void init(int argc, const char* argv[]);
void setLastError(const char* message);
void help(const char* message, bool issueLastError, ReStringList& lines);
ReProgramArgs args("test","example");
args.addBool("boolarg", "This is a boolean arg", 'b', "boolval", false);
try {
- char* argv[] = { "test", "-v" };
+ const char* argv[] = { "test", "-v" };
args.init(2, argv);
checkF(true);
} catch (ReOptionException& exc) {
const char* vector[] = {
"testprog", "-bB+i123", "-S", "-x-", "-Y+", "-s", "2nd string", "arg1", "arg2"
};
- args.init(sizeof vector / sizeof vector[0], (char**) vector);
+ args.init(sizeof vector / sizeof vector[0], vector);
checkEqu("testprog", args.getProgramName());
checkT(args.getBool("boolarg"));
"--string=x y", "--estring=", "--estring2=not empty",
"arg1", "arg2"
};
- args.init(sizeof vector / sizeof vector[0], (char**) vector);
+ args.init(sizeof vector / sizeof vector[0], vector);
checkEqu("testprog", args.getProgramName());
checkT(args.getBool("boolarg"));
void checkSetFilterFromProgramArgs(){
ReDirOptions opts(s_empty, s_empty);
opts.addStandardFilterOptions();
- char* argv[] = { "x", "-y1970.01.02", "-o1970.01.03",
+ const char* argv[] = { "x", "-y1970.01.02", "-o1970.01.03",
"-D5", "-d1", "-z1k", "-Z2M", "-p;*;-*~"
};
ReDirEntryFilter_t filter;
const char* ReDirTools::m_version = "2015.01.05";
-static const char* s_empty[] = { NULL };
-
static const char* s_helpSummary[] = {
"dirtool or dt <command> <opts>",
" Useful commands around directory trees.",
time_t ReDirOptions::checkSize(const char* value){
int64_t rc = 0;
char unit = 'b';
- switch (sscanf(value, "%lld%c", &rc, &unit)){
+ switch (sscanf(value, "%lld%c", (long long int*) &rc, &unit)){
case 1:
case 2:
switch(unit){
* @throws ReOptionExecption
*/
const char* ReDirOptions::checkPatternList(const char* value){
- if (iscsym(*value) || *value == '*' || *value == '.' || *value == '-')
+ if (isalnum(*value) || *value == '_' || *value == '*'
+ || *value == '.' || *value == '-')
throw ReOptionException(&m_programArgs,
i18n("invalid separator (first character): $1 use ';' instead"),
value);
* @param arc count of arguments in <code>argv</code>
* @param argv the program arguments.
*/
-void ReDirStatistic::run(int argc, char* argv[]){
+void ReDirStatistic::run(int argc, const char* argv[]){
time_t start = time(NULL);
try {
m_programArgs.init(argc, argv);
// set up a new stack entry:
if (currentDepth != topOfStack + 1)
assert(currentDepth == topOfStack + 1);
+ //@todo
+ if (strstr("dir2", entry->node()) != NULL || strstr("dir2", entry->m_path.str()))
+ ReByteBuffer breaker;
+
topOfStack++;
if (dataStack[topOfStack] == NULL)
dataStack[topOfStack] = new ReDirStatisticData();
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirList::list(int argc, char* argv[]){
+void ReDirList::list(int argc, const char* argv[]){
ReDirEntryFilter_t filter;
try {
time_t start = time(NULL);
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirBatch::createBatch(int argc, char* argv[]){
+void ReDirBatch::createBatch(int argc, const char* argv[]){
ReDirEntryFilter_t filter;
try {
time_t start = time(NULL);
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirSync::synchronize(int argc, char* argv[]){
+void ReDirSync::synchronize(int argc, const char* argv[]){
ReDirEntryFilter_t filter;
const char* sep = ReTraverser::m_separatorStr;
struct stat info;
size_t lengthTargetBase = target.length();
bool verbose = ! m_programArgs.getBool("quiet");
bool chatterMode = true;
+ bool copyExistingOnly = false;
setFilterFromProgramArgs(filter);
int64_t sumSizes = 0;
int files = 0;
makeDirWithParents(target, ixTargetRelative);
targetFile.set(target).append(entry->node(), -1);
bool exists = stat(targetFile.str(), &info) == 0;
- if (! exists && ! copyExistingOnly
+ if ( (! exists && ! copyExistingOnly)
|| entry->filetimeToTime(entry->modified()) - info.st_mtime
> maxFileTimeDiff) {
if (chatterMode)
- printf("%s%s same time\n", entry->m_path.str(), entry->node);
+ printf("%s%s same time\n", entry->m_path.str(), entry->node());
continue;
} else {
+ }
+
if (entry->isDirectory())
dirs++;
else{
}
if (verbose){
int duration = int(time(NULL) - start);
-#if defined __linux__
- const char* prefix = "#";
-#elif defined __WIN32__
- const char* prefix = "rem";
-#endif
- printf ("%s %d dir(s) and %d file(s) with %.6f MByte in %02d:%02d sec\n",
- prefix, dirs, files, sumSizes / 1E6, duration / 60, duration % 60);
+ printf ("=== %d dir(s) and %d file(s) with %.6f MByte in %02d:%02d sec\n",
+ dirs, files, sumSizes / 1E6, duration / 60, duration % 60);
}
} catch(ReOptionException& exc){
help(exc.getMessage());
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirTools::list(int argc, char* argv[]){
+void ReDirTools::list(int argc, const char* argv[]){
ReDirList lister;
lister.list(argc, argv);
}
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirTools::batch(int argc, char* argv[]){
+void ReDirTools::batch(int argc, const char* argv[]){
ReDirBatch batch;
batch.createBatch(argc, argv);
}
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirTools::help(int argc, char* argv[]){
+void ReDirTools::help(int argc, const char* argv[]){
if (argc <= 1)
printField(s_helpSummary);
else {
* @param argc the number of arguments
* @param argav the argument vector
*/
-void ReDirTools::statistic(int argc, char* argv[]){
+void ReDirTools::statistic(int argc, const char* argv[]){
ReDirStatistic statistic;
statistic.run(argc, argv);
}
* Gets the arguments for any command and execute this.
*
* @param argc the number of arguments
- * @param argav the argument vector
+ * @param orgArgv the argument vector
*/
-int ReDirTools::main(int argc, char* argv[]){
+int ReDirTools::main(int argc, char* orgArgv[]){
ReDirTools tools;
+ const char** argv = (const char**) orgArgv;
if (argc < 2)
tools.help(0, argv);
argc--;
public:
ReDirBatch();
public:
- void createBatch(int argc, char* argv[]);
+ void createBatch(int argc, const char* argv[]);
virtual bool printOneFile(ReDirStatus_t* entry)
{ return false; }
};
public:
ReDirSync();
public:
- void synchronize(int argc, char* argv[]);
+ void synchronize(int argc, const char* argv[]);
};
class ReDirList : public ReDirOptions {
public:
ReDirList();
public:
- void list(int argc, char* argv[]);
+ void list(int argc, const char* argv[]);
virtual bool printOneFile(ReDirStatus_t* entry)
{ return false; }
};
const ReStringList& calculate(const char* base, int depth,
void (*format)(const ReDirStatisticData& data, ReDirStatistic& parent,
ReByteBuffer& line) = formatLikeDu);
- void run(int argc, char* argv[]);
+ void run(int argc, const char* argv[]);
void setTraceInterval(int interval){
m_traceInterval = interval;
}
public:
virtual void usage(const char* msg, const char* msg2 = NULL);
void dirListUsage();
- void batch(int argc, char* argv[]);
- void help(int argc, char* argv[]);
- void list(int argc, char* argv[]);
+ void batch(int argc, const char* argv[]);
+ void help(int argc, const char* argv[]);
+ void list(int argc, const char* argv[]);
void statisticUsage();
- void statistic(int argc, char* argv[]);
+ void statistic(int argc, const char* argv[]);
public:
static int main(int argc, char* argv[]);
public:
* Constructor.\r
*/\r
ReDirStatus_t::ReDirStatus_t() :\r
+ m_path(),\r
+ m_passNo(0),\r
#ifdef __linux__\r
m_handle(NULL),\r
- m_data(NULL)\r
+ m_data(NULL),\r
//m_status;\r
+ m_fullName()\r
#elif defined WIN32\r
m_handle(INVALID_HANDLE_VALUE)\r
//m_data;\r
* @return the status of the current file\r
*/\r
struct stat* ReDirStatus_t::getStatus() {\r
- if (m_status.st_ino == 0)\r
- if (stat(m_data->d_name, &m_status) != 0)\r
+ if (m_status.st_ino == 0){\r
+ m_fullName.set(m_path).append(m_data->d_name, -1);\r
+ if (stat(m_fullName.str(), &m_status) != 0)\r
memset((void*) &m_status, 0, sizeof m_status);\r
+ }\r
return &m_status;\r
}\r
#endif\r
* @param base the base directory. The traversal starts at this point\r
*/\r
ReTraverser::ReTraverser(const char* base) :\r
- m_level(-1),\r
m_minLevel(0),\r
m_maxLevel(512),\r
+ m_level(-1),\r
m_base(base),\r
// m_dirs\r
m_passNoForDirSearch(2)\r
if (current->m_passNo == 1){\r
// we start the second pass:\r
alreadyRead = initEntry(current->m_path, NULL, -1);\r
- if (strcmp(current->m_path.str(), "E:\\user\\winfried\\") == 0)\r
- current->m_passNo = 2;\r
current->m_passNo = 2;\r
again = true;\r
} else {\r
DIR* m_handle;
struct dirent* m_data;
struct stat m_status;
+ ReByteBuffer m_fullName;
public:
struct stat* getStatus();
#elif defined WIN32