Skip to content

Commit

Permalink
ESE file parser to extract [POSITIONS]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirollos committed Apr 11, 2024
1 parent ba41426 commit 55a4231
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
68 changes: 68 additions & 0 deletions DiscordEuroscope/ESEHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "stdafx.h"
#include "ESEHandler.h"
#include <filesystem>
#include <fstream>

std::vector<std::string> ESEHandler::path_to_ese;
std::vector<ESEPositionItem> ESEHandler::positions;

bool ESEHandler::LocateESEFile(std::string relative_path_to_ese)
{
path_to_ese.clear();
for (auto& file : std::filesystem::directory_iterator(relative_path_to_ese))
{
if (file.is_regular_file() && stricmp(file.path().filename().extension().string().c_str(), ".ese") == 0)
{
path_to_ese.push_back(file.path().string());
}
}
return path_to_ese.size() > 0;
}

int ESEHandler::ParsePositions(void)
{
if (path_to_ese.size() > 0)
{
for (auto& file : path_to_ese)
{
bool start_pos = false;
std::ifstream fs(file);
std::string line;
while (std::getline(fs, line))
{
if (line == "[POSITIONS]")
{
start_pos = true;
continue;
}
if (!start_pos) continue;

if (!(line[0] >= 'A' && line[0] <= 'Z'))
{
if (line[0] == '[') break;
continue;
}

ESEPositionItem pos;
int idx1 = line.find_first_of(':');
pos.callsign = line.substr(0, idx1);
int idx2 = line.find_first_of(':', idx1 + 1);
pos.radio_callsign = line.substr(idx1 + 1, idx2 - idx1 - 1);
idx1 = line.find_first_of(':', idx2 + 1);
pos.frequency = line.substr(idx2 + 1, idx1 - idx2 - 1);
positions.push_back(pos);
}
fs.close();
}
}
return positions.size();
}

void ESEHandler::GetRadioCallsigns(std::map<std::string, std::string>& rcs)
{
rcs.clear();
for (auto& pos : positions)
{
rcs.insert(std::pair<std::string, std::string>(pos.callsign, pos.radio_callsign));
}
}
40 changes: 40 additions & 0 deletions DiscordEuroscope/ESEHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright(C) 2023-2024 Kirollos Nashaat
This program is free software : you can redistribute it and /or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see < https://www.gnu.org/licenses/>.
*/

#pragma once
#include <string>
#include <vector>
#include <map>


struct ESEPositionItem
{
std::string callsign;
std::string radio_callsign;
std::string frequency;
};

class ESEHandler
{
private:
static std::vector<std::string> path_to_ese;
static std::vector<ESEPositionItem> positions;
public:
static bool LocateESEFile(std::string relative_path_to_ese);
static int ParsePositions(void);
static void GetRadioCallsigns(std::map<std::string, std::string>& rcs);
};

0 comments on commit 55a4231

Please sign in to comment.