forked from premiere/premiere-libtorrent
fix more warnings in examples and tools
This commit is contained in:
parent
8586023022
commit
c3a22b90b3
|
@ -52,7 +52,7 @@ std::vector<char> load_file(std::string const& filename)
|
|||
size_t const size = size_t(in.tellg());
|
||||
in.seekg(0, std::ios_base::beg);
|
||||
std::vector<char> ret(size);
|
||||
in.read(ret.data(), ret.size());
|
||||
in.read(ret.data(), size);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,9 +48,9 @@ std::string to_string(int v, int width)
|
|||
return buf;
|
||||
}
|
||||
|
||||
std::string add_suffix_float(float val, char const* suffix)
|
||||
std::string add_suffix_float(double val, char const* suffix)
|
||||
{
|
||||
if (val < 0.001f)
|
||||
if (val < 0.001)
|
||||
{
|
||||
std::string ret;
|
||||
ret.resize(4 + 2, ' ');
|
||||
|
@ -63,8 +63,8 @@ std::string add_suffix_float(float val, char const* suffix)
|
|||
int i = 0;
|
||||
for (; i < num_prefix - 1; ++i)
|
||||
{
|
||||
val /= 1000.f;
|
||||
if (std::fabs(val) < 1000.f) break;
|
||||
val /= 1000.;
|
||||
if (std::fabs(val) < 1000.) break;
|
||||
}
|
||||
char ret[100];
|
||||
std::snprintf(ret, sizeof(ret), "%4.*f%s%s", val < 99 ? 1 : 0, val, prefix[i], suffix ? suffix : "");
|
||||
|
@ -88,7 +88,7 @@ std::string const& progress_bar(int progress, int width, color_code c
|
|||
bar.clear();
|
||||
bar.reserve(size_t(width + 10));
|
||||
|
||||
int const progress_chars = (progress * width + 500) / 1000;
|
||||
auto const progress_chars = static_cast<std::size_t>((progress * width + 500) / 1000);
|
||||
|
||||
if (caption.empty())
|
||||
{
|
||||
|
@ -181,13 +181,13 @@ std::string const& piece_bar(lt::bitfield const& p, int width)
|
|||
// now, print color[0] and [1]
|
||||
// bg determines whether we're settings foreground or background color
|
||||
static int const bg[] = { 38, 48};
|
||||
for (int i = 0; i < 2; ++i)
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
if (color[i] != last_color[i])
|
||||
if (color[k] != last_color[k])
|
||||
{
|
||||
char buf[40];
|
||||
std::snprintf(buf, sizeof(buf), "\x1b[%d;5;%dm", bg[i & 1], 232 + color[i]);
|
||||
last_color[i] = color[i];
|
||||
std::snprintf(buf, sizeof(buf), "\x1b[%d;5;%dm", bg[k & 1], 232 + color[k]);
|
||||
last_color[k] = color[k];
|
||||
bar += buf;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ char const* esc(char const* code);
|
|||
|
||||
std::string to_string(int v, int width);
|
||||
|
||||
std::string add_suffix_float(float val, char const* suffix);
|
||||
std::string add_suffix_float(double val, char const* suffix);
|
||||
|
||||
template<class T> std::string add_suffix(T val, char const* suffix = 0) {
|
||||
return add_suffix_float(float(val), suffix);
|
||||
template<class T> std::string add_suffix(T val, char const* suffix = nullptr) {
|
||||
return add_suffix_float(double(val), suffix);
|
||||
}
|
||||
|
||||
std::string color(std::string const& s, color_code c);
|
||||
|
|
|
@ -39,11 +39,11 @@ using namespace lt;
|
|||
int main()
|
||||
{
|
||||
std::vector<stats_metric> m = session_stats_metrics();
|
||||
for (int i = 0; i < int(m.size()); ++i)
|
||||
for (auto const& c : m)
|
||||
{
|
||||
std::printf("%s: %s (%d)\n"
|
||||
, m[i].type == metric_type_t::counter ? "CNTR" : "GAUG"
|
||||
, m[i].name, m[i].value_index);
|
||||
, c.type == metric_type_t::counter ? "CNTR" : "GAUG"
|
||||
, c.name, c.value_index);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/session.hpp"
|
||||
#include "libtorrent/alert_types.hpp"
|
||||
|
||||
namespace {
|
||||
char const* timestamp()
|
||||
{
|
||||
std::time_t t = std::time(nullptr);
|
||||
|
@ -59,6 +60,7 @@ void print_alert(lt::alert const* a)
|
|||
std::printf("[%s] %s\n", timestamp(), a->message().c_str());
|
||||
std::printf("%s", "\x1b[0m");
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
int main(int argc, char*[])
|
||||
{
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
add_executable(parse_access_log parse_access_log.cpp)
|
||||
target_link_libraries(parse_access_log PRIVATE torrent-rasterbar)
|
||||
|
||||
add_executable(dht dht_put.cpp)
|
||||
target_link_libraries(dht PRIVATE torrent-rasterbar)
|
||||
|
||||
|
|
|
@ -63,6 +63,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
#else
|
||||
|
||||
namespace {
|
||||
void usage()
|
||||
{
|
||||
std::fprintf(stderr,
|
||||
|
@ -190,7 +191,7 @@ void load_dht_state(lt::session& s)
|
|||
std::vector<char> state;
|
||||
state.resize(static_cast<std::size_t>(size));
|
||||
|
||||
f.read(state.data(), state.size());
|
||||
f.read(state.data(), size);
|
||||
if (f.fail())
|
||||
{
|
||||
std::fprintf(stderr, "failed to read .dht");
|
||||
|
@ -210,7 +211,6 @@ void load_dht_state(lt::session& s)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
int save_dht_state(lt::session& s)
|
||||
{
|
||||
entry e;
|
||||
|
@ -219,9 +219,10 @@ int save_dht_state(lt::session& s)
|
|||
bencode(std::back_inserter(state), e);
|
||||
|
||||
std::fstream f(".dht", std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
|
||||
f.write(state.data(), state.size());
|
||||
f.write(state.data(), static_cast<std::streamsize>(state.size()));
|
||||
return 0;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
|
@ -251,7 +252,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
settings_pack sett;
|
||||
sett.set_bool(settings_pack::enable_dht, false);
|
||||
sett.set_int(settings_pack::alert_mask, 0xffffffff);
|
||||
sett.set_int(settings_pack::alert_mask, 0x7fffffff);
|
||||
lt::session s(sett);
|
||||
|
||||
sett.set_bool(settings_pack::enable_dht, true);
|
||||
|
@ -272,7 +273,7 @@ int main(int argc, char* argv[])
|
|||
usage();
|
||||
}
|
||||
sha1_hash target;
|
||||
bool ret = from_hex({argv[0], 40}, (char*)&target[0]);
|
||||
bool ret = from_hex({argv[0], 40}, target.data());
|
||||
if (!ret)
|
||||
{
|
||||
std::fprintf(stderr, "invalid hex encoding of target hash\n");
|
||||
|
|
|
@ -44,7 +44,7 @@ int main(int /*argc*/, char* /*argv*/[])
|
|||
std::printf("press Ctrl+C, kill the process or wait for 1000 alerts\n");
|
||||
|
||||
settings_pack sett;
|
||||
sett.set_int(settings_pack::alert_mask, 0xffffffff);
|
||||
sett.set_int(settings_pack::alert_mask, 0x7fffffff);
|
||||
session s(sett);
|
||||
|
||||
int count = 0;
|
||||
|
|
Loading…
Reference in New Issue