refactor: remove TR_PRIsv macros (#3842)
* refactor: remove TR_PRIsv from transmission-show * refactor: remove TR_PRIsv from transmission-edit * refactor: remove TR_PRIsv from transmission-remote * refactor: remove TR_PRIsv from log.cc * refactor: remove TR_PRIsv macro * chore: remove FMT_STRING macro in transmission-edit * refactor: use __android_log_write()
This commit is contained in:
parent
326d9f3daf
commit
d82090658f
|
@ -125,10 +125,11 @@ void logAddImpl(
|
|||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
__android_log_print(prio, "transmission", "%" TR_PRIsv, TR_PRIsv_ARG(msg));
|
||||
auto const szmsg = fmt::format("{:s}", msg);
|
||||
#else
|
||||
__android_log_print(prio, "transmission", "[%s:%d] %" TR_PRIsv, file, line, TR_PRIsv_ARG(msg));
|
||||
auto const szmsg = fmt::format("[{:s}:{:d}] {:s}", file, line, msg);
|
||||
#endif
|
||||
__android_log_write(prio, "transmission", szmsg.c_str());
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -70,9 +70,6 @@
|
|||
// Mostly to enforce better formatting
|
||||
#define TR_ARG_TUPLE(...) __VA_ARGS__
|
||||
|
||||
#define TR_PRIsv "*.*s"
|
||||
#define TR_PRIsv_ARG(sv) TR_ARG_TUPLE(int(std::size(sv)), int(std::size(sv)), std::data(sv))
|
||||
|
||||
// https://www.bittorrent.org/beps/bep_0003.html
|
||||
// A string of length 20 which this downloader uses as its id. Each
|
||||
// downloader generates its own id at random at the start of a new
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "transmission.h"
|
||||
|
||||
#include "file.h"
|
||||
#include "platform.h"
|
||||
#include "tr-strbuf.h"
|
||||
|
||||
#include "test-fixtures.h"
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include <array>
|
||||
#include <stdio.h> /* fprintf() */
|
||||
#include <stdlib.h> /* EXIT_FAILURE */
|
||||
#include <cstdlib> // EXIT_FAILURE
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
|
||||
#include <libtransmission/error.h>
|
||||
|
@ -98,7 +99,7 @@ static bool removeURL(tr_variant* metainfo, std::string_view url)
|
|||
|
||||
if (tr_variantDictFindStrView(metainfo, TR_KEY_announce, &sv) && url == sv)
|
||||
{
|
||||
printf("\tRemoved \"%" TR_PRIsv "\" from \"announce\"\n", TR_PRIsv_ARG(sv));
|
||||
fmt::print("\tRemoved '{:s}' from 'announce'\n", sv);
|
||||
tr_variantDictRemove(metainfo, TR_KEY_announce);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ static bool removeURL(tr_variant* metainfo, std::string_view url)
|
|||
{
|
||||
if (tr_variantGetStrView(node, &sv) && url == sv)
|
||||
{
|
||||
printf("\tRemoved \"%" TR_PRIsv "\" from \"announce-list\" tier #%d\n", TR_PRIsv_ARG(sv), tierIndex + 1);
|
||||
fmt::print("\tRemoved '{:s}' from 'announce-list' tier #{:d}\n", sv, tierIndex + 1);
|
||||
tr_variantListRemove(tier, nodeIndex);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -128,7 +129,7 @@ static bool removeURL(tr_variant* metainfo, std::string_view url)
|
|||
|
||||
if (tr_variantListSize(tier) == 0)
|
||||
{
|
||||
printf("\tNo URLs left in tier #%d... removing tier\n", tierIndex + 1);
|
||||
fmt::print("\tNo URLs left in tier #{:d}... removing tier\n", tierIndex + 1);
|
||||
tr_variantListRemove(announce_list, tierIndex);
|
||||
}
|
||||
else
|
||||
|
@ -139,7 +140,7 @@ static bool removeURL(tr_variant* metainfo, std::string_view url)
|
|||
|
||||
if (tr_variantListSize(announce_list) == 0)
|
||||
{
|
||||
printf("\tNo tiers left... removing announce-list\n");
|
||||
fmt::print("\tNo tiers left... removing announce-list\n");
|
||||
tr_variantDictRemove(metainfo, TR_KEY_announce_list);
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +156,7 @@ static bool removeURL(tr_variant* metainfo, std::string_view url)
|
|||
if ((node != nullptr) && tr_variantGetStrView(node, &sv))
|
||||
{
|
||||
tr_variantDictAddStr(metainfo, TR_KEY_announce, sv);
|
||||
printf("\tAdded \"%" TR_PRIsv "\" to announce\n", TR_PRIsv_ARG(sv));
|
||||
fmt::print("\tAdded '{:s}' to announce\n", sv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,7 +192,7 @@ static bool replaceURL(tr_variant* metainfo, std::string_view oldval, std::strin
|
|||
if (tr_variantDictFindStrView(metainfo, TR_KEY_announce, &sv) && tr_strvContains(sv, oldval))
|
||||
{
|
||||
auto const newstr = replaceSubstr(sv, oldval, newval);
|
||||
printf("\tReplaced in \"announce\": \"%" TR_PRIsv "\" --> \"%s\"\n", TR_PRIsv_ARG(sv), newstr.c_str());
|
||||
fmt::print("\tReplaced in 'announce': '{:s}' --> '{:s}'\n", sv, newstr);
|
||||
tr_variantDictAddStr(metainfo, TR_KEY_announce, newstr);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -211,11 +212,7 @@ static bool replaceURL(tr_variant* metainfo, std::string_view oldval, std::strin
|
|||
if (tr_variantGetStrView(node, &sv) && tr_strvContains(sv, oldval))
|
||||
{
|
||||
auto const newstr = replaceSubstr(sv, oldval, newval);
|
||||
printf(
|
||||
"\tReplaced in \"announce-list\" tier %d: \"%" TR_PRIsv "\" --> \"%s\"\n",
|
||||
tierCount + 1,
|
||||
TR_PRIsv_ARG(sv),
|
||||
newstr.c_str());
|
||||
fmt::print("\tReplaced in 'announce-list' tier #{:d}: '{:s}' --> '{:s}'\n", tierCount + 1, sv, newstr);
|
||||
tr_variantClear(node);
|
||||
tr_variantInitStr(node, newstr);
|
||||
changed = true;
|
||||
|
@ -269,7 +266,7 @@ static bool addURL(tr_variant* metainfo, char const* url)
|
|||
if (!had_announce && !had_announce_list)
|
||||
{
|
||||
/* this new tracker is the only one, so add it to "announce"... */
|
||||
printf("\tAdded \"%s\" in \"announce\"\n", url);
|
||||
fmt::print("\tAdded '{:s}' in 'announce'\n", url);
|
||||
tr_variantDictAddStr(metainfo, TR_KEY_announce, url);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -294,7 +291,7 @@ static bool addURL(tr_variant* metainfo, char const* url)
|
|||
{
|
||||
tr_variant* tier = tr_variantListAddList(announce_list, 1);
|
||||
tr_variantListAddStr(tier, url);
|
||||
printf("\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_variantListSize(announce_list));
|
||||
fmt::print("\tAdded '{:s}' to 'announce-list' tier #{:d}\n", url, tr_variantListSize(announce_list));
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
@ -310,13 +307,13 @@ static bool setSource(tr_variant* metainfo, char const* source_value)
|
|||
|
||||
if (!had_source)
|
||||
{
|
||||
printf("\tAdded \"%s\" as source\n", source_value);
|
||||
fmt::print("\tAdded '{:s}' as source\n", source_value);
|
||||
tr_variantDictAddStr(metainfo, TR_KEY_source, source_value);
|
||||
changed = true;
|
||||
}
|
||||
else if (current_source.compare(source_value) != 0)
|
||||
{
|
||||
printf("\tUpdated source: \"%s\" -> \"%s\"\n", current_source.data(), source_value);
|
||||
fmt::print("\tUpdated source: '{:s}' -> '{:s}'\n", current_source.data(), source_value);
|
||||
tr_variantDictAddStr(metainfo, TR_KEY_source, source_value);
|
||||
changed = true;
|
||||
}
|
||||
|
@ -338,23 +335,23 @@ int tr_main(int argc, char* argv[])
|
|||
|
||||
if (options.show_version)
|
||||
{
|
||||
fprintf(stderr, "%s %s\n", MyName, LONG_VERSION_STRING);
|
||||
fmt::print(stderr, "{:s} {:s}\n", MyName, LONG_VERSION_STRING);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (std::empty(options.files))
|
||||
{
|
||||
fprintf(stderr, "ERROR: No torrent files specified.\n");
|
||||
fmt::print(stderr, "ERROR: No torrent files specified.\n");
|
||||
tr_getopt_usage(MyName, Usage, std::data(Options));
|
||||
fprintf(stderr, "\n");
|
||||
fmt::print(stderr, "\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (options.add == nullptr && options.deleteme == nullptr && options.replace[0] == nullptr && options.source == nullptr)
|
||||
{
|
||||
fprintf(stderr, "ERROR: Must specify -a, -d, -r or -s\n");
|
||||
fmt::print(stderr, "ERROR: Must specify -a, -d, -r or -s\n");
|
||||
tr_getopt_usage(MyName, Usage, std::data(Options));
|
||||
fprintf(stderr, "\n");
|
||||
fmt::print(stderr, "\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -364,11 +361,11 @@ int tr_main(int argc, char* argv[])
|
|||
bool changed = false;
|
||||
tr_error* error = nullptr;
|
||||
|
||||
printf("%" TR_PRIsv "\n", TR_PRIsv_ARG(filename));
|
||||
fmt::print("{:s}\n", filename);
|
||||
|
||||
if (!tr_variantFromFile(&top, TR_VARIANT_PARSE_BENC, filename, &error))
|
||||
{
|
||||
printf("\tError reading file: %s\n", error->message);
|
||||
fmt::print("\tError reading file: {:s}\n", error->message);
|
||||
tr_error_free(error);
|
||||
continue;
|
||||
}
|
||||
|
@ -402,7 +399,7 @@ int tr_main(int argc, char* argv[])
|
|||
tr_variantClear(&top);
|
||||
}
|
||||
|
||||
printf("Changed %d files\n", changedCount);
|
||||
fmt::print("Changed {:d} files\n", changedCount);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
396
utils/remote.cc
396
utils/remote.cc
File diff suppressed because it is too large
Load Diff
|
@ -5,8 +5,6 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cinttypes> // PRIu64
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
@ -190,33 +188,33 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
|||
**/
|
||||
if (opts.print_info)
|
||||
{
|
||||
printf("GENERAL\n\n");
|
||||
printf(" Name: %s\n", metainfo.name().c_str());
|
||||
fmt::print("GENERAL\n\n");
|
||||
fmt::print(" Name: {:s}\n", metainfo.name());
|
||||
if (metainfo.hasV1Metadata())
|
||||
{
|
||||
printf(" Hash v1: %" TR_PRIsv "\n", TR_PRIsv_ARG(metainfo.infoHashString()));
|
||||
fmt::print(" Hash v1: {:s}\n", metainfo.infoHashString());
|
||||
}
|
||||
if (metainfo.hasV2Metadata())
|
||||
{
|
||||
printf(" Hash v2: %" TR_PRIsv "\n", TR_PRIsv_ARG(metainfo.infoHash2String()));
|
||||
fmt::print(" Hash v2: {:s}\n", metainfo.infoHash2String());
|
||||
}
|
||||
printf(" Created by: %s\n", std::empty(metainfo.creator()) ? "Unknown" : metainfo.creator().c_str());
|
||||
printf(" Created on: %s\n\n", toString(metainfo.dateCreated()).c_str());
|
||||
fmt::print(" Created by: {:s}\n", std::empty(metainfo.creator()) ? "Unknown" : metainfo.creator());
|
||||
fmt::print(" Created on: {:s}\n\n", toString(metainfo.dateCreated()));
|
||||
|
||||
if (!std::empty(metainfo.comment()))
|
||||
{
|
||||
printf(" Comment: %s\n", metainfo.comment().c_str());
|
||||
fmt::print(" Comment: {:s}\n", metainfo.comment());
|
||||
}
|
||||
|
||||
if (!std::empty(metainfo.source()))
|
||||
{
|
||||
printf(" Source: %s\n", metainfo.source().c_str());
|
||||
fmt::print(" Source: {:s}\n", metainfo.source());
|
||||
}
|
||||
|
||||
printf(" Piece Count: %" PRIu32 "\n", metainfo.pieceCount());
|
||||
printf(" Piece Size: %s\n", tr_formatter_mem_B(metainfo.pieceSize()).c_str());
|
||||
printf(" Total Size: %s\n", tr_formatter_size_B(metainfo.totalSize()).c_str());
|
||||
printf(" Privacy: %s\n", metainfo.isPrivate() ? "Private torrent" : "Public torrent");
|
||||
fmt::print(" Piece Count: {:d}\n", metainfo.pieceCount());
|
||||
fmt::print(" Piece Size: {:s}\n", tr_formatter_mem_B(metainfo.pieceSize()));
|
||||
fmt::print(" Total Size: {:s}\n", tr_formatter_size_B(metainfo.totalSize()));
|
||||
fmt::print(" Privacy: {:s}\n", metainfo.isPrivate() ? "Private torrent" : "Public torrent");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,7 +223,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
|||
|
||||
if (opts.print_trackers)
|
||||
{
|
||||
printf("\nTRACKERS\n");
|
||||
fmt::print("\nTRACKERS\n");
|
||||
auto current_tier = std::optional<tr_tracker_tier_t>{};
|
||||
auto print_tier = size_t{ 1 };
|
||||
for (auto const& tracker : metainfo.announceList())
|
||||
|
@ -233,24 +231,24 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
|||
if (!current_tier || current_tier != tracker.tier)
|
||||
{
|
||||
current_tier = tracker.tier;
|
||||
printf("\n Tier #%zu\n", print_tier);
|
||||
fmt::print("\n Tier #{:d}\n", print_tier);
|
||||
++print_tier;
|
||||
}
|
||||
|
||||
printf(" %" TR_PRIsv "\n", TR_PRIsv_ARG(tracker.announce.sv()));
|
||||
fmt::print(" {:s}\n", tracker.announce.sv());
|
||||
}
|
||||
|
||||
/**
|
||||
***
|
||||
**/
|
||||
***
|
||||
**/
|
||||
|
||||
if (auto const n_webseeds = metainfo.webseedCount(); n_webseeds > 0)
|
||||
{
|
||||
printf("\nWEBSEEDS\n\n");
|
||||
fmt::print("\nWEBSEEDS\n\n");
|
||||
|
||||
for (size_t i = 0; i < n_webseeds; ++i)
|
||||
{
|
||||
printf(" %s\n", metainfo.webseed(i).c_str());
|
||||
fmt::print(" {:s}\n", metainfo.webseed(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -263,7 +261,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
|||
{
|
||||
if (!opts.show_bytesize)
|
||||
{
|
||||
printf("\nFILES\n\n");
|
||||
fmt::print("\nFILES\n\n");
|
||||
}
|
||||
|
||||
auto filenames = std::vector<std::string>{};
|
||||
|
@ -301,7 +299,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
|||
|
||||
for (auto const& filename : filenames)
|
||||
{
|
||||
printf("%s\n", filename.c_str());
|
||||
fmt::print("{:s}\n", filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -343,7 +341,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
auto delimiter = tr_strvContains(scrape_url, '?') ? '&' : '?';
|
||||
scrape_url.append(delimiter, "info_hash=");
|
||||
tr_urlPercentEncode(std::back_inserter(scrape_url), metainfo.infoHash());
|
||||
printf("%" TR_PRIsv " ... ", TR_PRIsv_ARG(scrape_url));
|
||||
fmt::print("{:s} ... ", scrape_url);
|
||||
fflush(stdout);
|
||||
|
||||
// execute the http scrape
|
||||
|
@ -351,7 +349,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, TimeoutSecs);
|
||||
if (auto const res = curl_easy_perform(curl); res != CURLE_OK)
|
||||
{
|
||||
printf("error: %s\n", curl_easy_strerror(res));
|
||||
fmt::print("error: {:s}\n", curl_easy_strerror(res));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -360,7 +358,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
|
||||
if (response != 200 /*HTTP OK*/)
|
||||
{
|
||||
printf("error: unexpected response %ld \"%s\"\n", response, tr_webGetResponseStr(response));
|
||||
fmt::print("error: unexpected response {:d} '{:s}'\n", response, tr_webGetResponseStr(response));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -370,7 +368,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
auto sv = std::string_view{ begin, evbuffer_get_length(buf) };
|
||||
if (!tr_variantFromBuf(&top, TR_VARIANT_PARSE_BENC | TR_VARIANT_PARSE_INPLACE, sv))
|
||||
{
|
||||
printf("error parsing scrape response\n");
|
||||
fmt::print("error parsing scrape response\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -391,7 +389,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
auto i = int64_t{};
|
||||
auto const seeders = tr_variantDictFindInt(val, TR_KEY_complete, &i) ? int(i) : -1;
|
||||
auto const leechers = tr_variantDictFindInt(val, TR_KEY_incomplete, &i) ? int(i) : -1;
|
||||
printf("%d seeders, %d leechers\n", seeders, leechers);
|
||||
fmt::print("{:d} seeders, {:d} leechers\n", seeders, leechers);
|
||||
matched = true;
|
||||
}
|
||||
|
||||
|
@ -403,7 +401,7 @@ void doScrape(tr_torrent_metainfo const& metainfo)
|
|||
|
||||
if (!matched)
|
||||
{
|
||||
printf("no match\n");
|
||||
fmt::print("no match\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,16 +426,16 @@ int tr_main(int argc, char* argv[])
|
|||
|
||||
if (opts.show_version)
|
||||
{
|
||||
fprintf(stderr, "%s %s\n", MyName, LONG_VERSION_STRING);
|
||||
fmt::print(stderr, "{:s} {:s}\n", MyName, LONG_VERSION_STRING);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* make sure the user specified a filename */
|
||||
if (std::empty(opts.filename))
|
||||
{
|
||||
fprintf(stderr, "ERROR: No torrent file specified.\n");
|
||||
fmt::print(stderr, "ERROR: No torrent file specified.\n");
|
||||
tr_getopt_usage(MyName, Usage, std::data(options));
|
||||
fprintf(stderr, "\n");
|
||||
fmt::print(stderr, "\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -447,12 +445,7 @@ int tr_main(int argc, char* argv[])
|
|||
auto const parsed = metainfo.parseTorrentFile(opts.filename, nullptr, &error);
|
||||
if (error != nullptr)
|
||||
{
|
||||
fprintf(
|
||||
stderr,
|
||||
"Error parsing torrent file \"%" TR_PRIsv "\": %s (%d)\n",
|
||||
TR_PRIsv_ARG(opts.filename),
|
||||
error->message,
|
||||
error->code);
|
||||
fmt::print(stderr, "Error parsing torrent file '{:s}': {:s} ({:d})\n", opts.filename, error->message, error->code);
|
||||
tr_error_clear(&error);
|
||||
}
|
||||
if (!parsed)
|
||||
|
@ -462,15 +455,15 @@ int tr_main(int argc, char* argv[])
|
|||
|
||||
if (opts.show_magnet)
|
||||
{
|
||||
printf("%s", metainfo.magnet().c_str());
|
||||
fmt::print("{:s}", metainfo.magnet());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (opts.print_header)
|
||||
{
|
||||
printf("Name: %s\n", metainfo.name().c_str());
|
||||
printf("File: %" TR_PRIsv "\n", TR_PRIsv_ARG(opts.filename));
|
||||
printf("\n");
|
||||
fmt::print("Name: {:s}\n", metainfo.name());
|
||||
fmt::print("File: {:s}\n", opts.filename);
|
||||
fmt::print("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue