[MPlayer-dev-eng] [PATCH] mp_msg cleanup

Oded Shimon ods15 at ods15.dyndns.org
Wed Sep 28 19:20:41 CEST 2005


On Wed, Sep 28, 2005 at 08:19:41PM +0300, Oded Shimon wrote:
> Fix mp_msg abomination.
> Basically a cleanup, I can't work like this...
> 
> Is anyone against?.. the only part I was slightly unsure of is why there 
> are different mp_msg macros for __GNUC__ and non gnuc, as the latter macro 
> works for all compilers, or atleast should by ansi C.
> 
> I'll commit soon...
> 
> - ods15
> 
> _______________________________________________
> MPlayer-dev-eng mailing list
> MPlayer-dev-eng at mplayerhq.hu
> http://mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
-------------- next part --------------
Index: mp_msg.h
===================================================================
RCS file: /cvsroot/mplayer/main/mp_msg.h,v
retrieving revision 1.33
diff -u -r1.33 mp_msg.h
--- mp_msg.h	20 Jan 2005 13:22:52 -0000	1.33
+++ mp_msg.h	28 Sep 2005 17:09:54 -0000
@@ -114,26 +114,17 @@
 #endif
 
 #ifdef __GNUC__
-void mp_msg_c( int x, const char *format, ... ) __attribute__ ((format (printf, 2, 3)));
-#define mp_msg(mod,lev, args... ) mp_msg_c(((mod)<<8)|(lev), ## args )
-
-#ifdef MP_DEBUG
-#define mp_dbg(mod,lev, args... ) mp_msg_c(((mod)<<8)|(lev), ## args )
-#else
-// these messages are only usefull for developers, disable them
-#define mp_dbg(mod,lev, args... ) 
-#endif
+void mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4)));
 #else // not GNU C
-void mp_msg_c( int x, const char *format, ... );
-#define mp_msg(mod,lev, ... ) mp_msg_c(((mod)<<8)|(lev), __VA_ARGS__)
+void mp_msg(int mod, int lev, const char *format, ... );
+#endif
 
 #ifdef MP_DEBUG
-#define mp_dbg(mod,lev, ... ) mp_msg_c(((mod)<<8)|(lev), __VA_ARGS__)
+#define mp_dbg(mod,lev, ... ) mp_msg(mod, lev, __VA_ARGS__)
 #else
 // these messages are only usefull for developers, disable them
 #define mp_dbg(mod,lev, ... ) 
 #endif
-#endif
 
 #endif
 #endif
Index: mp_msg.c
===================================================================
RCS file: /cvsroot/mplayer/main/mp_msg.c,v
retrieving revision 1.27
diff -u -r1.27 mp_msg.c
--- mp_msg.c	3 Sep 2005 19:27:48 -0000	1.27
+++ mp_msg.c	28 Sep 2005 17:09:54 -0000
@@ -8,14 +8,10 @@
 #include "config.h"
 
 #if	defined(FOR_MENCODER) || defined(CODECS2HTML)
-#undef	ENABLE_GUI_CODE
-#elif	defined(HAVE_NEW_GUI)
-#define	ENABLE_GUI_CODE	HAVE_NEW_GUI
-#else
-#undef	ENABLE_GUI_CODE
+#undef HAVE_NEW_GUI
 #endif
 
-#if ENABLE_GUI_CODE
+#ifdef HAVE_NEW_GUI
 #include "Gui/interface.h"
 extern int use_gui;
 #endif
@@ -26,8 +22,6 @@
 
 static int mp_msg_levels[MSGT_MAX]; // verbose level of this module
 
-#if 1
-
 void mp_msg_init(){
 #ifdef USE_I18N
 #ifdef MP_DEBUG
@@ -57,21 +51,20 @@
     return lev <= mp_msg_levels[mod];
 }
 
