sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Seth Troisi <braintwo@gmail.com>
Cc: sox-devel@lists.sourceforge.net
Subject: Re: [Patch] Change to exit(0) for --help-format
Date: Tue, 17 Dec 2019 12:01:56 +0000	[thread overview]
Message-ID: <yw1xa77rw47f.fsf@mansr.com> (raw)
In-Reply-To: <CAEvcHoCfgv1GTcGmZS6+JqW6FxpQLpBqt=SoKXGqTqNx4BTG3g@mail.gmail.com> (Seth Troisi's message of "Mon, 16 Dec 2019 10:13:53 -0800")

Seth Troisi <braintwo@gmail.com> writes:

> I'd like to know if the mp3 format is supported from python.
> it's much easier to check an exit code than to grep over stdout for a string

I'd rather not change things unnecessarily in case there's someone
relying on the current behaviour.

How about this instead?

From 24f71c24ce62d7ea18e5480ab2544b429b652e14 Mon Sep 17 00:00:00 2001
From: Mans Rullgard <mans@mansr.com>
Date: Tue, 17 Dec 2019 12:00:32 +0000
Subject: [PATCH] add --check-read and --check-write options

---
 src/sox.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/sox.c b/src/sox.c
index 0b103e269092..ffb5d9984f7b 100644
--- a/src/sox.c
+++ b/src/sox.c
@@ -1941,6 +1941,8 @@ static void usage(char const * message)
 "GLOBAL OPTIONS (gopts) (can be specified at any point before the first effect):",
 "--buffer BYTES           Set the size of all processing buffers (default 8192)",
 "--clobber                Don't prompt to overwrite output file (default)",
+"--check-read NAME        Check if format NAME can be read",
+"--check-write NAME       Check if format NAME can be written",
 "--combine concatenate    Concatenate all input files (default for sox, rec)",
 "--combine sequence       Sequence all input files (default for play)",
 "-D, --no-dither          Don't dither automatically",
@@ -2146,6 +2148,23 @@ static void usage_format(char const * name)
   exit(1);
 }
 
+static void check_format(const char *fmt, sox_bool write)
+{
+  const sox_format_handler_t *f = sox_find_format(fmt, sox_false);
+  sox_bool ok = sox_false;
+
+  if (f) {
+    if (write)
+      ok = f->startwrite || f->write;
+    else
+      ok = f->startread || f->read;
+  }
+
+  printf("%s %s: %s\n", fmt, write ? "write" : "read", ok ? "yes" : "no");
+
+  exit(!ok);
+}
+
 static void read_comment_file(sox_comments_t * comments, char const * const filename)
 {
   int c;
@@ -2209,6 +2228,8 @@ static struct lsx_option_t const long_options[] = {
   {"no-clobber"      , lsx_option_arg_none    , NULL, 0},
   {"multi-threaded"  , lsx_option_arg_none    , NULL, 0},
   {"dft-min"         , lsx_option_arg_required, NULL, 0},
+  {"check-read"      , lsx_option_arg_required, NULL, 0},
+  {"check-write"     , lsx_option_arg_required, NULL, 0},
 
   {"bits"            , lsx_option_arg_required, NULL, 'b'},
   {"channels"        , lsx_option_arg_required, NULL, 'c'},
@@ -2402,6 +2423,8 @@ static char parse_gopts_and_fopts(file_t * f)
         }
         sox_globals.log2_dft_min_size = i;
         break;
+      case 26: check_format(optstate.arg, sox_false); break;
+      case 27: check_format(optstate.arg, sox_true); break;
       }
       break;
 
-- 
2.24.1



-- 
Måns Rullgård


_______________________________________________
SoX-devel mailing list
SoX-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sox-devel

  reply	other threads:[~2019-12-17 12:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13  1:21 [Patch] Change to exit(0) for --help-format Seth Troisi
2019-12-16 11:51 ` Måns Rullgård
2019-12-16 18:13   ` Seth Troisi
2019-12-17 12:01     ` Måns Rullgård [this message]
2019-12-17 18:43       ` Seth Troisi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.sourceforge.net/lists/listinfo/sox-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yw1xa77rw47f.fsf@mansr.com \
    --to=sox-devel@lists.sourceforge.net \
    --cc=braintwo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/sox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).