m_lastError()
{
m_properties.setCapacity(64, 64*8, 64*1024);
+ ReByteBuffer line;
for (const char** argv = usageList; *argv != NULL; argv++){
- m_usage.add(-1, *argv, -1);
+ line.set(*argv);
+ if (line.endsWith("\n"))
+ line.setLength(line.length() - 1);
+ m_usage.append(line.str());
}
if (examples != NULL){
for (const char** argv = examples; *argv != NULL; argv++){
{
m_usage.split(usageString, '\n');
if (examples != NULL){
- if (strstr(examples, "$0") != NULL)
+ if (strstr(examples, "$0") == NULL)
m_examples.split(examples, '\n');
else{
ReByteBuffer line;
}
void createExpectedShortHelp(const char* filename){
createFile(filename,
-"test <opts> <args>This tests the usage of ReProgramArg\n"
-"This tests the usage of ReProgramArg\n"
+"test <opts> <args>\n"
+"This tests the usage of ReProgramArgs\n"
"\n"
"<options>:\n"
"-B or --boolval2\n"
"-u<not empty string> or --string2=<not empty string> Default value: 'undef'\n"
" This 2nd string must be non empty\n"
"Example(s):\n"
-"$0 -b+ -B- file dir\ttest of an exampl+++ Not really an error!\n"
-"\ttest of an exampl+++ Not really an error!\n"
+"? -b+ -B- file dir\n"
+"\ttest of an example\n"
"+++ Not really an error!\n"
);
}
}
void createExpectedLongHelp(const char* filename){
createFile(filename,
-"test <opts> <argsThis tests the usage of ReProgramArg\n"
-"This tests the usage of ReProgramArg\n"
+"test <opts> <args>\n"
+"This tests the usage of ReProgramArgs\n"
"\n"
"<options>:\n"
"--boolval2\n"
"If the first character is '-' the pattern is a 'not pattern':\n"
"A directory will be entered if at least one of the positive patterns\n"
"and none of the 'not patterns' matches\n"
- "examples: ';*;-*/.git/' ',*/cache/,*/temp/"),
+ "examples:\n"
+ "';*/music/;pic*' enters music and xy/Music and PIC and pictures but not xy/pic and img\n"
+ "';*;-*/.git;.hg' ignores .git and xy/z/.git and .ht, but enters xy/.hg"),
'P', "path-pattern", false, NULL);
m_programArgs.addString("nodepattern",
i18n("a list of patterns for the basename (name without path) separated by ';'\n"
m_programArgs.help(msg.str(), false, stdout);
exit(1);
}
+
/**
* Checks the correctness of the standard filter options.
*
memset(m_compoundUsage, 0, size);
m_countCompoundUsage = count;
}
+
+/**
+ * Optimizes the path patterns.
+ *
+ * For all patterns of the list:
+ * <ul><li>remove a trailing "\" and "\*"</li>
+ * <li>change "*\xy" to "*\xy" and "xy" (finds xy in the root directory)</li>
+ * <li>replaces "/" with the os specific path separator</li>
+ * </ul>
+ *
+ * @param buffer the pattern list as string, e.g. ";*;-cache"
+ */
+void ReDirOptions::optimizePathPattern(ReByteBuffer& buffer){
+ ReStringList list;
+ ReStringList rootList;
+ list.split(buffer.str() + 1, buffer.str()[0]);
+ buffer.replaceAll(OS_SEPARATOR, 1, "/", 1);
+ ReByteBuffer item;
+ for (int ix = 0; ix < list.count(); ix++){
+ item.set(list.strOf(ix), -1);
+ if (item.endsWith("/*"))
+ item.setLength(item.length() - 2);
+ if (item.endsWith("/"))
+ item.setLength(item.length() - 1);
+ bool notAnchored = item.startsWith("*/") || item.startsWith("-*/");
+ item.replaceAll("/", 1, OS_SEPARATOR, 1);
+ list.replace(ix, item.str());
+ if (notAnchored){
+ item.remove(item.str()[0] == '-' ? 1 : 0, 2);
+ rootList.append(item.str(), 0);
+ }
+ }
+ if (rootList.count() > 0)
+ list.append(rootList);
+ item.set(buffer.str(), 1);
+ list.join(item.str(), buffer);
+}
/**
* Sets the standard filter options given by the program arguments.
*
}
if (m_programArgs.getString("pathpattern", buffer)[0] != '\0'){
checkPatternList(buffer.str());
+ optimizePathPattern(buffer);
m_pathPatterns.set(buffer.str());
filter.m_pathPatterns = &m_pathPatterns;
}