From b9dbaf104921b07f1181f2eb7ee441d20a568a41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Sun, 11 Nov 2018 11:35:05 -0500 Subject: [PATCH] finish moving the argv checks to cli --- src/cli.cc | 14 +++++++++++++- src/opustags.cc | 22 +++++----------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/cli.cc b/src/cli.cc index 8a69098..2c2f2f6 100644 --- a/src/cli.cc +++ b/src/cli.cc @@ -120,7 +120,7 @@ ot::status ot::process_options(int argc, char** argv, ot::options& opt) return status::exit_now; } if (optind != argc - 1) { - fputs("invalid arguments\n", stderr); + fputs("exactly one input file must be specified\n", stderr); return status::bad_arguments; } opt.path_in = argv[optind]; @@ -128,6 +128,18 @@ ot::status ot::process_options(int argc, char** argv, ot::options& opt) fputs("input's file path cannot be empty\n", stderr); return status::bad_arguments; } + if (opt.inplace != nullptr && !opt.path_out.empty()) { + fputs("cannot combine --in-place and --output\n", stderr); + return status::bad_arguments; + } + if (opt.path_in == "-" && opt.set_all) { + fputs("can't open stdin for input when -S is specified\n", stderr); + return status::bad_arguments; + } + if (opt.path_in == "-" && opt.inplace) { + fputs("cannot modify stdin in-place\n", stderr); + return status::bad_arguments; + } return status::ok; } diff --git a/src/opustags.cc b/src/opustags.cc index a908ccd..7d4ea9b 100644 --- a/src/opustags.cc +++ b/src/opustags.cc @@ -29,10 +29,6 @@ static void print_tags(ot::opus_tags &tags) static int run(ot::options& opt) { - if (opt.inplace != nullptr && !opt.path_out.empty()) { - fputs("cannot combine --in-place and --output\n", stderr); - return EXIT_FAILURE; - } if (!opt.path_out.empty() && opt.path_in != "-" && opt.path_out != "-") { char canon_in[PATH_MAX+1], canon_out[PATH_MAX+1]; if (realpath(opt.path_in.c_str(), canon_in) && realpath(opt.path_out.c_str(), canon_out)) { @@ -45,21 +41,13 @@ static int run(ot::options& opt) ot::ogg_reader reader; ot::ogg_writer writer; if (opt.path_in == "-") { - if (opt.set_all) { - fputs("can't open stdin for input when -S is specified\n", stderr); - return EXIT_FAILURE; - } - if (opt.inplace) { - fputs("cannot modify stdin in-place\n", stderr); - return EXIT_FAILURE; - } reader.file = stdin; - } - else + } else { reader.file = fopen(opt.path_in.c_str(), "r"); - if(!reader.file){ - perror("fopen"); - return EXIT_FAILURE; + if (reader.file == nullptr) { + perror("fopen"); + return EXIT_FAILURE; + } } writer.file = NULL; if (opt.inplace != nullptr)