stuff-from-scratch/apps/xml-practice.cpp

39 lines
853 B
C++
Raw Normal View History

2020-05-02 07:31:03 +00:00
#include <filesystem>
#include <iostream>
#include <fstream>
#include "CommandLineArgs.h"
#include "XmlParser.h"
int main(int argc, char *argv[])
{
2021-03-29 20:31:24 +00:00
CommandLineArgs command_line_args;
command_line_args.Process(argc, argv);
2020-05-02 07:31:03 +00:00
2021-03-29 20:31:24 +00:00
if(command_line_args.GetNumberOfArgs() < 2)
{
std::cerr << "Expected a filepath argument" << std::endl;
return -1;
}
2020-05-02 07:31:03 +00:00
2021-03-29 20:31:24 +00:00
XmlParser parser;
const auto filepath = command_line_args.GetArg(1);
2020-05-02 07:31:03 +00:00
2021-03-29 20:31:24 +00:00
if(!std::filesystem::exists(filepath))
{
std::cerr << "Couldn't find file: " << filepath << std::endl;
return -1;
}
2020-05-02 07:31:03 +00:00
2021-03-29 20:31:24 +00:00
std::ifstream xml_file;
xml_file.open(filepath, std::ifstream::in);
while(xml_file.good())
{
std::string line;
std::getline(xml_file, line);
parser.ProcessLine(line);
}
xml_file.close();
2020-05-02 07:31:03 +00:00
2021-03-29 20:31:24 +00:00
return 0;
2020-05-02 07:31:03 +00:00
}