Skip to content

Commit 4eb0839

Browse files
committed
Make cmdline switches friendlier to Unix absolute paths
1 parent 482ef03 commit 4eb0839

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

source/common.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,19 @@ class cmdline_processor
322322
if (arg.text.empty()) {
323323
continue;
324324
}
325+
326+
// Provide a way to ignore the rest of the command line
327+
// for the purpose of looking for switches
328+
if (arg.text == "--") {
329+
arg.pos = processed;
330+
break;
331+
}
332+
325333
for (auto& flag : flags) {
334+
auto length_to_match = std::max(flag.unique_prefix, as<int>(arg.text.length())-1);
326335
// Allow a switch to start with either - or /
327-
if (arg.text.starts_with("-" + flag.name.substr(0, flag.unique_prefix)) ||
328-
arg.text.starts_with("/" + flag.name.substr(0, flag.unique_prefix)) ||
336+
if (arg.text.starts_with("-" + flag.name.substr(0, length_to_match)) ||
337+
arg.text.starts_with("/" + flag.name.substr(0, length_to_match)) ||
329338
arg.text == "-" + flag.synonym ||
330339
arg.text == "/" + flag.synonym
331340
)
@@ -335,11 +344,15 @@ class cmdline_processor
335344
break;
336345
}
337346
}
338-
if (arg.pos != processed && (arg.text.starts_with("-") || arg.text.starts_with("/"))) {
339-
arg.pos = processed;
340-
print("Unknown option: " + arg.text + " (try -help)\n");
341-
help_requested = true;
342-
}
347+
348+
// For now comment this out to try leaving unmatched switches alone, so that
349+
// Unix absolute filenames work... and in case an absolute filename collides
350+
// with a legit switch name, also added "--" above... let's see how this works
351+
//if (arg.pos != processed && (arg.text.starts_with("-") || arg.text.starts_with("/"))) {
352+
// arg.pos = processed;
353+
// print("Unknown option: " + arg.text + " (try -help)\n");
354+
// help_requested = true;
355+
//}
343356
}
344357

345358
std::erase_if( args, [=](auto& arg){ return arg.pos == processed; } );

0 commit comments

Comments
 (0)