<commit_before>#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sstream>
#include <stdexcept>
#include <string>
#include "throttle.hpp"

/**
 * Read a configuration file.
 *
 * This function is guaranteed to read in all syntactically correct files, but
 * might also accept others.
 */
Conf::Conf(const char *config_fn) {
	// open the file
	std::ifstream conf_file(config_fn);
	if (!conf_file)
		throw std::runtime_error(std::string("Couldn't open config file '") + config_fn + '\'');

	// read every line and put it in the map
	char line[LINE_LENGTH];
	std::string name;

	// parse: first comes the name of the command
	while (conf_file >> name) {
		// if line starts with '#', ignore it
		if (name[0] == '#') {
			conf_file.ignore(LINE_LENGTH, '\n');
			continue;
		}

		conf_file.ignore(LINE_LENGTH, '=');
		conf_file.ignore(LINE_LENGTH, ' ');
		conf_file.getline(line, LINE_LENGTH);

		DEBUG_PRINT("[Conf] " << name << " = " << line);

		// write into map
		attributes[name] = std::string(line);
	}
}

/**
 * Translation table for a command queue.
 */
const std::map<std::string, CommQueue::Command> CommQueue::translate = {
	{"max", CommQueue::SET_MAX},
	{"min", CommQueue::SET_MIN},
	{"freq", CommQueue::SET_FREQ},
	{"reset", CommQueue::RESET}
};

/**
 * Construct a command queue.<commit_msg>Ignore as much as it takes<commit_after>#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits>
#include <sstream>
#include <stdexcept>
#include <string>
#include "throttle.hpp"

/**
 * Read a configuration file.
 *
 * This function is guaranteed to read in all syntactically correct files, but
 * might also accept others.
 */
Conf::Conf(const char *config_fn) {
	// open the file
	std::ifstream conf_file(config_fn);
	if (!conf_file)
		throw std::runtime_error(std::string("Couldn't open config file '") + config_fn + '\'');

	// read every line and put it in the map
	char line[LINE_LENGTH];
	std::string name;

	// parse: first comes the name of the command
	while (conf_file >> name) {
		// if line starts with '#', ignore it
		if (name[0] == '#') {
			conf_file.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
			continue;
		}

		conf_file.ignore(std::numeric_limits<std::streamsize>::max(), '=');
		conf_file.ignore(std::numeric_limits<std::streamsize>::max(), ' ');
		conf_file.getline(line, LINE_LENGTH);

		DEBUG_PRINT("[Conf] " << name << " = " << line);

		// write into map
		attributes[name] = std::string(line);
	}
}

/**
 * Translation table for a command queue.
 */
const std::map<std::string, CommQueue::Command> CommQueue::translate = {
	{"max", CommQueue::SET_MAX},
	{"min", CommQueue::SET_MIN},
	{"freq", CommQueue::SET_FREQ},
	{"reset", CommQueue::RESET}
};

/**
 * Construct a command queue.
{'fraction_non_alphanumeric': 0.17336228736880202, 'fraction_numerical': 0.0007238508867173362, 'mean_word_length': 4.528, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 25, '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': '3654155', 'n_tokens_mistral': 984, 'n_tokens_neox': 944, 'n_words': 244}