Skip to content

Commit fac03ec

Browse files
author
MarcoFalke
committed
scripted-diff: Replace fprintf with tfm::format
-BEGIN VERIFY SCRIPT- sed -i --regexp-extended -e 's/fprintf\(std(err|out), /tfm::format(std::c\1, /g' $(git grep -l 'fprintf(' -- ':(exclude)src/crypto' ':(exclude)src/leveldb' ':(exclude)src/univalue' ':(exclude)src/secp256k1') -END VERIFY SCRIPT- fixup! scripted-diff: Replace fprintf with tfm::format
1 parent fa72a64 commit fac03ec

File tree

10 files changed

+57
-57
lines changed

10 files changed

+57
-57
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main(int argc, char** argv)
3636
SetupBenchArgs();
3737
std::string error;
3838
if (!gArgs.ParseParameters(argc, argv, error)) {
39-
fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());
39+
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str());
4040
return EXIT_FAILURE;
4141
}
4242

@@ -53,7 +53,7 @@ int main(int argc, char** argv)
5353

5454
double scaling_factor;
5555
if (!ParseDouble(scaling_str, &scaling_factor)) {
56-
fprintf(stderr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str());
56+
tfm::format(std::cerr, "Error parsing scaling factor as double: %s\n", scaling_str.c_str());
5757
return EXIT_FAILURE;
5858
}
5959

src/bitcoin-cli.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static int AppInitRPC(int argc, char* argv[])
101101
SetupCliArgs();
102102
std::string error;
103103
if (!gArgs.ParseParameters(argc, argv, error)) {
104-
fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());
104+
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str());
105105
return EXIT_FAILURE;
106106
}
107107
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
@@ -115,26 +115,26 @@ static int AppInitRPC(int argc, char* argv[])
115115
strUsage += "\n" + gArgs.GetHelpMessage();
116116
}
117117

118-
fprintf(stdout, "%s", strUsage.c_str());
118+
tfm::format(std::cout, "%s", strUsage.c_str());
119119
if (argc < 2) {
120-
fprintf(stderr, "Error: too few parameters\n");
120+
tfm::format(std::cerr, "Error: too few parameters\n");
121121
return EXIT_FAILURE;
122122
}
123123
return EXIT_SUCCESS;
124124
}
125125
if (!fs::is_directory(GetDataDir(false))) {
126-
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
126+
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
127127
return EXIT_FAILURE;
128128
}
129129
if (!gArgs.ReadConfigFiles(error, true)) {
130-
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
130+
tfm::format(std::cerr, "Error reading configuration file: %s\n", error.c_str());
131131
return EXIT_FAILURE;
132132
}
133133
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
134134
try {
135135
SelectBaseParams(gArgs.GetChainName());
136136
} catch (const std::exception& e) {
137-
fprintf(stderr, "Error: %s\n", e.what());
137+
tfm::format(std::cerr, "Error: %s\n", e.what());
138138
return EXIT_FAILURE;
139139
}
140140
return CONTINUE_EXECUTION;
@@ -508,7 +508,7 @@ int main(int argc, char* argv[])
508508
#endif
509509
SetupEnvironment();
510510
if (!SetupNetworking()) {
511-
fprintf(stderr, "Error: Initializing networking failed\n");
511+
tfm::format(std::cerr, "Error: Initializing networking failed\n");
512512
return EXIT_FAILURE;
513513
}
514514
event_set_log_callback(&libevent_log_cb);

src/bitcoin-tx.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ static int AppInitRawTx(int argc, char* argv[])
8282
SetupBitcoinTxArgs();
8383
std::string error;
8484
if (!gArgs.ParseParameters(argc, argv, error)) {
85-
fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());
85+
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str());
8686
return EXIT_FAILURE;
8787
}
8888

8989
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
9090
try {
9191
SelectParams(gArgs.GetChainName());
9292
} catch (const std::exception& e) {
93-
fprintf(stderr, "Error: %s\n", e.what());
93+
tfm::format(std::cerr, "Error: %s\n", e.what());
9494
return EXIT_FAILURE;
9595
}
9696

@@ -104,10 +104,10 @@ static int AppInitRawTx(int argc, char* argv[])
104104
"\n";
105105
strUsage += gArgs.GetHelpMessage();
106106

107-
fprintf(stdout, "%s", strUsage.c_str());
107+
tfm::format(std::cout, "%s", strUsage.c_str());
108108

109109
if (argc < 2) {
110-
fprintf(stderr, "Error: too few parameters\n");
110+
tfm::format(std::cerr, "Error: too few parameters\n");
111111
return EXIT_FAILURE;
112112
}
113113
return EXIT_SUCCESS;
@@ -723,21 +723,21 @@ static void OutputTxJSON(const CTransaction& tx)
723723
TxToUniv(tx, uint256(), entry);
724724

725725
std::string jsonOutput = entry.write(4);
726-
fprintf(stdout, "%s\n", jsonOutput.c_str());
726+
tfm::format(std::cout, "%s\n", jsonOutput.c_str());
727727
}
728728

729729
static void OutputTxHash(const CTransaction& tx)
730730
{
731731
std::string strHexHash = tx.GetHash().GetHex(); // the hex-encoded transaction hash (aka the transaction id)
732732

733-
fprintf(stdout, "%s\n", strHexHash.c_str());
733+
tfm::format(std::cout, "%s\n", strHexHash.c_str());
734734
}
735735

736736
static void OutputTxHex(const CTransaction& tx)
737737
{
738738
std::string strHex = EncodeHexTx(tx);
739739

740-
fprintf(stdout, "%s\n", strHex.c_str());
740+
tfm::format(std::cout, "%s\n", strHex.c_str());
741741
}
742742

743743
static void OutputTx(const CTransaction& tx)

src/bitcoin-wallet.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static bool WalletAppInit(int argc, char* argv[])
3636
SetupWalletToolArgs();
3737
std::string error_message;
3838
if (!gArgs.ParseParameters(argc, argv, error_message)) {
39-
fprintf(stderr, "Error parsing command line arguments: %s\n", error_message.c_str());
39+
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message.c_str());
4040
return false;
4141
}
4242
if (argc < 2 || HelpRequested(gArgs)) {
@@ -48,15 +48,15 @@ static bool WalletAppInit(int argc, char* argv[])
4848
" bitcoin-wallet [options] <command>\n\n" +
4949
gArgs.GetHelpMessage();
5050

51-
fprintf(stdout, "%s", usage.c_str());
51+
tfm::format(std::cout, "%s", usage.c_str());
5252
return false;
5353
}
5454

5555
// check for printtoconsole, allow -debug
5656
LogInstance().m_print_to_console = gArgs.GetBoolArg("-printtoconsole", gArgs.GetBoolArg("-debug", false));
5757

5858
if (!fs::is_directory(GetDataDir(false))) {
59-
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
59+
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
6060
return false;
6161
}
6262
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
@@ -87,21 +87,21 @@ int main(int argc, char* argv[])
8787
for(int i = 1; i < argc; ++i) {
8888
if (!IsSwitchChar(argv[i][0])) {
8989
if (!method.empty()) {
90-
fprintf(stderr, "Error: two methods provided (%s and %s). Only one method should be provided.\n", method.c_str(), argv[i]);
90+
tfm::format(std::cerr, "Error: two methods provided (%s and %s). Only one method should be provided.\n", method.c_str(), argv[i]);
9191
return EXIT_FAILURE;
9292
}
9393
method = argv[i];
9494
}
9595
}
9696

9797
if (method.empty()) {
98-
fprintf(stderr, "No method provided. Run `bitcoin-wallet -help` for valid methods.\n");
98+
tfm::format(std::cerr, "No method provided. Run `bitcoin-wallet -help` for valid methods.\n");
9999
return EXIT_FAILURE;
100100
}
101101

102102
// A name must be provided when creating a file
103103
if (method == "create" && !gArgs.IsArgSet("-wallet")) {
104-
fprintf(stderr, "Wallet name must be provided when creating a new wallet.\n");
104+
tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n");
105105
return EXIT_FAILURE;
106106
}
107107

src/bitcoind.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static bool AppInit(int argc, char* argv[])
7070
SetupServerArgs();
7171
std::string error;
7272
if (!gArgs.ParseParameters(argc, argv, error)) {
73-
fprintf(stderr, "Error parsing command line arguments: %s\n", error.c_str());
73+
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error.c_str());
7474
return false;
7575
}
7676

@@ -88,33 +88,33 @@ static bool AppInit(int argc, char* argv[])
8888
strUsage += "\n" + gArgs.GetHelpMessage();
8989
}
9090

91-
fprintf(stdout, "%s", strUsage.c_str());
91+
tfm::format(std::cout, "%s", strUsage.c_str());
9292
return true;
9393
}
9494

9595
try
9696
{
9797
if (!fs::is_directory(GetDataDir(false)))
9898
{
99-
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
99+
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
100100
return false;
101101
}
102102
if (!gArgs.ReadConfigFiles(error, true)) {
103-
fprintf(stderr, "Error reading configuration file: %s\n", error.c_str());
103+
tfm::format(std::cerr, "Error reading configuration file: %s\n", error.c_str());
104104
return false;
105105
}
106106
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
107107
try {
108108
SelectParams(gArgs.GetChainName());
109109
} catch (const std::exception& e) {
110-
fprintf(stderr, "Error: %s\n", e.what());
110+
tfm::format(std::cerr, "Error: %s\n", e.what());
111111
return false;
112112
}
113113

114114
// Error out when loose non-argument tokens are encountered on command line
115115
for (int i = 1; i < argc; i++) {
116116
if (!IsSwitchChar(argv[i][0])) {
117-
fprintf(stderr, "Error: Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]);
117+
tfm::format(std::cerr, "Error: Command line contains unexpected token '%s', see bitcoind -h for a list of options.\n", argv[i]);
118118
return false;
119119
}
120120
}
@@ -146,18 +146,18 @@ static bool AppInit(int argc, char* argv[])
146146
#pragma GCC diagnostic push
147147
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
148148
#endif
149-
fprintf(stdout, "Bitcoin server starting\n");
149+
tfm::format(std::cout, "Bitcoin server starting\n");
150150

151151
// Daemonize
152152
if (daemon(1, 0)) { // don't chdir (1), do close FDs (0)
153-
fprintf(stderr, "Error: daemon() failed: %s\n", strerror(errno));
153+
tfm::format(std::cerr, "Error: daemon() failed: %s\n", strerror(errno));
154154
return false;
155155
}
156156
#if defined(MAC_OSX)
157157
#pragma GCC diagnostic pop
158158
#endif
159159
#else
160-
fprintf(stderr, "Error: -daemon is not supported on this operating system\n");
160+
tfm::format(std::cerr, "Error: -daemon is not supported on this operating system\n");
161161
return false;
162162
#endif // HAVE_DECL_DAEMON
163163
}

src/noui.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& ca
3737

3838
if (!fSecure)
3939
LogPrintf("%s: %s\n", strCaption, message);
40-
fprintf(stderr, "%s: %s\n", strCaption.c_str(), message.c_str());
40+
tfm::format(std::cerr, "%s: %s\n", strCaption.c_str(), message.c_str());
4141
return false;
4242
}
4343

src/qt/utilitydialog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ HelpMessageDialog::~HelpMessageDialog()
124124
void HelpMessageDialog::printToConsole()
125125
{
126126
// On other operating systems, the expected action is to print the message to the console.
127-
fprintf(stdout, "%s\n", qPrintable(text));
127+
tfm::format(std::cout, "%s\n", qPrintable(text));
128128
}
129129

130130
void HelpMessageDialog::showOrPrint()

src/sync.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
118118
LogPrintf(" %s\n", i.second.ToString());
119119
}
120120
if (g_debug_lockorder_abort) {
121-
fprintf(stderr, "Assertion failed: detected inconsistent lock order at %s:%i, details in debug log.\n", __FILE__, __LINE__);
121+
tfm::format(std::cerr, "Assertion failed: detected inconsistent lock order at %s:%i, details in debug log.\n", __FILE__, __LINE__);
122122
abort();
123123
}
124124
throw std::logic_error("potential deadlock detected");
@@ -175,15 +175,15 @@ void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine,
175175
for (const std::pair<void*, CLockLocation>& i : g_lockstack)
176176
if (i.first == cs)
177177
return;
178-
fprintf(stderr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
178+
tfm::format(std::cerr, "Assertion failed: lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
179179
abort();
180180
}
181181

182182
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs)
183183
{
184184
for (const std::pair<void*, CLockLocation>& i : g_lockstack) {
185185
if (i.first == cs) {
186-
fprintf(stderr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
186+
tfm::format(std::cerr, "Assertion failed: lock %s held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
187187
abort();
188188
}
189189
}

src/util/system.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ void PrintExceptionContinue(const std::exception* pex, const char* pszThread)
673673
{
674674
std::string message = FormatException(pex, pszThread);
675675
LogPrintf("\n\n************************\n%s\n", message);
676-
fprintf(stderr, "\n\n************************\n%s\n", message.c_str());
676+
tfm::format(std::cerr, "\n\n************************\n%s\n", message.c_str());
677677
}
678678

679679
fs::path GetDefaultDataDir()
@@ -933,7 +933,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
933933
}
934934
}
935935
for (const std::string& to_include : includeconf) {
936-
fprintf(stderr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include.c_str());
936+
tfm::format(std::cerr, "warning: -includeconf cannot be used from included files; ignoring -includeconf=%s\n", to_include.c_str());
937937
}
938938
}
939939
}

0 commit comments

Comments
 (0)