13
0

fix/improve/test hotspot file parsing

This commit is contained in:
Paul Davis 2014-09-10 19:39:52 -04:00
parent 233d2e8530
commit 7449de6e8f

View File

@ -20,8 +20,13 @@
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include "pbd/error.h"
#include "pbd/compose.h"
#include "gtkmm2ext/cursors.h" #include "gtkmm2ext/cursors.h"
#include "i18n.h"
using namespace Gtkmm2ext; using namespace Gtkmm2ext;
CursorInfo::Infos CursorInfo::infos; CursorInfo::Infos CursorInfo::infos;
@ -46,24 +51,39 @@ CursorInfo::load_cursor_info (const std::string& path)
std::string name; std::string name;
int x; int x;
int y; int y;
bool parse_ok;
int line_number = 1;
do { do {
s << infofile; parse_ok = false;
infofile >> name;
if (!infofile) {
/* failing here is OK ... EOF */
parse_ok = true;
break;
}
infofile >> x;
if (!infofile) { if (!infofile) {
break; break;
} }
s >> name; infofile >> y;
s >> x; if (!infofile) {
s >> y;
if (!s) {
break; break;
} }
CursorInfo* ci = new CursorInfo (name, x, y); parse_ok = true;
infos[name] = ci; line_number++;
infos[name] = new CursorInfo (name, x, y);
} while (true); } while (true);
if (!parse_ok) {
PBD::error << string_compose (_("cursor hotspots info file %1 has an error on line %2"), path, line_number) << endmsg;
infos.clear ();
return -1;
}
return 0; return 0;
} }