diff --git a/distrib/ChangeLog b/distrib/ChangeLog index a17f0573b..dc6a209d1 100644 --- a/distrib/ChangeLog +++ b/distrib/ChangeLog @@ -15,6 +15,7 @@ ChangeLog ========= 2013/07/07: +8105: Config: report line and position for syntax errors in config files (ygrek) 8104: BT: suppress warning for peers6 entry in tracker response (ygrek) 7954: Fix handling of full disc (jcea) 7917: Allow upnp_stub.c to be compiled on Mac OS X (zbroyar) diff --git a/src/utils/lib/options.ml4 b/src/utils/lib/options.ml4 index 647031ae9..a5ae1f0c4 100644 --- a/src/utils/lib/options.ml4 +++ b/src/utils/lib/options.ml4 @@ -251,7 +251,18 @@ let exec_chooks o = try f o with _ -> ()) o.option_class.class_hooks - + +let count_lines ic pos = + seek_in ic 0; + let prev = ref 0 in + let lines = ref 0 in + while pos_in ic < pos do + prev := pos_in ic; + incr lines; + ignore (input_line ic); + done; + !lines, pos - !prev + let really_load filename sections = let temp_file = filename ^ ".tmp" in if Sys.file_exists temp_file then @@ -271,8 +282,9 @@ let really_load filename sections = try parse_gwmlrc stream with e -> - lprintf "Syntax error while parsing file %s at pos %d:(%s)\n" - filename (Stream.count s) (Printexc2.to_string e); + let (line,col) = count_lines ic (Stream.count s) in + lprintf "Syntax error while parsing file %s at position %d:%d: %s\n" + filename line col (Printexc2.to_string e); lprintf "it seems that %s is corrupt,\n" filename; lprintf "try to use a backup from %s\n" (Filename.concat (Sys.getcwd ()) "old_config");