commit c0ba0c7ecffcc002b2d23e3bf484cc02bda7e78b
Author: Oswald Buddenhagen <[email protected]>
Date:   Sun Nov 24 19:32:42 2013 +0100

    replace global_* with a channel_conf_t instance
    
    this makes the (growing) list of getopt_helper()'s parameters
    manageable. the few wasted bytes are worth it.

 src/config.c |   47 +++++++++++++++++++++++------------------------
 src/isync.h  |    3 +--
 src/main.c   |    6 +++---
 src/sync.c   |    4 ++--
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/src/config.c b/src/config.c
index 7bf8aa3..7fde567 100644
--- a/src/config.c
+++ b/src/config.c
@@ -34,11 +34,10 @@
 
 driver_t *drivers[N_DRIVERS] = { &maildir_driver, &imap_driver };
 
+channel_conf_t global_conf;
 store_conf_t *stores;
 channel_conf_t *channels;
 group_conf_t *groups;
-int global_ops[2];
-char *global_sync_state;
 int FSyncLevel = FSYNC_NORMAL;
 
 #define ARG_OPTIONAL 0
@@ -152,7 +151,7 @@ parse_size( conffile_t *cfile )
 }
 
 static int
-getopt_helper( conffile_t *cfile, int *cops, int ops[], char **sync_state )
+getopt_helper( conffile_t *cfile, int *cops, channel_conf_t *conf )
 {
        char *arg;
 
@@ -172,21 +171,21 @@ getopt_helper( conffile_t *cfile, int *cops, int ops[], 
char **sync_state )
                        else if (!strcasecmp( "Flags", arg ))
                                *cops |= OP_FLAGS;
                        else if (!strcasecmp( "PullReNew", arg ))
-                               ops[S] |= OP_RENEW;
+                               conf->ops[S] |= OP_RENEW;
                        else if (!strcasecmp( "PullNew", arg ))
-                               ops[S] |= OP_NEW;
+                               conf->ops[S] |= OP_NEW;
                        else if (!strcasecmp( "PullDelete", arg ))
-                               ops[S] |= OP_DELETE;
+                               conf->ops[S] |= OP_DELETE;
                        else if (!strcasecmp( "PullFlags", arg ))
-                               ops[S] |= OP_FLAGS;
+                               conf->ops[S] |= OP_FLAGS;
                        else if (!strcasecmp( "PushReNew", arg ))
-                               ops[M] |= OP_RENEW;
+                               conf->ops[M] |= OP_RENEW;
                        else if (!strcasecmp( "PushNew", arg ))
-                               ops[M] |= OP_NEW;
+                               conf->ops[M] |= OP_NEW;
                        else if (!strcasecmp( "PushDelete", arg ))
-                               ops[M] |= OP_DELETE;
+                               conf->ops[M] |= OP_DELETE;
                        else if (!strcasecmp( "PushFlags", arg ))
-                               ops[M] |= OP_FLAGS;
+                               conf->ops[M] |= OP_FLAGS;
                        else if (!strcasecmp( "All", arg ) || !strcasecmp( 
"Full", arg ))
                                *cops |= XOP_PULL|XOP_PUSH;
                        else if (strcasecmp( "None", arg ) && strcasecmp( 
"Noop", arg )) {
@@ -195,41 +194,41 @@ getopt_helper( conffile_t *cfile, int *cops, int ops[], 
char **sync_state )
                                cfile->err = 1;
                        }
                while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
-               ops[M] |= XOP_HAVE_TYPE;
+               conf->ops[M] |= XOP_HAVE_TYPE;
        } else if (!strcasecmp( "Expunge", cfile->cmd )) {
                arg = cfile->val;
                do
                        if (!strcasecmp( "Both", arg ))
                                *cops |= OP_EXPUNGE;
                        else if (!strcasecmp( "Master", arg ))
-                               ops[M] |= OP_EXPUNGE;
+                               conf->ops[M] |= OP_EXPUNGE;
                        else if (!strcasecmp( "Slave", arg ))
-                               ops[S] |= OP_EXPUNGE;
+                               conf->ops[S] |= OP_EXPUNGE;
                        else if (strcasecmp( "None", arg )) {
                                error( "%s:%d: invalid Expunge arg '%s'\n",
                                       cfile->file, cfile->line, arg );
                                cfile->err = 1;
                        }
                while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
-               ops[M] |= XOP_HAVE_EXPUNGE;
+               conf->ops[M] |= XOP_HAVE_EXPUNGE;
        } else if (!strcasecmp( "Create", cfile->cmd )) {
                arg = cfile->val;
                do
                        if (!strcasecmp( "Both", arg ))
                                *cops |= OP_CREATE;
                        else if (!strcasecmp( "Master", arg ))
-                               ops[M] |= OP_CREATE;
+                               conf->ops[M] |= OP_CREATE;
                        else if (!strcasecmp( "Slave", arg ))
-                               ops[S] |= OP_CREATE;
+                               conf->ops[S] |= OP_CREATE;
                        else if (strcasecmp( "None", arg )) {
                                error( "%s:%d: invalid Create arg '%s'\n",
                                       cfile->file, cfile->line, arg );
                                cfile->err = 1;
                        }
                while ((arg = get_arg( cfile, ARG_OPTIONAL, 0 )));
-               ops[M] |= XOP_HAVE_CREATE;
+               conf->ops[M] |= XOP_HAVE_CREATE;
        } else if (!strcasecmp( "SyncState", cfile->cmd ))
