Changeset 2430


Ignore:
Timestamp:
Jul 19, 2007, 11:54:37 AM (16 years ago)
Author:
charles
Message:

simplify xml.c and utils.c's dependencies

Location:
trunk/libtransmission
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/internal.h

    r2428 r2430  
    8686#endif
    8787
    88 /* Sometimes the system defines MAX/MIN, sometimes not. In the latter
    89    case, define those here since we will use them */
    90 #ifndef MAX
    91 #define MAX(a,b) ((a)>(b)?(a):(b))
    92 #endif
    93 #ifndef MIN
    94 #define MIN(a,b) ((a)>(b)?(b):(a))
    95 #endif
    96 
    9788#define TR_MAX_PEER_COUNT 60
    9889
    9990typedef struct tr_completion_s tr_completion_t;
    10091typedef struct tr_shared_s tr_shared_t;
    101 typedef struct tr_bitfield_s tr_bitfield_t;
    10292
    10393typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t;
     
    130120void tr_torrentWriterLock    ( tr_torrent_t * );
    131121void tr_torrentWriterUnlock  ( tr_torrent_t * );
     122
     123#define tr_blockPiece(a) _tr_blockPiece(tor,a)
     124int _tr_blockPiece( const tr_torrent_t * tor, int block );
     125
     126#define tr_blockSize(a) _tr_blockSize(tor,a)
     127int _tr_blockSize( const tr_torrent_t * tor, int block );
     128
     129#define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a)
     130int _tr_blockPosInPiece( const tr_torrent_t * tor, int block );
     131
     132#define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a)
     133int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece );
     134
     135#define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a)
     136int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece );
     137
     138#define tr_pieceSize(a) _tr_pieceSize(tor,a)
     139int _tr_pieceSize( const tr_torrent_t * tor, int piece );
     140
     141#define tr_block(a,b) _tr_block(tor,a,b)
     142int _tr_block( const tr_torrent_t * tor, int index, int begin );
     143
    132144
    133145typedef enum
  • trunk/libtransmission/torrent.c

    r2423 r2430  
    13351335        tr_torrentSetFileDL( tor, files[i], doDownload );
    13361336}
     1337
     1338/***
     1339****
     1340***/
     1341
     1342int _tr_blockPiece( const tr_torrent_t * tor, int block )
     1343{
     1344    const tr_info_t * inf = &tor->info;
     1345    return block / ( inf->pieceSize / tor->blockSize );
     1346}
     1347
     1348int _tr_blockSize( const tr_torrent_t * tor, int block )
     1349{
     1350    const tr_info_t * inf = &tor->info;
     1351    int dummy;
     1352
     1353    if( block != tor->blockCount - 1 ||
     1354        !( dummy = inf->totalSize % tor->blockSize ) )
     1355    {
     1356        return tor->blockSize;
     1357    }
     1358
     1359    return dummy;
     1360}
     1361
     1362int _tr_blockPosInPiece( const tr_torrent_t * tor, int block )
     1363{
     1364    const tr_info_t * inf = &tor->info;
     1365    return tor->blockSize *
     1366        ( block % ( inf->pieceSize / tor->blockSize ) );
     1367}
     1368
     1369int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece )
     1370{
     1371    const tr_info_t * inf = &tor->info;
     1372    if( piece < inf->pieceCount - 1 ||
     1373        !( tor->blockCount % ( inf->pieceSize / tor->blockSize ) ) )
     1374    {
     1375        return inf->pieceSize / tor->blockSize;
     1376    }
     1377    return tor->blockCount % ( inf->pieceSize / tor->blockSize );
     1378}
     1379
     1380int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece )
     1381{
     1382    const tr_info_t * inf = &tor->info;
     1383    return piece * ( inf->pieceSize / tor->blockSize );
     1384}
     1385
     1386int _tr_pieceSize( const tr_torrent_t * tor, int piece )
     1387{
     1388    const tr_info_t * inf = &tor->info;
     1389    if( piece < inf->pieceCount - 1 ||
     1390        !( inf->totalSize % inf->pieceSize ) )
     1391    {
     1392        return inf->pieceSize;
     1393    }
     1394    return inf->totalSize % inf->pieceSize;
     1395}
     1396
     1397int _tr_block( const tr_torrent_t * tor, int index, int begin )
     1398{
     1399    const tr_info_t * inf = &tor->info;
     1400    return index * ( inf->pieceSize / tor->blockSize ) +
     1401        begin / tor->blockSize;
     1402}
  • trunk/libtransmission/utils.c

    r2429 r2430  
    2424
    2525#include <ctype.h>
     26#include <errno.h>
    2627#include <stdarg.h>
     28#include <stdio.h>
     29#include <stdlib.h>
     30#include <string.h>
     31
    2732#include <sys/time.h>
    2833#include <sys/types.h>
     
    3237#include "transmission.h"
    3338#include "trcompat.h"
     39#include "utils.h"
     40#include "platform.h"
    3441
    3542#define SPRINTF_BUFSIZE         100
     
    696703#endif
    697704}
    698 
    699 /***
    700 ****
    701 ***/
    702 
    703 int _tr_blockPiece( const tr_torrent_t * tor, int block )
    704 {
    705     const tr_info_t * inf = &tor->info;
    706     return block / ( inf->pieceSize / tor->blockSize );
    707 }
    708 
    709 int _tr_blockSize( const tr_torrent_t * tor, int block )
    710 {
    711     const tr_info_t * inf = &tor->info;
    712     int dummy;
    713 
    714     if( block != tor->blockCount - 1 ||
    715         !( dummy = inf->totalSize % tor->blockSize ) )
    716     {
    717         return tor->blockSize;
    718     }
    719 
    720     return dummy;
    721 }
    722 
    723 int _tr_blockPosInPiece( const tr_torrent_t * tor, int block )
    724 {
    725     const tr_info_t * inf = &tor->info;
    726     return tor->blockSize *
    727         ( block % ( inf->pieceSize / tor->blockSize ) );
    728 }
    729 
    730 int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece )
    731 {
    732     const tr_info_t * inf = &tor->info;
    733     if( piece < inf->pieceCount - 1 ||
    734         !( tor->blockCount % ( inf->pieceSize / tor->blockSize ) ) )
    735     {
    736         return inf->pieceSize / tor->blockSize;
    737     }
    738     return tor->blockCount % ( inf->pieceSize / tor->blockSize );
    739 }
    740 
    741 int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece )
    742 {
    743     const tr_info_t * inf = &tor->info;
    744     return piece * ( inf->pieceSize / tor->blockSize );
    745 }
    746 
    747 int _tr_pieceSize( const tr_torrent_t * tor, int piece )
    748 {
    749     const tr_info_t * inf = &tor->info;
    750     if( piece < inf->pieceCount - 1 ||
    751         !( inf->totalSize % inf->pieceSize ) )
    752     {
    753         return inf->pieceSize;
    754     }
    755     return inf->totalSize % inf->pieceSize;
    756 }
    757 
    758 int _tr_block( const tr_torrent_t * tor, int index, int begin )
    759 {
    760     const tr_info_t * inf = &tor->info;
    761     return index * ( inf->pieceSize / tor->blockSize ) +
    762         begin / tor->blockSize;
    763 }
  • trunk/libtransmission/utils.h

    r2399 r2430  
    2727
    2828#include <stdarg.h>
     29#include <stdint.h>
    2930
    3031void tr_msgInit( void );
     
    3334#define tr_inf( a... ) tr_msg( TR_MSG_INF, ## a )
    3435#define tr_dbg( a... ) tr_msg( TR_MSG_DBG, ## a )
    35 void tr_msg  ( int level, char * msg, ... ) PRINTF( 2, 3 );
     36void tr_msg  ( int level, char * msg, ... );
    3637
    3738int  tr_rand ( int );
     
    6263 **********************************************************************/
    6364int tr_sprintf( char ** buf, int * used, int * max,
    64                 const char * format, ... ) PRINTF( 4, 5 );
     65                const char * format, ... );
    6566/* gee, it sure would be nice if BeOS had va_copy() */
    6667int tr_vsprintf( char **, int *, int *, const char *, va_list, va_list );
     
    8586void tr_wait( uint64_t delay_milliseconds );
    8687
    87 #define tr_blockPiece(a) _tr_blockPiece(tor,a)
    88 int _tr_blockPiece( const tr_torrent_t * tor, int block );
     88/***
     89****
     90***/
    8991
    90 #define tr_blockSize(a) _tr_blockSize(tor,a)
    91 int _tr_blockSize( const tr_torrent_t * tor, int block );
    92 
    93 #define tr_blockPosInPiece(a) _tr_blockPosInPiece(tor,a)
    94 int _tr_blockPosInPiece( const tr_torrent_t * tor, int block );
    95 
    96 #define tr_pieceCountBlocks(a) _tr_pieceCountBlocks(tor,a)
    97 int _tr_pieceCountBlocks( const tr_torrent_t * tor, int piece );
    98 
    99 #define tr_pieceStartBlock(a) _tr_pieceStartBlock(tor,a)
    100 int _tr_pieceStartBlock( const tr_torrent_t * tor, int piece );
    101 
    102 #define tr_pieceSize(a) _tr_pieceSize(tor,a)
    103 int _tr_pieceSize( const tr_torrent_t * tor, int piece );
    104 
    105 #define tr_block(a,b) _tr_block(tor,a,b)
    106 int _tr_block( const tr_torrent_t * tor, int index, int begin );
     92/* Sometimes the system defines MAX/MIN, sometimes not. In the latter
     93   case, define those here since we will use them */
     94#ifndef MAX
     95#define MAX(a,b) ((a)>(b)?(a):(b))
     96#endif
     97#ifndef MIN
     98#define MIN(a,b) ((a)>(b)?(b):(a))
     99#endif
    107100
    108101/***
     
    129122***/
    130123
    131 struct tr_bitfield_s
     124typedef struct tr_bitfield_s
    132125{
    133126    uint8_t * bits;
    134127    size_t len;
    135 };
     128}
     129tr_bitfield_t;
    136130
    137131tr_bitfield_t* tr_bitfieldNew( size_t bitcount );
  • trunk/libtransmission/xml.c

    r2311 r2430  
    2323 *****************************************************************************/
    2424
    25 #include "transmission.h"
     25#include <assert.h>
     26#include <string.h>
     27#include <stdlib.h>
     28
     29#include "utils.h"
    2630#include "xml.h"
    2731
Note: See TracChangeset for help on using the changeset viewer.