1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 03:42:09 +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)
return;
_errorString = "parse error";
_errorString = QString("parse error on line: %1").arg(ctx.line);
ctx.token = ERROR;
}
@ -142,9 +142,11 @@ void PRJFile::nextToken(CTX &ctx)
switch (state) {
case 0:
if (isspace(c))
if (isspace(c)) {
if (c == '\n')
ctx.line++;
break;
if (c == '[') {
} if (c == '[') {
ctx.token = LBRK;
return;
}
@ -522,7 +524,6 @@ void PRJFile::projectedCS(CTX &ctx, PCS *pcs)
int epsg = -1;
GCS gcs;
LinearUnits lu;
CoordinateSystem cs(CoordinateSystem::XY);
Projection::Method method;
Projection::Setup setup;
@ -539,7 +540,9 @@ void PRJFile::projectedCS(CTX &ctx, PCS *pcs)
optProjectedCS(ctx, &epsg);
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)
@ -772,6 +775,9 @@ PRJFile::PRJFile(const QString &fileName)
nextToken(ctx);
CS(ctx);
if (ctx.token != ERROR && !_projection.isValid())
_errorString = "invalid/incomplete projection";
if (ctx.token == EOI) {
if (!_projection.isValid())
_errorString = "unknown/incomplete projection";
} else
_projection = Projection();
}

View File

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