mirror of
https://github.com/supleed2/svd2cpp.git
synced 2024-12-22 13:45:50 +00:00
Added error checking in XmlParser, added sample file
This commit is contained in:
parent
a00ced6aa1
commit
e5605248ea
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
*.o
|
*.o
|
||||||
|
*.a
|
2
Makefile
2
Makefile
|
@ -3,7 +3,7 @@ SOURCE = Src/main.cpp tinyxml2/tinyxml2.cpp
|
||||||
INCLUDE = -I tinyxml2 -I cxxopts/include -I Src
|
INCLUDE = -I tinyxml2 -I cxxopts/include -I Src
|
||||||
OUT = svd2cpp
|
OUT = svd2cpp
|
||||||
CC = g++
|
CC = g++
|
||||||
FLAGS = -g -c -Wall
|
FLAGS = -g -c -Wall -std=c++17
|
||||||
|
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
$(CC) -g $(OBJS) -o $(OUT) $(LFLAGS)
|
$(CC) -g $(OBJS) -o $(OUT) $(LFLAGS)
|
||||||
|
|
24923
Sample/STM32F103xx.svd
Normal file
24923
Sample/STM32F103xx.svd
Normal file
File diff suppressed because it is too large
Load diff
|
@ -2,5 +2,15 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
XmlParser::XmlParser(const std::string& inputFile){
|
XmlParser::XmlParser(const std::string& inputFile){
|
||||||
std::cout << inputFile;
|
xmlDocument.LoadFile(inputFile.c_str());
|
||||||
|
}
|
||||||
|
std::optional<std::string> XmlParser::isError() const{
|
||||||
|
return xmlDocument.Error() ? std::optional<std::string>(xmlDocument.ErrorStr()) : std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void XmlParser::parseXml(){
|
||||||
|
root = xmlDocument.FirstChildElement();
|
||||||
|
if(root == nullptr)
|
||||||
|
return;
|
||||||
|
std::cout << root->GetText();
|
||||||
}
|
}
|
|
@ -3,12 +3,17 @@
|
||||||
|
|
||||||
#include <tinyxml2.h>
|
#include <tinyxml2.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
struct XmlParser{
|
struct XmlParser{
|
||||||
XmlParser(const std::string& inputFile);
|
XmlParser(const std::string& inputFile);
|
||||||
|
std::optional<std::string> isError() const;
|
||||||
|
void parseXml();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
tinyxml2::XMLDocument xmlDocument;
|
||||||
|
tinyxml2::XMLElement* root;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -26,7 +26,13 @@ int main(int argc, char** argv){
|
||||||
}
|
}
|
||||||
catch(cxxopts::OptionException& ex){
|
catch(cxxopts::OptionException& ex){
|
||||||
std::cout << ex.what() << std::endl;
|
std::cout << ex.what() << std::endl;
|
||||||
return -1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
//Try to parse the file
|
||||||
XmlParser xmlParser(inputFile);
|
XmlParser xmlParser(inputFile);
|
||||||
|
if (auto err = xmlParser.isError()){
|
||||||
|
std::cout << "There was an error while reading " << inputFile << ":" << std::endl << *err << std::endl;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
xmlParser.parseXml();
|
||||||
}
|
}
|
Loading…
Reference in a new issue