shithub: sox

Download patch

ref: f8a42f45b72f991fcac0afb3aa4fc552ac3be15c
parent: faca3a328fef437f119ab0b3b5dc2fd697ab8565
author: robs <robs>
date: Sat Feb 7 02:11:59 EST 2009

use --magic to enable libmagic

--- a/ChangeLog
+++ b/ChangeLog
@@ -98,6 +98,8 @@
   o Can now use `u' & `d' keys to adjust volume whilst playing audio (on some
     systems).  (robs)
   o New bitrate, time in seconds, & total options for soxi.  (robs)
+  o `Magic' (libmagic) file type detection now selected using `--magic'
+    option (where supported).
 
 Other bug fixes:
 
--- a/sox.1
+++ b/sox.1
@@ -728,6 +728,10 @@
 See \fBInput File Combining\fR above for a description of the different
 combining methods.
 .TP
+.B \-\-magic
+If SoX has been built with the optional `libmagic' library, then this
+option can be given to enable its use in helping to detect audio file types.
+.TP
 \fB\-D\fR, \fB\-\-no\-dither\fR
 SoX, by default, automatically invokes the dither effect (with TPDF) when reducing
 bit-depth.  This option can be given to prevent this behaviour.
--- a/src/formats.c
+++ b/src/formats.c
@@ -418,7 +418,7 @@
       filetype = detect_format(ft, lsx_find_file_extension(path));
       lsx_rewind(ft);
 #if HAVE_MAGIC
-      if (!filetype) {
+      if (sox_globals.use_magic && !filetype) {
         static magic_t magic;
         if (!magic) {
           magic = magic_open(MAGIC_MIME | MAGIC_SYMLINK);
--- a/src/libsox.c
+++ b/src/libsox.c
@@ -52,7 +52,8 @@
   NULL,            /* char const * stdin_in_use_by */
   NULL,            /* char const * stdout_in_use_by */
   NULL,            /* char const * subsystem */
-  NULL             /* char       * tmp_path */
+  NULL,            /* char       * tmp_path */
+  sox_false        /* sox_bool     use_magic */
 };
 
 char const * sox_strerror(int sox_errno)
--- a/src/sox.c
+++ b/src/sox.c
@@ -1742,6 +1742,7 @@
 "--interactive            Prompt to overwrite output file",
 "-m, --combine mix        Mix multiple input files (instead of concatenating)",
 "-M, --combine merge      Merge multiple input files (instead of concatenating)",
+"--magic                  Use `magic' file-type detection",
 "--norm                   Guard (see --guard) & normalise",
 "--plot gnuplot|octave    Generate script to plot response of filter effect",
 "-q, --no-show-progress   Run in quiet mode; opposite of -S",
@@ -1954,6 +1955,7 @@
     {"single-threaded" ,       no_argument, NULL, 0},
     {"ignore-length"   ,       no_argument, NULL, 0},
     {"norm"            ,       no_argument, NULL, 0},
+    {"magic"           ,       no_argument, NULL, 0},
 
     {"bits"            , required_argument, NULL, 'b'},
     {"channels"        , required_argument, NULL, 'c'},
@@ -2120,6 +2122,11 @@
       case 17: single_threaded = sox_true; break;
       case 18: f->signal.length = SOX_IGNORE_LENGTH; break;
       case 19: do_guarded_norm = is_guarded = sox_true; break;
+#if HAVE_MAGIC
+      case 20: sox_globals.use_magic = sox_true; break;
+#else
+      case 20: lsx_warn("this build of SoX does not include `magic'"); break;
+#endif
       }
       break;
 
--- a/src/sox.h
+++ b/src/sox.h
@@ -181,6 +181,7 @@
   char const * stdout_in_use_by;
   char const * subsystem;
   char       * tmp_path;
+  sox_bool     use_magic;
 } sox_globals_t;
 extern sox_globals_t sox_globals;