mirror of
https://git.disroot.org/80486DX2-66/polonium.git
synced 2024-12-28 08:00:33 +05:30
feature: support file paths that resemble help options
This commit is contained in:
parent
44bc736d96
commit
078590846a
17
src/main.c
17
src/main.c
@ -186,12 +186,15 @@ static bool args_match(const char* arg, const char* args_list[]) {
|
||||
int main(int argc, char** argv) {
|
||||
puts("Polonium: a file corrupter\n");
|
||||
|
||||
if (argc < 2 || args_match(argv[argc - 1], ARGS_HELP)) {
|
||||
if (!(argc > 2 && !strcmp(argv[1], "--")) &&
|
||||
(argc < 2 || args_match(argv[argc - 1], ARGS_HELP))) {
|
||||
char* program_name = my_basename(argv[0]);
|
||||
printf(
|
||||
"Usage: %s <file to corrupt> [parameters] [options]\n"
|
||||
" OR\n"
|
||||
" %s <-h | -help | --help>\n"
|
||||
" OR\n"
|
||||
" %s -- <file to corrupt: -h | -help | --help> [parameters] [options]\n"
|
||||
"\n"
|
||||
"Both parameters and options are optional.\n"
|
||||
"\n"
|
||||
@ -230,6 +233,7 @@ int main(int argc, char** argv) {
|
||||
" random, set the option to `random`.\n"
|
||||
"\n"
|
||||
" -verbose : Enable verbose output\n",
|
||||
program_name,
|
||||
program_name,
|
||||
program_name,
|
||||
UINT16_MAX,
|
||||
@ -243,14 +247,23 @@ int main(int argc, char** argv) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int arg_position = 2;
|
||||
|
||||
/* Allow passing file paths that resemble help options by using the help
|
||||
* option delimiter (`--`). */
|
||||
const char* file_path = argv[1];
|
||||
if (argc > 2 && !strcmp(argv[1], "--")) {
|
||||
file_path = argv[2];
|
||||
arg_position++;
|
||||
}
|
||||
|
||||
file_type_t file_type = FILE_TYPE_AUTO;
|
||||
|
||||
if (argc > 2) {
|
||||
uint8_t arg_destination = ARG_NO_DEST;
|
||||
bool read_off_value = false;
|
||||
|
||||
for (int i = 2; i < argc; ++i) {
|
||||
for (int i = arg_position; i < argc; ++i) {
|
||||
bool last_arg = i == (argc - 1);
|
||||
|
||||
#define arg argv[i]
|
||||
|
Loading…
Reference in New Issue
Block a user