ttyname: increase server request string length for argc == 1
[nedit-bw.git] / parseErrorLineNo.diff
blob5380f595c739c5f0fa8c86328712ed20fee2f9c1
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.
10 ---
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,7 +5652,8 @@ int ParseError(Widget toDialog, const ch
19 int len, nNonWhite = 0;
20 const char *c;
21 char *errorLine;
23 + int lineNo = 1;
25 for (c=stoppedAt; c>=stringStart; c--) {
26 if (c == stringStart)
27 break;
28 @@ -5661,6 +5662,12 @@ int ParseError(Widget toDialog, const ch
29 else if (*c != ' ' && *c != '\t')
30 nNonWhite++;
33 + for (; stringStart <= c; ++stringStart) {
34 + if (*stringStart == '\n')
35 + ++lineNo;
36 + }
38 len = stoppedAt - c + (*stoppedAt == '\0' ? 0 : 1);
39 errorLine = XtMalloc(len+4);
40 strncpy(errorLine, c, len);
41 @@ -5670,11 +5677,13 @@ int ParseError(Widget toDialog, const ch
42 errorLine[len] = '\0';
43 if (toDialog == NULL)
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);
48 } else
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);
56 XtFree(errorLine);
57 return False;