From c27076105252c4c19128ce27bacceca22dd62613 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Fri, 26 Aug 2016 13:23:07 +1200 Subject: [PATCH] Add caret width for *sd and *equate diagnostics --- src/commands.c | 17 +++++-- src/datain.c | 23 +++++++-- src/datain.h | 3 +- src/readval.c | 6 +-- tests/cmd_equate_bad.out | 5 +- tests/cmd_equate_bad.svx | 3 +- tests/cmd_fix_bad.out | 120 +++++++++++++++++++++++------------------------ 7 files changed, 104 insertions(+), 73 deletions(-) diff --git a/src/commands.c b/src/commands.c index f0f07765..b35195dd 100644 --- a/src/commands.c +++ b/src/commands.c @@ -866,23 +866,28 @@ cmd_fix(void) compile_diagnostic(DIAG_ERR, /*The output projection is set but the input projection isn't*/438); } + get_pos(&fp); sdx = read_numeric(fTrue); if (sdx <= 0) { - compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_COL, /*Standard deviation must be positive*/48); + set_pos(&fp); + compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_NUM, /*Standard deviation must be positive*/48); return; } if (sdx != HUGE_REAL) { real sdy, sdz; real cxy = 0, cyz = 0, czx = 0; + get_pos(&fp); sdy = read_numeric(fTrue); if (sdy == HUGE_REAL) { /* only one variance given */ sdy = sdz = sdx; } else { if (sdy <= 0) { - compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_COL, /*Standard deviation must be positive*/48); + set_pos(&fp); + compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_NUM, /*Standard deviation must be positive*/48); return; } + get_pos(&fp); sdz = read_numeric(fTrue); if (sdz == HUGE_REAL) { /* two variances given - horizontal & vertical */ @@ -890,7 +895,8 @@ cmd_fix(void) sdy = sdx; } else { if (sdz <= 0) { - compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_COL, /*Standard deviation must be positive*/48); + set_pos(&fp); + compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_NUM, /*Standard deviation must be positive*/48); return; } cxy = read_numeric(fTrue); @@ -1022,19 +1028,22 @@ cmd_equate(void) { prefix *name1, *name2; bool fOnlyOneStn = fTrue; /* to trap eg *equate entrance.6 */ + filepos fp; + get_pos(&fp); name1 = read_prefix(PFX_STATION|PFX_ALLOW_ROOT|PFX_SUSPECT_TYPO); while (fTrue) { name2 = name1; skipblanks(); if (isEol(ch) || isComm(ch)) { if (fOnlyOneStn) { + set_pos(&fp); /* TRANSLATORS: EQUATE is a command name, so shouldn’t be * translated. * * Here "station" is a survey station, not a train station. */ - compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_COL, /*Only one station in EQUATE command*/33); + compile_diagnostic(DIAG_ERR|DIAG_SKIP|DIAG_TOKEN, /*Only one station in EQUATE command*/33); } return; } diff --git a/src/datain.c b/src/datain.c index 158114e5..966aa0f3 100644 --- a/src/datain.c +++ b/src/datain.c @@ -209,7 +209,7 @@ compile_diagnostic(int diag_flags, int en, ...) { va_list ap; va_start(ap, en); - if (diag_flags & (DIAG_TOKEN|DIAG_NUM|DIAG_DATE)) { + if (diag_flags & (DIAG_TOKEN|DIAG_UINT|DIAG_DATE|DIAG_NUM)) { char *p = NULL; int len = 0; skipblanks(); @@ -218,16 +218,33 @@ compile_diagnostic(int diag_flags, int en, ...) s_catchar(&p, &len, (char)ch); nextch(); } - } else if (diag_flags & DIAG_NUM) { + } else if (diag_flags & DIAG_UINT) { while (isdigit(ch)) { s_catchar(&p, &len, (char)ch); nextch(); } - } else { + } else if (diag_flags & DIAG_DATE) { while (isdigit(ch) || ch == '.') { s_catchar(&p, &len, (char)ch); nextch(); } + } else { + if (isMinus(ch) || isPlus(ch)) { + s_catchar(&p, &len, (char)ch); + nextch(); + } + while (isdigit(ch)) { + s_catchar(&p, &len, (char)ch); + nextch(); + } + if (isDecimal(ch)) { + s_catchar(&p, &len, (char)ch); + nextch(); + } + while (isdigit(ch)) { + s_catchar(&p, &len, (char)ch); + nextch(); + } } if (p) { caret_width = strlen(p); diff --git a/src/datain.h b/src/datain.h index afc14ea8..f0c19dea 100644 --- a/src/datain.h +++ b/src/datain.h @@ -62,8 +62,9 @@ void skipline(void); #define DIAG_SKIP 0x08 #define DIAG_BUF 0x10 #define DIAG_TOKEN 0x20 -#define DIAG_NUM 0x40 +#define DIAG_UINT 0x40 #define DIAG_DATE 0x80 +#define DIAG_NUM 0x100 #define DIAG_WARN 0x00 #define DIAG_ERR 0x01 diff --git a/src/readval.c b/src/readval.c index 508de918..45d1f004 100644 --- a/src/readval.c +++ b/src/readval.c @@ -519,7 +519,7 @@ read_date(int *py, int *pm, int *pd) if (y < 100) y += 1900; if (y < 1900 || y > 2078) { set_pos(&fp_date); - compile_diagnostic(DIAG_WARN|DIAG_NUM, /*Invalid year (< 1900 or > 2078)*/58); + compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Invalid year (< 1900 or > 2078)*/58); LONGJMP(file.jbSkipLine); return; /* for brain-fried compilers */ } @@ -530,7 +530,7 @@ read_date(int *py, int *pm, int *pd) m = read_uint_internal(/*Expecting date, found “%s”*/198, &fp_date); if (m < 1 || m > 12) { set_pos(&fp); - compile_diagnostic(DIAG_WARN|DIAG_NUM, /*Invalid month*/86); + compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Invalid month*/86); LONGJMP(file.jbSkipLine); return; /* for brain-fried compilers */ } @@ -541,7 +541,7 @@ read_date(int *py, int *pm, int *pd) if (d < 1 || d > last_day(y, m)) { set_pos(&fp); /* TRANSLATORS: e.g. 31st of April, or 32nd of any month */ - compile_diagnostic(DIAG_WARN|DIAG_NUM, /*Invalid day of the month*/87); + compile_diagnostic(DIAG_WARN|DIAG_UINT, /*Invalid day of the month*/87); LONGJMP(file.jbSkipLine); return; /* for brain-fried compilers */ } diff --git a/tests/cmd_equate_bad.out b/tests/cmd_equate_bad.out index 12b5f0c8..aefb0db9 100644 --- a/tests/cmd_equate_bad.out +++ b/tests/cmd_equate_bad.out @@ -4,6 +4,9 @@ ./cmd_equate_bad.svx:6:13: error: Character "=" not allowed in station name (use *SET NAMES to set allowed characters) *equate 1 2 = ^ +./cmd_equate_bad.svx:9:9: error: Only one station in EQUATE command + *equate foo + ^~~ Removing trailing traverses... @@ -27,4 +30,4 @@ Total plan length of survey legs = 0.00m Total vertical length of survey legs = 0.00m 2 1-nodes. 2 2-nodes. -There were 0 warning(s) and 2 error(s) - no output files produced. +There were 0 warning(s) and 3 error(s) - no output files produced. diff --git a/tests/cmd_equate_bad.svx b/tests/cmd_equate_bad.svx index 4c762027..40ce7c43 100644 --- a/tests/cmd_equate_bad.svx +++ b/tests/cmd_equate_bad.svx @@ -1,4 +1,4 @@ -; pos=fail warn=0 error=2 +; pos=fail warn=0 error=3 ; We used to report "End of line not blank" but 1.2.22 gives "Character "=" not ; allowed in station name (use *SET NAMES to set allowed characters)" instead. *fix 1 reference 0 0 0 @@ -6,3 +6,4 @@ *equate 1 2 = *equate 3 4 *equate 2 1 3 ; test +*equate foo diff --git a/tests/cmd_fix_bad.out b/tests/cmd_fix_bad.out index a1de8b96..9faf8707 100644 --- a/tests/cmd_fix_bad.out +++ b/tests/cmd_fix_bad.out @@ -28,96 +28,96 @@ ./cmd_fix_bad.svx:12:19: error: Expecting numeric field, found "test" *fix Er reference test ^~~~ -./cmd_fix_bad.svx:14:32: error: Standard deviation must be positive +./cmd_fix_bad.svx:14:31: error: Standard deviation must be positive *fix W1 reference 123 456 789 0 - ^ -./cmd_fix_bad.svx:15:32: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:15:31: error: Standard deviation must be positive *fix W2 reference 123 456 789 0 0 - ^ -./cmd_fix_bad.svx:16:32: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:16:31: error: Standard deviation must be positive *fix W3 reference 123 456 789 0 0 0 - ^ -./cmd_fix_bad.svx:17:34: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:17:32: error: Standard deviation must be positive *fix W1m reference 123 456 789 -1 - ^ -./cmd_fix_bad.svx:18:34: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:18:32: error: Standard deviation must be positive *fix W2m reference 123 456 789 -1 -1 - ^ -./cmd_fix_bad.svx:19:34: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:19:32: error: Standard deviation must be positive *fix W3m reference 123 456 789 -1 -1 -1 - ^ -./cmd_fix_bad.svx:20:34: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:20:32: error: Standard deviation must be positive *fix W1o reference 123 456 789 -1 0 - ^ -./cmd_fix_bad.svx:21:33: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:21:32: error: Standard deviation must be positive *fix W2o reference 123 456 789 0 -1 - ^ -./cmd_fix_bad.svx:22:33: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:22:32: error: Standard deviation must be positive *fix W3o reference 123 456 789 0 -1 -1 - ^ -./cmd_fix_bad.svx:23:34: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:23:32: error: Standard deviation must be positive *fix W4o reference 123 456 789 -1 0 -1 - ^ -./cmd_fix_bad.svx:24:34: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:24:32: error: Standard deviation must be positive *fix W5o reference 123 456 789 -1 -1 0 - ^ -./cmd_fix_bad.svx:25:33: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:25:32: error: Standard deviation must be positive *fix W6o reference 123 456 789 0 0 -1 - ^ -./cmd_fix_bad.svx:26:33: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:26:32: error: Standard deviation must be positive *fix W7o reference 123 456 789 0 -1 0 - ^ -./cmd_fix_bad.svx:27:34: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:27:32: error: Standard deviation must be positive *fix W8o reference 123 456 789 -1 0 0 - ^ -./cmd_fix_bad.svx:28:32: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:28:31: error: Standard deviation must be positive *fix X1 reference 123 456 789 0 0.1 - ^ -./cmd_fix_bad.svx:29:36: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:29:35: error: Standard deviation must be positive *fix X2 reference 123 456 789 0.1 0 - ^ -./cmd_fix_bad.svx:30:36: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:30:32: error: Standard deviation must be positive *fix X1m reference 123 456 789 -0.1 0.1 - ^ -./cmd_fix_bad.svx:31:40: error: Standard deviation must be positive + ^~~~ +./cmd_fix_bad.svx:31:36: error: Standard deviation must be positive *fix X2m reference 123 456 789 0.1 -0.1 - ^ -./cmd_fix_bad.svx:32:32: error: Standard deviation must be positive + ^~~~ +./cmd_fix_bad.svx:32:31: error: Standard deviation must be positive *fix Y1 reference 123 456 789 0 0.1 0.1 - ^ -./cmd_fix_bad.svx:33:36: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:33:35: error: Standard deviation must be positive *fix Y2 reference 123 456 789 0.1 0 0.1 - ^ -./cmd_fix_bad.svx:34:40: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:34:39: error: Standard deviation must be positive *fix Y3 reference 123 456 789 0.1 0.1 0 - ^ -./cmd_fix_bad.svx:35:32: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:35:31: error: Standard deviation must be positive *fix Y4 reference 123 456 789 0 0 0.1 - ^ -./cmd_fix_bad.svx:36:32: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:36:31: error: Standard deviation must be positive *fix Y5 reference 123 456 789 0 0.1 0 - ^ -./cmd_fix_bad.svx:37:36: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:37:35: error: Standard deviation must be positive *fix Y6 reference 123 456 789 0.1 0 0 - ^ -./cmd_fix_bad.svx:38:34: error: Standard deviation must be positive + ^ +./cmd_fix_bad.svx:38:32: error: Standard deviation must be positive *fix Y1m reference 123 456 789 -1 0.1 0.1 - ^ -./cmd_fix_bad.svx:39:38: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:39:36: error: Standard deviation must be positive *fix Y2m reference 123 456 789 0.1 -1 0.1 - ^ -./cmd_fix_bad.svx:40:42: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:40:40: error: Standard deviation must be positive *fix Y3m reference 123 456 789 0.1 0.1 -1 - ^ -./cmd_fix_bad.svx:41:34: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:41:32: error: Standard deviation must be positive *fix Y4m reference 123 456 789 -1 -1 0.1 - ^ -./cmd_fix_bad.svx:42:34: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:42:32: error: Standard deviation must be positive *fix Y5m reference 123 456 789 -1 0.1 -1 - ^ -./cmd_fix_bad.svx:43:38: error: Standard deviation must be positive + ^~ +./cmd_fix_bad.svx:43:36: error: Standard deviation must be positive *fix Y6m reference 123 456 789 0.1 -1 -1 - ^ + ^~ Removing trailing traverses... -- 2.11.4.GIT