<commit_before>// Copyright (c) 2015-2016 <NAME> (at gmail dot com)
// This file is distributed under the MIT License.

#include "ofp/ofp.h"
#include "./ofpx_decode.h"
#include "./ofpx_encode.h"
#if LIBOFP_ENABLE_JSONRPC
#include <openssl/ssl.h>  // For OPENSSL_VERSION_NUMBER
#include <asio/version.hpp>
#include "./ofpx_jsonrpc.h"
#endif  // LIBOFP_ENABLE_JSONRPC
#include "./libofp.h"
#include "./ofpx_help.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

struct SubprogramEntry {
  const char *name;
  ofpx::RunSubprogram run;
};

static const SubprogramEntry programs[] = {
    {"encode", ofpx::Run<ofpx::Encode>},
    {"decode", ofpx::Run<ofpx::Decode>},
#if LIBOFP_ENABLE_JSONRPC
    {"jsonrpc", ofpx::Run<ofpx::JsonRpc>},
#endif  // LIBOFP_ENABLE_JSONRPC
    {"help", ofpx::Run<ofpx::Help>}};

static void print_usage(std::ostream &out);
static void print_version();
static void force_link_api();

int main(int argc, const char *const *argv) {
  if (argc < 2) {
    if (argc == 0)
      force_link_api();
    print_usage(std::cerr);
    return 1;
  }

  std::string name = argv[1];
  if (name == "--help" || name == "-h") {
    print_usage(std::cout);
    return 0;
  }

  if (name == "version" || name == "-v" || name == "-version" ||
      name == "--version") {
    print_version();
    return 0;
  }

  cl::SetVersionPrinter(print_version);

  for (size_t i = 0; i < ofp::ArrayLength(programs); ++i) {
    if (name == programs[i].name) {
      return (*programs[i].run)(argc - 1, argv + 1);
    }
  }

  std::cerr << "libofp: '" << name
            << "' is not a libofp command. See 'libofp --help'.\n";

  return 1;
}

void print_usage(std::ostream &out) {
  out << "Usage: libofp <command> [ <options> ]\n\n";
  out << "Commands:\n";
  for (size_t i = 0; i < ofp::ArrayLength(programs); ++i) {
    out << "  " << programs[i].name << '\n';
  }
  out << '\n';
}

void print_version() {
  raw_ostream &os = outs();

  std::string libofpCommit{LIBOFP_GIT_COMMIT_LIBOFP};
  os << "libofp " << LIBOFP_VERSION_STRING << " (" << libofpCommit.substr(0, 7)
     << ")";

  os << "  <" << LIBOFP_GITHUB_URL << ">\n";

#ifndef __OPTIMIZE__
  os << "  DEBUG build";
#else
  os << "  Optimized build";
#endif
#ifndef NDEBUG
  os << " with assertions";<commit_msg>Include 32/64 bit build information in version string.<commit_after>// Copyright (c) 2015-2016 <NAME> (at gmail dot com)
// This file is distributed under the MIT License.

#include "ofp/ofp.h"
#include "./ofpx_decode.h"
#include "./ofpx_encode.h"
#if LIBOFP_ENABLE_JSONRPC
#include <openssl/ssl.h>  // For OPENSSL_VERSION_NUMBER
#include <asio/version.hpp>
#include "./ofpx_jsonrpc.h"
#endif  // LIBOFP_ENABLE_JSONRPC
#include "./libofp.h"
#include "./ofpx_help.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

struct SubprogramEntry {
  const char *name;
  ofpx::RunSubprogram run;
};

static const SubprogramEntry programs[] = {
    {"encode", ofpx::Run<ofpx::Encode>},
    {"decode", ofpx::Run<ofpx::Decode>},
#if LIBOFP_ENABLE_JSONRPC
    {"jsonrpc", ofpx::Run<ofpx::JsonRpc>},
#endif  // LIBOFP_ENABLE_JSONRPC
    {"help", ofpx::Run<ofpx::Help>}};

static void print_usage(std::ostream &out);
static void print_version();
static void force_link_api();

int main(int argc, const char *const *argv) {
  if (argc < 2) {
    if (argc == 0)
      force_link_api();
    print_usage(std::cerr);
    return 1;
  }

  std::string name = argv[1];
  if (name == "--help" || name == "-h") {
    print_usage(std::cout);
    return 0;
  }

  if (name == "version" || name == "-v" || name == "-version" ||
      name == "--version") {
    print_version();
    return 0;
  }

  cl::SetVersionPrinter(print_version);

  for (size_t i = 0; i < ofp::ArrayLength(programs); ++i) {
    if (name == programs[i].name) {
      return (*programs[i].run)(argc - 1, argv + 1);
    }
  }

  std::cerr << "libofp: '" << name
            << "' is not a libofp command. See 'libofp --help'.\n";

  return 1;
}

void print_usage(std::ostream &out) {
  out << "Usage: libofp <command> [ <options> ]\n\n";
  out << "Commands:\n";
  for (size_t i = 0; i < ofp::ArrayLength(programs); ++i) {
    out << "  " << programs[i].name << '\n';
  }
  out << '\n';
}

void print_version() {
  raw_ostream &os = outs();

  std::string libofpCommit{LIBOFP_GIT_COMMIT_LIBOFP};
  os << "libofp " << LIBOFP_VERSION_STRING << " (" << libofpCommit.substr(0, 7)
     << ")";

  os << "  <" << LIBOFP_GITHUB_URL << ">\n";

  const char *bits = "? bit";
  if (sizeof(void*) == 8) {
    bits = "64 bit";
  } else if (sizeof(void*) == 4) {
    bits = "32 bit";
  }

#ifndef __OPTIMIZE__
  os << "  DEBUG ";
#else
  os << "  Optimized ";
#endif
  os << bits << " build";
#ifndef NDEBUG
  os << " with assertions";
{'fraction_non_alphanumeric': 0.1911184893131355, 'fraction_numerical': 0.010790620460676489, 'mean_word_length': 3.462962962962963, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7430932', 'n_tokens_mistral': 1883, 'n_tokens_neox': 1828, 'n_words': 426}