Ignore:
Timestamp:
Sep 23, 2008, 7:11:04 PM (13 years ago)
Author:
charles
Message:

run libT, cli, daemon, gtk through the source-code formatter "uncrustify" as promised/threatened

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r6425 r6795  
    3333struct tr_completion
    3434{
    35     unsigned int sizeWhenDoneIsDirty : 1;
    36 
    37     tr_torrent * tor;
     35    unsigned int    sizeWhenDoneIsDirty : 1;
     36
     37    tr_torrent *    tor;
    3838
    3939    /* do we have this block? */
    40     tr_bitfield * blockBitfield;
     40    tr_bitfield *  blockBitfield;
    4141
    4242    /* do we have this piece? */
    43     tr_bitfield * pieceBitfield;
     43    tr_bitfield *  pieceBitfield;
    4444
    4545    /* a block is complete if and only if we have it */
    46     uint16_t * completeBlocks;
     46    uint16_t *  completeBlocks;
    4747
    4848    /* number of bytes we'll have when done downloading. [0..info.totalSize]
    4949       DON'T access this directly; it's a lazy field.
    5050       use tr_cpSizeWhenDone() instead! */
    51     uint64_t sizeWhenDoneLazy;
     51    uint64_t    sizeWhenDoneLazy;
    5252
    5353    /* number of bytes we want or have now. [0..sizeWhenDone] */
    54     uint64_t sizeNow;
     54    uint64_t    sizeNow;
    5555};
    5656
     
    6060    tr_bitfieldClear( cp->pieceBitfield );
    6161    tr_bitfieldClear( cp->blockBitfield );
    62     memset( cp->completeBlocks, 0, sizeof(uint16_t) * cp->tor->info.pieceCount );
     62    memset( cp->completeBlocks, 0,
     63            sizeof( uint16_t ) * cp->tor->info.pieceCount );
    6364    cp->sizeNow = 0;
    6465    cp->sizeWhenDoneIsDirty = 1;
     
    6970{
    7071    tr_completion * cp  = tr_new( tr_completion, 1 );
     72
    7173    cp->tor             = tor;
    7274    cp->blockBitfield   = tr_bitfieldNew( tor->blockCount );
     
    8789
    8890void
    89 tr_cpInvalidateDND ( tr_completion * cp )
     91tr_cpInvalidateDND( tr_completion * cp )
    9092{
    9193    cp->sizeWhenDoneIsDirty = 1;
     
    9799    if( ccp->sizeWhenDoneIsDirty )
    98100    {
    99         tr_completion * cp = (tr_completion *) ccp; /* mutable */
     101        tr_completion *    cp = (tr_completion *) ccp; /* mutable */
    100102        const tr_torrent * tor = cp->tor;
    101         const tr_info * info = &tor->info;
    102         tr_piece_index_t i;
    103         uint64_t size = 0;
    104 
    105         for( i=0; i<info->pieceCount; ++i )
     103        const tr_info *    info = &tor->info;
     104        tr_piece_index_t   i;
     105        uint64_t           size = 0;
     106
     107        for( i = 0; i < info->pieceCount; ++i )
    106108        {
    107             if( !info->pieces[i].dnd ) {
     109            if( !info->pieces[i].dnd )
     110            {
    108111                /* we want the piece... */
    109112                size += tr_torPieceCountBytes( tor, i );
    110             } else if( tr_cpPieceIsComplete( cp, i ) ) {
     113            }
     114            else if( tr_cpPieceIsComplete( cp, i ) )
     115            {
    111116                /* we have the piece... */
    112117                size += tr_torPieceCountBytes( tor, i );
    113             } else if( cp->completeBlocks[i] ) {
     118            }
     119            else if( cp->completeBlocks[i] )
     120            {
    114121                /* we have part of the piece... */
    115122                const tr_block_index_t b = tr_torPieceFirstBlock( tor, i );
    116                 const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i );
    117                 tr_block_index_t j;
    118                 for( j=b; j<e; ++j )
     123                const tr_block_index_t e = b + tr_torPieceCountBlocks( tor,
     124                                                                       i );
     125                tr_block_index_t       j;
     126                for( j = b; j < e; ++j )
    119127                    if( tr_cpBlockIsComplete( cp, j ) )
    120128                        size += tr_torBlockCountBytes( tor, j );
     
    132140
    133141int
    134 tr_cpPieceIsComplete( const tr_completion  * cp,
    135                       tr_piece_index_t       piece )
    136 {
    137     return cp->completeBlocks[piece] == tr_torPieceCountBlocks(cp->tor,piece);
     142tr_cpPieceIsComplete( const tr_completion * cp,
     143                      tr_piece_index_t      piece )
     144{
     145    return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor,
     146                                                                piece );
    138147}
    139148
     
    145154
    146155void
    147 tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t piece )
    148 {
    149     const tr_torrent * tor = cp->tor;
    150     const tr_block_index_t start = tr_torPieceFirstBlock(tor,piece);
    151     const tr_block_index_t end = start + tr_torPieceCountBlocks(tor, piece);
    152     tr_block_index_t i;
    153 
    154     for( i=start; i<end; ++i )
    155         tr_cpBlockAdd( cp, i );
    156 }
    157 
    158 void
    159 tr_cpPieceRem( tr_completion * cp, tr_piece_index_t piece )
    160 {
    161     const tr_torrent * tor = cp->tor;
     156tr_cpPieceAdd( tr_completion *  cp,
     157               tr_piece_index_t piece )
     158{
     159    const tr_torrent *     tor = cp->tor;
    162160    const tr_block_index_t start = tr_torPieceFirstBlock( tor, piece );
    163161    const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, piece );
    164     tr_block_index_t block;
     162    tr_block_index_t       i;
     163
     164    for( i = start; i < end; ++i )
     165        tr_cpBlockAdd( cp, i );
     166}
     167
     168void
     169tr_cpPieceRem( tr_completion *  cp,
     170               tr_piece_index_t piece )
     171{
     172    const tr_torrent *     tor = cp->tor;
     173    const tr_block_index_t start = tr_torPieceFirstBlock( tor, piece );
     174    const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, piece );
     175    tr_block_index_t       block;
    165176
    166177    assert( cp );
     
    170181    assert( end <= tor->blockCount );
    171182
    172     for( block=start; block<end; ++block )
     183    for( block = start; block < end; ++block )
    173184        if( tr_cpBlockIsComplete( cp, block ) )
    174185            cp->sizeNow -= tr_torBlockCountBytes( tor, block );
     
    181192
    182193int
    183 tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block )
     194tr_cpBlockIsComplete( const tr_completion * cp,
     195                      tr_block_index_t      block )
    184196{
    185197    return tr_bitfieldHas( cp->blockBitfield, block );
     
    187199
    188200void
    189 tr_cpBlockAdd( tr_completion * cp, tr_block_index_t block )
     201tr_cpBlockAdd( tr_completion *  cp,
     202               tr_block_index_t block )
    190203{
    191204    const tr_torrent * tor = cp->tor;
     
    194207    {
    195208        const tr_piece_index_t piece = tr_torBlockPiece( tor, block );
    196         const int blockSize = tr_torBlockCountBytes( tor, block );
     209        const int              blockSize = tr_torBlockCountBytes( tor,
     210                                                                  block );
    197211
    198212        ++cp->completeBlocks[piece];
     
    221235
    222236tr_errno
    223 tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * bitfield )
     237tr_cpBlockBitfieldSet( tr_completion * cp,
     238                       tr_bitfield *   bitfield )
    224239{
    225240    tr_block_index_t i;
     
    229244    assert( cp->blockBitfield );
    230245
    231     if( !tr_bitfieldTestFast( bitfield, cp->tor->blockCount-1 ) )
     246    if( !tr_bitfieldTestFast( bitfield, cp->tor->blockCount - 1 ) )
    232247        return TR_ERROR_ASSERT;
    233248
    234249    tr_cpReset( cp );
    235     for( i=0; i<cp->tor->blockCount; ++i )
     250    for( i = 0; i < cp->tor->blockCount; ++i )
    236251        if( tr_bitfieldHasFast( bitfield, i ) )
    237252            tr_cpBlockAdd( cp, i );
     
    241256
    242257int
    243 tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
    244 {
    245     return tr_torPieceCountBlocks( cp->tor, piece ) - cp->completeBlocks[piece];
     258tr_cpMissingBlocksInPiece( const tr_completion * cp,
     259                           tr_piece_index_t      piece )
     260{
     261    return tr_torPieceCountBlocks( cp->tor,
     262                                   piece ) - cp->completeBlocks[piece];
    246263}
    247264
     
    253270tr_cpPercentDone( const tr_completion * cp )
    254271{
    255     return tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone(cp) );
     272    return tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) );
    256273}
    257274
    258275float
    259 tr_cpPercentComplete ( const tr_completion * cp )
     276tr_cpPercentComplete( const tr_completion * cp )
    260277{
    261278    return tr_getRatio( cp->sizeNow, cp->tor->info.totalSize );
     
    263280
    264281uint64_t
    265 tr_cpLeftUntilDone ( const tr_completion * cp )
    266 {
    267     return tr_cpSizeWhenDone(cp) - cp->sizeNow;
    268 }
    269 
    270 uint64_t
    271 tr_cpLeftUntilComplete ( const tr_completion * cp )
     282tr_cpLeftUntilDone( const tr_completion * cp )
     283{
     284    return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
     285}
     286
     287uint64_t
     288tr_cpLeftUntilComplete( const tr_completion * cp )
    272289{
    273290    return cp->tor->info.totalSize - cp->sizeNow;
     
    275292
    276293cp_status_t
    277 tr_cpGetStatus ( const tr_completion * cp )
     294tr_cpGetStatus( const tr_completion * cp )
    278295{
    279296    if( cp->sizeNow == cp->tor->info.totalSize ) return TR_CP_COMPLETE;
    280     if( cp->sizeNow == tr_cpSizeWhenDone(cp) ) return TR_CP_DONE;
     297    if( cp->sizeNow == tr_cpSizeWhenDone( cp ) ) return TR_CP_DONE;
    281298    return TR_CP_INCOMPLETE;
    282299}
     
    285302tr_cpHaveValid( const tr_completion * cp )
    286303{
    287     uint64_t b = 0;
    288     tr_piece_index_t i;
     304    uint64_t           b = 0;
     305    tr_piece_index_t   i;
    289306    const tr_torrent * tor = cp->tor;
    290307
    291     for( i=0; i<tor->info.pieceCount; ++i )
     308    for( i = 0; i < tor->info.pieceCount; ++i )
    292309        if( tr_cpPieceIsComplete( cp, i ) )
    293310            b += tr_torPieceCountBytes( tor, i );
     
    303320
    304321void
    305 tr_cpGetAmountDone( const tr_completion * cp, float * tab, int tabCount )
    306 {
    307     int i;
     322tr_cpGetAmountDone( const tr_completion * cp,
     323                    float *               tab,
     324                    int                   tabCount )
     325{
     326    int                i;
    308327    const tr_torrent * tor = cp->tor;
    309     const float interval = tor->info.pieceCount / (float)tabCount;
    310     const int isComplete = tr_cpGetStatus ( tor->completion ) == TR_CP_COMPLETE;
    311 
    312     for( i=0; i<tabCount; ++i )
     328    const float        interval = tor->info.pieceCount / (float)tabCount;
     329    const int          isComplete = tr_cpGetStatus ( tor->completion ) ==
     330                                    TR_CP_COMPLETE;
     331
     332    for( i = 0; i < tabCount; ++i )
    313333    {
    314334        const tr_piece_index_t piece = i * interval;
     
    318338        else if( isComplete || tr_cpPieceIsComplete( cp, piece ) )
    319339            tab[i] = 1.0f;
    320         else
    321             tab[i] = (float)cp->completeBlocks[piece] / tr_torPieceCountBlocks( tor, piece );
     340        else
     341            tab[i] = (float)cp->completeBlocks[piece] /
     342                     tr_torPieceCountBlocks( tor, piece );
    322343    }
    323344}
     345
Note: See TracChangeset for help on using the changeset viewer.