jedParser: check if a \r char is present

This commit is contained in:
Gwenhael Goavec-Merou 2020-05-02 08:51:24 +02:00
parent 050a3a3f8d
commit 3221fd8ee2
2 changed files with 24 additions and 2 deletions

View File

@ -15,6 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
/*
* http://k1.spdns.de/Develop/Projects/GalAsm/info/galer/jedecfile.html
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@ -44,6 +48,23 @@ JedParser::JedParser(string filename, bool verbose):
{ {
} }
/*!
* \brief read a line with '\r''\n' or '\n' terminaison
* check if last char is '\r'
* \return the line without [\r]\n
*/
string JedParser::readline()
{
string buffer;
std::getline(_fd, buffer, '\n');
if (buffer.size() != 0) {
/* if '\r' is present -> drop */
if (buffer[buffer.size() -1] == '\r')
buffer.pop_back();
}
return buffer;
}
/* fill a vector with consecutive lines until '*' /* fill a vector with consecutive lines until '*'
*/ */
vector<string> JedParser::readJEDLine() vector<string> JedParser::readJEDLine()
@ -53,7 +74,7 @@ vector<string> JedParser::readJEDLine()
bool inLine = true; bool inLine = true;
do { do {
std::getline(_fd, buffer, '\n'); buffer = readline();
if (buffer.size() == 0) if (buffer.size() == 0)
break; break;
@ -191,7 +212,7 @@ int JedParser::parse()
_fd.seekg(0, _fd.beg); _fd.seekg(0, _fd.beg);
/* First line must STX (0x02) */ /* First line must STX (0x02) */
std::getline(_fd, content, '\n'); content = readline();
if (content[0] != 0x02) { if (content[0] != 0x02) {
printf("wrong file\n"); printf("wrong file\n");
return EXIT_FAILURE; return EXIT_FAILURE;

View File

@ -50,6 +50,7 @@ class JedParser: public ConfigBitstreamParser {
uint64_t featuresRow() {return _featuresRow;} uint64_t featuresRow() {return _featuresRow;}
private: private:
std::string readline();
std::vector<std::string>readJEDLine(); std::vector<std::string>readJEDLine();
void buildDataArray(const std::string &content, struct jed_data &jed); void buildDataArray(const std::string &content, struct jed_data &jed);
void parseEField(const std::vector<std::string> content); void parseEField(const std::vector<std::string> content);