changeset 6063:dab02b1fc89d HEAD

If section opening fails, show the line where the last section was opened or closed.
author Timo Sirainen <tss@iki.fi>
date Wed, 18 Jul 2007 06:26:56 +0300
parents 8341db7a1698
children 5d9e48e97f5a
files src/lib-settings/settings.c
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-settings/settings.c	Wed Jul 18 06:17:47 2007 +0300
+++ b/src/lib-settings/settings.c	Wed Jul 18 06:26:56 2007 +0300
@@ -8,6 +8,8 @@
 #include <stdio.h>
 #include <fcntl.h>
 
+#define SECTION_ERRORMSG "%s (section changed at line %d)"
+
 settings_section_callback_t *null_settings_section_callback = NULL;
 
 static const char *get_bool(const char *value, bool *result)
@@ -70,7 +72,7 @@
 	const char *errormsg, *next_section, *name;
 	char *line, *key, *p, quote;
 	size_t len;
-	int fd, linenum, skip, sections, root_section;
+	int fd, linenum, last_section_line = 0, skip, sections, root_section;
 
 	fd = open(path, O_RDONLY);
 	if (fd < 0) {
@@ -185,6 +187,7 @@
 			if (*line != '{')
 				errormsg = "Expecting '='";
 			else {
+				last_section_line = linenum;
 				sections++;
 				if (next_section != NULL &&
 				    strcmp(next_section, name) == 0) {
@@ -208,6 +211,12 @@
 						!sect_callback(key, name,
 							       context,
 							       &errormsg);
+					if (errormsg != NULL &&
+					    last_section_line != 0) {
+						errormsg = t_strdup_printf(
+							SECTION_ERRORMSG,
+							errormsg, linenum);
+					}
 				}
 			}
 		} else {
@@ -227,6 +236,7 @@
 						break;
 					}
 				}
+				last_section_line = linenum;
 				sections--;
 			}
 		}