Skipped 8 existing revision(s) on branch 'async'.

commit 575e0fd846cf6452ac984a74a53cad4c47598675
Author: Oswald Buddenhagen <o...@kde.org>
Date:   Sun Apr 10 09:58:41 2011 +0200

    de-duplicate error paths
    
    makes the code more compact. yay for gotos.

 src/sync.c |   63 ++++++++++++---------------------------------------
 1 files changed, 15 insertions(+), 48 deletions(-)

diff --git a/src/sync.c b/src/sync.c
index c695e54..052c578 100644
--- a/src/sync.c
+++ b/src/sync.c
@@ -558,35 +558,28 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
                debug( "reading sync state %s ...\n", svars->dname );
                if (!fgets( buf, sizeof(buf), jfp ) || !(t = strlen( buf )) || 
buf[t - 1] != '\n') {
                        error( "Error: incomplete sync state header in %s\n", 
svars->dname );
+                 jbail:
                        fclose( jfp );
+                 bail:
                        svars->ret = SYNC_FAIL;
                        sync_bail( svars );
                        return;
                }
                if (sscanf( buf, "%d:%d %d:%d:%d", &svars->uidval[M], 
&svars->maxuid[M], &svars->uidval[S], &svars->smaxxuid, &svars->maxuid[S]) != 
5) {
                        error( "Error: invalid sync state header in %s\n", 
svars->dname );
-                       fclose( jfp );
-                       svars->ret = SYNC_FAIL;
-                       sync_bail( svars );
-                       return;
+                       goto jbail;
                }
                line = 1;
                while (fgets( buf, sizeof(buf), jfp )) {
                        line++;
                        if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
                                error( "Error: incomplete sync state entry at 
%s:%d\n", svars->dname, line );
-                               fclose( jfp );
-                               svars->ret = SYNC_FAIL;
-                               sync_bail( svars );
-                               return;
+                               goto jbail;
                        }
                        fbuf[0] = 0;
                        if (sscanf( buf, "%d %d %15s", &t1, &t2, fbuf ) < 2) {
                                error( "Error: invalid sync state entry at 
%s:%d\n", svars->dname, line );
-                               fclose( jfp );
-                               svars->ret = SYNC_FAIL;
-                               sync_bail( svars );
-                               return;
+                               goto jbail;
                        }
                        srec = nfmalloc( sizeof(*srec) );
                        srec->uid[M] = t1;
@@ -609,9 +602,7 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
        } else {
                if (errno != ENOENT) {
                        error( "Error: cannot read sync state %s\n", 
svars->dname );
-                       svars->ret = SYNC_FAIL;
-                       sync_bail( svars );
-                       return;
+                       goto bail;
                }
        }
        line = 0;
@@ -620,18 +611,12 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
                        debug( "recovering journal ...\n" );
                        if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
                                error( "Error: incomplete journal header in 
%s\n", svars->jname );
-                               fclose( jfp );
-                               svars->ret = SYNC_FAIL;
-                               sync_bail( svars );
-                               return;
+                               goto jbail;
                        }
                        if (memcmp( buf, JOURNAL_VERSION "\n", 
strlen(JOURNAL_VERSION) + 1 )) {
                                error( "Error: incompatible journal version "
                                                 "(got %.*s, expected " 
JOURNAL_VERSION ")\n", t - 1, buf );
-                               fclose( jfp );
-                               svars->ret = SYNC_FAIL;
-                               sync_bail( svars );
-                               return;
+                               goto jbail;
                        }
                        srec = 0;
                        line = 1;
@@ -639,10 +624,7 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
                                line++;
                                if (!(t = strlen( buf )) || buf[t - 1] != '\n') 
{
                                        error( "Error: incomplete journal entry 
at %s:%d\n", svars->jname, line );
-                                       fclose( jfp );
-                                       svars->ret = SYNC_FAIL;
-                                       sync_bail( svars );
-                                       return;
+                                       goto jbail;
                                }
                                if (buf[0] == '#' ?
                                      (t3 = 0, (sscanf( buf + 2, "%d %d %n", 
&t1, &t2, &t3 ) < 2) || !t3 || (t - t3 != TUIDL + 3)) :
@@ -653,10 +635,7 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
                                          (sscanf( buf + 2, "%d %d %d", &t1, 
&t2, &t3 ) != 3))
                                {
                                        error( "Error: malformed journal entry 
at %s:%d\n", svars->jname, line );
-                                       fclose( jfp );
-                                       svars->ret = SYNC_FAIL;
-                                       sync_bail( svars );
-                                       return;
+                                       goto jbail;
                                }
                                if (buf[0] == '(')
                                        svars->maxuid[M] = t1;
@@ -685,10 +664,7 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
                                                if (srec->uid[M] == t1 && 
srec->uid[S] == t2)
                                                        goto syncfnd;
                                        error( "Error: journal entry at %s:%d 
refers to non-existing sync state entry\n", svars->jname, line );
-                                       fclose( jfp );
-                                       svars->ret = SYNC_FAIL;
-                                       sync_bail( svars );
-                                       return;
+                                       goto jbail;
                                  syncfnd:
                                        debugn( "  entry(%d,%d,%u) ", 
srec->uid[M], srec->uid[S], srec->flags );
                                        switch (buf[0]) {
@@ -746,10 +722,7 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
                                                break;
                                        default:
                                                error( "Error: unrecognized 
journal entry at %s:%d\n", svars->jname, line );
-                                               fclose( jfp );
-                                               svars->ret = SYNC_FAIL;
-                                               sync_bail( svars );
-                                               return;
+                                               goto jbail;
                                        }
                                }
                        }
@@ -758,23 +731,17 @@ sync_boxes( store_t *ctx[], const char *names[], 
channel_conf_t *chan,
        } else {
                if (errno != ENOENT) {
                        error( "Error: cannot read journal %s\n", svars->jname 
);
-                       svars->ret = SYNC_FAIL;
-                       sync_bail( svars );
-                       return;
+                       goto bail;
                }
        }
        if (!(svars->nfp = fopen( svars->nname, "w" ))) {
                error( "Error: cannot write new sync state %s\n", svars->nname 
);
-               svars->ret = SYNC_FAIL;
-               sync_bail( svars );
-               return;
+               goto bail;
        }
        if (!(svars->jfp = fopen( svars->jname, "a" ))) {
                error( "Error: cannot write journal %s\n", svars->jname );
                fclose( svars->nfp );
-               svars->ret = SYNC_FAIL;
-               sync_bail( svars );
-               return;
+               goto bail;
        }
        setlinebuf( svars->jfp );
        if (!line)

------------------------------------------------------------------------------
Xperia(TM) PLAY
It's a major breakthrough. An authentic gaming
smartphone on the nation's most reliable network.
And it wants your games.
http://p.sf.net/sfu/verizon-sfdev
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to