Added XmlParser

This commit is contained in:
Łukasz Czyż 2019-11-14 10:34:46 +01:00
parent 2fac6035ab
commit a00ced6aa1
5 changed files with 57 additions and 6 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.o

View file

@ -1,6 +1,6 @@
OBJS = Build/main.o tinyxml2/tinyxml2.o
OBJS = Build/main.o Build/XmlParser.o tinyxml2/libtinyxml2.a
SOURCE = Src/main.cpp tinyxml2/tinyxml2.cpp
INCLUDE = -I tinyxml2 -I cxxopts/include
INCLUDE = -I tinyxml2 -I cxxopts/include -I Src
OUT = svd2cpp
CC = g++
FLAGS = -g -c -Wall
@ -12,7 +12,11 @@ Build/main.o: Src/main.cpp
mkdir -p Build
$(CC) $(FLAGS) Src/main.cpp $(INCLUDE) -o Build/main.o
tinyxml2/tinyxml2.o:
Build/XmlParser.o: Src/XmlParser.cpp
mkdir -p Build
$(CC) $(FLAGS) Src/XmlParser.cpp $(INCLUDE) -o Build/XmlParser.o
tinyxml2/libtinyxml2.a:
$(MAKE) -C tinyxml2/ staticlib

6
Src/XmlParser.cpp Normal file
View file

@ -0,0 +1,6 @@
#include <XmlParser.hpp>
#include <iostream>
XmlParser::XmlParser(const std::string& inputFile){
std::cout << inputFile;
}

14
Src/XmlParser.hpp Normal file
View file

@ -0,0 +1,14 @@
#ifndef XML_PARSER
#define XML_PARSER
#include <tinyxml2.h>
#include <string>
struct XmlParser{
XmlParser(const std::string& inputFile);
private:
};
#endif

View file

@ -1,6 +1,32 @@
#include <tinyxml2.h>
#include <iostream>
#include <cxxopts.hpp>
#include <XmlParser.hpp>
int main(){
int main(int argc, char** argv){
// Create and configure options for the program
cxxopts::Options options("svd2cpp", "Parser from svd files to C++ header");
options.add_options()
("i, input", "File to be parsed", cxxopts::value<std::string>())
("o, output", "OutputFile", cxxopts::value<std::string>());
std::string inputFile, outputFile;
try
{
auto result = options.parse(argc, argv);
if(result.count("input") != 1){
std::cout << "Missing input file!" << std::endl;
return 1;
}
if(result.count("output") != 1){
std::cout << "Missing output file!" << std::endl;
return 1;
}
inputFile = result["input"].as<std::string>();
outputFile = result["output"].as<std::string>();
std::cout << "Input: " << inputFile << "\tOutput: " << outputFile << std::endl;
}
catch(cxxopts::OptionException& ex){
std::cout << ex.what() << std::endl;
return -1;
}
XmlParser xmlParser(inputFile);
}