<commit_before>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2015-2018 The Bitcoin Unlimited developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif

#include "compat.h"

#include "util.h"

#include "chainparamsbase.h"
#include "fs.h"
#include "random.h"
#include "serialize.h"
#include "sync.h"
#include "utilstrencodings.h"
#include "utiltime.h"

#include <sstream>
#include <stdarg.h>

#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
#include <pthread.h>
#include <pthread_np.h>
#endif

#ifndef WIN32
// for posix_fallocate
#ifdef __linux__

#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif

#define _POSIX_C_SOURCE 200112L

#endif // __linux__

#include <algorithm>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h>

#else

#ifdef _MSC_VER
#pragma warning(disable : 4786)
#pragma warning(disable : 4804)
#pragma warning(disable : 4805)
#pragma warning(disable : 4717)
#endif

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501

#ifdef _WIN32_IE
#undef _WIN32_IE
#endif
#define _WIN32_IE 0x0501

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <io.h> /* for _commit */
#include <shlobj.h>
#endif

#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif

#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
#include <boost/foreach.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/thread.hpp>
#include <openssl/conf.h>
#include <openssl/crypto.h>
#include <openssl/rand.h>

// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is
// neither visible in the template definition nor found by argument-dependent lookup
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
//           http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost
{
namespace program_options
{
std::string to_internal(const std::string &);
}

} // namespace boost

using namespace std;

namespace Logging
{
// Globals defined here because link fails if in globals.cpp.
// Keep at top of file so init first:
uint64_t categoriesEnabled = 0; // 64 bit log id mask.
static map<uint64_t, std::string> logLabelMap = LOGLABELMAP; // Lookup log label from log id.


uint64_t LogFindCategory(const std::string label)
{
    for (auto &x : logLabelMap)
    {
        if ((std::string)x.second == label)
            return (uint64_t)x.first;
    }
    return NONE;
}

std::string LogGetLabel(uint64_t category)
{
    string label = "none";
    if (logLabelMap.count(category) != 0)
        label = logLabelMap[category];

    return label;
}

std::string LogGetAllString()
{
    string ret = "";
    for (auto &x : logLabelMap)
    {
        if (x.first == ALL || x.first == NONE)
            continue;

        // ret += (std::string)x.second;
        if (LogAcceptCategory(x.first))
            ret += "on ";
        else
            ret += "   ";

        ret += (std::string)x.second;
        ret += "\n";
    }

    return ret;
}

void LogInit()
{
    string category = "";
    uint64_t catg = Logging::NONE;
    const vector<string> &categories = mapMultiArgs["-debug"];

    for (string const &cat : categories)
    {
        category = boost::algorithm::to_lower_copy(cat);
        catg = LogFindCategory(category);

        if (catg == NONE) // Not a valid category
            continue;

        LogToggleCategory(catg, true);
    }
}
}

const char *const BITCOIN_CONF_FILENAME = "bitcoin.conf";
const char *const BITCOIN_PID_FILENAME = "bitcoind.pid";
const char *const FORKS_CSV_FILENAME = "forks.csv"; // bip135 added

map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs;
bool fDebug = false;
bool fPrintToConsole = false;
bool fPrintToDebugLog = true;
bool fDaemon = false;
bool fServer = false;<commit_msg>Resurrect old log-all command line functionality<commit_after>// Copyright (c) 2009-2010 <NAME>
// Copyright (c) 2009-2015 The Bitcoin Core developers
// Copyright (c) 2015-2018 The Bitcoin Unlimited developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#if defined(HAVE_CONFIG_H)
#include "config/bitcoin-config.h"
#endif

#include "compat.h"

#include "util.h"

#include "chainparamsbase.h"
#include "fs.h"
#include "random.h"
#include "serialize.h"
#include "sync.h"
#include "utilstrencodings.h"
#include "utiltime.h"

#include <sstream>
#include <stdarg.h>

#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
#include <pthread.h>
#include <pthread_np.h>
#endif

