commit c1eb3566b1ab1bc6a910f46bce8bfce7d67f3c30
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Mon Jun 6 12:29:48 2022 +0200

    split Verbosity off from DFlags
    
    this clearly documents the permitted states.

 src/common.h | 11 ++++++++---
 src/driver.h |  2 +-
 src/main.c   | 53 ++++++++++++++++++++++++++--------------------------
 src/sync.c   |  2 +-
 src/util.c   |  9 +++++----
 5 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/src/common.h b/src/common.h
index 8f0ded56..9ec6b369 100644
--- a/src/common.h
+++ b/src/common.h
@@ -83,6 +83,13 @@ typedef unsigned long ulong;
 
 /* main.c */
 
+enum {
+       VERYQUIET,
+       QUIET,
+       TERSE,
+       VERBOSE,
+};
+
 #define DEBUG_CRASH     0x01
 #define DEBUG_MAILDIR   0x02
 #define DEBUG_NET       0x04
@@ -91,10 +98,7 @@ typedef unsigned long ulong;
 #define DEBUG_MAIN      0x20
 #define DEBUG_DRV       0x40
 #define DEBUG_DRV_ALL   0x80
-#define QUIET           0x100
-#define VERYQUIET       0x200
 #define PROGRESS        0x400
-#define VERBOSE         0x800
 #define KEEPJOURNAL     0x1000
 #define ZERODELAY       0x2000
 #define FORCEASYNC      0x4000
@@ -103,6 +107,7 @@ typedef unsigned long ulong;
 #define DEBUG_ALL (DEBUG_ANY | DEBUG_CRASH)
 
 // Global options
+extern int Verbosity;
 extern int DFlags;
 extern int JLimit;
 extern int UseFSync;
