1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 11:52:08 +01:00

Improved error handling

This commit is contained in:
Martin Tůma 2021-06-27 16:00:08 +02:00
parent 1a3660ba2f
commit f5ea667f34
2 changed files with 15 additions and 8 deletions

View File

@ -118,7 +118,7 @@ void PRJFile::error(CTX &ctx)
if (ctx.token == ERROR) if (ctx.token == ERROR)
return; return;
_errorString = "parse error"; _errorString = QString("parse error on line: %1").arg(ctx.line);
ctx.token = ERROR; ctx.token = ERROR;
} }
@ -142,9 +142,11 @@ void PRJFile::nextToken(CTX &ctx)
switch (state) { switch (state) {
case 0: case 0:
if (isspace(c)) if (isspace(c)) {
if (c == '\n')
ctx.line++;
break; break;
if (c == '[') { } if (c == '[') {
ctx.token = LBRK; ctx.token = LBRK;
return; return;
} }
@ -522,7 +524,6 @@ void PRJFile::projectedCS(CTX &ctx, PCS *pcs)
int epsg = -1; int epsg = -1;
GCS gcs; GCS gcs;
LinearUnits lu; LinearUnits lu;
CoordinateSystem cs(CoordinateSystem::XY);
Projection::Method method; Projection::Method method;
Projection::Setup setup; Projection::Setup setup;
@ -539,7 +540,9 @@ void PRJFile::projectedCS(CTX &ctx, PCS *pcs)
optProjectedCS(ctx, &epsg); optProjectedCS(ctx, &epsg);
compare(ctx, RBRK); compare(ctx, RBRK);
*pcs = (epsg > 0) ? PCS::pcs(epsg) : PCS(gcs, method, setup, lu, cs); *pcs = (epsg > 0)
? PCS::pcs(epsg)
: PCS(gcs, method, setup, lu, CoordinateSystem());
} }
void PRJFile::axisType(CTX &ctx) void PRJFile::axisType(CTX &ctx)
@ -772,6 +775,9 @@ PRJFile::PRJFile(const QString &fileName)
nextToken(ctx); nextToken(ctx);
CS(ctx); CS(ctx);
if (ctx.token != ERROR && !_projection.isValid()) if (ctx.token == EOI) {
_errorString = "invalid/incomplete projection"; if (!_projection.isValid())
_errorString = "unknown/incomplete projection";
} else
_projection = Projection();
} }

View File

@ -36,12 +36,13 @@ private:
}; };
struct CTX { struct CTX {
CTX(const QString &fileName) : file(fileName), token(START) {} CTX(const QString &fileName) : file(fileName), token(START), line(1) {}
QFile file; QFile file;
Token token; Token token;
QString string; QString string;
double number; double number;
int line;
}; };
Token keyword(CTX &ctx); Token keyword(CTX &ctx);