#ifndef WIN32
// for posix_fallocate
#ifdef __linux__

#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif

#define _POSIX_C_SOURCE 200112L

#endif // __linux__

#include <algorithm>
#include <fcntl.h>
#include <sys/resource.h>
#include <sys/stat.h>

#else

#ifdef _MSC_VER
#pragma warning(disable : 4786)
#pragma warning(disable : 4804)
#pragma warning(disable : 4805)
#pragma warning(disable : 4717)
#endif

#ifdef _WIN32_WINNT
#undef _WIN32_WINNT
#endif
#define _WIN32_WINNT 0x0501

#ifdef _WIN32_IE
#undef _WIN32_IE
#endif
#define _WIN32_IE 0x0501

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif

#ifndef NOMINMAX
#define NOMINMAX
#endif

#include <io.h> /* for _commit */
#include <shlobj.h>
#endif

#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
#endif

#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string/predicate.hpp> // for startswith() and endswith()
#include <boost/foreach.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/thread.hpp>
#include <openssl/conf.h>
#include <openssl/crypto.h>
#include <openssl/rand.h>

// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is
// neither visible in the template definition nor found by argument-dependent lookup
// See also: http://stackoverflow.com/questions/10020179/compilation-fail-in-boost-librairies-program-options
//           http://clang.debian.net/status.php?version=3.0&key=CANNOT_FIND_FUNCTION
namespace boost
{
namespace program_options
{
std::string to_internal(const std::string &);
}

} // namespace boost

using namespace std;

namespace Logging
{
// Globals defined here because link fails if in globals.cpp.
// Keep at top of file so init first:
uint64_t categoriesEnabled = 0; // 64 bit log id mask.
static map<uint64_t, std::string> logLabelMap = LOGLABELMAP; // Lookup log label from log id.


uint64_t LogFindCategory(const std::string label)
{
    for (auto &x : logLabelMap)
    {
        if ((std::string)x.second == label)
            return (uint64_t)x.first;
    }
    return NONE;
}

std::string LogGetLabel(uint64_t category)
{
    string label = "none";
    if (logLabelMap.count(category) != 0)
        label = logLabelMap[category];

    return label;
}

std::string LogGetAllString()
{
    string ret = "";
    for (auto &x : logLabelMap)
    {
        if (x.first == ALL || x.first == NONE)
            continue;

        // ret += (std::string)x.second;
        if (LogAcceptCategory(x.first))
            ret += "on ";
        else
            ret += "   ";

        ret += (std::string)x.second;
        ret += "\n";
    }

    return ret;
}

void LogInit()
{
    string category = "";
    uint64_t catg = Logging::NONE;
    const vector<string> &categories = mapMultiArgs["-debug"];

    // enable all when given -debug=1 or -debug
    if (categories.size() == 1 && (categories[0] == "" || categories[0] == "1"))
    {
        Logging::LogToggleCategory(Logging::ALL, true);
        return;
    }
    for (string const &cat : categories)
    {
        category = boost::algorithm::to_lower_copy(cat);
        catg = LogFindCategory(category);

        if (catg == NONE) // Not a valid category
            continue;

        LogToggleCategory(catg, true);
    }
}
}

const char *const BITCOIN_CONF_FILENAME = "bitcoin.conf";
const char *const BITCOIN_PID_FILENAME = "bitcoind.pid";
const char *const FORKS_CSV_FILENAME = "forks.csv"; // bip135 added

map<string, string> mapArgs;
map<string, vector<string> > mapMultiArgs;
bool fDebug = false;
bool fPrintToConsole = false;
bool fPrintToDebugLog = true;
bool fDaemon = false;
bool fServer = false;
{'fraction_non_alphanumeric': 0.12821650399290152, 'fraction_numerical': 0.025399290150842947, 'mean_word_length': 3.8296732726298877, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6290509', 'n_tokens_mistral': 3276, 'n_tokens_neox': 3063, 'n_words': 776}