arg parsing for IP

lean
Avril 4 years ago
parent d5b4ff0f38
commit 3dd8abc461
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -20,9 +20,10 @@ extern "C" {
#define dprintf(fmt, ...) #define dprintf(fmt, ...)
#endif #endif
extern const char* _prog_name;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _SHUFFLE3_H */ #endif /* _SHUFFLE3_H */

@ -11,26 +11,62 @@
#include <rng.h> #include <rng.h>
#include <work.h> #include <work.h>
#define noreturn __attribute__((noreturn)) void
_Static_assert(sizeof(float)==sizeof(uint32_t), "float is not 32 bits"); _Static_assert(sizeof(float)==sizeof(uint32_t), "float is not 32 bits");
const char* _prog_name;
noreturn help_then_exit()
{
fprintf(stderr, "Try passing `-h`\n");
exit(1);
}
void usage()
{
printf( "shuffle3 - 3 pass binary shuffler\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");
}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
//struct prog_args args = {.argc = argc, .argv = argv}; _prog_name = argv[0];
//rng_test(); work_args_t parsed;
//rng_t r = rng_new(RNG_INIT(RNG_KIND_FRNG, frng = { { 1.0, 2.0 } })); if( !argv[1] || *(argv[1]) != '-') help_then_exit();
//rng_test_spec(r);
//rng_free(r);
if( argv[1] ) { switch(argv[1][1])
//map_and_then(argv[1], &map_callback, &args); {
return do_work((work_args_t) { case 's':
.op = OP_SHUFFLE_IP, parsed.op = OP_SHUFFLE_IP;
.data.op_shuffle_ip.file = argv[1], if(!(parsed.data.op_shuffle_ip.file = argv[2]))
}); {
fprintf(stderr, "Error: -s expected file argument.\n");
return 1;
}
break;
case 'u':
parsed.op = OP_UNSHUFFLE_IP;
if(!(parsed.data.op_unshuffle_ip.file = argv[2]))
{
fprintf(stderr, "Error: -u expected file argument.\n");
return 1;
}
break;
case 'h':
usage();
return 0;
default:
fprintf(stderr, "Error: unknown argument `%s'\n\n", argv[1]);
help_then_exit();
} }
return 0; return do_work(parsed);
} }

Loading…
Cancel
Save