Changeset 3473


Ignore:
Timestamp:
Oct 20, 2007, 3:17:36 PM (15 years ago)
Author:
charles
Message:

dead code removal.

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/metainfo.c

    r3430 r3473  
    5656                       benc_val_t * files, benc_val_t * length );
    5757
     58/***
     59****
     60***/
     61
     62#define WANTBYTES( want, got ) \
     63    if( (want) > (got) ) { return; } else { (got) -= (want); }
     64static void
     65strlcat_utf8( void * dest, const void * src, size_t len, char skip )
     66{
     67    char       * s      = dest;
     68    const char * append = src;
     69    const char * p;
     70
     71    /* don't overwrite the nul at the end */
     72    len--;
     73
     74    /* Go to the end of the destination string */
     75    while( s[0] )
     76    {
     77        s++;
     78        len--;
     79    }
     80
     81    /* Now start appending, converting on the fly if necessary */
     82    for( p = append; p[0]; )
     83    {
     84        /* skip over the requested character */
     85        if( skip == p[0] )
     86        {
     87            p++;
     88            continue;
     89        }
     90
     91        if( !( p[0] & 0x80 ) )
     92        {
     93            /* ASCII character */
     94            WANTBYTES( 1, len );
     95            *(s++) = *(p++);
     96            continue;
     97        }
     98
     99        if( ( p[0] & 0xE0 ) == 0xC0 && ( p[1] & 0xC0 ) == 0x80 )
     100        {
     101            /* 2-bytes UTF-8 character */
     102            WANTBYTES( 2, len );
     103            *(s++) = *(p++); *(s++) = *(p++);
     104            continue;
     105        }
     106
     107        if( ( p[0] & 0xF0 ) == 0xE0 && ( p[1] & 0xC0 ) == 0x80 &&
     108            ( p[2] & 0xC0 ) == 0x80 )
     109        {
     110            /* 3-bytes UTF-8 character */
     111            WANTBYTES( 3, len );
     112            *(s++) = *(p++); *(s++) = *(p++);
     113            *(s++) = *(p++);
     114            continue;
     115        }
     116
     117        if( ( p[0] & 0xF8 ) == 0xF0 && ( p[1] & 0xC0 ) == 0x80 &&
     118            ( p[2] & 0xC0 ) == 0x80 && ( p[3] & 0xC0 ) == 0x80 )
     119        {
     120            /* 4-bytes UTF-8 character */
     121            WANTBYTES( 4, len );
     122            *(s++) = *(p++); *(s++) = *(p++);
     123            *(s++) = *(p++); *(s++) = *(p++);
     124            continue;
     125        }
     126
     127        /* ISO 8859-1 -> UTF-8 conversion */
     128        WANTBYTES( 2, len );
     129        *(s++) = 0xC0 | ( ( *p & 0xFF ) >> 6 );
     130        *(s++) = 0x80 | ( *(p++) & 0x3F );
     131    }
     132}
     133
    58134/***********************************************************************
    59135 * tr_metainfoParse
  • trunk/libtransmission/peer-msgs.c

    r3469 r3473  
    10641064            assert( msglen == 0 );
    10651065            dbgmsg( msgs, "Got a BT_HAVE_NONE" );
    1066             memset( msgs->info->have->bits, 1, msgs->info->have->len );
     1066            tr_bitfieldClear( msgs->info->have );
    10671067            updatePeerProgress( msgs );
    10681068            break;
  • trunk/libtransmission/utils.c

    r3457 r3473  
    296296***/
    297297
    298 
    299 #if 0
    300 void*
    301 tr_memmem( const void* haystack, size_t hl,
    302            const void* needle,   size_t nl)
    303 {
    304     const char *walk, *end;
    305 
    306     if( !nl )
    307         return (void*) haystack;
    308 
    309     if( hl < nl )
    310         return NULL;
    311 
    312     for (walk=(const char*)haystack, end=walk+hl-nl; walk!=end; ++walk)
    313         if( !memcmp( walk, needle, nl ) )
    314             return (void*) walk;
    315 
    316     return NULL;
    317 }
    318 #else
    319298void * tr_memmem ( const void *vbig, size_t big_len,
    320299                   const void *vlittle, size_t little_len )
     
    346325    return NULL;
    347326}
    348 #endif
    349327
    350328/**
     
    353331
    354332int
    355 tr_compareUint8 (  uint8_t a,  uint8_t b )
     333tr_compareUint16( uint16_t a, uint16_t b )
    356334{
    357335    if( a < b ) return -1;
     
    361339
    362340int
    363 tr_compareUint16( uint16_t a, uint16_t b )
     341tr_compareUint32( uint32_t a, uint32_t b )
    364342{
    365343    if( a < b ) return -1;
     
    368346}
    369347
    370 int
    371 tr_compareUint32( uint32_t a, uint32_t b )
    372 {
    373     if( a < b ) return -1;
    374     if( a > b ) return 1;
    375     return 0;
    376 }
    377 
    378 int
    379 tr_compareUint64( uint64_t a, uint64_t b )
    380 {
    381     if( a < b ) return -1;
    382     if( a > b ) return 1;
    383     return 0;
    384 }
    385 
    386348/**
    387349***
    388350**/
    389 
    390 struct timeval
    391 timevalSec ( int seconds )
    392 {
    393     struct timeval ret;
    394     ret.tv_sec = seconds;
    395     ret.tv_usec = 0;
    396     return ret;
    397 }
    398351
    399352struct timeval
     
    869822
    870823tr_bitfield*
    871 tr_bitfieldNegate( tr_bitfield * b )
    872 {
    873     uint8_t *it;
    874     const uint8_t *end;
    875 
    876     for( it=b->bits, end=it+b->len; it!=end; ++it )
    877         *it = ~*it;
    878 
    879     return b;
    880 }
    881 
    882 tr_bitfield*
    883824tr_bitfieldAnd( tr_bitfield * a, const tr_bitfield * b )
    884825{
     
    950891#endif
    951892}
    952 
    953 #define WANTBYTES( want, got ) \
    954     if( (want) > (got) ) { return; } else { (got) -= (want); }
    955 void
    956 strlcat_utf8( void * dest, const void * src, size_t len, char skip )
    957 {
    958     char       * s      = dest;
    959     const char * append = src;
    960     const char * p;
    961 
    962     /* don't overwrite the nul at the end */
    963     len--;
    964 
    965     /* Go to the end of the destination string */
    966     while( s[0] )
    967     {
    968         s++;
    969         len--;
    970     }
    971 
    972     /* Now start appending, converting on the fly if necessary */
    973     for( p = append; p[0]; )
    974     {
    975         /* skip over the requested character */
    976         if( skip == p[0] )
    977         {
    978             p++;
    979             continue;
    980         }
    981 
    982         if( !( p[0] & 0x80 ) )
    983         {
    984             /* ASCII character */
    985             WANTBYTES( 1, len );
    986             *(s++) = *(p++);
    987             continue;
    988         }
    989 
    990         if( ( p[0] & 0xE0 ) == 0xC0 && ( p[1] & 0xC0 ) == 0x80 )
    991         {
    992             /* 2-bytes UTF-8 character */
    993             WANTBYTES( 2, len );
    994             *(s++) = *(p++); *(s++) = *(p++);
    995             continue;
    996         }
    997 
    998         if( ( p[0] & 0xF0 ) == 0xE0 && ( p[1] & 0xC0 ) == 0x80 &&
    999             ( p[2] & 0xC0 ) == 0x80 )
    1000         {
    1001             /* 3-bytes UTF-8 character */
    1002             WANTBYTES( 3, len );
    1003             *(s++) = *(p++); *(s++) = *(p++);
    1004             *(s++) = *(p++);
    1005             continue;
    1006         }
    1007 
    1008         if( ( p[0] & 0xF8 ) == 0xF0 && ( p[1] & 0xC0 ) == 0x80 &&
    1009             ( p[2] & 0xC0 ) == 0x80 && ( p[3] & 0xC0 ) == 0x80 )
    1010         {
    1011             /* 4-bytes UTF-8 character */
    1012             WANTBYTES( 4, len );
    1013             *(s++) = *(p++); *(s++) = *(p++);
    1014             *(s++) = *(p++); *(s++) = *(p++);
    1015             continue;
    1016         }
    1017 
    1018         /* ISO 8859-1 -> UTF-8 conversion */
    1019         WANTBYTES( 2, len );
    1020         *(s++) = 0xC0 | ( ( *p & 0xFF ) >> 6 );
    1021         *(s++) = 0x80 | ( *(p++) & 0x3F );
    1022     }
    1023 }
    1024 
    1025 size_t
    1026 bufsize_utf8( const void * vstr, int * changed )
    1027 {
    1028     const char * str = vstr;
    1029     size_t       ii, grow;
    1030 
    1031     if( NULL != changed )
    1032         *changed = 0;
    1033 
    1034     ii   = 0;
    1035     grow = 1;
    1036     while( '\0' != str[ii] )
    1037     {
    1038         if( !( str[ii] & 0x80 ) )
    1039             /* ASCII character */
    1040             ii++;
    1041         else if( ( str[ii]   & 0xE0 ) == 0xC0 && ( str[ii+1] & 0xC0 ) == 0x80 )
    1042             /* 2-bytes UTF-8 character */
    1043             ii += 2;
    1044         else if( ( str[ii]   & 0xF0 ) == 0xE0 && ( str[ii+1] & 0xC0 ) == 0x80 &&
    1045                  ( str[ii+2] & 0xC0 ) == 0x80 )
    1046             /* 3-bytes UTF-8 character */
    1047             ii += 3;
    1048         else if( ( str[ii]   & 0xF8 ) == 0xF0 && ( str[ii+1] & 0xC0 ) == 0x80 &&
    1049                  ( str[ii+2] & 0xC0 ) == 0x80 && ( str[ii+3] & 0xC0 ) == 0x80 )
    1050             /* 4-bytes UTF-8 character */
    1051             ii += 4;
    1052         else
    1053         {
    1054             /* ISO 8859-1 -> UTF-8 conversion */
    1055             ii++;
    1056             grow++;
    1057             if( NULL != changed )
    1058                 *changed = 1;
    1059         }
    1060     }
    1061 
    1062     return ii + grow;
    1063 }
  • trunk/libtransmission/utils.h

    r3457 r3473  
    8484                   const char * first_element, ... );
    8585
    86 struct timeval timevalSec( int seconds );
    8786struct timeval timevalMsec( uint64_t milliseconds );
    8887
     
    9796/* wait the specified number of milliseconds */
    9897void tr_wait( uint64_t delay_milliseconds );
    99 
    100 /***********************************************************************
    101  * strlcat_utf8
    102  ***********************************************************************
    103  * According to the official specification, all strings in the torrent
    104  * file are supposed to be UTF-8 encoded. However, there are
    105  * non-compliant torrents around... If we encounter an invalid UTF-8
    106  * character, we assume it is ISO 8859-1 and convert it to UTF-8.
    107  **********************************************************************/
    108 void strlcat_utf8( void *, const void *, size_t, char );
    109 size_t bufsize_utf8( const void *, int * );
    11098
    11199/***
     
    156144                     void * userData );
    157145                   
    158 int tr_compareUint8 (  uint8_t a,  uint8_t b );
    159146int tr_compareUint16( uint16_t a, uint16_t b );
    160147int tr_compareUint32( uint32_t a, uint32_t b );
    161 int tr_compareUint64( uint64_t a, uint64_t b );
    162148
    163149/***
     
    188174size_t tr_bitfieldCountTrueBits( const tr_bitfield* );
    189175
    190 tr_bitfield* tr_bitfieldNegate( tr_bitfield* );
    191176tr_bitfield* tr_bitfieldAnd( tr_bitfield*, const tr_bitfield* );
    192177
Note: See TracChangeset for help on using the changeset viewer.