From 1f3ead026dd2863500547d3003f2e655ba7b1f6a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 25 Jun 2010 01:13:35 +0000 Subject: [PATCH] (trunk) #3311 "MingW build of Transmission" -- modify tr_strip_positional_args() to strip out the ' printf flag. Platforms not supporting $ tend to not support ' either --- libtransmission/utils-test.c | 24 ++++++++++++++++++++++++ libtransmission/utils.c | 12 ++++++------ libtransmission/utils.h | 3 ++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index a2fe748ac..c8335723c 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -102,6 +102,28 @@ test_bitfields( void ) return 0; } +static int +test_strip_positional_args( void ) +{ + const char * in; + const char * out; + const char * expected; + + in = "Hello %1$s foo %2$.*f"; + expected = "Hello %s foo %.*f"; + out = tr_strip_positional_args( in ); + check( out != NULL ) + check( !strcmp( out, expected ) ) + + in = "Hello %1$'d foo %2$'f"; + expected = "Hello %d foo %f"; + out = tr_strip_positional_args( in ); + check( out != NULL ) + check( !strcmp( out, expected ) ) + + return 0; +} + static int test_strstrip( void ) { @@ -392,6 +414,8 @@ main( void ) return i; if( ( i = test_lowerbound( ) ) ) return i; + if( ( i = test_strip_positional_args( ) ) ) + return i; if( ( i = test_strstrip( ) ) ) return i; if( ( i = test_buildpath( ) ) ) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 402e769fa..48495455d 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -404,8 +404,6 @@ tr_set_compare( const void * va, **** ***/ -#ifdef DISABLE_GETTEXT - const char* tr_strip_positional_args( const char* str ) { @@ -424,23 +422,25 @@ tr_strip_positional_args( const char* str ) for( out = buf; *str; ++str ) { *out++ = *str; + if( ( *str == '%' ) && isdigit( str[1] ) ) { const char * tmp = str + 1; while( isdigit( *tmp ) ) ++tmp; - if( *tmp == '$' ) - str = tmp; + str = tmp[1]=='\'' ? tmp+1 : tmp; } + + if( ( *str == '%' ) && ( str[1] == '\'' ) ) + str = str + 1; + } *out = '\0'; return strcmp( buf, in ) ? buf : in; } -#endif - /** *** **/ diff --git a/libtransmission/utils.h b/libtransmission/utils.h index bff74395f..07d9862db 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -88,6 +88,8 @@ extern "C" { **** ***/ +const char * tr_strip_positional_args( const char * fmt ); + #if !defined( _ ) #if defined( HAVE_LIBINTL_H ) && !defined( SYS_DARWIN ) #include @@ -104,7 +106,6 @@ extern "C" { #endif #endif #ifdef DISABLE_GETTEXT - const char * tr_strip_positional_args( const char * fmt ); #undef _ #define _( a ) tr_strip_positional_args( a ) #endif