Diego Biurrun
2014-11-17 21:13:37 UTC
This reduces library size by ~10%.
Also allow passing extra arguments to the error printing function.
---
src/error.c | 32 ++++++++++++++++++++++++++++++--
src/libdvdcss.h | 11 ++---------
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/src/error.c b/src/error.c
index 2bdcfc9..2e7ae13 100644
--- a/src/error.c
+++ b/src/error.c
@@ -20,19 +20,47 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
+#include <stdarg.h>
#include <stdio.h>
#include "libdvdcss.h"
+static void print_message( const char *prefix, const char *psz_string,
+ va_list args )
+{
+ fprintf( stderr, "libdvdcss %s: ", prefix );
+ vfprintf( stderr, psz_string, args );
+ fprintf( stderr, "\n" );
+}
+
/*****************************************************************************
* Error messages
*****************************************************************************/
-void print_error( struct dvdcss *dvdcss, const char *psz_string )
+void print_error( struct dvdcss *dvdcss, const char * const psz_string, ... )
{
if( dvdcss->b_errors )
{
- fprintf( stderr, "libdvdcss error: %s\n", psz_string );
+ va_list args;
+
+ va_start( args, psz_string );
+ print_message("error", psz_string, args);
+ va_end( args );
}
dvdcss->psz_error = psz_string;
}
+
+/*****************************************************************************
+ * Debug messages
+ *****************************************************************************/
+void print_debug( const struct dvdcss *dvdcss, const char *psz_string, ... )
+{
+ if( dvdcss->b_debug )
+ {
+ va_list args;
+
+ va_start( args, psz_string );
+ print_message("debug", psz_string, args );
+ va_end( args );
+ }
+}
diff --git a/src/libdvdcss.h b/src/libdvdcss.h
index 1831865..adf43c6 100644
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -84,14 +84,7 @@ struct dvdcss
/*****************************************************************************
* Functions used across the library
*****************************************************************************/
-#define print_debug( dvdcss, ... ) \
- if( dvdcss->b_debug ) \
- { \
- fprintf( stderr, "libdvdcss debug: " ); \
- fprintf( stderr, __VA_ARGS__ ); \
- fprintf( stderr, "\n" ); \
- }
-
-void print_error ( struct dvdcss *, const char * );
+void print_error ( struct dvdcss *, const char * const, ... );
+void print_debug ( const struct dvdcss *, const char * const, ... );
#endif /* DVDCSS_LIBDVDCSS_H */
Also allow passing extra arguments to the error printing function.
---
src/error.c | 32 ++++++++++++++++++++++++++++++--
src/libdvdcss.h | 11 ++---------
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/src/error.c b/src/error.c
index 2bdcfc9..2e7ae13 100644
--- a/src/error.c
+++ b/src/error.c
@@ -20,19 +20,47 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
+#include <stdarg.h>
#include <stdio.h>
#include "libdvdcss.h"
+static void print_message( const char *prefix, const char *psz_string,
+ va_list args )
+{
+ fprintf( stderr, "libdvdcss %s: ", prefix );
+ vfprintf( stderr, psz_string, args );
+ fprintf( stderr, "\n" );
+}
+
/*****************************************************************************
* Error messages
*****************************************************************************/
-void print_error( struct dvdcss *dvdcss, const char *psz_string )
+void print_error( struct dvdcss *dvdcss, const char * const psz_string, ... )
{
if( dvdcss->b_errors )
{
- fprintf( stderr, "libdvdcss error: %s\n", psz_string );
+ va_list args;
+
+ va_start( args, psz_string );
+ print_message("error", psz_string, args);
+ va_end( args );
}
dvdcss->psz_error = psz_string;
}
+
+/*****************************************************************************
+ * Debug messages
+ *****************************************************************************/
+void print_debug( const struct dvdcss *dvdcss, const char *psz_string, ... )
+{
+ if( dvdcss->b_debug )
+ {
+ va_list args;
+
+ va_start( args, psz_string );
+ print_message("debug", psz_string, args );
+ va_end( args );
+ }
+}
diff --git a/src/libdvdcss.h b/src/libdvdcss.h
index 1831865..adf43c6 100644
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -84,14 +84,7 @@ struct dvdcss
/*****************************************************************************
* Functions used across the library
*****************************************************************************/
-#define print_debug( dvdcss, ... ) \
- if( dvdcss->b_debug ) \
- { \
- fprintf( stderr, "libdvdcss debug: " ); \
- fprintf( stderr, __VA_ARGS__ ); \
- fprintf( stderr, "\n" ); \
- }
-
-void print_error ( struct dvdcss *, const char * );
+void print_error ( struct dvdcss *, const char * const, ... );
+void print_debug ( const struct dvdcss *, const char * const, ... );
#endif /* DVDCSS_LIBDVDCSS_H */
--
2.1.0
2.1.0