<commit_before>/**
 * @file		TextInspector.cpp
 * @ingroup
 * @author	<NAME> <<EMAIL>>
 * @brief
 * @details
 *
 * Copyright (c) 2014 Georgia Institute of Technology.  All Rights Reserved.
 *
 * TODO add License
 */


#include <string>
#include <iostream>
#include <iterator>  // for ostream_iterator


#include <fcntl.h>      // for open
#include <sys/stat.h>   // block size.
#include <unistd.h>     // sysconf
#include <sys/mman.h>   // mmap
#include <cstring>      // memcpy, strerror

#include <cassert>
#include "io/file_loader.hpp"
#include "partition/range.hpp"


int main(int argc, char** argv) {

  assert(argc > 0);

  std::string filename;
  filename.assign(argv[1]);



  /// get file size.
  struct stat filestat;
  int ret = stat(filename.c_str(), &filestat);
  if (ret < 0 ) {
    ERROR( "ERROR in file open to get size." );
    exit(-1);
  }
  size_t file_size = static_cast<size_t>(filestat.st_size);


  /// open the file and get a handle.
  int file_handle = open(filename.c_str(), O_RDONLY);
  if (file_handle == -1)
  {
    int myerr = errno;
    FATAL("ERROR in file open: ["  << filename << "] error " << myerr << ": " << strerror(myerr));
  }


  // mmap
  unsigned char* data = (unsigned char*)mmap(nullptr, file_size,
                                       PROT_READ,
                                       MAP_PRIVATE, file_handle,
                                       0);



  std::cout << "please enter start and end positions.  enter a negative number to exit." << std::endl;
  ///
  int pos = 0;
  int endpos = 0;
  do {
    pos = 0;
    endpos = 0;
    std::cin >> pos >> endpos;
    if (pos >= 0) {
      std::cout << "char at pos " << pos << " - " << endpos << std::endl;
      std::ostream_iterator<unsigned char> oit(std::cout);
      std::copy(data + pos, data + endpos, oit);
      std::cout << std::endl;
    }
  } while (pos >= 0);
<commit_msg>FIX: text inspector utility fixed to avoid cin's issue with missing inputs<commit_after>/**
 * @file		TextInspector.cpp
 * @ingroup
 * @author	<NAME> <<EMAIL>>
 * @brief
 * @details
 *
 * Copyright (c) 2014 Georgia Institute of Technology.  All Rights Reserved.
 *
 * TODO add License
 */


#include <string>
#include <iostream>
#include <iterator>  // for ostream_iterator


#include <fcntl.h>      // for open
#include <sys/stat.h>   // block size.
#include <unistd.h>     // sysconf
#include <sys/mman.h>   // mmap
#include <cstring>      // memcpy, strerror

#include <cassert>
#include "io/file_loader.hpp"
#include "partition/range.hpp"


int main(int argc, char** argv) {

  assert(argc > 0);

  std::string filename;
  filename.assign(argv[1]);



  /// get file size.
  struct stat filestat;
  int ret = stat(filename.c_str(), &filestat);
  if (ret < 0 ) {
    ERROR( "ERROR in file open to get size." );
    exit(-1);
  }
  size_t file_size = static_cast<size_t>(filestat.st_size);


  /// open the file and get a handle.
  int file_handle = open(filename.c_str(), O_RDONLY);
  if (file_handle == -1)
  {
    int myerr = errno;
    FATAL("ERROR in file open: ["  << filename << "] error " << myerr << ": " << strerror(myerr));
  }


  // mmap
  unsigned char* data = (unsigned char*)mmap(nullptr, file_size,
                                       PROT_READ,
                                       MAP_PRIVATE, file_handle,
                                       0);



  std::cout << "please enter start and end positions (separated by space).  negative numbers to exit exit." << std::endl;
  ///
  int pos = 0;
  int endpos = 0;
  do {
	pos = -1;
	endpos = -1;
	scanf("%d %d", &pos, &endpos);
    if (pos >= 0 && endpos >= 0) {
      std::cout << "char at pos " << pos << " - " << endpos << std::endl;
      std::ostream_iterator<unsigned char> oit(std::cout);
      std::copy(data + pos, data + endpos, oit);
      std::cout << std::endl;
    }
  } while (pos >= 0 && endpos >= 0);

{'fraction_non_alphanumeric': 0.1566606544704973, 'fraction_numerical': 0.008760628703942282, 'mean_word_length': 2.358131487889273, 'pattern_counts': {'":': 2, '<': 85, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5867574', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1307, 'n_words': 370}