CVS commit by ossi: 

"fprintf( stderr," => "error(". new functions debugn() and infon()
for messages with missing newline; warn() and error() act upon this.


  M +26 -29    config.c   1.30
  M +56 -60    drv_imap.c   1.18
  M +20 -20    drv_maildir.c   1.13
  M +4 -1      isync.h   1.55
  M +8 -7      main.c   1.54
  M +25 -25    sync.c   1.77
  M +51 -3     util.c   1.8


--- isync/src/config.c  #1.29:1.30
@@ -51,5 +51,5 @@ parse_bool( conffile_t *cfile )
            strcasecmp( cfile->val, "off" ) &&
            strcmp( cfile->val, "0" ))
-               fprintf( stderr, "%s:%d: invalid boolean value '%s'\n",
+               error( "%s:%d: invalid boolean value '%s'\n",
                         cfile->file, cfile->line, cfile->val );
        return 0;
@@ -64,5 +64,5 @@ parse_int( conffile_t *cfile )
        ret = strtol( cfile->val, &p, 10 );
        if (*p) {
-               fprintf( stderr, "%s:%d: invalid integer value '%s'\n",
+               error( "%s:%d: invalid integer value '%s'\n",
                         cfile->file, cfile->line, cfile->val );
                return 0;
@@ -131,5 +131,5 @@ getopt_helper( conffile_t *cfile, int *c
                                *cops |= XOP_PULL|XOP_PUSH;
                        else if (strcasecmp( "None", arg ) && strcasecmp( 
"Noop", arg ))
-                               fprintf( stderr, "%s:%d: invalid Sync arg 
'%s'\n",
+                               error( "%s:%d: invalid Sync arg '%s'\n",
                                         cfile->file, cfile->line, arg );
                while ((arg = next_arg( &cfile->rest )));
@@ -145,5 +145,5 @@ getopt_helper( conffile_t *cfile, int *c
                                ops[S] |= OP_EXPUNGE;
                        else if (strcasecmp( "None", arg ))
-                               fprintf( stderr, "%s:%d: invalid Expunge arg 
'%s'\n",
+                               error( "%s:%d: invalid Expunge arg '%s'\n",
                                         cfile->file, cfile->line, arg );
                while ((arg = next_arg( &cfile->rest )));
@@ -159,5 +159,5 @@ getopt_helper( conffile_t *cfile, int *c
                                ops[S] |= OP_CREATE;
                        else if (strcasecmp( "None", arg ))
-                               fprintf( stderr, "%s:%d: invalid Create arg 
'%s'\n",
+                               error( "%s:%d: invalid Create arg '%s'\n",
                                         cfile->file, cfile->line, arg );
                while ((arg = next_arg( &cfile->rest )));
@@ -183,6 +183,5 @@ getcline( conffile_t *cfile )
                        continue;
                if (!(cfile->val = next_arg( &p ))) {
-                       fprintf( stderr, "%s:%d: parameter missing\n",
-                                cfile->file, cfile->line );
+                       error( "%s:%d: parameter missing\n", cfile->file, 
cfile->line );
                        continue;
                }
@@ -204,5 +203,5 @@ merge_ops( int cops, int ops[] )
                        if (aops & cops & OP_MASK_TYPE) {
                          cfl:
-                               fprintf( stderr, "Conflicting Sync args 
specified.\n" );
+                               error( "Conflicting Sync args specified.\n" );
                                return 1;
                        }
@@ -232,5 +231,5 @@ merge_ops( int cops, int ops[] )
        if (ops[M] & XOP_HAVE_EXPUNGE) {
                if (aops & cops & OP_EXPUNGE) {
-                       fprintf( stderr, "Conflicting Expunge args 
specified.\n" );
+                       error( "Conflicting Expunge args specified.\n" );
                        return 1;
                }
@@ -240,5 +239,5 @@ merge_ops( int cops, int ops[] )
        if (ops[M] & XOP_HAVE_CREATE) {
                if (aops & cops & OP_CREATE) {
-                       fprintf( stderr, "Conflicting Create args specified.\n" 
);
+                       error( "Conflicting Create args specified.\n" );
                        return 1;
                }
@@ -322,5 +321,5 @@ load_config( const char *where, int pseu
                                  linkst:
                                        if (*cfile.val != ':' || !(p = strchr( 
cfile.val + 1, ':' ))) {
-                                               fprintf( stderr, "%s:%d: 
malformed mailbox spec\n",
+                                               error( "%s:%d: malformed 
mailbox spec\n",
                                                         cfile.file, cfile.line 
);
                                                err = 1;
@@ -333,5 +332,5 @@ load_config( const char *where, int pseu
                                                        goto stpcom;
                                                }
-                                       fprintf( stderr, "%s:%d: unknown store 
'%s'\n",
+                                       error( "%s:%d: unknown store '%s'\n",
                                                 cfile.file, cfile.line, 
cfile.val + 1 );
                                        err = 1;
@@ -341,14 +340,13 @@ load_config( const char *where, int pseu
                                                channel->boxes[ms] = nfstrdup( 
p );
                                } else if (!getopt_helper( &cfile, &cops, 
channel->ops, &channel->sync_state )) {
-                                       fprintf( stderr, "%s:%d: unknown 
keyword '%s'\n",
-                                                cfile.file, cfile.line, 
cfile.cmd );
+                                       error( "%s:%d: unknown keyword '%s'\n", 
cfile.file, cfile.line, cfile.cmd );
                                        err = 1;
                                }
                        }
                        if (!channel->stores[M]) {
-                               fprintf( stderr, "channel '%s' refers to no 
master store\n", channel->name );
+                               error( "channel '%s' refers to no master 
store\n", channel->name );
                                err = 1;
                        } else if (!channel->stores[S]) {
-                               fprintf( stderr, "channel '%s' refers to no 
slave store\n", channel->name );
+                               error( "channel '%s' refers to no slave 
store\n", channel->name );
                                err = 1;
                        } else if (merge_ops( cops, channel->ops ))
@@ -392,5 +390,5 @@ load_config( const char *where, int pseu
                                else
                                {
-                                       fprintf( stderr, "%s:%d: unknown 
keyword '%s'\n",
+                                       error( "%s:%d: unknown keyword '%s'\n",
                                                 cfile.file, cfile.line, 
cfile.cmd );
                                        err = 1;
@@ -401,5 +399,5 @@ load_config( const char *where, int pseu
                else if (!getopt_helper( &cfile, &gcops, global_ops, 
&global_sync_state ))
                {
-                       fprintf( stderr, "%s:%d: unknown section keyword 
'%s'\n",
+                       error( "%s:%d: unknown section keyword '%s'\n",
                                 cfile.file, cfile.line, cfile.cmd );
                        err = 1;
@@ -433,6 +431,5 @@ parse_generic_store( store_conf_t *store
                store->map_inbox = nfstrdup( cfg->val );
        else {
-               fprintf( stderr, "%s:%d: unknown keyword '%s'\n",
-                        cfg->file, cfg->line, cfg->cmd );
+               error( "%s:%d: unknown keyword '%s'\n", cfg->file, cfg->line, 
cfg->cmd );
                *err = 1;
        }

--- isync/src/drv_imap.c  #1.17:1.18
@@ -195,10 +195,9 @@ verify_cert( SSL *ssl )
        int err;
        char buf[256];
-       int ret = -1;
        BIO *bio;
 
        cert = SSL_get_peer_certificate( ssl );
        if (!cert) {
-               fprintf( stderr, "Error, no server certificate\n" );
+               error( "Error, no server certificate\n" );
                return -1;
        }
@@ -208,5 +207,5 @@ verify_cert( SSL *ssl )
                return 0;
 
-       fprintf( stderr, "Error, can't verify certificate: %s (%d)\n",
+       error( "Error, can't verify certificate: %s (%d)\n",
                 X509_verify_cert_error_string(err), err );
 
@@ -231,8 +230,8 @@ verify_cert( SSL *ssl )
               "\nAccept this certificate anyway? [no]: ",  stderr );
        if (fgets( buf, sizeof(buf), stdin ) && (buf[0] == 'y' || buf[0] == 
'Y')) {
-               ret = 0;
-               fprintf( stderr, "\n*** Fine, but don't say I didn't warn 
you!\n\n" );
+               error( "\n*** Fine, but don't say I didn't warn you!\n\n" );
+               return 0;
        }
-       return ret;
+       return -1;
 }
 
@@ -253,8 +252,8 @@ init_ssl_ctx( imap_store_t *ctx )
 
        if (!srvc->cert_file) {
-               fprintf( stderr, "Error, CertificateFile not defined\n" );
+               error( "Error, CertificateFile not defined\n" );
                return -1;
        } else if (!SSL_CTX_load_verify_locations( imap->SSLContext, 
srvc->cert_file, NULL )) {
-               fprintf( stderr, "Error while loading certificate file '%s': 
%s\n",
+               error( "Error while loading certificate file '%s': %s\n",
                         srvc->cert_file, ERR_error_string( ERR_get_error(), 0 
) );
                return -1;
@@ -288,12 +287,12 @@ socket_perror( const char *func, Socket_
                        if ((err = ERR_get_error()) == 0) {
                                if (ret == 0)
-                                       fprintf( stderr, "SSL_%s:got EOF\n", 
func );
+                                       error( "SSL_%s:got EOF\n", func );
                                else
-                                       fprintf( stderr, "SSL_%s:%d:%s\n", 
func, errno, strerror(errno) );
+                                       error( "SSL_%s:%d:%s\n", func, errno, 
strerror(errno) );
                        } else
-                               fprintf( stderr, "SSL_%s:%d:%s\n", func, err, 
ERR_error_string( err, 0 ) );
+                               error( "SSL_%s:%d:%s\n", func, err, 
ERR_error_string( err, 0 ) );
                        return;
                default:
-                       fprintf( stderr, "SSL_%s:%d:unhandled SSL error\n", 
func, err );
+                       error( "SSL_%s:%d:unhandled SSL error\n", func, err );
                        break;
                }
@@ -306,5 +305,5 @@ socket_perror( const char *func, Socket_
                perror( func );
        else
-               fprintf( stderr, "%s: unexpected EOF\n", func );
+               error( "%s: unexpected EOF\n", func );
 }
 
@@ -715,5 +714,5 @@ parse_fetch( imap_t *imap, char *cmd ) /
 
        if (!is_list( list )) {
-               fprintf( stderr, "IMAP error: bogus FETCH response\n" );
+               error( "IMAP error: bogus FETCH response\n" );
                free_list( list );
                return -1;
@@ -727,5 +726,5 @@ parse_fetch( imap_t *imap, char *cmd ) /
                                        uid = atoi( tmp->val );
                                else
-                                       fprintf( stderr, "IMAP error: unable to 
parse UID\n" );
+                                       error( "IMAP error: unable to parse 
UID\n" );
                        } else if (!strcmp( "FLAGS", tmp->val )) {
                                tmp = tmp->next;
@@ -743,13 +742,13 @@ parse_fetch( imap_t *imap, char *cmd ) /
                                                                                
goto flagok;
                                                                        }
-                                                               fprintf( 
stderr, "IMAP warning: unknown system flag %s\n", flags->val );
+                                                               error( "IMAP 
warning: unknown system flag %s\n", flags->val );
                                                        }
                                                  flagok: ;
                                                } else
-                                                       fprintf( stderr, "IMAP 
error: unable to parse FLAGS list\n" );
+                                                       error( "IMAP error: 
unable to parse FLAGS list\n" );
                                        }
                                        status |= M_FLAGS;
                                } else
-                                       fprintf( stderr, "IMAP error: unable to 
parse FLAGS\n" );
+                                       error( "IMAP error: unable to parse 
FLAGS\n" );
                        } else if (!strcmp( "RFC822.SIZE", tmp->val )) {
                                tmp = tmp->next;
@@ -757,5 +756,5 @@ parse_fetch( imap_t *imap, char *cmd ) /
                                        size = atoi( tmp->val );
                                else
-                                       fprintf( stderr, "IMAP error: unable to 
parse RFC822.SIZE\n" );
+                                       error( "IMAP error: unable to parse 
RFC822.SIZE\n" );
                        } else if (!strcmp( "BODY[]", tmp->val )) {
                                tmp = tmp->next;
@@ -765,5 +764,5 @@ parse_fetch( imap_t *imap, char *cmd ) /
                                        size = tmp->len;
                                } else
-                                       fprintf( stderr, "IMAP error: unable to 
parse BODY[]\n" );
+                                       error( "IMAP error: unable to parse 
BODY[]\n" );
                        }
                }
@@ -774,5 +773,5 @@ parse_fetch( imap_t *imap, char *cmd ) /
                        if (cmdp->cb.uid == uid)
                                goto gotuid;
-               fprintf( stderr, "IMAP error: unexpected FETCH response (UID 
%d)\n", uid );
+               error( "IMAP error: unexpected FETCH response (UID %d)\n", uid 
);
                free_list( list );
                return -1;
@@ -823,5 +822,5 @@ parse_response_code( imap_store_t *ctx, 
        s++;
        if (!(p = strchr( s, ']' ))) {
-               fprintf( stderr, "IMAP error: malformed response code\n" );
+               error( "IMAP error: malformed response code\n" );
                return RESP_BAD;
        }
@@ -830,10 +829,10 @@ parse_response_code( imap_store_t *ctx, 
        if (!strcmp( "UIDVALIDITY", arg )) {
                if (!(arg = next_arg( &s )) || !(ctx->gen.uidvalidity = atoi( 
arg ))) {
-                       fprintf( stderr, "IMAP error: malformed UIDVALIDITY 
status\n" );
+                       error( "IMAP error: malformed UIDVALIDITY status\n" );
                        return RESP_BAD;
                }
        } else if (!strcmp( "UIDNEXT", arg )) {
                if (!(arg = next_arg( &s )) || !(imap->uidnext = atoi( arg ))) {
-                       fprintf( stderr, "IMAP error: malformed NEXTUID 
status\n" );
+                       error( "IMAP error: malformed NEXTUID status\n" );
                        return RESP_BAD;
                }
@@ -845,10 +844,10 @@ parse_response_code( imap_store_t *ctx, 
                 */
                for (; isspace( (unsigned char)*p ); p++);
-               fprintf( stderr, "*** IMAP ALERT *** %s\n", p );
+               error( "*** IMAP ALERT *** %s\n", p );
        } else if (cb && cb->ctx && !strcmp( "APPENDUID", arg )) {
                if (!(arg = next_arg( &s )) || !(ctx->gen.uidvalidity = atoi( 
arg )) ||
                    !(arg = next_arg( &s )) || !(*(int *)cb->ctx = atoi( arg )))
                {
-                       fprintf( stderr, "IMAP error: malformed APPENDUID 
status\n" );
+                       error( "IMAP error: malformed APPENDUID status\n" );
                        return RESP_BAD;
                }
@@ -867,5 +866,5 @@ parse_search( imap_t *imap, char *cmd )
                uid = -1;
        else if (!(uid = atoi( arg ))) {
-               fprintf( stderr, "IMAP error: malformed SEARCH response\n" );
+               error( "IMAP error: malformed SEARCH response\n" );
                return;
        } else if (next_arg( &cmd )) {
@@ -883,5 +882,5 @@ parse_search( imap_t *imap, char *cmd )
                        return;
                }
-       fprintf( stderr, "IMAP error: unexpected SEARCH response (UID %u)\n", 
uid );
+       error( "IMAP error: unexpected SEARCH response (UID %u)\n", uid );
 }
 
@@ -929,5 +928,5 @@ get_cmd_result( imap_store_t *ctx, struc
                        arg = next_arg( &cmd );
                        if (!arg) {
-                               fprintf( stderr, "IMAP error: unable to parse 
untagged response\n" );
+                               error( "IMAP error: unable to parse untagged 
response\n" );
                                return RESP_BAD;
                        }
@@ -957,9 +956,9 @@ get_cmd_result( imap_store_t *ctx, struc
                                }
                        } else {
-                               fprintf( stderr, "IMAP error: unable to parse 
untagged response\n" );
+                               error( "IMAP error: unable to parse untagged 
response\n" );
                                return RESP_BAD;
                        }
                } else if (!imap->in_progress) {
-                       fprintf( stderr, "IMAP error: unexpected reply: %s 
%s\n", arg, cmd ? cmd : "" );
+                       error( "IMAP error: unexpected reply: %s %s\n", arg, 
cmd ? cmd : "" );
                        return RESP_BAD;
                } else if (*arg == '+') {
@@ -978,5 +977,5 @@ get_cmd_result( imap_store_t *ctx, struc
                                        return RESP_BAD;
                        } else {
-                               fprintf( stderr, "IMAP error: unexpected 
command continuation request\n" );
+                               error( "IMAP error: unexpected command 
continuation request\n" );
                                return RESP_BAD;
                        }
@@ -992,5 +991,5 @@ get_cmd_result( imap_store_t *ctx, struc
                                if (cmdp->tag == tag)
                                        goto gottag;
-                       fprintf( stderr, "IMAP error: unexpected tag %s\n", arg 
);
+                       error( "IMAP error: unexpected tag %s\n", arg );
                        return RESP_BAD;
                  gottag:
@@ -1029,7 +1028,6 @@ get_cmd_result( imap_store_t *ctx, struc
                                } else /*if (!strcmp( "BAD", arg ))*/
                                        resp = RESP_BAD;
-                               fprintf( stderr, "IMAP command '%s' returned an 
error: %s %s\n",
-                                        memcmp (cmdp->cmd, "LOGIN", 5) ?
-                                                       cmdp->cmd : "LOGIN 
<user> <pass>",
+                               error( "IMAP command '%s' returned an error: %s 
%s\n",
+                                      memcmp( cmdp->cmd, "LOGIN", 5 ) ? 
cmdp->cmd : "LOGIN <user> <pass>",
                                                        arg, cmd ? cmd : "");
                        }
@@ -1223,5 +1221,5 @@ imap_open_store( store_conf_t *conf, sto
 
        if (srvc->tunnel) {
-               info( "Starting tunnel '%s'... ", srvc->tunnel );
+               infon( "Starting tunnel '%s'... ", srvc->tunnel );
 
                if (socketpair( PF_UNIX, SOCK_STREAM, 0, a )) {
@@ -1249,5 +1247,5 @@ imap_open_store( store_conf_t *conf, sto
                addr.sin_family = AF_INET;
 
-               info( "Resolving %s... ", srvc->host );
+               infon( "Resolving %s... ", srvc->host );
                he = gethostbyname( srvc->host );
                if (!he) {
@@ -1261,5 +1259,5 @@ imap_open_store( store_conf_t *conf, sto
                s = socket( PF_INET, SOCK_STREAM, 0 );
 
-               info( "Connecting to %s:%hu... ", inet_ntoa( addr.sin_addr ), 
ntohs( addr.sin_port ) );
+               infon( "Connecting to %s:%hu... ", inet_ntoa( addr.sin_addr ), 
ntohs( addr.sin_port ) );
                if (connect( s, (struct sockaddr *)&addr, sizeof(addr) )) {
                        close( s );
@@ -1282,10 +1280,10 @@ imap_open_store( store_conf_t *conf, sto
        /* read the greeting string */
        if (buffer_gets( &imap->buf, &rsp )) {
-               fprintf( stderr, "IMAP error: no greeting response\n" );
+               error( "IMAP error: no greeting response\n" );
                goto bail;
        }
        arg = next_arg( &rsp );
        if (!arg || *arg != '*' || (arg = next_arg( &rsp )) == NULL) {
-               fprintf( stderr, "IMAP error: invalid greeting response\n" );
+               error( "IMAP error: invalid greeting response\n" );
                goto bail;
        }
@@ -1294,5 +1292,5 @@ imap_open_store( store_conf_t *conf, sto
                preauth = 1;
        else if (strcmp( "OK", arg ) != 0) {
-               fprintf( stderr, "IMAP error: unknown greeting response\n" );
+               error( "IMAP error: unknown greeting response\n" );
                goto bail;
        }
@@ -1316,5 +1314,5 @@ imap_open_store( store_conf_t *conf, sto
                        } else {
                                if (srvc->require_ssl) {
-                                       fprintf( stderr, "IMAP error: SSL 
support not available\n" );
+                                       error( "IMAP error: SSL support not 
available\n" );
                                        goto bail;
                                } else
@@ -1326,5 +1324,5 @@ imap_open_store( store_conf_t *conf, sto
                info ("Logging in...\n");
                if (!srvc->user) {
-                       fprintf( stderr, "Skipping server %s, no user\n", 
srvc->host );
+                       error( "Skipping server %s, no user\n", srvc->host );
                        goto bail;
                }
@@ -1338,5 +1336,5 @@ imap_open_store( store_conf_t *conf, sto
                        }
                        if (!*arg) {
-                               fprintf( stderr, "Skipping account [EMAIL 
PROTECTED], no password\n", srvc->user, srvc->host );
+                               error( "Skipping account [EMAIL PROTECTED], no 
password\n", srvc->user, srvc->host );
                                goto bail;
                        }
@@ -1357,5 +1355,5 @@ imap_open_store( store_conf_t *conf, sto
                                goto bail;
                } else if (srvc->require_cram) {
-                       fprintf( stderr, "IMAP error: CRAM-MD5 authentication 
is not supported by server\n" );
+                       error( "IMAP error: CRAM-MD5 authentication is not 
supported by server\n" );
                        goto bail;
                } else
@@ -1363,5 +1361,5 @@ imap_open_store( store_conf_t *conf, sto
                {
                        if (CAP(NOLOGIN)) {
-                               fprintf( stderr, "Skipping account [EMAIL 
PROTECTED], server forbids LOGIN\n", srvc->user, srvc->host );
+                               error( "Skipping account [EMAIL PROTECTED], 
server forbids LOGIN\n", srvc->user, srvc->host );
                                goto bail;
                        }
@@ -1371,5 +1369,5 @@ imap_open_store( store_conf_t *conf, sto
                                warn( "*** IMAP Warning *** Password is being 
sent in the clear\n" );
                        if (imap_exec( ctx, 0, "LOGIN \"%s\" \"%s\"", 
srvc->user, srvc->pass ) != RESP_OK) {
-                               fprintf( stderr, "IMAP error: LOGIN failed\n" );
+                               error( "IMAP error: LOGIN failed\n" );
                                goto bail;
                        }
@@ -1701,5 +1699,5 @@ imap_parse_store( conffile_t *cfg, store
                        server->cert_file = expand_strdup( cfg->val );
                        if (access( server->cert_file, R_OK )) {
-                               fprintf( stderr, "%s:%d: CertificateFile '%s': 
%s\n",
+                               error( "%s:%d: CertificateFile '%s': %s\n",
                                         cfg->file, cfg->line, 
server->cert_file, strerror( errno ) );
                                *err = 1;
@@ -1723,6 +1721,5 @@ imap_parse_store( conffile_t *cfg, store
                                        if (srv->name && !strcmp( srv->name, 
cfg->val ))
                                                goto gotsrv;
-                               fprintf( stderr, "%s:%d: unknown IMAP account 
'%s'\n",
-                                        cfg->file, cfg->line, cfg->val );
+                               error( "%s:%d: unknown IMAP account '%s'\n", 
cfg->file, cfg->line, cfg->val );
                                *err = 1;
                                continue;
@@ -1737,6 +1734,5 @@ imap_parse_store( conffile_t *cfg, store
                        continue;
                } else {
-                       fprintf( stderr, "%s:%d: unknown/misplaced keyword 
'%s'\n",
-                                cfg->file, cfg->line, cfg->cmd );
+                       error( "%s:%d: unknown/misplaced keyword '%s'\n", 
cfg->file, cfg->line, cfg->cmd );
                        *err = 1;
                        continue;
@@ -1747,7 +1743,7 @@ imap_parse_store( conffile_t *cfg, store
                if (!server->tunnel && !server->host) {
                        if (store)
-                               fprintf( stderr, "IMAP store '%s' has 
incomplete/missing connection details\n", store->gen.name );
+                               error( "IMAP store '%s' has incomplete/missing 
connection details\n", store->gen.name );
                        else
-                               fprintf( stderr, "IMAP account '%s' has 
incomplete/missing connection details\n", server->name );
+                               error( "IMAP account '%s' has 
incomplete/missing connection details\n", server->name );
                        *err = 1;
                        return 1;
@@ -1759,5 +1755,5 @@ imap_parse_store( conffile_t *cfg, store
                        memcpy( store->server, &sserver, sizeof(sserver) );
                } else if (acc_opt) {
-                       fprintf( stderr, "IMAP store '%s' has both Account and 
account-specific options\n", store->gen.name );
+                       error( "IMAP store '%s' has both Account and 
account-specific options\n", store->gen.name );
                        *err = 1;
                }

--- isync/src/drv_maildir.c  #1.12:1.13
@@ -105,5 +105,5 @@ maildir_open_store( store_conf_t *conf, 
                maildir_close_store( oldctx );
        if (stat( conf->path, &st ) || !S_ISDIR(st.st_mode)) {
-               fprintf( stderr, "Maildir error: cannot open store %s\n", 
conf->path );
+               error( "Maildir error: cannot open store %s\n", conf->path );
                return 0;
        }
@@ -158,5 +158,5 @@ maildir_list( store_t *gctx, string_list
 
        if (!(dir = opendir( gctx->conf->path ))) {
-               fprintf( stderr, "%s: %s\n", gctx->conf->path, strerror(errno) 
);
+               error( "%s: %s\n", gctx->conf->path, strerror(errno) );
                return DRV_STORE_BAD;
        }
@@ -222,5 +222,5 @@ maildir_validate( const char *prefix, co
                        if (create) {
                                if (mkdir( buf, 0700 )) {
-                                       fprintf( stderr, "Maildir error: mkdir 
%s: %s (errno %d)\n",
+                                       error( "Maildir error: mkdir %s: %s 
(errno %d)\n",
                                                 buf, strerror(errno), errno );
                                        return DRV_STORE_BAD;
@@ -230,5 +230,5 @@ maildir_validate( const char *prefix, co
                                        memcpy( buf + bl, subdirs[i], 4 );
                                        if (mkdir( buf, 0700 )) {
-                                               fprintf( stderr, "Maildir 
error: mkdir %s: %s (errno %d)\n",
+                                               error( "Maildir error: mkdir 
%s: %s (errno %d)\n",
                                                         buf, strerror(errno), 
errno );
                                                return DRV_BOX_BAD;
@@ -236,9 +236,9 @@ maildir_validate( const char *prefix, co
                                }
                        } else {
-                               fprintf( stderr, "Maildir error: mailbox '%s' 
does not exist\n", buf );
+                               error( "Maildir error: mailbox '%s' does not 
exist\n", buf );
                                return DRV_BOX_BAD;
                        }
                } else {
-                       fprintf( stderr, "Maildir error: stat %s: %s (errno 
%d)\n",
+                       error( "Maildir error: stat %s: %s (errno %d)\n",
                                 buf, strerror(errno), errno );
                        return DRV_BOX_BAD;
@@ -253,5 +253,5 @@ maildir_validate( const char *prefix, co
                        goto mkdirs;
                if (j != 3) {
-                       fprintf( stderr, "Maildir error: '%.*s' is no valid 
mailbox\n", bl, buf );
+                       error( "Maildir error: '%.*s' is no valid mailbox\n", 
bl, buf );
                        return DRV_BOX_BAD;
                }
@@ -259,5 +259,5 @@ maildir_validate( const char *prefix, co
                bl += 4;
                if (!(dirp = opendir( buf ))) {
-                       fprintf( stderr, "Maildir error: opendir: %s: %s (errno 
%d)\n",
+                       error( "Maildir error: opendir: %s: %s (errno %d)\n",
                                 buf, strerror(errno), errno );
                        return DRV_BOX_BAD;
@@ -267,5 +267,5 @@ maildir_validate( const char *prefix, co
                        nfsnprintf( buf + bl, sizeof(buf) - bl, "%s", 
entry->d_name );
                        if (stat( buf, &st ))
-                               fprintf( stderr, "Maildir error: stat: %s: %s 
(errno %d)\n",
+                               error( "Maildir error: stat: %s: %s (errno 
%d)\n",
                                         buf, strerror(errno), errno );
                        else if (S_ISREG(st.st_mode) && now - st.st_ctime >= 
_24_HOURS) {
@@ -275,5 +275,5 @@ maildir_validate( const char *prefix, co
                                info( "Maildir notice: removing stale file 
%s\n", buf );
                                if (unlink( buf ))
-                                       fprintf( stderr, "Maildir error: 
unlink: %s: %s (errno %d)\n",
+                                       error( "Maildir error: unlink: %s: %s 
(errno %d)\n",
                                                 buf, strerror(errno), errno );
                        }
@@ -338,5 +338,5 @@ maildir_store_uid( maildir_store_t *ctx 
        lseek( ctx->uvfd, 0, SEEK_SET );
        if (write( ctx->uvfd, buf, n ) != n || ftruncate( ctx->uvfd, n )) {
-               fprintf( stderr, "Maildir error: cannot write UIDVALIDITY.\n" );
+               error( "Maildir error: cannot write UIDVALIDITY.\n" );
                return DRV_BOX_BAD;
        }
@@ -369,5 +369,5 @@ maildir_uidval_lock( maildir_store_t *ct
        /* This is legacy only */
        if (flock( ctx->uvfd, LOCK_EX ) < 0) {
-               fprintf( stderr, "Maildir error: cannot flock UIDVALIDITY.\n" );
+               error( "Maildir error: cannot flock UIDVALIDITY.\n" );
                return DRV_BOX_BAD;
        }
@@ -380,5 +380,5 @@ maildir_uidval_lock( maildir_store_t *ct
        lck.l_type = F_WRLCK;
        if (fcntl( ctx->uvfd, F_SETLKW, &lck )) {
-               fprintf( stderr, "Maildir error: cannot fcntl lock 
UIDVALIDITY.\n" );
+               error( "Maildir error: cannot fcntl lock UIDVALIDITY.\n" );
                return DRV_BOX_BAD;
        }
@@ -1009,5 +1009,5 @@ maildir_store_msg( store_t *gctx, msg_da
                        perror( buf );
                else
-                       fprintf( stderr, "Maildir error: %s: partial write\n", 
buf );
+                       error( "Maildir error: %s: partial write\n", buf );
                close( fd );
                return DRV_BOX_BAD;

--- isync/src/isync.h  #1.54:1.55
@@ -206,10 +206,13 @@ extern const char *Home;
 #define KEEPJOURNAL  16
 
-extern int DFlags;
+extern int DFlags, Ontty;
 
 void debug( const char *, ... );
+void debugn( const char *, ... );
 void info( const char *, ... );
+void infon( const char *, ... );
 void infoc( char );
 void warn( const char *, ... );
+void error( const char *, ... );
 
 char *next_arg( char ** );

--- isync/src/main.c  #1.53:1.54
@@ -93,5 +93,5 @@ crashHandler( int n )
        dup2( 0, 1 );
        dup2( 0, 2 );
-       fprintf( stderr, "*** " EXE " caught signal %d. Starting debugger 
...\n", n );
+       error( "*** " EXE " caught signal %d. Starting debugger ...\n", n );
        switch ((dpid = fork ())) {
        case -1:
@@ -209,4 +209,5 @@ main( int argc, char **argv )
                return 1;
        }
+       Ontty = isatty( 1 ) && isatty( 2 );
        arc4_init();
 
@@ -221,5 +222,5 @@ main( int argc, char **argv )
                                if (!strcmp( opt, "config" )) {
                                        if (oind >= argc) {
-                                               fprintf( stderr, "--config 
requires an argument.\n" );
+                                               error( "--config requires an 
argument.\n" );
                                                return 1;
                                        }
@@ -300,5 +301,5 @@ main( int argc, char **argv )
                                        else {
                                          badopt:
-                                               fprintf( stderr, "Unknown 
option '%s'\n", argv[oind - 1] );
+                                               error( "Unknown option '%s'\n", 
argv[oind - 1] );
                                                return 1;
                                        }
@@ -314,5 +315,5 @@ main( int argc, char **argv )
                        ochar = argv[oind++] + 1;
                        if (!*ochar) {
-                               fprintf( stderr, "Invalid option '-'\n" );
+                               error( "Invalid option '-'\n" );
                                return 1;
                        }
@@ -331,5 +332,5 @@ main( int argc, char **argv )
                        }
                        if (oind >= argc) {
-                               fprintf( stderr, "-c requires an argument.\n" );
+                               error( "-c requires an argument.\n" );
                                return 1;
                        }
@@ -412,5 +413,5 @@ main( int argc, char **argv )
                        usage( 0 );
                default:
-                       fprintf( stderr, "Unknown option '-%c'\n", *(ochar - 1) 
);
+                       error( "Unknown option '-%c'\n", *(ochar - 1) );
                        return 1;
                }
@@ -478,5 +479,5 @@ main( int argc, char **argv )
                                if (!strcmp( chan->name, channame ))
                                        goto gotchan;
-                       fprintf( stderr, "No channel or group named '%s' 
defined.\n", channame );
+                       error( "No channel or group named '%s' defined.\n", 
channame );
                        ret = 1;
                        goto gotnone;

--- isync/src/sync.c  #1.76:1.77
@@ -127,5 +127,5 @@ select_box( sync_rec_t *srecs, store_t *
        } else
                maxwuid = 0;
-       info( "Selecting %s %s... ", str_ms[t], ctx[t]->name );
+       infon( "Selecting %s %s... ", str_ms[t], ctx[t]->name );
        debug( maxwuid == INT_MAX ? "selecting %s [%d,inf]\n" : "selecting %s 
[%d,%d]\n", str_ms[t], minwuid, maxwuid );
        switch (ctx[t]->conf->driver->select( ctx[t], minwuid, maxwuid, mexcs, 
nmexcs )) {
@@ -134,5 +134,5 @@ select_box( sync_rec_t *srecs, store_t *
        }
        if (uidval[t] && uidval[t] != ctx[t]->uidvalidity) {
-               fprintf( stderr, "Error: UIDVALIDITY of %s changed (got %d, 
expected %d)\n", str_ms[t], ctx[t]->uidvalidity, uidval[t] );
+               error( "Error: UIDVALIDITY of %s changed (got %d, expected 
%d)\n", str_ms[t], ctx[t]->uidvalidity, uidval[t] );
                return SYNC_FAIL;
        }
@@ -402,5 +402,5 @@ sync_boxes( store_t *ctx[], const char *
        if (!strcmp( chan->sync_state ? chan->sync_state : global_sync_state, 
"*" )) {
                if (!ctx[S]->path) {
-                       fprintf( stderr, "Error: store '%s' does not support 
in-box sync state\n", chan->stores[S]->name );
+                       error( "Error: store '%s' does not support in-box sync 
state\n", chan->stores[S]->name );
                        return SYNC_BAD(S);
                }
@@ -419,5 +419,5 @@ sync_boxes( store_t *ctx[], const char *
        }
        if (!(s = strrchr( dname, '/' ))) {
-               fprintf( stderr, "Error: invalid SyncState '%s'\n", dname );
+               error( "Error: invalid SyncState '%s'\n", dname );
                free( dname );
                return SYNC_BAD(S);
@@ -425,5 +425,5 @@ sync_boxes( store_t *ctx[], const char *
        *s = 0;
        if (mkdir( dname, 0700 ) && errno != EEXIST) {
-               fprintf( stderr, "Error: cannot create SyncState directory 
'%s': %s\n", dname, strerror(errno) );
+               error( "Error: cannot create SyncState directory '%s': %s\n", 
dname, strerror(errno) );
                free( dname );
                return SYNC_BAD(S);
@@ -442,10 +442,10 @@ sync_boxes( store_t *ctx[], const char *
 #endif
        if ((lfd = open( lname, O_WRONLY|O_CREAT, 0666 )) < 0) {
-               fprintf( stderr, "Error: cannot create lock file %s: %s\n", 
lname, strerror(errno) );
+               error( "Error: cannot create lock file %s: %s\n", lname, 
strerror(errno) );
                ret = SYNC_FAIL;
                goto bail2;
        }
        if (fcntl( lfd, F_SETLK, &lck )) {
-               fprintf( stderr, "Error: channel :%s:%s-:%s:%s is locked\n",
+               error( "Error: channel :%s:%s-:%s:%s is locked\n",
                         chan->stores[M]->name, ctx[M]->name, 
chan->stores[S]->name, ctx[S]->name );
                ret = SYNC_FAIL;
@@ -455,5 +455,5 @@ sync_boxes( store_t *ctx[], const char *
                debug( "reading sync state %s ...\n", dname );
                if (!fgets( buf, sizeof(buf), dfp ) || !(t = strlen( buf )) || 
buf[t - 1] != '\n') {
-                       fprintf( stderr, "Error: incomplete sync state header 
in %s\n", dname );
+                       error( "Error: incomplete sync state header in %s\n", 
dname );
                        fclose( dfp );
                        ret = SYNC_FAIL;
@@ -461,5 +461,5 @@ sync_boxes( store_t *ctx[], const char *
                }
                if (sscanf( buf, "%d:%d %d:%d:%d", &uidval[M], &maxuid[M], 
&uidval[S], &smaxxuid, &maxuid[S]) != 5) {
-                       fprintf( stderr, "Error: invalid sync state header in 
%s\n", dname );
+                       error( "Error: invalid sync state header in %s\n", 
dname );
                        fclose( dfp );
                        ret = SYNC_FAIL;
@@ -470,5 +470,5 @@ sync_boxes( store_t *ctx[], const char *
                        sline++;
                        if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
-                               fprintf( stderr, "Error: incomplete sync state 
entry at %s:%d\n", dname, sline );
+                               error( "Error: incomplete sync state entry at 
%s:%d\n", dname, sline );
                                fclose( dfp );
                                ret = SYNC_FAIL;
@@ -477,5 +477,5 @@ sync_boxes( store_t *ctx[], const char *
                        fbuf[0] = 0;
                        if (sscanf( buf, "%d %d %15s", &t1, &t2, fbuf ) < 2) {
-                               fprintf( stderr, "Error: invalid sync state 
entry at %s:%d\n", dname, sline );
+                               error( "Error: invalid sync state entry at 
%s:%d\n", dname, sline );
                                fclose( dfp );
                                ret = SYNC_FAIL;
@@ -502,5 +502,5 @@ sync_boxes( store_t *ctx[], const char *
        } else {
                if (errno != ENOENT) {
-                       fprintf( stderr, "Error: cannot read sync state %s\n", 
dname );
+                       error( "Error: cannot read sync state %s\n", dname );
                        ret = SYNC_FAIL;
                        goto bail;
@@ -512,5 +512,5 @@ sync_boxes( store_t *ctx[], const char *
                        debug( "recovering journal ...\n" );
                        if (!(t = strlen( buf )) || buf[t - 1] != '\n') {
-                               fprintf( stderr, "Error: incomplete journal 
header in %s\n", jname );
+                               error( "Error: incomplete journal header in 
%s\n", jname );
                                fclose( jfp );
                                ret = SYNC_FAIL;
@@ -518,5 +518,5 @@ sync_boxes( store_t *ctx[], const char *
                        }
                        if (memcmp( buf, JOURNAL_VERSION "\n", 
strlen(JOURNAL_VERSION) + 1 )) {
-                               fprintf( stderr, "Error: incompatible journal 
version "
+                               error( "Error: incompatible journal version "
                                                 "(got %.*s, expected " 
JOURNAL_VERSION ")\n", t - 1, buf );
                                fclose( jfp );
@@ -529,5 +529,5 @@ sync_boxes( store_t *ctx[], const char *
                                line++;
                                if (!(t = strlen( buf )) || buf[t - 1] != '\n') 
{
-                                       fprintf( stderr, "Error: incomplete 
journal entry at %s:%d\n", jname, line );
+                                       error( "Error: incomplete journal entry 
at %s:%d\n", jname, line );
                                        fclose( jfp );
                                        ret = SYNC_FAIL;
@@ -542,5 +542,5 @@ sync_boxes( store_t *ctx[], const char *
                                          (sscanf( buf + 2, "%d %d %d", &t1, 
&t2, &t3 ) != 3))
                                {
-                                       fprintf( stderr, "Error: malformed 
journal entry at %s:%d\n", jname, line );
+                                       error( "Error: malformed journal entry 
at %s:%d\n", jname, line );
                                        fclose( jfp );
                                        ret = SYNC_FAIL;
@@ -573,10 +573,10 @@ sync_boxes( store_t *ctx[], const char *
                                                if (srec->uid[M] == t1 && 
srec->uid[S] == t2)
                                                        goto syncfnd;
-                                       fprintf( stderr, "Error: journal entry 
at %s:%d refers to non-existing sync state entry\n", jname, line );
+                                       error( "Error: journal entry at %s:%d 
refers to non-existing sync state entry\n", jname, line );
                                        fclose( jfp );
                                        ret = SYNC_FAIL;
                                        goto bail;
                                  syncfnd:
-                                       debug( "  entry(%d,%d,%u) ", 
srec->uid[M], srec->uid[S], srec->flags );
+                                       debugn( "  entry(%d,%d,%u) ", 
srec->uid[M], srec->uid[S], srec->flags );
                                        switch (buf[0]) {
                                        case '-':
@@ -633,5 +633,5 @@ sync_boxes( store_t *ctx[], const char *
                                                break;
                                        default:
-                                               fprintf( stderr, "Error: 
unrecognized journal entry at %s:%d\n", jname, line );
+                                               error( "Error: unrecognized 
journal entry at %s:%d\n", jname, line );
                                                fclose( jfp );
                                                ret = SYNC_FAIL;
@@ -644,5 +644,5 @@ sync_boxes( store_t *ctx[], const char *
        } else {
                if (errno != ENOENT) {
-                       fprintf( stderr, "Error: cannot read journal %s\n", 
jname );
+                       error( "Error: cannot read journal %s\n", jname );
                        ret = SYNC_FAIL;
                        goto bail;
@@ -650,10 +650,10 @@ sync_boxes( store_t *ctx[], const char *
        }
        if (!(nfp = fopen( nname, "w" ))) {
-               fprintf( stderr, "Error: cannot write new sync state %s\n", 
nname );
+               error( "Error: cannot write new sync state %s\n", nname );
                ret = SYNC_FAIL;
                goto bail;
        }
        if (!(jfp = fopen( jname, "a" ))) {
-               fprintf( stderr, "Error: cannot write journal %s\n", jname );
+               error( "Error: cannot write journal %s\n", jname );
                fclose( nfp );
                ret = SYNC_FAIL;
@@ -767,7 +767,7 @@ sync_boxes( store_t *ctx[], const char *
                        }
                }
-               debug( "  exception list is:" );
+               debugn( "  exception list is:" );
                for (t = 0; t < nmexcs; t++)
-                       debug( " %d", mexcs[t] );
+                       debugn( " %d", mexcs[t] );
                debug( "\n" );
        } else if (ctx[M]->opts & OPEN_OLD)
@@ -812,5 +812,5 @@ sync_boxes( store_t *ctx[], const char *
                                        if ((tmsg->flags & F_FLAGGED) || 
!chan->stores[t]->max_size || tmsg->size <= chan->stores[t]->max_size) {
                                                if (!nmsgs)
-                                                       info( t ? "Pulling new 
messages..." : "Pushing new messages..." );
+                                                       infon( t ? "Pulling new 
messages..." : "Pushing new messages..." );
                                                else
                                                        infoc( '.' );

--- isync/src/util.c  #1.7:1.8
@@ -31,5 +31,6 @@
 #include <ctype.h>
 
-int DFlags;
+int DFlags, Ontty;
+static int need_nl;
 
 void
@@ -47,4 +48,18 @@ debug( const char *msg, ... )
 
 void
+debugn( const char *msg, ... )
+{
+       va_list va;
+
+       if (DFlags & DEBUG) {
+               va_start( va, msg );
+               vprintf( msg, va );
+               va_end( va );
+               fflush( stdout );
+               need_nl = Ontty;
+       }
+}
+
+void
 info( const char *msg, ... )
 {
@@ -60,4 +75,18 @@ info( const char *msg, ... )
 
 void
+infon( const char *msg, ... )
+{
+       va_list va;
+
+       if (!(DFlags & QUIET)) {
+               va_start( va, msg );
+               vprintf( msg, va );
+               va_end( va );
+               fflush( stdout );
+               need_nl = Ontty;
+       }
+}
+
+void
 infoc( char c )
 {
@@ -65,4 +94,5 @@ infoc( char c )
                putchar( c );
                fflush( stdout );
+               need_nl = Ontty;
        }
 }
@@ -74,4 +104,8 @@ warn( const char *msg, ... )
 
        if (!(DFlags & VERYQUIET)) {
+               if (need_nl) {
+                       putchar( '\n' );
+                       need_nl = 0;
+               }
                va_start( va, msg );
                vfprintf( stderr, msg, va );
@@ -80,4 +114,18 @@ warn( const char *msg, ... )
 }
 
+void
+error( const char *msg, ... )
+{
+       va_list va;
+
+       if (need_nl) {
+               putchar( '\n' );
+               need_nl = 0;
+       }
+       va_start( va, msg );
+       vfprintf( stderr, msg, va );
+       va_end( va );
+}
+
 char *
 next_arg( char **s )
@@ -336,9 +384,9 @@ arc4_init( void )
 
        if ((fd = open( "/dev/urandom", O_RDONLY )) < 0 && (fd = open( 
"/dev/random", O_RDONLY )) < 0) {
-               fprintf( stderr, "Fatal: no random number source available.\n" 
);
+               error( "Fatal: no random number source available.\n" );
                exit( 3 );
        }
        if (read( fd, dat, 128 ) != 128) {
-               fprintf( stderr, "Fatal: cannot read random number source.\n" );
+               error( "Fatal: cannot read random number source.\n" );
                exit( 3 );
        }




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to