From 98f4fd45864c4ffac5b1c310f7efa53187d54a84 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 24 Apr 2022 14:30:10 +0200 Subject: [PATCH] shuffle around global variables the new organization clarifies the ownership, making things more self-contained. this will potentially help with unit testing. --- src/common.h | 9 ++------- src/config.c | 6 ++++++ src/config.h | 2 ++ src/main.c | 18 ------------------ src/sync.c | 6 ++++++ src/sync.h | 6 ++++++ src/tst_timers.c | 4 ---- src/util.c | 8 ++++++++ 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/common.h b/src/common.h index 939c9e5..55a20a2 100644 --- a/src/common.h +++ b/src/common.h @@ -96,21 +96,16 @@ typedef unsigned long ulong; #define DEBUG_ANY (DEBUG_MAILDIR | DEBUG_NET | DEBUG_SYNC | DEBUG_MAIN | DEBUG_DRV) #define DEBUG_ALL (DEBUG_ANY | DEBUG_CRASH) +// Global options extern int DFlags; extern int JLimit; extern int UseFSync; -extern char FieldDelimiter; +// Global constants (inited by main()) extern int Pid; extern char Hostname[256]; extern const char *Home; -extern uint BufferLimit; - -extern int new_total[2], new_done[2]; -extern int flags_total[2], flags_done[2]; -extern int trash_total[2], trash_done[2]; - void stats( void ); /* util.c */ diff --git a/src/config.c b/src/config.c index d7eac08..10a1206 100644 --- a/src/config.c +++ b/src/config.c @@ -19,6 +19,12 @@ #include #include +#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) +char FieldDelimiter = ';'; +#else +char FieldDelimiter = ':'; +#endif + static store_conf_t *stores; char * diff --git a/src/config.h b/src/config.h index bcc9c9a..375ef8c 100644 --- a/src/config.h +++ b/src/config.h @@ -21,6 +21,8 @@ typedef struct { char *cmd, *val, *rest; } conffile_t; +extern char FieldDelimiter; + #define ARG_OPTIONAL 0 #define ARG_REQUIRED 1 diff --git a/src/main.c b/src/main.c index b9299fd..1ebed1e 100644 --- a/src/main.c +++ b/src/main.c @@ -19,26 +19,8 @@ # include #endif -int DFlags; -int JLimit; -int UseFSync = 1; -#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) || defined(__CYGWIN__) -char FieldDelimiter = ';'; -#else -char FieldDelimiter = ':'; -#endif - -int Pid; /* for maildir and imap */ -char Hostname[256]; /* for maildir */ -const char *Home; /* for config */ - -uint BufferLimit = 10 * 1024 * 1024; - static int chans_total, chans_done; static int boxes_total, boxes_done; -int new_total[2], new_done[2]; -int flags_total[2], flags_done[2]; -int trash_total[2], trash_done[2]; static void ATTR_NORETURN version( void ) diff --git a/src/sync.c b/src/sync.c index 0a65628..bf41d8a 100644 --- a/src/sync.c +++ b/src/sync.c @@ -30,6 +30,12 @@ channel_conf_t global_conf; channel_conf_t *channels; group_conf_t *groups; +uint BufferLimit = 10 * 1024 * 1024; + +int new_total[2], new_done[2]; +int flags_total[2], flags_done[2]; +int trash_total[2], trash_done[2]; + const char *str_fn[] = { "far side", "near side" }, *str_hl[] = { "push", "pull" }; static void ATTR_PRINTFLIKE(1, 2) diff --git a/src/sync.h b/src/sync.h index b54daea..dbcbede 100644 --- a/src/sync.h +++ b/src/sync.h @@ -53,6 +53,12 @@ extern channel_conf_t global_conf; extern channel_conf_t *channels; extern group_conf_t *groups; +extern uint BufferLimit; + +extern int new_total[2], new_done[2]; +extern int flags_total[2], flags_done[2]; +extern int trash_total[2], trash_done[2]; + extern const char *str_fn[2], *str_hl[2]; #define SYNC_OK 0 /* assumed to be 0 */ diff --git a/src/tst_timers.c b/src/tst_timers.c index 9b2e28d..ec9561e 100644 --- a/src/tst_timers.c +++ b/src/tst_timers.c @@ -10,10 +10,6 @@ #include #include -/* Just to satisfy the references in util.c */ -int DFlags; -const char *Home; - typedef struct { int id; int first, other, morph_at, morph_to; diff --git a/src/util.c b/src/util.c index f2819cf..9496980 100644 --- a/src/util.c +++ b/src/util.c @@ -17,6 +17,14 @@ #include #include +int DFlags; +int JLimit; +int UseFSync = 1; + +int Pid; +char Hostname[256]; +const char *Home; + static int need_nl; void