sox-devel@lists.sourceforge.net unofficial mirror
 help / color / mirror / code / Atom feed
* [Patch] Change to exit(0) for --help-format
@ 2019-12-13  1:21 Seth Troisi
  2019-12-16 11:51 ` Måns Rullgård
  0 siblings, 1 reply; 5+ messages in thread
From: Seth Troisi @ 2019-12-13  1:21 UTC (permalink / raw)
  To: sox-devel


[-- Attachment #1.1: Type: text/plain, Size: 176 bytes --]

exit(0) if --help-format <fmt> is found (or all).
continue to exit(1) if fmt is not found.

This is my first patch, let me know what I can do to make this happen.
Thanks,
Seth

[-- Attachment #1.2: Type: text/html, Size: 257 bytes --]

[-- Attachment #2: 0001-Change-exit-to-0-for-help-format-fmt-if-fmt-is-found.patch --]
[-- Type: text/x-patch, Size: 921 bytes --]

From 61fafa760a32f9ec1b096ff92ed4f39c1f9d95e7 Mon Sep 17 00:00:00 2001
From: Seth Troisi <sethtroisi@google.com>
Date: Thu, 12 Dec 2019 17:16:44 -0800
Subject: [PATCH] Change exit to 0 for --help-format <fmt> if fmt is found

---
 src/sox.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/sox.c b/src/sox.c
index 15f0df67..b5a827fc 100644
--- a/src/sox.c
+++ b/src/sox.c
@@ -2133,6 +2133,7 @@ static void usage_format(char const * name)
     if (!(f = sox_find_format(name, sox_false))) {
       printf("Cannot find a format called `%s'.\n", name);
       display_supported_formats();
+      exit(1);
     }
     else usage_format1(f);
   }
@@ -2143,7 +2144,7 @@ static void usage_format(char const * name)
         usage_format1(f);
     }
   }
-  exit(1);
+  exit(0);
 }
 
 static void read_comment_file(sox_comments_t * comments, char const * const filename)
-- 
2.24.1.735.g03f4e72817-goog


[-- Attachment #3: Type: text/plain, Size: 0 bytes --]



[-- Attachment #4: Type: text/plain, Size: 158 bytes --]

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] Change to exit(0) for --help-format
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Måns Rullgård @ 2019-12-16 11:51 UTC (permalink / raw)
  To: Seth Troisi; +Cc: sox-devel

Seth Troisi <braintwo@gmail.com> writes:

> exit(0) if --help-format <fmt> is found (or all).
> continue to exit(1) if fmt is not found.
>
> This is my first patch, let me know what I can do to make this happen.

Could you explain why you want to make this change?  What problem does
it solve?

> From 61fafa760a32f9ec1b096ff92ed4f39c1f9d95e7 Mon Sep 17 00:00:00 2001
> From: Seth Troisi <sethtroisi@google.com>
> Date: Thu, 12 Dec 2019 17:16:44 -0800
> Subject: [PATCH] Change exit to 0 for --help-format <fmt> if fmt is found
>
> ---
>  src/sox.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/sox.c b/src/sox.c
> index 15f0df67..b5a827fc 100644
> --- a/src/sox.c
> +++ b/src/sox.c
> @@ -2133,6 +2133,7 @@ static void usage_format(char const * name)
>      if (!(f = sox_find_format(name, sox_false))) {
>        printf("Cannot find a format called `%s'.\n", name);
>        display_supported_formats();
> +      exit(1);
>      }
>      else usage_format1(f);
>    }
> @@ -2143,7 +2144,7 @@ static void usage_format(char const * name)
>          usage_format1(f);
>      }
>    }
> -  exit(1);
> +  exit(0);
>  }
>  
>  static void read_comment_file(sox_comments_t * comments, char const * const filename)
> -- 
> 2.24.1.735.g03f4e72817-goog
>
>
> _______________________________________________
> SoX-devel mailing list
> SoX-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sox-devel
>

-- 
Måns Rullgård


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] Change to exit(0) for --help-format
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Seth Troisi @ 2019-12-16 18:13 UTC (permalink / raw)
  To: Måns Rullgård; +Cc: sox-devel


[-- Attachment #1.1: Type: text/plain, Size: 1849 bytes --]

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





On Mon, Dec 16, 2019 at 3:51 AM Måns Rullgård <mans@mansr.com> wrote:

> Seth Troisi <braintwo@gmail.com> writes:
>
> > exit(0) if --help-format <fmt> is found (or all).
> > continue to exit(1) if fmt is not found.
> >
> > This is my first patch, let me know what I can do to make this happen.
>
> Could you explain why you want to make this change?  What problem does
> it solve?
>
> > From 61fafa760a32f9ec1b096ff92ed4f39c1f9d95e7 Mon Sep 17 00:00:00 2001
> > From: Seth Troisi <sethtroisi@google.com>
> > Date: Thu, 12 Dec 2019 17:16:44 -0800
> > Subject: [PATCH] Change exit to 0 for --help-format <fmt> if fmt is found
> >
> > ---
> >  src/sox.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/src/sox.c b/src/sox.c
> > index 15f0df67..b5a827fc 100644
> > --- a/src/sox.c
> > +++ b/src/sox.c
> > @@ -2133,6 +2133,7 @@ static void usage_format(char const * name)
> >      if (!(f = sox_find_format(name, sox_false))) {
> >        printf("Cannot find a format called `%s'.\n", name);
> >        display_supported_formats();
> > +      exit(1);
> >      }
> >      else usage_format1(f);
> >    }
> > @@ -2143,7 +2144,7 @@ static void usage_format(char const * name)
> >          usage_format1(f);
> >      }
> >    }
> > -  exit(1);
> > +  exit(0);
> >  }
> >
> >  static void read_comment_file(sox_comments_t * comments, char const *
> const filename)
> > --
> > 2.24.1.735.g03f4e72817-goog
> >
> >
> > _______________________________________________
> > SoX-devel mailing list
> > SoX-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/sox-devel
> >
>
> --
> Måns Rullgård
>

[-- Attachment #1.2: Type: text/html, Size: 2809 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



[-- Attachment #3: Type: text/plain, Size: 158 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] Change to exit(0) for --help-format
  2019-12-16 18:13   ` Seth Troisi
@ 2019-12-17 12:01     ` Måns Rullgård
  2019-12-17 18:43       ` Seth Troisi
  0 siblings, 1 reply; 5+ messages in thread
From: Måns Rullgård @ 2019-12-17 12:01 UTC (permalink / raw)
  To: Seth Troisi; +Cc: sox-devel

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] Change to exit(0) for --help-format
  2019-12-17 12:01     ` Måns Rullgård
@ 2019-12-17 18:43       ` Seth Troisi
  0 siblings, 0 replies; 5+ messages in thread
From: Seth Troisi @ 2019-12-17 18:43 UTC (permalink / raw)
  To: Måns Rullgård; +Cc: sox-devel


[-- Attachment #1.1: Type: text/plain, Size: 3367 bytes --]

I'd be surprised to find someone depending on an exit status that is
constant (e.g. if (false) { effectively dead code };)
I like the new names in your patch, they are descriptive of what the flag
does which is nice.
I'm happy with either patch, both of which will satisfies my use case.

Thanks for considering.

On Tue, Dec 17, 2019 at 4:01 AM Måns Rullgård <mans@mansr.com> wrote:

> 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
>

[-- Attachment #1.2: Type: text/html, Size: 4365 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



[-- Attachment #3: Type: text/plain, Size: 158 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-12-17 18:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-12-17 18:43       ` Seth Troisi

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).