You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shuffle3/src/main.c

84 lines
1.7 KiB

4 years ago
#include <stdlib.h>
5 years ago
#include <stdio.h>
4 years ago
#include <string.h>
5 years ago
4 years ago
#include <shuffle3.h>
#include <panic.h>
#include <reinterpret.h>
#include <map.h>
5 years ago
#include <rng.h>
4 years ago
#include <work.h>
5 years ago
4 years ago
#include <debug.h>
4 years ago
#define noreturn __attribute__((noreturn)) void
4 years ago
_Static_assert(sizeof(float)==sizeof(uint32_t), "float is not 32 bits");
5 years ago
4 years ago
const char* _prog_name;
5 years ago
extern void _fb_run_tests();
4 years ago
noreturn help_then_exit()
5 years ago
{
4 years ago
fprintf(stderr, "Try passing `-h`\n");
exit(1);
5 years ago
}
4 years ago
void usage()
5 years ago
{
4 years ago
printf( "shuffle3-lean - improved 3 pass binary shuffler\n"
" written by Avril <flanchan@cumallover.me> (flanchan.moe) with <3\n"
" licensed with GPL v3.0 or later\n\n"
"Usage: %s -s <file>\n"
"Usage: %s -u <file>\n", _prog_name, _prog_name);
printf("\nOPTIONS:\n"
" -s\tShuffle file in place\n"
" -u\tUnshuffle file in place\n");
5 years ago
}
4 years ago
int main(int argc, char** argv)
5 years ago
{
4 years ago
_prog_name = argv[0];
5 years ago
//_fb_run_tests();
4 years ago
work_args_t parsed;
5 years ago
4 years ago
if( !argv[1] || *(argv[1]) != '-') help_then_exit();
4 years ago
4 years ago
D_dprintf("Parsing `%c'", argv[1][1]);
switch(argv[1][1])
{
4 years ago
case 's':
parsed.op = OP_SHUFFLE_IP;
if(!(parsed.data.op_shuffle_ip.file = argv[2]))
{
4 years ago
fprintf(stderr, "Error: -s expected file argument.\n");
5 years ago
return 1;
}
4 years ago
D_dprintf("parsed.op = %d", OP_SHUFFLE_IP);
break;
case 'u':
parsed.op = OP_UNSHUFFLE_IP;
if(!(parsed.data.op_unshuffle_ip.file = argv[2]))
5 years ago
{
4 years ago
fprintf(stderr, "Error: -u expected file argument.\n");
return 1;
5 years ago
}
4 years ago
D_dprintf("parsed.op = %d", OP_UNSHUFFLE_IP);
break;
case 'h':
usage();
return 0;
default:
fprintf(stderr, "Error: unknown argument `%s'\n\n", argv[1]);
help_then_exit();
panic("Unreachable");
}
5 years ago
4 years ago
return do_work(parsed);
5 years ago
}
4 years ago