diff options
author | Max Kellermann <max@musicpd.org> | 2020-03-11 20:03:00 +0100 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-03-12 21:40:27 +0100 |
commit | de0affe1157a7852adca5c71391136befe8024a5 (patch) | |
tree | 5854b5ae0e3132d52a5686ac113e8233542e3cd1 | |
parent | 26e718c7c38b4e8f69c995b2c6e95be25acca733 (diff) |
test/run_convert: move code to ParseCommandLine()
-rw-r--r-- | test/run_convert.cxx | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/test/run_convert.cxx b/test/run_convert.cxx index 9bb8592c4..734e2c918 100644 --- a/test/run_convert.cxx +++ b/test/run_convert.cxx @@ -28,32 +28,47 @@ #include "pcm/Convert.hxx" #include "util/ConstBuffer.hxx" #include "util/StaticFifoBuffer.hxx" +#include "util/OptionParser.hxx" #include "util/PrintException.hxx" +#include <stdexcept> + #include <assert.h> #include <stddef.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> -int -main(int argc, char **argv) -try { - if (argc != 3) { - fprintf(stderr, - "Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT\n"); - return 1; +struct CommandLine { + AudioFormat in_audio_format, out_audio_format; +}; + +static CommandLine +ParseCommandLine(int argc, char **argv) +{ + CommandLine c; + + OptionParser option_parser(nullptr, argc, argv); + while (option_parser.Next()) { } - const auto in_audio_format = ParseAudioFormat(argv[1], false); - const auto out_audio_format_mask = ParseAudioFormat(argv[2], false); + auto args = option_parser.GetRemaining(); + if (args.size != 2) + throw std::runtime_error("Usage: run_convert IN_FORMAT OUT_FORMAT <IN >OUT"); - const auto out_audio_format = - in_audio_format.WithMask(out_audio_format_mask); + c.in_audio_format = ParseAudioFormat(args[0], false); + c.out_audio_format = c.in_audio_format.WithMask(ParseAudioFormat(args[1], false)); + return c; +} + +int +main(int argc, char **argv) +try { + const auto c = ParseCommandLine(argc, argv); - const size_t in_frame_size = in_audio_format.GetFrameSize(); + const size_t in_frame_size = c.in_audio_format.GetFrameSize(); - PcmConvert state(in_audio_format, out_audio_format); + PcmConvert state(c.in_audio_format, c.out_audio_format); StaticFifoBuffer<uint8_t, 4096> buffer; |