1
0
mirror of https://git.disroot.org/80486DX2-66/polonium.git synced 2024-12-26 07:09:50 +05:30

Merge branch 'main' into load_into_mem

This commit is contained in:
Intel A80486DX2-66 2024-11-24 12:16:40 +03:00
commit 6bc3de42b4
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B
3 changed files with 26 additions and 11 deletions

View File

@ -106,8 +106,4 @@ typedef off_t file_offset_t;
#define SET_CONFIG(x) config |= (x) #define SET_CONFIG(x) config |= (x)
#define CLEAR_CONFIG(x) config &= ~(x) #define CLEAR_CONFIG(x) config &= ~(x)
#define LOOP_ACTION_CONFIG(f, x) \
f(x); \
continue
#endif /* _COMMON_H */ #endif /* _COMMON_H */

View File

@ -18,6 +18,7 @@ const size_t UINT16_MAX_PLUS_1 = UINT16_MAX + 1;
/* function definitions */ /* function definitions */
static bool get_chance(uint16_t desired_chance); static bool get_chance(uint16_t desired_chance);
static bool is_line_ending(byte c); static bool is_line_ending(byte c);
static enum Interoperation_Result corrupt_byte(Interoperation_Input_Vars);
/* function implementations */ /* function implementations */
static bool get_chance(uint16_t desired_chance) { static bool get_chance(uint16_t desired_chance) {

View File

@ -186,12 +186,15 @@ static bool args_match(const char* arg, const char* args_list[]) {
int main(int argc, char** argv) { int main(int argc, char** argv) {
puts("Polonium: a file corrupter\n"); 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]); char* program_name = my_basename(argv[0]);
printf( printf(
"Usage: %s <file to corrupt> [parameters] [options]\n" "Usage: %s <file to corrupt> [parameters] [options]\n"
" OR\n" " OR\n"
" %s <-h | -help | --help>\n" " %s <-h | -help | --help>\n"
" OR\n"
" %s -- <file to corrupt: -h | -help | --help> [parameters] [options]\n"
"\n" "\n"
"Both parameters and options are optional.\n" "Both parameters and options are optional.\n"
"\n" "\n"
@ -230,6 +233,7 @@ int main(int argc, char** argv) {
" random, set the option to `random`.\n" " random, set the option to `random`.\n"
"\n" "\n"
" -verbose : Enable verbose output\n", " -verbose : Enable verbose output\n",
program_name,
program_name, program_name,
program_name, program_name,
UINT16_MAX, UINT16_MAX,
@ -243,14 +247,23 @@ int main(int argc, char** argv) {
return EXIT_FAILURE; 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]; 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; file_type_t file_type = FILE_TYPE_AUTO;
if (argc > 2) { if (argc > 2) {
uint8_t arg_destination = ARG_NO_DEST; uint8_t arg_destination = ARG_NO_DEST;
bool read_off_value = false; 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); bool last_arg = i == (argc - 1);
#define arg argv[i] #define arg argv[i]
@ -270,15 +283,20 @@ int main(int argc, char** argv) {
else if (ARG_MATCH(arg, ARG_SEED)) else if (ARG_MATCH(arg, ARG_SEED))
arg_destination = ARG_DEST_SEED; arg_destination = ARG_DEST_SEED;
else if (ARG_MATCH(arg, ARG_NOCONFIRM)) { else if (ARG_MATCH(arg, ARG_NOCONFIRM)) {
LOOP_ACTION_CONFIG(CLEAR_CONFIG, C_CONFIRM); CLEAR_CONFIG(C_CONFIRM);
continue;
} else if (ARG_MATCH(arg, ARG_CONTENTS)) { } else if (ARG_MATCH(arg, ARG_CONTENTS)) {
LOOP_ACTION_CONFIG(SET_CONFIG, C_CONTENTS); SET_CONFIG(C_CONTENTS);
continue;
} else if (ARG_MATCH(arg, ARG_LINE_ENDINGS)) { } else if (ARG_MATCH(arg, ARG_LINE_ENDINGS)) {
LOOP_ACTION_CONFIG(SET_CONFIG, C_LINE_ENDINGS); SET_CONFIG(C_LINE_ENDINGS);
continue;
} else if (ARG_MATCH(arg, ARG_PRINTABLE)) { } else if (ARG_MATCH(arg, ARG_PRINTABLE)) {
LOOP_ACTION_CONFIG(SET_CONFIG, C_PRINTABLE); SET_CONFIG(C_PRINTABLE);
continue;
} else if (ARG_MATCH(arg, ARG_VERBOSE)) { } else if (ARG_MATCH(arg, ARG_VERBOSE)) {
LOOP_ACTION_CONFIG(SET_CONFIG, C_VERBOSE); SET_CONFIG(C_VERBOSE);
continue;
} else } else
FATAL_ERROR_RET("Unknown command line parameter '%s'.\n" FATAL_ERROR_RET("Unknown command line parameter '%s'.\n"
"Please invoke the program with argument %s to " "Please invoke the program with argument %s to "