<commit_before>#include <cstdio>

#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <memory>

#include "parser.h"
#include "packet.h"
#include "exceptions.h"

void print_packets(std::list<std::shared_ptr<parse4880::PGPPacket>> packets,
                   int level) {
  std::string newline_replacement = "";
  for(int i = 0; i < level; i++) {
    newline_replacement += "    ";
  }
  for (auto i = packets.begin(); i != packets.end(); i++) {
    printf("%sPacket: %s\n", newline_replacement.c_str(), (*i)->str().c_str());
    print_packets((*i)->subpackets(), level+1);
  }
}

int main(int argc, char** argv) {
  if (argc < 2) {
    std::cerr << "USAGE: parsepgp <file>" << std::endl;
    return 1;
  }

  std::ifstream pgp_file;
  pgp_file.open(argv[1]); // Flawfinder: ignore (give the user what they want)

  std::stringstream str_stream;
  str_stream << pgp_file.rdbuf();

  std::list<std::shared_ptr<parse4880::PGPPacket>> packets;
  try {
    packets = parse4880::parse(str_stream.str());
  }
  catch(parse4880::parse4880_error e) {
    fprintf(stderr, "Parse error:\n\t%s\n", e.what());
    return 1;
  }

  print_packets(packets, 0);
}<commit_msg>Changed parsepgp to catch by reference.<commit_after>#include <cstdio>

#include <iostream>
#include <fstream>
#include <sstream>
#include <list>
#include <memory>

#include "parser.h"
#include "packet.h"
#include "exceptions.h"

void print_packets(std::list<std::shared_ptr<parse4880::PGPPacket>> packets,
                   int level) {
  std::string newline_replacement = "";
  for(int i = 0; i < level; i++) {
    newline_replacement += "    ";
  }
  for (auto i = packets.begin(); i != packets.end(); i++) {
    printf("%sPacket: %s\n", newline_replacement.c_str(), (*i)->str().c_str());
    print_packets((*i)->subpackets(), level+1);
  }
}

int main(int argc, char** argv) {
  if (argc < 2) {
    std::cerr << "USAGE: parsepgp <file>" << std::endl;
    return 1;
  }

  std::ifstream pgp_file;
  pgp_file.open(argv[1]); // Flawfinder: ignore (give the user what they want)

  std::stringstream str_stream;
  str_stream << pgp_file.rdbuf();

  std::list<std::shared_ptr<parse4880::PGPPacket>> packets;
  try {
    packets = parse4880::parse(str_stream.str());
  }
  catch(const parse4880::parse4880_error& e) {
    fprintf(stderr, "Parse error:\n\t%s\n", e.what());
    return 1;
  }

  print_packets(packets, 0);
}
{'fraction_non_alphanumeric': 0.18347862183478622, 'fraction_numerical': 0.0224159402241594, 'mean_word_length': 4.084388185654008, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 29, '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': '4459170', 'n_tokens_mistral': 940, 'n_tokens_neox': 902, 'n_words': 186}