<commit_before>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2017-2018 by <NAME>. Some rights reserved, see LICENSE

This file contains definitions for the scenario flightplan data structure.
The code takes care of parsing flight plans from file, representing
them as lists of actions.
*/

#include <fstream>

#include "flightplan.hpp"

#define LOGURU_WITH_STREAMS 1
#include "loguru.hpp"

namespace sim {

std::optional<FlightPlan> parse_flight_plan(std::string fname, int default_code)
{

    std::ifstream cfile(fname);
    int           line_no = 0;
    std::string   line;
    FlightPlan    flt;
    bool          header_section = true;

    if (!cfile) {
        LOG_S(ERROR) << fname << ": Flight plan not found";
        return {};
    }

    // Some miscellaneous defaults
    flt.body.color = 0xffffff;
    flt.body.code  = default_code;

    while (std::getline(cfile, line)) {
        line_no++;

        line = trim_whitespace(trim_comments(line));

        if (line.length() == 0) // Ignore empty lines
            continue;

        if (header_section) {
            std::optional<KeyValue> kv = get_key_value(line);
            if (kv) {
                if (kv->key == "plan") {
                    header_section = false;
                } else {
                    if (!flt.set_key_value(kv)) {
                        LOG_S(WARNING) << "Line " << line_no << ": Unknown key "
                                       << kv->key << ": ignoring";
                    }
                }
            } else {
                LOG_S(ERROR)
                    << "Error parsing line: " << line_no << " (" << line << ")";
            }
        } else {
            auto fpa = parse_line_into_action(line, line_no);
            if (fpa) {
                flt.plan.push_back(*fpa);
            }
        }
    }
    return flt;
}
}<commit_msg>Set spaceship body_type correctly<commit_after>/*
This file is part of Groho, a simulator for inter-planetary travel and warfare.
Copyright (c) 2017-2018 by <NAME>. Some rights reserved, see LICENSE

This file contains definitions for the scenario flightplan data structure.
The code takes care of parsing flight plans from file, representing
them as lists of actions.
*/

#include <fstream>

#include "flightplan.hpp"

#define LOGURU_WITH_STREAMS 1
#include "loguru.hpp"

namespace sim {

std::optional<FlightPlan> parse_flight_plan(std::string fname, int default_code)
{

    std::ifstream cfile(fname);
    int           line_no = 0;
    std::string   line;
    FlightPlan    flt;
    bool          header_section = true;

    if (!cfile) {
        LOG_S(ERROR) << fname << ": Flight plan not found";
        return {};
    }

    // Some miscellaneous defaults
    flt.body.body_type = SPACESHIP;
    flt.body.color     = 0xffffff;
    flt.body.code      = default_code;

    while (std::getline(cfile, line)) {
        line_no++;

        line = trim_whitespace(trim_comments(line));

        if (line.length() == 0) // Ignore empty lines
            continue;

        if (header_section) {
            std::optional<KeyValue> kv = get_key_value(line);
            if (kv) {
                if (kv->key == "plan") {
                    header_section = false;
                } else {
                    if (!flt.set_key_value(kv)) {
                        LOG_S(WARNING) << "Line " << line_no << ": Unknown key "
                                       << kv->key << ": ignoring";
                    }
                }
            } else {
                LOG_S(ERROR)
                    << "Error parsing line: " << line_no << " (" << line << ")";
            }
        } else {
            auto fpa = parse_line_into_action(line, line_no);
            if (fpa) {
                flt.plan.push_back(*fpa);
            }
        }
    }
    return flt;
}
}
{'fraction_non_alphanumeric': 0.11317829457364341, 'fraction_numerical': 0.006201550387596899, 'mean_word_length': 1.7203092059030218, 'pattern_counts': {'":': 6, '<': 59, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3715895', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1118, 'n_words': 297}