1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-12 07:03:44 +00:00

dead code removal.

This commit is contained in:
Charles Kerr 2007-10-20 15:17:36 +00:00
parent ad2f1ecb10
commit 6527f4e12a
4 changed files with 77 additions and 187 deletions

View file

@ -55,6 +55,82 @@ static char * announceToScrape( const char * announce );
static int parseFiles( tr_info * inf, benc_val_t * name,
benc_val_t * files, benc_val_t * length );
/***
****
***/
#define WANTBYTES( want, got ) \
if( (want) > (got) ) { return; } else { (got) -= (want); }
static void
strlcat_utf8( void * dest, const void * src, size_t len, char skip )
{
char * s = dest;
const char * append = src;
const char * p;
/* don't overwrite the nul at the end */
len--;
/* Go to the end of the destination string */
while( s[0] )
{
s++;
len--;
}
/* Now start appending, converting on the fly if necessary */
for( p = append; p[0]; )
{
/* skip over the requested character */
if( skip == p[0] )
{
p++;
continue;
}
if( !( p[0] & 0x80 ) )
{
/* ASCII character */
WANTBYTES( 1, len );
*(s++) = *(p++);
continue;
}
if( ( p[0] & 0xE0 ) == 0xC0 && ( p[1] & 0xC0 ) == 0x80 )
{
/* 2-bytes UTF-8 character */
WANTBYTES( 2, len );
*(s++) = *(p++); *(s++) = *(p++);
continue;
}
if( ( p[0] & 0xF0 ) == 0xE0 && ( p[1] & 0xC0 ) == 0x80 &&
( p[2] & 0xC0 ) == 0x80 )
{
/* 3-bytes UTF-8 character */
WANTBYTES( 3, len );
*(s++) = *(p++); *(s++) = *(p++);
*(s++) = *(p++);
continue;
}
if( ( p[0] & 0xF8 ) == 0xF0 && ( p[1] & 0xC0 ) == 0x80 &&
( p[2] & 0xC0 ) == 0x80 && ( p[3] & 0xC0 ) == 0x80 )
{
/* 4-bytes UTF-8 character */
WANTBYTES( 4, len );
*(s++) = *(p++); *(s++) = *(p++);
*(s++) = *(p++); *(s++) = *(p++);
continue;
}
/* ISO 8859-1 -> UTF-8 conversion */
WANTBYTES( 2, len );
*(s++) = 0xC0 | ( ( *p & 0xFF ) >> 6 );
*(s++) = 0x80 | ( *(p++) & 0x3F );
}
}
/***********************************************************************
* tr_metainfoParse
***********************************************************************

View file

@ -1063,7 +1063,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf )
case BT_HAVE_NONE: {
assert( msglen == 0 );
dbgmsg( msgs, "Got a BT_HAVE_NONE" );
memset( msgs->info->have->bits, 1, msgs->info->have->len );
tr_bitfieldClear( msgs->info->have );
updatePeerProgress( msgs );
break;
}

View file

@ -295,27 +295,6 @@ tr_set_compare( const void * va, size_t aCount,
****
***/
#if 0
void*
tr_memmem( const void* haystack, size_t hl,
const void* needle, size_t nl)
{
const char *walk, *end;
if( !nl )
return (void*) haystack;
if( hl < nl )
return NULL;
for (walk=(const char*)haystack, end=walk+hl-nl; walk!=end; ++walk)
if( !memcmp( walk, needle, nl ) )
return (void*) walk;
return NULL;
}
#else
void * tr_memmem ( const void *vbig, size_t big_len,
const void *vlittle, size_t little_len )
{
@ -345,20 +324,11 @@ void * tr_memmem ( const void *vbig, size_t big_len,
return NULL;
}
#endif
/**
***
**/
int
tr_compareUint8 ( uint8_t a, uint8_t b )
{
if( a < b ) return -1;
if( a > b ) return 1;
return 0;
}
int
tr_compareUint16( uint16_t a, uint16_t b )
{
@ -375,27 +345,10 @@ tr_compareUint32( uint32_t a, uint32_t b )
return 0;
}
int
tr_compareUint64( uint64_t a, uint64_t b )
{
if( a < b ) return -1;
if( a > b ) return 1;
return 0;
}
/**
***
**/
struct timeval
timevalSec ( int seconds )
{
struct timeval ret;
ret.tv_sec = seconds;
ret.tv_usec = 0;
return ret;
}
struct timeval
timevalMsec( uint64_t milliseconds )
{
@ -867,18 +820,6 @@ tr_bitfieldRemRange ( tr_bitfield * b,
tr_bitfieldRem( b, i );
}
tr_bitfield*
tr_bitfieldNegate( tr_bitfield * b )
{
uint8_t *it;
const uint8_t *end;
for( it=b->bits, end=it+b->len; it!=end; ++it )
*it = ~*it;
return b;
}
tr_bitfield*
tr_bitfieldAnd( tr_bitfield * a, const tr_bitfield * b )
{
@ -949,115 +890,3 @@ tr_wait( uint64_t delay_milliseconds )
usleep( 1000 * delay_milliseconds );
#endif
}
#define WANTBYTES( want, got ) \
if( (want) > (got) ) { return; } else { (got) -= (want); }
void
strlcat_utf8( void * dest, const void * src, size_t len, char skip )
{
char * s = dest;
const char * append = src;
const char * p;
/* don't overwrite the nul at the end */
len--;
/* Go to the end of the destination string */
while( s[0] )
{
s++;
len--;
}
/* Now start appending, converting on the fly if necessary */
for( p = append; p[0]; )
{
/* skip over the requested character */
if( skip == p[0] )
{
p++;
continue;
}
if( !( p[0] & 0x80 ) )
{
/* ASCII character */
WANTBYTES( 1, len );
*(s++) = *(p++);
continue;
}
if( ( p[0] & 0xE0 ) == 0xC0 && ( p[1] & 0xC0 ) == 0x80 )
{
/* 2-bytes UTF-8 character */
WANTBYTES( 2, len );
*(s++) = *(p++); *(s++) = *(p++);
continue;
}
if( ( p[0] & 0xF0 ) == 0xE0 && ( p[1] & 0xC0 ) == 0x80 &&
( p[2] & 0xC0 ) == 0x80 )
{
/* 3-bytes UTF-8 character */
WANTBYTES( 3, len );
*(s++) = *(p++); *(s++) = *(p++);
*(s++) = *(p++);
continue;
}
if( ( p[0] & 0xF8 ) == 0xF0 && ( p[1] & 0xC0 ) == 0x80 &&
( p[2] & 0xC0 ) == 0x80 && ( p[3] & 0xC0 ) == 0x80 )
{
/* 4-bytes UTF-8 character */
WANTBYTES( 4, len );
*(s++) = *(p++); *(s++) = *(p++);
*(s++) = *(p++); *(s++) = *(p++);
continue;
}
/* ISO 8859-1 -> UTF-8 conversion */
WANTBYTES( 2, len );
*(s++) = 0xC0 | ( ( *p & 0xFF ) >> 6 );
*(s++) = 0x80 | ( *(p++) & 0x3F );
}
}
size_t
bufsize_utf8( const void * vstr, int * changed )
{
const char * str = vstr;
size_t ii, grow;
if( NULL != changed )
*changed = 0;
ii = 0;
grow = 1;
while( '\0' != str[ii] )
{
if( !( str[ii] & 0x80 ) )
/* ASCII character */
ii++;
else if( ( str[ii] & 0xE0 ) == 0xC0 && ( str[ii+1] & 0xC0 ) == 0x80 )
/* 2-bytes UTF-8 character */
ii += 2;
else if( ( str[ii] & 0xF0 ) == 0xE0 && ( str[ii+1] & 0xC0 ) == 0x80 &&
( str[ii+2] & 0xC0 ) == 0x80 )
/* 3-bytes UTF-8 character */
ii += 3;
else if( ( str[ii] & 0xF8 ) == 0xF0 && ( str[ii+1] & 0xC0 ) == 0x80 &&
( str[ii+2] & 0xC0 ) == 0x80 && ( str[ii+3] & 0xC0 ) == 0x80 )
/* 4-bytes UTF-8 character */
ii += 4;
else
{
/* ISO 8859-1 -> UTF-8 conversion */
ii++;
grow++;
if( NULL != changed )
*changed = 1;
}
}
return ii + grow;
}

View file

@ -83,7 +83,6 @@ int tr_concat( char ** buf, int * used, int * max,
void tr_buildPath( char* buf, size_t buflen,
const char * first_element, ... );
struct timeval timevalSec( int seconds );
struct timeval timevalMsec( uint64_t milliseconds );
@ -97,17 +96,6 @@ uint64_t tr_date( void );
/* wait the specified number of milliseconds */
void tr_wait( uint64_t delay_milliseconds );
/***********************************************************************
* strlcat_utf8
***********************************************************************
* According to the official specification, all strings in the torrent
* file are supposed to be UTF-8 encoded. However, there are
* non-compliant torrents around... If we encounter an invalid UTF-8
* character, we assume it is ISO 8859-1 and convert it to UTF-8.
**********************************************************************/
void strlcat_utf8( void *, const void *, size_t, char );
size_t bufsize_utf8( const void *, int * );
/***
****
***/
@ -155,10 +143,8 @@ void tr_set_compare( const void * a, size_t aCount,
tr_set_func in_both_cb,
void * userData );
int tr_compareUint8 ( uint8_t a, uint8_t b );
int tr_compareUint16( uint16_t a, uint16_t b );
int tr_compareUint32( uint32_t a, uint32_t b );
int tr_compareUint64( uint64_t a, uint64_t b );
/***
****
@ -187,7 +173,6 @@ int tr_bitfieldHas( const tr_bitfield*, size_t bit );
int tr_bitfieldIsEmpty( const tr_bitfield* );
size_t tr_bitfieldCountTrueBits( const tr_bitfield* );
tr_bitfield* tr_bitfieldNegate( tr_bitfield* );
tr_bitfield* tr_bitfieldAnd( tr_bitfield*, const tr_bitfield* );
#endif