1:- module(pls_index_lines, [ 2 index_lines/1 3]). 4 5:- use_module(documents). 6 7index_lines(URI) :- 8 clear_document_lines(URI), 9 clear_document_line_count(URI), 10 forall( 11 document_line_position(URI, Line, Position), 12 add_document_line(URI, Line, Position) 13 ), 14 findall(Line, get_document_line_position(URI, Line, _), Lines), 15 max_list(Lines, LineCount), 16 set_document_line_count(URI, LineCount). 17 18document_line_position(URI, Line, Position) :- 19 with_content(URI, In, 20 stream_line_position(In, Line, Position) 21 ). 22 23stream_line_position(_In, 0, 0). 24stream_line_position(In, Line, Position) :- 25 repeat, 26 read_line_to_string(In, Text), 27 ( Text \== end_of_file 28 -> ( 29 line_count(In, Count), 30 Line is Count - 1, 31 character_count(In, Position) 32 ) 33 ; ( !, fail) 34 )