<commit_before>#ifndef joedb_run_interpreted_client_declared
#define joedb_run_interpreted_client_declared

#include "joedb/concurrency/Connection.h"
#include "joedb/concurrency/Interpreted_Client.h"
#include "joedb/io/Interpreter.h"
#include "joedb/journal/File.h"
#include "joedb/journal/Memory_File.h"

#include <iostream>
#include <memory>
#include <limits>

namespace joedb
{
 ////////////////////////////////////////////////////////////////////////////
 inline void run_interpreted_client(Interpreted_Client &client)
 ////////////////////////////////////////////////////////////////////////////
 {
  while (std::cin)
  {
   const int64_t diff = client.get_checkpoint_difference();

   if (diff > 0)
    std::cout << "You can push " << diff << " bytes. ";
   else if (diff < 0)
    std::cout << "You can pull " << -diff << " bytes. ";

   std::cout << "R(read), P(pull), S(push), T(transaction), or Q(quit)? ";
   std::cout.flush();
   std::string input;

   if (!(std::cin >> input))
   {
    std::cout << '\n';
    break;
   }

   std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

   if (input == "T")
   {
    std::cout << "Waiting for lock... ";
    std::cout.flush();

    client.transaction([](Readable &readable, Writable &writable)
    {
     std::cout << "OK\n";
     Interpreter(readable, writable).main_loop(std::cin, std::cout);
    });
   }
   else if (input == "P")
    client.pull();
   else if (input == "S")
    client.push_unlock();
   else if (input == "R")
    Readonly_Interpreter(client.get_database()).main_loop(std::cin, std::cout);
   else if (input == "Q")
    break;
  }
 }

 ////////////////////////////////////////////////////////////////////////////
 inline void run_interpreted_client
 ////////////////////////////////////////////////////////////////////////////
 (
  Connection &connection,
  const char *file_name
 )
 {
  std::unique_ptr<Generic_File> local_file;

  if (file_name && *file_name)<commit_msg>improve run_interpreted_client<commit_after>#ifndef joedb_run_interpreted_client_declared
#define joedb_run_interpreted_client_declared

#include "joedb/concurrency/Connection.h"
#include "joedb/concurrency/Interpreted_Client.h"
#include "joedb/io/Interpreter.h"
#include "joedb/journal/File.h"
#include "joedb/journal/Memory_File.h"

#include <iostream>
#include <memory>
#include <limits>

namespace joedb
{
 ////////////////////////////////////////////////////////////////////////////
 inline void run_interpreted_client(Interpreted_Client &client)
 ////////////////////////////////////////////////////////////////////////////
 {
  while (std::cin)
  {
   const int64_t diff = client.get_checkpoint_difference();

   if (diff > 0)
    std::cout << "You can push " << diff << " bytes. ";
   else if (diff < 0)
    std::cout << "You can pull " << -diff << " bytes. ";

   std::cout << "R(read)";
   if (diff > 0)
    std::cout << ", P(push)";
   else
    std::cout << ", P(pull), T(transaction)";
   std::cout << ", or Q(quit)? ";
   std::cout.flush();
   std::string input;

   if (!(std::cin >> input))
   {
    std::cout << '\n';
    break;
   }

   std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

   if (input == "T" && diff <= 0)
   {
    std::cout << "Waiting for lock... ";
    std::cout.flush();

    client.transaction([](Readable &readable, Writable &writable)
    {
     std::cout << "OK\n";
     Interpreter(readable, writable).main_loop(std::cin, std::cout);
    });
   }
   else if (input == "P" && diff <= 0)
    client.pull();
   else if (input == "P" && diff > 0)
    client.push_unlock();
   else if (input == "R")
    Readonly_Interpreter(client.get_database()).main_loop(std::cin, std::cout);
   else if (input == "Q")
    break;
   else
    std::cout << "Error: unknown command\n";
  }
 }

 ////////////////////////////////////////////////////////////////////////////
 inline void run_interpreted_client
 ////////////////////////////////////////////////////////////////////////////
 (
  Connection &connection,
  const char *file_name
 )
 {
  std::unique_ptr<Generic_File> local_file;

  if (file_name && *file_name)
{'fraction_non_alphanumeric': 0.29735629396070823, 'fraction_numerical': 0.002910502061605627, 'mean_word_length': 2.0256786500366837, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 21, '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': '4876351', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1270, 'n_words': 258}