static void OutputDebugString( const void * unused UNUSED ) { }
#endif
-void
+static void
tr_msgInit( void )
{
- if( !messageLock )
+ static tr_bool initialized = FALSE;
+
+ if( !initialized )
+ {
+ char * env = getenv( "TR_DEBUG" );
+ messageLevel = ( env ? atoi( env ) : 0 ) + 1;
+ messageLevel = MAX( 1, messageLevel );
+
messageLock = tr_lockNew( );
+
+ initialized = TRUE;
+ }
}
FILE*
{
tr_msgInit( );
tr_lockLock( messageLock );
+
messageLevel = MAX( 0, level );
+
tr_lockUnlock( messageLock );
}
tr_getMessageLevel( void )
{
int ret;
-
tr_msgInit( );
tr_lockLock( messageLock );
+
ret = messageLevel;
- tr_lockUnlock( messageLock );
+ tr_lockUnlock( messageLock );
return ret;
}
{
tr_msgInit( );
tr_lockLock( messageLock );
+
messageQueuing = enabled;
+
tr_lockUnlock( messageLock );
}
tr_getMessageQueuing( void )
{
int ret;
-
tr_msgInit( );
tr_lockLock( messageLock );
+
ret = messageQueuing;
- tr_lockUnlock( messageLock );
+ tr_lockUnlock( messageLock );
return ret;
}
tr_getQueuedMessages( void )
{
tr_msg_list * ret;
-
- assert( NULL != messageLock );
+ tr_msgInit( );
tr_lockLock( messageLock );
+
ret = messageQueue;
messageQueue = NULL;
messageQueueTail = &messageQueue;
- tr_lockUnlock( messageLock );
+ tr_lockUnlock( messageLock );
return ret;
}
/***
****
***/
+
+
+int
+tr_msgLoggingIsActive( int level )
+{
+ tr_msgInit( );
+
+ return messageLevel >= level;
+}
void
tr_msg( const char * file,
... )
{
FILE * fp;
-
- if( messageLock )
- tr_lockLock( messageLock );
+ tr_msgInit( );
+ tr_lockLock( messageLock );
fp = tr_getLog( );
- if( !messageLevel )
- {
- char * env = getenv( "TR_DEBUG" );
- messageLevel = ( env ? atoi( env ) : 0 ) + 1;
- messageLevel = MAX( 1, messageLevel );
- }
-
if( messageLevel >= level )
{
va_list ap;
}
}
- if( messageLock )
- tr_lockUnlock( messageLock );
+ tr_lockUnlock( messageLock );
}
/***
#define _( a ) tr_strip_positional_args( a )
#endif
-#define tr_nerr( n, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, n, __VA_ARGS__ )
-#define tr_ninf( n, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, n, __VA_ARGS__ )
-#define tr_ndbg( n, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, n, __VA_ARGS__ )
+/****
+*****
+****/
-#define tr_torerr( tor, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, tor->info.name, __VA_ARGS__ )
-#define tr_torinf( tor, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, tor->info.name, __VA_ARGS__ )
-#define tr_tordbg( tor, ... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, tor->info.name, __VA_ARGS__ )
-
-#define tr_err( ... ) tr_msg( __FILE__, __LINE__, TR_MSG_ERR, NULL, __VA_ARGS__ )
-#define tr_inf( ... ) tr_msg( __FILE__, __LINE__, TR_MSG_INF, NULL, __VA_ARGS__ )
-#define tr_dbg( ... ) tr_msg( __FILE__, __LINE__, TR_MSG_DBG, NULL, __VA_ARGS__ )
-
-int tr_wildmat( const char * text,
- const char * pattern );
-
-void tr_msgInit( void );
+int tr_msgLoggingIsActive( int level );
void tr_msg( const char * file,
int line,
const char * fmt,
... ) TR_GNUC_PRINTF( 5, 6 );
+#define tr_nerr( n, ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_ERR, n, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_ninf( n, ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_INF) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_INF, n, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_ndbg( n, ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_DBG) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_DBG, n, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_torerr( tor, ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_ERR, tor->info.name, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_torinf( tor, ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_INF ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_INF, tor->info.name, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_tordbg( tor, ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_DBG ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_DBG, tor->info.name, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_err( ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_ERR ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_ERR, NULL, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_inf( ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_INF ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_INF, NULL, __VA_ARGS__ ); \
+ } while( 0 )
+
+#define tr_dbg( ... ) \
+ do { \
+ if( tr_msgLoggingIsActive( TR_MSG_DBG ) ) \
+ tr_msg( __FILE__, __LINE__, TR_MSG_DBG, NULL, __VA_ARGS__ ); \
+ } while( 0 )
+
+
+
FILE* tr_getLog( void );
int tr_deepLoggingIsActive( void );
char* tr_getLogTimeStr( char * buf,
int buflen );
+
+int tr_wildmat( const char * text,
+ const char * pattern );
+
/** a portability wrapper for basename(). */
char* tr_basename( const char * path ) TR_GNUC_MALLOC;
void tr_bitfieldClear( tr_bitfield* );
-int tr_bitfieldAdd( tr_bitfield*,
- size_t bit );
+int tr_bitfieldAdd( tr_bitfield*, size_t bit );
-int tr_bitfieldRem( tr_bitfield*,
- size_t bit );
+int tr_bitfieldRem( tr_bitfield*, size_t bit );
-int tr_bitfieldAddRange( tr_bitfield *,
- size_t begin,
- size_t end );
+int tr_bitfieldAddRange( tr_bitfield *, size_t begin, size_t end );
-int tr_bitfieldRemRange( tr_bitfield*,
- size_t begin,
- size_t end );
+int tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
-void tr_bitfieldDifference( tr_bitfield *,
- const tr_bitfield * );
+void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * );
int tr_bitfieldIsEmpty( const tr_bitfield* );
size_t tr_bitfieldCountTrueBits( const tr_bitfield* );
-tr_bitfield* tr_bitfieldOr( tr_bitfield*,
- const tr_bitfield* );
+tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
/** A stripped-down version of bitfieldHas to be used
for speed when you're looping quickly. This version