-void mp_msg_c( int x, const char *format, ... ){
-#if 1
+void mp_msg(int mod, int lev, const char *format, ... ){
     va_list va;
     char tmp[MSGSIZE_MAX];
     
-    if((x&255)>mp_msg_levels[x>>8]) return; // do not display
+    if (lev > mp_msg_levels[mod]) return; // do not display
     va_start(va, format);
     vsnprintf(tmp, MSGSIZE_MAX, mp_gettext(format), va);
     va_end(va);
     tmp[MSGSIZE_MAX-2] = '\n';
     tmp[MSGSIZE_MAX-1] = 0;
 
-#if ENABLE_GUI_CODE
+#ifdef HAVE_NEW_GUI
     if(use_gui)
-        guiMessageBox(x&255, tmp);
+        guiMessageBox(lev, tmp);
 #endif
 
 #ifdef MSG_USE_COLORS
@@ -139,83 +132,21 @@
                                 "NETST",
                                 "MUXER"};
 
-	int c=v_colors[(x & 255)];
-        int c2=((x>>8)+1)%15+1;
+	int c=v_colors[lev];
+        int c2=(mod+1)%15+1;
         static int header=1;
-        FILE *stream= (x & 255) <= MSGL_WARN ? stderr : stdout;
+        FILE *stream= (lev) <= MSGL_WARN ? stderr : stdout;
         if(header){
-            fprintf(stream, "\033[%d;3%dm%9s\033[0;37m: ",c2>>3,c2&7, mod_text[x>>8]);
+            fprintf(stream, "\033[%d;3%dm%9s\033[0;37m: ",c2>>3,c2&7, mod_text[mod]);
         }
         fprintf(stream, "\033[%d;3%dm",c>>3,c&7);
         header=    tmp[strlen(tmp)-1] == '\n'
                  /*||tmp[strlen(tmp)-1] == '\r'*/;
     }
 #endif
-    if ((x & 255) <= MSGL_WARN){
+    if (lev <= MSGL_WARN){
 	fprintf(stderr, "%s", tmp);fflush(stderr);
     } else {
 	printf("%s", tmp);fflush(stdout);
     }
-
-#else
-    va_list va;
-    if((x&255)>mp_msg_levels[x>>8]) return; // do not display
-    va_start(va, format);
-#if ENABLE_GUI_CODE
-    if(use_gui){
-      char tmp[16*80];
-      vsnprintf( tmp,8*80,format,va ); tmp[8*80-1]=0;
-      switch( x&255 ) {
-       case MSGL_FATAL: 
-              fprintf( stderr,"%s",tmp );
-	      fflush(stderr);
-              gtkMessageBox( GTK_MB_FATAL|GTK_MB_SIMPLE,tmp );
-       	   break;
-       case MSGL_ERR:
-              fprintf( stderr,"%s",tmp );
-	      fflush(stderr);
-              gtkMessageBox( GTK_MB_ERROR|GTK_MB_SIMPLE,tmp );
-       	   break;
-       case MSGL_WARN:
-              fprintf( stderr, "%s",tmp );
-	      fflush(stdout);
-              gtkMessageBox( GTK_MB_WARNING|GTK_MB_SIMPLE,tmp );
-       	   break;
-       default:
-              fprintf(stderr, "%s",tmp );
-	      fflush(stdout);
-      }
-    } else
-#endif
-    if((x&255)<=MSGL_ERR){
-//    fprintf(stderr,"%%%%%% ");
-      vfprintf(stderr,format, va);
-      fflush(stderr);
-    } else {
-//	printf("%%%%%% ");
-      vfprintf(stderr,format, va);
-      fflush(stdout);
-    }
-    va_end(va);
-#endif
-}
-
-#else
-
-FILE *mp_msg_file[MSGT_MAX]; // print message to this file (can be stdout/err)
-static FILE* mp_msg_last_file=NULL;
-
-// how to handle errors->stderr messages->stdout  ?
-void mp_msg( int x, const char *format, ... ){
-    if((x&255)>mp_msg_levels[x>>8] || !mp_msg_file[x>>8]) return; // do not display
-    va_list va;
-    va_start(va, format);
-    vfprintf(mp_msg_file[x>>8],format, va);
-    if(mp_msg_last_file!=mp_msg_file[x>>8]){
-	fflush(mp_msg_file[x>>8]);
-	mp_msg_last_file=mp_msg_file[x>>8];
-    }
-    va_end(va);
 }
-
-#endif


More information about the MPlayer-dev-eng mailing list