1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Show the line number at which a parse error occured
4 This patch counts the number of newlines from the start of the source buffer
5 whose parse has failed. This will be the line number in a macro or macro
6 file where the error was detected. If an error is found in the parsing of
7 the NEdit configuration (nedit.rc), the line number is that of the unit
8 being parsed, not the whole file.
12 source/preferences.c | 17 +++++++++++++----
13 1 file changed, 13 insertions(+), 4 deletions(-)
15 diff --quilt old/source/preferences.c new/source/preferences.c
16 --- old/source/preferences.c
17 +++ new/source/preferences.c
18 @@ -5654,7 +5654,8 @@ int ParseError(Widget toDialog, const ch
19 int len, nNonWhite = 0;
25 for (c=stoppedAt; c>=stringStart; c--) {
28 @@ -5663,6 +5664,12 @@ int ParseError(Widget toDialog, const ch
29 else if (*c != ' ' && *c != '\t')
33 + for (; stringStart <= c; ++stringStart) {
34 + if (*stringStart == '\n')
38 len = stoppedAt - c + (*stoppedAt == '\0' ? 0 : 1);
39 errorLine = XtMalloc(len+4);
40 strncpy(errorLine, c, len);
41 @@ -5672,11 +5679,13 @@ int ParseError(Widget toDialog, const ch
42 errorLine[len] = '\0';
45 - fprintf(stderr, "NEdit: %s in %s:\n%s\n", message, errorIn, errorLine);
46 + fprintf(stderr, "NEdit: %s in %s:%d:\n%s\n",
47 + message, errorIn, lineNo, errorLine);
50 - DialogF(DF_WARN, toDialog, 1, "Parse Error", "%s in %s:\n%s", "OK",
51 - message, errorIn, errorLine);
52 + DialogF(DF_WARN, toDialog, 1,
53 + "Parse Error", "%s in %s:%d:\n%s", "OK",
54 + message, errorIn, lineNo, errorLine);