From a331582ec0693d86e4dcd17f6e4bc5f2658a082c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 30 Mar 2008 13:52:55 +0000 Subject: [PATCH] string folding --- daemon/misc.c | 2 +- gtk/conf.c | 4 ++-- gtk/ipc.c | 4 ++-- gtk/makemeta-ui.c | 2 +- gtk/msgwin.c | 2 +- gtk/tr-prefs.c | 2 +- libtransmission/bencode.c | 2 +- libtransmission/blocklist.c | 18 ++++++++++-------- libtransmission/fastresume.c | 4 ++-- libtransmission/fdlimit.c | 2 +- libtransmission/metainfo.c | 4 ++-- libtransmission/utils.c | 15 ++++++++------- 12 files changed, 32 insertions(+), 29 deletions(-) diff --git a/daemon/misc.c b/daemon/misc.c index 8c342aef8..2820f104e 100644 --- a/daemon/misc.c +++ b/daemon/misc.c @@ -133,7 +133,7 @@ writefile( const char * name, uint8_t * buf, ssize_t len ) fd = open( name, O_WRONLY | O_CREAT | O_TRUNC, 0666 ); if( 0 > fd ) { - errnomsg( "Couldn't open \"%s\": %s", name, tr_strerror( errno ) ); + errnomsg( "Couldn't open \"%1$s\": %2$s", name, tr_strerror( errno ) ); return -1; } diff --git a/gtk/conf.c b/gtk/conf.c index 7485127d1..fd9bd99f9 100644 --- a/gtk/conf.c +++ b/gtk/conf.c @@ -57,7 +57,7 @@ cf_init(const char *dir, char **errstr) return TRUE; if( errstr != NULL ) - *errstr = g_strdup_printf( _( "Couldn't create \"%s\": %s" ), + *errstr = g_strdup_printf( _( "Couldn't create \"%1$s\": %2$s" ), gl_confdir, g_strerror(errno) ); return FALSE; @@ -78,7 +78,7 @@ lockfile(const char * filename, char **errstr) if( errstr ) switch( state ) { case TR_LOCKFILE_EOPEN: - *errstr = g_strdup_printf( _( "Couldn't open \"%s\": %s" ), + *errstr = g_strdup_printf( _( "Couldn't open \"%1$s\": %2$s" ), filename, g_strerror( errno ) ); break; case TR_LOCKFILE_ELOCK: diff --git a/gtk/ipc.c b/gtk/ipc.c index 5b130d688..582a366d2 100644 --- a/gtk/ipc.c +++ b/gtk/ipc.c @@ -270,7 +270,7 @@ client_connect(char *path, struct constate *con) { strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1); if(0 > connect(con->fd, (struct sockaddr*)&addr, SUN_LEN(&addr))) { - g_message( _("Couldn't connect to \"%s\": %s"), path, g_strerror(errno)); + g_message( _("Couldn't connect to \"%1$s\": %2$s"), path, g_strerror(errno)); return FALSE; } @@ -477,7 +477,7 @@ serv_bind(struct constate *con) { return; fail: - errmsg(con->u.serv.wind, _("Couldn't set up socket: %s"), + errmsg(con->u.serv.wind, _("Couldn't create socket: %s"), g_strerror(errno)); if(0 <= con->fd) EVUTIL_CLOSESOCKET(con->fd); diff --git a/gtk/makemeta-ui.c b/gtk/makemeta-ui.c index 992414f69..d1a2be650 100644 --- a/gtk/makemeta-ui.c +++ b/gtk/makemeta-ui.c @@ -107,7 +107,7 @@ refresh_cb ( gpointer user_data ) break; case TR_MAKEMETA_IO_READ: { - char * tmp = g_strdup_printf( _( "Couldn't read \"%s\": %s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) ); + char * tmp = g_strdup_printf( _( "Couldn't read \"%1$s\": %2$s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) ); txt = g_strdup_printf( _( "Torrent creation failed: %s" ), tmp ); g_free( tmp ); break; diff --git a/gtk/msgwin.c b/gtk/msgwin.c index bfa2124b9..9b4fc0b0e 100644 --- a/gtk/msgwin.c +++ b/gtk/msgwin.c @@ -81,7 +81,7 @@ doSave( GtkWindow * parent, if( !fp ) { errmsg( parent, - _("Couldn't save file \"%s\": %s"), + _("Couldn't save file \"%1$s\": %2$s"), filename, g_strerror( errno ) ); } else diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index ed2ef0b47..24f875b61 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -368,7 +368,7 @@ updateBlocklist( gpointer vdata ) if( ok && !data->abortFlag ) { g_snprintf( data->secondary, sizeof( data->secondary ), - _( "Blocklist now has %'d rules" ), rules ); + _( "Blocklist updated with %'d rules" ), rules ); g_idle_add( blocklistDialogSetSecondary, data ); g_idle_add( blocklistDialogAllowClose, data->dialog ); } diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index e4229c354..3c661df67 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -690,7 +690,7 @@ static void saveStringFunc( const tr_benc * val, void * vevbuf ) { struct evbuffer * evbuf = vevbuf; - evbuffer_add_printf( evbuf, "%i:", val->val.s.i ); + evbuffer_add_printf( evbuf, "%d:", val->val.s.i ); evbuffer_add( evbuf, val->val.s.s, val->val.s.i ); } static void diff --git a/libtransmission/blocklist.c b/libtransmission/blocklist.c index 10ecc9a68..c651a1653 100644 --- a/libtransmission/blocklist.c +++ b/libtransmission/blocklist.c @@ -70,22 +70,23 @@ blocklistLoad( tr_blocklist * b ) { int fd; struct stat st; + const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" ); blocklistClose( b ); fd = open( b->filename, O_RDONLY ); if( fd == -1 ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), b->filename, tr_strerror(errno) ); + tr_err( err_fmt, b->filename, tr_strerror(errno) ); return; } if( fstat( fd, &st ) == -1 ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), b->filename, tr_strerror(errno) ); + tr_err( err_fmt, b->filename, tr_strerror(errno) ); close( fd ); return; } b->rules = mmap( 0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0 ); if( !b->rules ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), b->filename, tr_strerror(errno) ); + tr_err( err_fmt, b->filename, tr_strerror(errno) ); close( fd ); return; } @@ -93,7 +94,7 @@ blocklistLoad( tr_blocklist * b ) b->byteCount = st.st_size; b->ruleCount = st.st_size / sizeof( struct tr_ip_range ); b->fd = fd; - tr_inf( _( "Blocklist contains %'d IP ranges" ), b->ruleCount ); + tr_inf( _( "Blocklist contains %'d rules" ), b->ruleCount ); } static void @@ -212,6 +213,7 @@ tr_blocklistSetContent( tr_handle * handle, FILE * out; char * line; int lineCount = 0; + const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" ); if( !filename ) { blocklistDelete( b ); @@ -220,7 +222,7 @@ tr_blocklistSetContent( tr_handle * handle, in = fopen( filename, "r" ); if( !in ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), filename, tr_strerror(errno) ); + tr_err( err_fmt, filename, tr_strerror(errno) ); return 0; } @@ -228,7 +230,7 @@ tr_blocklistSetContent( tr_handle * handle, out = fopen( b->filename, "wb+" ); if( !out ) { - tr_err( _( "Couldn't save file \"%s\": %s" ), b->filename, tr_strerror( errno ) ); + tr_err( err_fmt, b->filename, tr_strerror( errno ) ); fclose( in ); return 0; } @@ -259,14 +261,14 @@ tr_blocklistSetContent( tr_handle * handle, free( line ); if( fwrite( &range, sizeof(struct tr_ip_range), 1, out ) != 1 ) { - tr_err( _( "Couldn't save file \"%s\": %s" ), b->filename, tr_strerror( errno ) ); + tr_err( _( "Couldn't save file \"%1$s\": %2$s" ), b->filename, tr_strerror( errno ) ); break; } ++lineCount; } - tr_inf( _( "Blocklist updated with %'d IP ranges" ), lineCount ); + tr_inf( _( "Blocklist updated with %'d rules" ), lineCount ); fclose( out ); fclose( in ); diff --git a/libtransmission/fastresume.c b/libtransmission/fastresume.c index 146d927c0..206475288 100644 --- a/libtransmission/fastresume.c +++ b/libtransmission/fastresume.c @@ -188,7 +188,7 @@ tr_fastResumeSave( const tr_torrent * tor ) fastResumeFileName( path, sizeof path, tor, 1 ); file = fopen( path, "wb+" ); if( !file ) { - tr_torerr( tor, _( "Couldn't open \"%s\": %s" ), path, tr_strerror( errno ) ); + tr_torerr( tor, _( "Couldn't open \"%1$s\": %2$s" ), path, tr_strerror( errno ) ); return; } @@ -543,7 +543,7 @@ parsePeers( tr_torrent * tor, const uint8_t * buf, uint32_t len ) tr_peerMgrAddPex( tor->handle->peerMgr, tor->info.hash, TR_PEER_FROM_CACHE, &pex ); } - tr_tordbg( tor, _( "Loaded %i peers from resume file" ), count ); + tr_tordbg( tor, _( "Loaded %d peers from resume file" ), count ); ret = TR_FR_PEERS; } diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 9f859c474..b32169669 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -163,7 +163,7 @@ TrOpenFile( int i, file->fd = open( filename, flags, 0666 ); if( file->fd == -1 ) { const int err = errno; - tr_err( _( "Couldn't open \"%s\": %s" ), filename, tr_strerror(err) ); + tr_err( _( "Couldn't open \"%1$s\": %2$s" ), filename, tr_strerror(err) ); return tr_ioErrorFromErrno( err ); } diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 12408c834..b54651277 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -589,13 +589,13 @@ tr_metainfoSave( const char * hash, const char * tag, file = fopen( path, "wb+" ); if( !file ) { - tr_err( _( "Couldn't open \"%s\": %s" ), path, tr_strerror( errno ) ); + tr_err( _( "Couldn't open \"%1$s\": %2$s" ), path, tr_strerror( errno ) ); return TR_EINVALID; } fseek( file, 0, SEEK_SET ); if( fwrite( buf, 1, buflen, file ) != buflen ) { - tr_err( _( "Couldn't save file \"%s\": %s" ), path, tr_strerror( errno ) ); + tr_err( _( "Couldn't save file \"%1$s\": %2$s" ), path, tr_strerror( errno ) ); fclose( file ); return TR_EINVALID; } diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 7e6710103..064227cf2 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -394,18 +394,19 @@ tr_loadFile( const char * path, size_t * size ) uint8_t * buf; struct stat sb; FILE * file; + const char * err_fmt = _( "Couldn't read \"%1$s\": %2$s" ); /* try to stat the file */ errno = 0; if( stat( path, &sb ) ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), path, tr_strerror(errno) ); + tr_dbg( err_fmt, path, tr_strerror(errno) ); return NULL; } if( ( sb.st_mode & S_IFMT ) != S_IFREG ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), path, _( "Not a regular file" ) ); + tr_err( err_fmt, path, _( "Not a regular file" ) ); return NULL; } @@ -413,20 +414,20 @@ tr_loadFile( const char * path, size_t * size ) file = fopen( path, "rb" ); if( !file ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), path, tr_strerror(errno) ); + tr_err( err_fmt, path, tr_strerror(errno) ); return NULL; } buf = malloc( sb.st_size ); if( NULL == buf ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), path, _( "Memory allocation failed" ) ); + tr_err( err_fmt, path, _( "Memory allocation failed" ) ); fclose( file ); return NULL; } fseek( file, 0, SEEK_SET ); if( fread( buf, sb.st_size, 1, file ) != 1 ) { - tr_err( _( "Couldn't read file \"%s\": %s" ), path, tr_strerror(errno) ); + tr_err( err_fmt, path, tr_strerror(errno) ); free( buf ); fclose( file ); return NULL; @@ -481,7 +482,7 @@ tr_mkdirp( const char * path_in, int permissions ) /* Folder doesn't exist yet */ if( tr_mkdir( path, permissions ) ) { const int err = errno; - tr_err( _( "Couldn't create \"%s\": %s" ), path, tr_strerror( err ) ); + tr_err( _( "Couldn't create \"%1$s\": %2$s" ), path, tr_strerror( err ) ); tr_free( path ); errno = err; return -1; @@ -492,7 +493,7 @@ tr_mkdirp( const char * path_in, int permissions ) /* Node exists but isn't a folder */ char buf[MAX_PATH_LENGTH]; snprintf( buf, sizeof( buf ), _( "File \"%s\" is in the way" ), path ); - tr_err( _( "Couldn't create \"%s\": %s" ), path_in, buf ); + tr_err( _( "Couldn't create \"%1$s\": %2$s" ), path_in, buf ); tr_free( path ); errno = ENOTDIR; return -1;