ref: df65582ea2b332660bdebe3ef0751473ed557295
parent: e4f8d65998444f8930823ed6f2a5ba5bec169244
author: robs <robs>
date: Mon Dec 29 04:49:33 EST 2008
sox_strerror
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -140,7 +140,7 @@
if (rate == 0)
{
- lsx_fail_errno(ft, SOX_ERATE, "Invalid sample rate");
+ lsx_fail_errno(ft, SOX_EHDR, "Invalid sample rate");
return(SOX_EOF);
}
if (strncmp(buf,"BODY",(size_t)4) != 0)
--- a/src/libsox.c
+++ b/src/libsox.c
@@ -43,13 +43,35 @@
}
sox_globals_t sox_globals = {
- 2,
- output_message,
- sox_false,
- 8192,
- 0,
- 0,
- NULL, NULL, NULL, NULL};
+ 2, /* unsigned verbosity */
+ output_message, /* sox_output_message_handler */
+ sox_false, /* sox_bool repeatable */
+ 8192, /* size_t bufsiz */
+ 0, /* size_t input_bufsiz */
+ 0, /* int32_t ranqd1 */
+ NULL, /* char const * stdin_in_use_by */
+ NULL, /* char const * stdout_in_use_by */
+ NULL, /* char const * subsystem */
+ NULL /* char * tmp_path */
+};
+
+char const * sox_strerror(int sox_errno)
+{
+ static char const * const errors[] = {
+ "Invalid Audio Header",
+ "Unsupported data format",
+ "Can't allocate memory",
+ "Operation not permitted",
+ "Operation not supported",
+ "Invalid argument",
+ };
+ if (sox_errno < SOX_EHDR)
+ return strerror(sox_errno);
+ sox_errno -= SOX_EHDR;
+ if (sox_errno < 0 || (size_t)sox_errno >= array_length(errors))
+ return "Unknown error";
+ return errors[sox_errno];
+}
void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap)
{
--- a/src/sox.c
+++ b/src/sox.c
@@ -392,23 +392,6 @@
display_file_info(f->ft, f, sox_true);
}
-static void display_error(sox_format_t * ft)
-{
- static char const * const sox_strerror[] = {
- "Invalid Audio Header",
- "Unsupported data format",
- "Unsupported rate for format",
- "Can't alloc memory",
- "Operation not permitted",
- "Operation not supported",
- "Invalid argument",
- "Unsupported file format",
- };
- lsx_fail("%s: %s: %s", ft->filename, ft->sox_errstr,
- ft->sox_errno < SOX_EHDR?
- strerror(ft->sox_errno) : sox_strerror[ft->sox_errno - SOX_EHDR]);
-}
-
static void progress_to_next_input_file(file_t * f)
{
if (user_skip) {
@@ -435,7 +418,8 @@
size_t len = max / combiner_signal.channels;
len = sox_read(ft, buf, len * ft->signal.channels) / ft->signal.channels;
if (!len && ft->sox_errno)
- display_error(ft);
+ lsx_fail("%s: %s: %s",
+ ft->filename, ft->sox_errstr, sox_strerror(ft->sox_errno));
return len;
}
@@ -597,7 +581,8 @@
output_eof = (len != *isamp) ? sox_true: sox_false;
if (len != *isamp) {
if (ofile->ft->sox_errno)
- display_error(ofile->ft);
+ lsx_fail("%s: %s: %s", ofile->ft->filename,
+ ofile->ft->sox_errstr, sox_strerror(ofile->ft->sox_errno));
return SOX_EOF;
}
return SOX_SUCCESS;
--- a/src/sox.h
+++ b/src/sox.h
@@ -39,15 +39,14 @@
#define SOX_SUCCESS 0
#define SOX_EOF (-1) /* End Of File or other error */
-/* libSoX specific error codes. The rest directly map from errno. */
-#define SOX_EHDR 2000 /* Invalid Audio Header */
-#define SOX_EFMT 2001 /* Unsupported data format */
-#define SOX_ERATE 2002 /* Unsupported rate for format */
-#define SOX_ENOMEM 2003 /* Can't alloc memory */
-#define SOX_EPERM 2004 /* Operation not permitted */
-#define SOX_ENOTSUP 2005 /* Operation not supported */
-#define SOX_EINVAL 2006 /* Invalid argument */
-#define SOX_EFFMT 2007 /* Unsupported file format */
+enum { /* libSoX specific error codes. The rest directly map from errno. */
+ SOX_EHDR = 2000, /* Invalid Audio Header */
+ SOX_EFMT, /* Unsupported data format */
+ SOX_ENOMEM, /* Can't alloc memory */
+ SOX_EPERM, /* Operation not permitted */
+ SOX_ENOTSUP, /* Operation not supported */
+ SOX_EINVAL /* Invalid argument */
+};
/* Boolean type, assignment (but not necessarily binary) compatible with
* C++ bool */
@@ -452,7 +451,7 @@
#define SOX_EFF_MCHAN 16 /* Effect can handle multi-channel */
#define SOX_EFF_NULL 32 /* Effect does nothing */
#define SOX_EFF_DEPRECATED 64 /* Effect is living on borrowed time */
-#define SOX_EFF_GETOPT 128 /* Effect uses getopt */
+#define SOX_EFF_GETOPT 128 /* FIXME eliminate: Effect uses getopt */
typedef enum {sox_plot_off, sox_plot_octave, sox_plot_gnuplot} sox_plot_t;
typedef struct sox_effect sox_effect_t;
@@ -541,6 +540,7 @@
sox_bool sox_is_playlist(char const * filename);
int sox_parse_playlist(sox_playlist_callback_t callback, void * p, char const * const listname);
+char const * sox_strerror(int sox_errno);
void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap);
/* WARNING BEGIN