Skip to content

Commit

Permalink
patch #8105
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralvoice committed Jul 7, 2013
1 parent 53b47e6 commit c3622ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions distrib/ChangeLog
Expand Up @@ -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)
Expand Down
18 changes: 15 additions & 3 deletions src/utils/lib/options.ml4
Expand Up @@ -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
Expand All @@ -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");
Expand Down

0 comments on commit c3622ef

Please sign in to comment.