shithub: sox

Download patch

ref: a994f4f597199b0da50e51edab34d4375ad47b19
parent: 339d38d10cbcf13f72694d9503e02d691f673e6c
author: Ulrich Klauer <ulrich@chirlu.de>
date: Mon Sep 26 11:49:34 EDT 2011

Reuse --interactive option for interactive mode

Allow user to enter interactive mode when SoX wouldn't do so normally, by
specifying --interactive.

--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,13 @@
 sox-14.4.0	20xx-xx-xx
 ----------
 
+Previously deprecated features that have been removed in this release:
+
+  Deprec-  Feature    [O(ption)]
+  ated in  [F(ormat)] [E(ffect)]   Replacement
+  -------  ----------------------  ----------------------
+  14.3.0   O --interactive         --no-clobber
+
 File formats:
 
   o Mention in man pages that WAV files support floating point encodings.
--- a/sox.1
+++ b/sox.1
@@ -864,9 +864,6 @@
 behave as
 .BR soxi (1).
 .TP
-\fB\-\-interactive\fR
-Deprecated alias for \fB\-\-no\-clobber\fR.
-.TP
 \fB\-m\fR\^|\^\fB\-M\fR
 Equivalent to \fB\-\-combine mix\fR and \fB\-\-combine merge\fR, respectively.
 .TP
--- a/src/sox.c
+++ b/src/sox.c
@@ -203,6 +203,7 @@
 #ifdef HAVE_TERMIOS_H
 #include <termios.h>
 static struct termios original_termios;
+static sox_bool original_termios_saved = sox_false;
 #endif
 
 static sox_bool stdin_is_a_tty, is_player, is_guarded, do_guarded_norm, no_dither, reported_sox_opts;
@@ -239,7 +240,7 @@
   }
 
 #ifdef HAVE_TERMIOS_H
-  if (interactive)
+  if (original_termios_saved)
     tcsetattr(fileno(stdin), TCSANOW, &original_termios);
 #endif
 
@@ -1666,18 +1667,31 @@
   optimize_trim();
 
 #if defined(HAVE_TERMIOS_H) || defined(HAVE_CONIO_H)
-  /* so we can be fully interactive. */
-  if (show_progress && !interactive && is_player && stdin_is_a_tty) {
+  if (stdin_is_a_tty) {
+    if (show_progress && is_player && !interactive) {
+      lsx_debug("automatically entering interactive mode");
+      interactive = sox_true;
+    }
+  } else if (interactive) {
+    /* User called for interactive mode, but ... */
+    lsx_warn("Standard input has to be a terminal for interactive mode");
+    interactive = sox_false;
+  }
+#endif
 #ifdef HAVE_TERMIOS_H
+  /* Prepare terminal for interactive mode and save the original termios
+     settings. Do this only once, otherwise the "original" settings won't
+     be original anymore after a second call to process() (next/restarted
+     effects chain). */
+  if (interactive && !original_termios_saved) {
     struct termios modified_termios;
 
+    original_termios_saved = sox_true;
     tcgetattr(fileno(stdin), &original_termios);
     modified_termios = original_termios;
     modified_termios.c_lflag &= ~(ICANON | ECHO);
     modified_termios.c_cc[VMIN] = modified_termios.c_cc[VTIME] = 0;
     tcsetattr(fileno(stdin), TCSANOW, &modified_termios);
-#endif
-    interactive = sox_true;
   }
 #endif
 
@@ -2229,7 +2243,13 @@
         sox_globals.input_bufsiz = i;
         break;
 
-      case 7: no_clobber = sox_true; break;
+      case 7:
+#if defined(HAVE_TERMIOS_H) || defined(HAVE_CONIO_H)
+        interactive = sox_true; break;
+#else
+        lsx_fail("Interactive mode has not been enabled at compile time.");
+        exit(1); break;
+#endif
       case 8: usage_effect(optstate.arg); break;
       case 9: usage_format(optstate.arg); break;
       case 10: f->no_glob = sox_true; break;