return *this;
}
/** @brief Tests whether another instance is equal to this instance.
- * @param buffer the buffer to compare
- * @return <code>true</code>: the buffer's contents are equal
+ * @param data string to compare
+ * @param length length of <code>data</code>. If -1: <code>strlen(data)</code>
+ * @param ignoreCase <code>true</code>: case insensitive comparison
+ * @return <code>true</code>: the buffer's contents are equal
*/
- inline bool equals(const ReByteBuffer& buffer) const{
- bool rc = buffer.length() == m_length && _memcmp(buffer.str(), m_buffer, m_length) == 0;
+ inline bool equals(const char* data, size_t length, bool ignoreCase = false) const{
+ if (length == (size_t) -1)
+ length = strlen(data);
+ bool rc = length == m_length
+ && (! ignoreCase && _memcmp(data, m_buffer, length) == 0
+ || ignoreCase && _strnicmp(data, m_buffer, length) == 0);
+ return rc;
+ }
+ /** @brief Tests whether another instance is equal to this instance.
+ * @param buffer the buffer to compare
+ * @param ignoreCase <code>true</code>: case insensitive comparison
+ * @return <code>true</code>: the buffer's contents are equal
+ */
+ inline bool equals(const ReByteBuffer& buffer, bool ignoreCase = false) const{
+ bool rc = buffer.length() == m_length
+ && (! ignoreCase && _memcmp(buffer.str(), m_buffer, m_length) == 0
+ || ignoreCase && _strnicmp(buffer.str(), m_buffer, m_length) == 0);
return rc;
}
ReByteBuffer& fill(Byte filler = 0, int start = 0, int end = -1);
"synchronize copies only modified or new files from",\r
" from a source directory tre to a target",\r
"touch sets the filetimes",\r
+ "which finds a file in a path list (like PATH)",\r
NULL\r
};\r
\r
NULL\r
};\r
\r
+const char* s_whichUsage[] = {\r
+ "<command>: w(hicht) [<opts>] <file_or_pattern1> [<file_or_pattern2> ...]",\r
+ " finds a file in a path list (like PATH)",\r
+ NULL\r
+};\r
+const char* s_whichExamples[] = {\r
+ "dirtool which --list=JAVA_CLASSPATH org.jdom.jar *.jdom*.jar",\r
+ "dirtool which find.exe",\r
+ NULL\r
+};\r
/**\r
* Constructor.\r
*\r
m_reservedFirst(reservedFirst),\r
m_reservedLast(reservedLast),\r
m_addCurrentDirIfNoArguments(addCurrentDirIfNoArguments),\r
+ m_hasStandardArgs(true),\r
m_traverser(NULL, this, logger),\r
m_filter(),\r
m_start(time(NULL)),\r
m_programArgs.init(argc, argv);\r
if (m_programArgs.getArgCount() < m_minArguments)\r
m_programArgs.help(i18n("too few arguments"), false, stdout);\r
- setFilterFromProgramArgs(m_filter);\r
+ if (m_hasStandardArgs)\r
+ setFilterFromProgramArgs(m_filter);\r
doIt();\r
+ if (m_output != stdout){\r
+ fclose(m_output);\r
+ m_output = stdout;\r
+ }\r
+ \r
} catch (ReOptionException& exc) {\r
m_programArgs.help(exc.getMessage(), false, stdout);\r
}\r
}\r
}\r
\r
+/**\r
+ * Constructor.\r
+ *\r
+ * @param logger logger for error handling\r
+ */\r
+ReDirWhich::ReDirWhich(ReLogger* logger) :\r
+ ReTool(s_batchUsage, s_batchExamples, 0, 0, 0, true, logger)\r
+{\r
+ // no standard options:\r
+ m_programArgs.addBool("all",\r
+ i18n("all files will be found, not only the first"),\r
+ 'a', "all", false);\r
+ m_programArgs.addString("list",\r
+ i18n("a path list (separator see option 'separator'"),\r
+ 'l', "list", false, NULL);\r
+ m_programArgs.addString("separator",\r
+ i18n("separator between the path elements"),\r
+ 's', "separator", false,\r
+#if defined __linux__\r
+ ":"\r
+#elif defined __WIN32__\r
+ ";"\r
+#endif\r
+ );\r
+ m_programArgs.addString("variable",\r
+ i18n("variable with the path list"),\r
+ 'v', "variable", false, "PATH");\r
+ m_hasStandardArgs = false;\r
+}\r
+\r
+/**\r
+ * Creates the batch file.\r
+ */\r
+void ReDirWhich::doIt(){\r
+ ReByteBuffer value, path;\r
+ bool all = false;\r
+ ReStringList items;
+ char sep = 0;\r
+ m_programArgs.getString("list", path);\r
+ if (path.length() == 0){\r
+ m_programArgs.getString("variable", value);\r
+ if (getenv(value.str()) == NULL)\r
+ help("Umgebungsvariable nicht definiert: ", value.str());\r
+ else\r
+ path = getenv(value.str());\r
+ m_programArgs.getString("separator", value);\r
+ sep = value.at(0);\r
+ }\r
+ items.split(path.str(), sep);\r
+ struct stat info;\r
+ ReByteBuffer full;\r
+ for (int ix = 0; ix < m_programArgs.getArgCount(); ix++){\r
+ bool found = false;\r
+\r
+ ReByteBuffer arg(m_programArgs.getArg(ix));\r
+ for (size_t ixItem = 0; ixItem < items.count(); ixItem++){\r
+ full.set(items.strOf(ixItem));\r
+ if (arg.indexOf('*') < 0){\r
+ full.ensureLastChar(OS_SEPARATOR_CHAR);\r
+ full.append(arg);\r
+ found = stat(full.str(), &info) == 0;\r
+ if (found)\r
+ printf("%s\n", full.str());\r
+ } else {\r
+ ReDirectory dir(full.str());\r
+ if (dir.findFirst(arg.str(), false)){\r
+ do {\r
+ printf("%s%c%s\n", full.str(), OS_SEPARATOR_CHAR, dir.currentFile());\r
+ } while(dir.findNext());\r
+ }\r
+ }\r
+ if (found && ! all)\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
/**\r
* Tests whether a abrevation of an argument is given.\r
* @param full the full name\r
} else if (isArg("list", arg0)){\r
ReDirList list(m_logger);\r
list.help(NULL);\r
- } else if (isArg("help", arg0))\r
+ } else if (isArg("help", arg0)){\r
printField(s_helpSummary);\r
- else if (isArg("statistic", arg0)){\r
+ } else if (isArg("md5", arg0)){\r
+ ReDirMD5 md5(m_logger);\r
+ md5.help(NULL);\r
+ } else if (isArg("statistic", arg0)){\r
ReDirStatistic stat(m_logger);\r
stat.help(NULL);\r
} else if (isArg("test", arg0)){\r
void testAll();\r
testAll();\r
+ } else if (isArg("touch", arg0)){\r
+ ReDirTouch touch(m_logger);\r
+ touch.help(NULL);\r
+ } else if (isArg("which", arg0)){\r
+ ReDirWhich which(m_logger);\r
+ which.help(NULL);\r
} else\r
printf("+++ unknown sub command: %s\n", arg0);\r
}\r
ReDirSync(m_logger).run(argc, argv);\r
else if (isArg("touch", arg0))\r
ReDirTouch(m_logger).run(argc, argv);\r
+ else if (isArg("which", arg0))\r
+ ReDirWhich(m_logger).run(argc, argv);\r
else if (isArg("test", arg0)){\r
void testAll();\r
testAll();\r
#pragma comment(lib, "advapi32.lib")\r
#endif\r
\r
-enum RELOC_TRAVERSER {
- LC_RIGHTS_AS_STRING_1 = LC_TRAVERSER + 1, // 50301
- LC_RIGHTS_AS_STRING_2, // 50302
- LC_RIGHTS_AS_STRING_3, // 50303
- LC_GET_PRIVILEGE_1, // 50304
- LC_GET_PRIVILEGE_2, // 50305
- LC_GET_PRIVILEGE_3, // 50306
- LC_GET_FILE_OWNER_1, // 50307
- LC_GET_FILE_OWNER_2, // 50308
-};
+enum RELOC_TRAVERSER {\r
+ LC_RIGHTS_AS_STRING_1 = LC_TRAVERSER + 1, // 50401\r
+ LC_RIGHTS_AS_STRING_2, // 50402\r
+ LC_RIGHTS_AS_STRING_3, // 50403\r
+ LC_GET_PRIVILEGE_1, // 50404\r
+ LC_GET_PRIVILEGE_2, // 50405\r
+ LC_GET_PRIVILEGE_3, // 50406\r
+ LC_GET_FILE_OWNER_1, // 50407\r
+ LC_GET_FILE_OWNER_2, // 50408\r
+};\r
\r
/**\r
* Constructor.\r
* @param privilege the name of the privilege, e.g. "SeBackup"\r
* @param logger logger for error logging\r
*/\r
-bool ReDirStatus_t::getPrivilege(const char* privilege, ReLogger* logger){
- bool rc = false;
+bool ReDirStatus_t::getPrivilege(const char* privilege, ReLogger* logger){\r
+ bool rc = false;\r
LUID luidPrivilege;\r
HANDLE hAccessToken;\r
if (! OpenProcessToken (GetCurrentProcess(), \r
}\r
}\r
return rc;\r
-}
+}\r
#endif /* __WIN32__ */\r
\r
/**\r
HANDLE handle = INVALID_HANDLE_VALUE;\r
if (! isDirectory()){\r
if ( (handle = CreateFile(name, GENERIC_READ, FILE_SHARE_READ, NULL,\r
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) != INVALID_HANDLE_VALUE)\r
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE)\r
m_logger->sayF(LOG_ERROR | CAT_FILE, LC_RIGHTS_AS_STRING_1,\r
"CreateFile($1): $2").arg(name).arg((int) GetLastError()).end();\r
} else if (m_getPrivilege){\r