diff --git a/src/driver.h b/src/driver.h
index 1201ce44..edb94040 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -124,7 +124,7 @@ typedef struct {
 */
 #define DRV_CRLF        1
 /*
-   This flag says that the driver will act upon (DFlags & VERBOSE).
+   This flag says that the driver will act upon (Verbosity >= VERBOSE).
 */
 #define DRV_VERBOSE     2
 /*
diff --git a/src/main.c b/src/main.c
index 3a9936f8..f22a28e3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -429,32 +429,30 @@ main( int argc, char **argv )
                                } else if (!strcmp( opt, "version" )) {
                                        version();
                                } else if (!strcmp( opt, "quiet" )) {
-                                       if (DFlags & QUIET)
-                                               DFlags |= VERYQUIET;
-                                       else
-                                               DFlags |= QUIET;
+                                       if (Verbosity > VERYQUIET)
+                                               Verbosity--;
                                } else if (!strcmp( opt, "verbose" )) {
-                                       DFlags |= VERBOSE;
+                                       Verbosity = VERBOSE;
                                } else if (starts_with( opt, -1, "debug", 5 )) {
                                        opt += 5;
                                        if (!*opt)
-                                               op = VERBOSE | DEBUG_ALL;
+                                               op = DEBUG_ALL;
                                        else if (!strcmp( opt, "-crash" ))
                                                op = DEBUG_CRASH;
                                        else if (!strcmp( opt, "-driver" ))
-                                               op = VERBOSE | DEBUG_DRV;
+                                               op = DEBUG_DRV;
                                        else if (!strcmp( opt, "-driver-all" ))
-                                               op = VERBOSE | DEBUG_DRV | 
DEBUG_DRV_ALL;
+                                               op = DEBUG_DRV | DEBUG_DRV_ALL;
                                        else if (!strcmp( opt, "-maildir" ))
-                                               op = VERBOSE | DEBUG_MAILDIR;
+                                               op = DEBUG_MAILDIR;
                                        else if (!strcmp( opt, "-main" ))
-                                               op = VERBOSE | DEBUG_MAIN;
+                                               op = DEBUG_MAIN;
                                        else if (!strcmp( opt, "-net" ))
-                                               op = VERBOSE | DEBUG_NET;
+                                               op = DEBUG_NET;
                                        else if (!strcmp( opt, "-net-all" ))
-                                               op = VERBOSE | DEBUG_NET | 
DEBUG_NET_ALL;
+                                               op = DEBUG_NET | DEBUG_NET_ALL;
                                        else if (!strcmp( opt, "-sync" ))
-                                               op = VERBOSE | DEBUG_SYNC;
+                                               op = DEBUG_SYNC;
                                        else
                                                goto badopt;
                                        DFlags |= op;
@@ -623,13 +621,11 @@ main( int argc, char **argv )
                        op = XOP_PUSH;
                        goto cac;
                case 'q':
-                       if (DFlags & QUIET)
-                               DFlags |= VERYQUIET;
-                       else
-                               DFlags |= QUIET;
+                       if (Verbosity > VERYQUIET)
+                               Verbosity--;
                        break;
                case 'V':
-                       DFlags |= VERBOSE;
+                       Verbosity = VERBOSE;
                        break;
                case 'D':
                        for (op = 0; *ochar; ochar++) {
@@ -638,25 +634,25 @@ main( int argc, char **argv )
                                        op |= DEBUG_CRASH;
                                        break;
                                case 'd':
-                                       op |= DEBUG_DRV | VERBOSE;
+                                       op |= DEBUG_DRV;
                                        break;
                                case 'D':
-                                       op |= DEBUG_DRV | DEBUG_DRV_ALL | 
VERBOSE;
+                                       op |= DEBUG_DRV | DEBUG_DRV_ALL;
                                        break;
                                case 'm':
-                                       op |= DEBUG_MAILDIR | VERBOSE;
+                                       op |= DEBUG_MAILDIR;
                                        break;
                                case 'M':
-                                       op |= DEBUG_MAIN | VERBOSE;
+                                       op |= DEBUG_MAIN;
                                        break;
                                case 'n':
-                                       op |= DEBUG_NET | VERBOSE;
+                                       op |= DEBUG_NET;
                                        break;
                                case 'N':
-                                       op |= DEBUG_NET | DEBUG_NET_ALL | 
VERBOSE;
+                                       op |= DEBUG_NET | DEBUG_NET_ALL;
                                        break;
                                case 's':
-                                       op |= DEBUG_SYNC | VERBOSE;
+                                       op |= DEBUG_SYNC;
                                        break;
                                default:
                                        error( "Unknown -D flag '%c'\n", *ochar 
);
@@ -664,7 +660,7 @@ main( int argc, char **argv )
                                }
                        }
                        if (!op)
-                               op = DEBUG_ALL | VERBOSE;
+                               op = DEBUG_ALL;
                        DFlags |= op;
                        break;
                case 'T':
@@ -698,8 +694,11 @@ main( int argc, char **argv )
        if (ms_warn)
                warn( "Notice: -master/-slave/m/s suffixes are deprecated; use 
-far/-near/f/n instead.\n" );
 
-       if (!(DFlags & (QUIET | DEBUG_ANY)) && isatty( 1 ))
+       if (DFlags & DEBUG_ANY) {
+               Verbosity = VERBOSE;
+       } else if (Verbosity >= TERSE && isatty( 1 )) {
                DFlags |= PROGRESS;
+       }
 
 #ifdef __linux__
        if (DFlags & DEBUG_CRASH) {
diff --git a/src/sync.c b/src/sync.c
index 2e69b88b..50bf56dd 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -64,7 +64,7 @@ static int check_cancel( sync_vars_t *svars );
 static uchar
 sanitize_flags( uchar tflags, sync_vars_t *svars, int t )
 {
-       if (!(DFlags & QUIET)) {
+       if (Verbosity >= TERSE) {
                // We complain only once per flag per store - even though 
_theoretically_
                // each mailbox can support different flags according to the 
IMAP spec.
                uchar bflags = tflags & ~(svars->good_flags[t] | 
svars->bad_flags[t]);
diff --git a/src/util.c b/src/util.c
index df150ee4..1fc2f9d4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -13,6 +13,7 @@
 #include <ctype.h>
 #include <pwd.h>
 
+int Verbosity = TERSE;
 int DFlags;
 int JLimit;
 int UseFSync = 1;
@@ -95,7 +96,7 @@ info( const char *msg, ... )
 {
        va_list va;
 
-       if (DFlags & VERBOSE) {
+       if (Verbosity >= VERBOSE) {
                va_start( va, msg );
                nvprint( msg, va );
                va_end( va );
@@ -107,7 +108,7 @@ infon( const char *msg, ... )
 {
        va_list va;
 
-       if (DFlags & VERBOSE) {
+       if (Verbosity >= VERBOSE) {
                va_start( va, msg );
                nvprint( msg, va );
                va_end( va );
@@ -120,7 +121,7 @@ notice( const char *msg, ... )
 {
        va_list va;
 
-       if (!(DFlags & QUIET)) {
+       if (Verbosity >= TERSE) {
                va_start( va, msg );
                nvprint( msg, va );
                va_end( va );
@@ -132,7 +133,7 @@ warn( const char *msg, ... )
 {
        va_list va;
 
-       if (!(DFlags & VERYQUIET)) {
+       if (Verbosity >= QUIET) {
                flushn();
                va_start( va, msg );
                vfprintf( stderr, msg, va );


_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to