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 @@ -5652,33 +5652,42 @@ int ParseError(Widget toDialog, const ch
19 const char *errorIn, const char *message)
21 int len, nNonWhite = 0;
27 for (c=stoppedAt; c>=stringStart; c--) {
30 else if (*c == '\n' && nNonWhite >= 5)
32 else if (*c != ' ' && *c != '\t')
36 + for (; stringStart <= c; ++stringStart) {
37 + if (*stringStart == '\n')
41 len = stoppedAt - c + (*stoppedAt == '\0' ? 0 : 1);
42 errorLine = XtMalloc(len+4);
43 strncpy(errorLine, c, len);
44 errorLine[len++] = '<';
45 errorLine[len++] = '=';
46 errorLine[len++] = '=';
47 errorLine[len] = '\0';
50 - fprintf(stderr, "NEdit: %s in %s:\n%s\n", message, errorIn, errorLine);
51 + fprintf(stderr, "NEdit: %s in %s:%d:\n%s\n",
52 + message, errorIn, lineNo, errorLine);
55 - DialogF(DF_WARN, toDialog, 1, "Parse Error", "%s in %s:\n%s", "OK",
56 - message, errorIn, errorLine);
57 + DialogF(DF_WARN, toDialog, 1,
58 + "Parse Error", "%s in %s:%d:\n%s", "OK",
59 + message, errorIn, lineNo, errorLine);