Browse Source

turn debug() functions into macros

this makes calling them with more expensive arguments efficient without
wrapping them into additional conditionals.
wip/maildir-path-under-inbox
Oswald Buddenhagen 3 years ago
parent
commit
6f023376a1
  1. 17
      src/common.h
  2. 12
      src/drv_maildir.c
  3. 22
      src/drv_proxy.c
  4. 12
      src/main.c
  5. 22
      src/sync.c
  6. 56
      src/util.c

17
src/common.h

@ -116,8 +116,21 @@ void stats( void );
/* util.c */ /* util.c */
void ATTR_PRINTFLIKE(2, 0) vdebug( int, const char *, va_list va ); #ifdef DEBUG_FLAG
void ATTR_PRINTFLIKE(2, 0) vdebugn( int, const char *, va_list va ); # define debug(...) \
do { \
if (DFlags & DEBUG_FLAG) \
print( __VA_ARGS__ ); \
} while (0)
# define debugn(...) \
do { \
if (DFlags & DEBUG_FLAG) \
printn( __VA_ARGS__ ); \
} while (0)
#endif
void ATTR_PRINTFLIKE(1, 2) print( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) printn( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) info( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) info( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) infon( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) infon( const char *, ... );
void ATTR_PRINTFLIKE(1, 2) progress( const char *, ... ); void ATTR_PRINTFLIKE(1, 2) progress( const char *, ... );

12
src/drv_maildir.c

@ -6,6 +6,8 @@
* mbsync - mailbox synchronizer * mbsync - mailbox synchronizer
*/ */
#define DEBUG_FLAG DEBUG_MAILDIR
#include "driver.h" #include "driver.h"
#include <ctype.h> #include <ctype.h>
@ -85,16 +87,6 @@ static struct flock lck;
static int MaildirCount; static int MaildirCount;
static void ATTR_PRINTFLIKE(1, 2)
debug( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebug( DEBUG_MAILDIR, msg, va );
va_end( va );
}
/* Keep the mailbox driver flag definitions in sync: */ /* Keep the mailbox driver flag definitions in sync: */
/* grep for MAILBOX_DRIVER_FLAG */ /* grep for MAILBOX_DRIVER_FLAG */
/* The order is according to alphabetical maildir flag sort */ /* The order is according to alphabetical maildir flag sort */

22
src/drv_proxy.c

@ -4,6 +4,8 @@
* mbsync - mailbox synchronizer * mbsync - mailbox synchronizer
*/ */
#define DEBUG_FLAG DEBUG_DRV
#include "driver.h" #include "driver.h"
typedef struct gen_cmd gen_cmd_t; typedef struct gen_cmd gen_cmd_t;
@ -25,26 +27,6 @@ typedef union proxy_store {
}; };
} proxy_store_t; } proxy_store_t;
static void ATTR_PRINTFLIKE(1, 2)
debug( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebug( DEBUG_DRV, msg, va );
va_end( va );
}
static void ATTR_PRINTFLIKE(1, 2)
debugn( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebugn( DEBUG_DRV, msg, va );
va_end( va );
}
/* Keep the mailbox driver flag definitions in sync: */ /* Keep the mailbox driver flag definitions in sync: */
/* grep for MAILBOX_DRIVER_FLAG */ /* grep for MAILBOX_DRIVER_FLAG */
/* The order is according to alphabetical maildir flag sort */ /* The order is according to alphabetical maildir flag sort */

12
src/main.c

@ -5,6 +5,8 @@
* mbsync - mailbox synchronizer * mbsync - mailbox synchronizer
*/ */
#define DEBUG_FLAG DEBUG_MAIN
#include "sync.h" #include "sync.h"
#include <fcntl.h> #include <fcntl.h>
@ -87,16 +89,6 @@ PACKAGE " " VERSION " - mailbox synchronizer\n"
exit( code ); exit( code );
} }
static void ATTR_PRINTFLIKE(1, 2)
debug( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebug( DEBUG_MAIN, msg, va );
va_end( va );
}
#ifdef __linux__ #ifdef __linux__
static void ATTR_NORETURN static void ATTR_NORETURN
crashHandler( int n ) crashHandler( int n )

22
src/sync.c

@ -5,6 +5,8 @@
* mbsync - mailbox synchronizer * mbsync - mailbox synchronizer
*/ */
#define DEBUG_FLAG DEBUG_SYNC
#include "sync.h" #include "sync.h"
#include <fcntl.h> #include <fcntl.h>
@ -30,26 +32,6 @@ int trash_total[2], trash_done[2];
const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" }; const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" };
static void ATTR_PRINTFLIKE(1, 2)
debug( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebug( DEBUG_SYNC, msg, va );
va_end( va );
}
static void ATTR_PRINTFLIKE(1, 2)
debugn( const char *msg, ... )
{
va_list va;
va_start( va, msg );
vdebugn( DEBUG_SYNC, msg, va );
va_end( va );
}
static void static void
Fclose( FILE *f, int safe ) Fclose( FILE *f, int safe )
{ {

56
src/util.c

@ -33,34 +33,38 @@ flushn( void )
} }
static void ATTR_PRINTFLIKE(1, 0) static void ATTR_PRINTFLIKE(1, 0)
printn( const char *msg, va_list va ) vprint( const char *msg, va_list va )
{ {
if (*msg == '\v')
msg++;
else
flushn();
vprintf( msg, va ); vprintf( msg, va );
fflush( stdout ); fflush( stdout );
need_nl = 0;
} }
void void
vdebug( int cat, const char *msg, va_list va ) print( const char *msg, ... )
{ {
if (DFlags & cat) { va_list va;
vprintf( msg, va );
fflush( stdout ); va_start( va, msg );
need_nl = 0; vprint( msg, va );
} va_end( va );
}
static void ATTR_PRINTFLIKE(1, 0)
vprintn( const char *msg, va_list va )
{
vprint( msg, va );
need_nl = 1;
} }
void void
vdebugn( int cat, const char *msg, va_list va ) printn( const char *msg, ... )
{ {
if (DFlags & cat) { va_list va;
vprintf( msg, va );
fflush( stdout ); va_start( va, msg );
need_nl = 1; vprintn( msg, va );
} va_end( va );
} }
void void
@ -75,6 +79,16 @@ progress( const char *msg, ... )
need_nl = 1; need_nl = 1;
} }
static void ATTR_PRINTFLIKE(1, 0)
nvprint( const char *msg, va_list va )
{
if (*msg == '\v')
msg++;
else
flushn();
vprint( msg, va );
}
void void
info( const char *msg, ... ) info( const char *msg, ... )
{ {
@ -82,9 +96,8 @@ info( const char *msg, ... )
if (DFlags & VERBOSE) { if (DFlags & VERBOSE) {
va_start( va, msg ); va_start( va, msg );
printn( msg, va ); nvprint( msg, va );
va_end( va ); va_end( va );
need_nl = 0;
} }
} }
@ -95,7 +108,7 @@ infon( const char *msg, ... )
if (DFlags & VERBOSE) { if (DFlags & VERBOSE) {
va_start( va, msg ); va_start( va, msg );
printn( msg, va ); nvprint( msg, va );
va_end( va ); va_end( va );
need_nl = 1; need_nl = 1;
} }
@ -108,9 +121,8 @@ notice( const char *msg, ... )
if (!(DFlags & QUIET)) { if (!(DFlags & QUIET)) {
va_start( va, msg ); va_start( va, msg );
printn( msg, va ); nvprint( msg, va );
va_end( va ); va_end( va );
need_nl = 0;
} }
} }

Loading…
Cancel
Save