-               *sync_state = expand_strdup( cfile->val );
+               conf->sync_state = expand_strdup( cfile->val );
        else
                return 0;
        return 1;
@@ -407,7 +406,7 @@ load_config( const char *where, int pseudo )
                                  stpcom:
                                        if (*++p)
                                                channel->boxes[ms] = nfstrdup( 
p );
-                               } else if (!getopt_helper( &cfile, &cops, 
channel->ops, &channel->sync_state )) {
+                               } else if (!getopt_helper( &cfile, &cops, 
channel )) {
                                        error( "%s:%d: unknown keyword '%s'\n", 
cfile.file, cfile.line, cfile.cmd );
                                        cfile.err = 1;
                                }
@@ -473,7 +472,7 @@ load_config( const char *where, int pseudo )
                        else if (!strcasecmp( "Thorough", arg ))
                                FSyncLevel = FSYNC_THOROUGH;
                }
-               else if (!getopt_helper( &cfile, &gcops, global_ops, 
&global_sync_state ))
+               else if (!getopt_helper( &cfile, &gcops, &global_conf ))
                {
                        error( "%s:%d: unknown section keyword '%s'\n",
                               cfile.file, cfile.line, cfile.cmd );
@@ -485,9 +484,9 @@ load_config( const char *where, int pseudo )
                }
        }
        fclose (cfile.fp);
-       cfile.err |= merge_ops( gcops, global_ops );
-       if (!global_sync_state)
-               global_sync_state = expand_strdup( "~/." EXE "/" );
+       cfile.err |= merge_ops( gcops, global_conf.ops );
+       if (!global_conf.sync_state)
+               global_conf.sync_state = expand_strdup( "~/." EXE "/" );
        if (!cfile.err && pseudo)
                unlink( where );
        return cfile.err;
diff --git a/src/isync.h b/src/isync.h
index 4d6249f..b67a969 100644
--- a/src/isync.h
+++ b/src/isync.h
@@ -484,10 +484,9 @@ void sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
 #define N_DRIVERS 2
 extern driver_t *drivers[N_DRIVERS];
 
+extern channel_conf_t global_conf;
 extern channel_conf_t *channels;
 extern group_conf_t *groups;
-extern int global_ops[2];
-extern char *global_sync_state;
 
 #define FSYNC_NONE     0
 #define FSYNC_NORMAL   1
diff --git a/src/main.c b/src/main.c
index fa769e7..2095931 100644
--- a/src/main.c
+++ b/src/main.c
@@ -179,9 +179,9 @@ merge_actions( channel_conf_t *chan, int ops[], int have, 
int mask, int def )
                chan->ops[S] &= ~mask;
                chan->ops[S] |= ops[S] & mask;
        } else if (!(chan->ops[M] & have)) {
-               if (global_ops[M] & have) {
-                       chan->ops[M] |= global_ops[M] & mask;
-                       chan->ops[S] |= global_ops[S] & mask;
+               if (global_conf.ops[M] & have) {
+                       chan->ops[M] |= global_conf.ops[M] & mask;
+                       chan->ops[S] |= global_conf.ops[S] & mask;
                } else {
                        chan->ops[M] |= def;
                        chan->ops[S] |= def;
diff --git a/src/sync.c b/src/sync.c
index 429e843..554843d 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -670,7 +670,7 @@ box_selected( int sts, void *aux )
                return;
 
        chan = svars->chan;
-       if (!strcmp( chan->sync_state ? chan->sync_state : global_sync_state, 
"*" )) {
+       if (!strcmp( chan->sync_state ? chan->sync_state : 
global_conf.sync_state, "*" )) {
                if (!ctx[S]->path) {
                        error( "Error: store '%s' does not support in-box sync 
state\n", chan->stores[S]->name );
                  sbail:
@@ -685,7 +685,7 @@ box_selected( int sts, void *aux )
                        nfasprintf( &svars->dname, "%s%s", chan->sync_state, 
csname );
                else {
                        cmname = clean_strdup( ctx[M]->name );
-                       nfasprintf( &svars->dname, "%s:%s:%s_:%s:%s", 
global_sync_state,
+                       nfasprintf( &svars->dname, "%s:%s:%s_:%s:%s", 
global_conf.sync_state,
                                    chan->stores[M]->name, cmname, 
chan->stores[S]->name, csname );
                        free( cmname );
                }

------------------------------------------------------------------------------
Sponsored by Intel(R) XDK 
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to