[m-rev.] diff: formatting and style fixes for samples/diff

Julien Fischer juliensf at csse.unimelb.edu.au
Sat Jan 8 03:35:15 AEDT 2011


Branches: main, 11.01

samples/diff/*.m:
 	Make this code conform to our current coding guidelines -- there
 	are no changes to any algorithms.

 	Delete imports of unused modules.

Julien.

Index: diff.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/diff.m,v
retrieving revision 1.11
diff -u -b -r1.11 diff.m
--- diff.m	28 Jun 2006 09:22:39 -0000	1.11
+++ diff.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1995-1998, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -34,108 +36,119 @@
  :- import_module getopt.
  :- import_module list.
  :- import_module maybe.
-:- import_module require.
-:- import_module string.

  %-----------------------------------------------------------------------------%

  	% main: top-level predicate.
-main -->
-	io__command_line_arguments(Args0),
-	{ options__get_option_ops(OptionOps) },
-	{ getopt__process_options(OptionOps, Args0, Args, Result0) },
-	postprocess_options(Result0, Result), 
-	( { Result = yes(Msg) },
-		usage_error(Msg)
-	; { Result = no },
-		globals__io_get_output_style(OutputStyle),
-		( { OutputStyle = help_only } ->
-			usage
-		; { OutputStyle = version_only } ->
-			version
+    %
+main(!IO) :-
+    io.command_line_arguments(Args0, !IO),
+    options.get_option_ops(OptionOps),
+    getopt.process_options(OptionOps, Args0, Args, Result0),
+    postprocess_options(Result0, Result, !IO), 
+    (
+        Result = yes(Msg),
+        usage_error(Msg, !IO)
  		;
-			main_2(Args)
+        Result = no,
+        globals.io_get_output_style(OutputStyle, !IO),
+        ( OutputStyle = help_only ->
+            usage(!IO)
+        ; OutputStyle = version_only ->
+            version(!IO)
+        ;
+            main_2(Args, !IO)
  		)
  	).

  %-----------------------------------------------------------------------------%

-:- pred usage_error(string :: in, io__state :: di, io__state :: uo) is det.
-usage_error(Msg) -->
-	io__progname_base("diff", ProgName),
-	io__stderr_stream(StdErr),
-	io__write_strings(StdErr, [ProgName, ": ", Msg, "\n"]),
-	io__set_exit_status(1),
-	usage.
-
-:- pred usage_io_error(io__error, io__state, io__state).
-:- mode usage_io_error(in, di, uo) is det.
-usage_io_error(Error) -->
-	{ io__error_message(Error, Msg) },
-	usage_error(Msg).
-
-:- pred usage(io__state :: di, io__state :: uo) is det.
-usage -->
-	io__write_string("Usage: diff [options] from-file to-file\n\n"),
-	options_help.
-
-:- pred version(io__state :: di, io__state :: uo) is det.
-version -->
-	io__write_string("diff - Mercury diff version 0.4\n").
+:- pred usage_error(string::in, io::di, io::uo) is det.
+
+usage_error(Msg, !IO) :-
+    io.progname_base("diff", ProgName, !IO),
+    io.stderr_stream(StdErr, !IO),
+    io.write_strings(StdErr, [ProgName, ": ", Msg, "\n"], !IO),
+    io.set_exit_status(1, !IO),
+    usage(!IO).
+
+:- pred usage_io_error(io.error::in, io::di, io::uo) is det.
+
+usage_io_error(Error, !IO) :-
+    io.error_message(Error, Msg),
+    usage_error(Msg, !IO).
+
+:- pred usage(io::di, io::uo) is det.
+
+usage(!IO) :-
+    io.write_string("Usage: diff [options] from-file to-file\n\n", !IO),
+    options_help(!IO).
+
+:- pred version(io::di, io::uo) is det.
+
+version(!IO) :-
+    io.write_string("diff - Mercury diff version 0.4\n", !IO).

  %-----------------------------------------------------------------------------%

  	% main_2 analyses the command-line arguments which are not
-	% options and calls diff__do_diff.
-:- pred main_2(list(string), io__state, io__state).
-:- mode main_2(in, di, uo) is det.
-main_2([]) -->
-	usage_error("missing operand").
-main_2([Fname1 | Rest]) -->
-	( { Rest = [Fname2 | _] },
-		( { Fname1 = Fname2 } ->
+    % options and calls diff.do_diff.
+    %
+:- pred main_2(list(string)::in, io::di, io::uo) is det.
+
+main_2([], !IO) :-
+    usage_error("missing operand", !IO).
+main_2([Fname1 | Rest], !IO)  :-
+    ( 
+        Rest = [Fname2 | _],
+        ( Fname1 = Fname2 ->
  			% Not sure why anyone would want to diff two
-			% files with the same name, but just in case...
-			( { Fname1 = "-" } ->
-				file__read_input(Fname1, Contents1),
-				{ Contents1 = Contents2 }
+            % files with the same name, but just in case ...
+            ( Fname1 = "-" ->
+                file.read_input(Fname1, Contents1, !IO),
+                Contents1 = Contents2
  			;
-				file__read_file(Fname1, Contents1),
-				{ Contents1 = Contents2 }
+                file.read_file(Fname1, Contents1, !IO),
+                Contents1 = Contents2
  			)
  		;
  			% If either file is "-", simply use standard input.
  			% (Note: Both can't be "-" since that was dealt with
  			% in the previous case.)
-			( { Fname1 = "-" } ->
-				file__read_input(Fname1, Contents1),
-				file__read_file(Fname2, Contents2)
-			; { Fname2 = "-" } ->
-				file__read_file(Fname1, Contents1),
-				file__read_input(Fname2, Contents2)
+            ( Fname1 = "-" ->
+                file.read_input(Fname1, Contents1, !IO),
+                file.read_file(Fname2, Contents2, !IO)
+            ; Fname2 = "-" ->
+                file.read_file(Fname1, Contents1, !IO),
+                file.read_input(Fname2, Contents2, !IO)
  			;
  			% Otherwise read the files normally.
-				file__read_file(Fname1, Contents1),
-				file__read_file(Fname2, Contents2)
+                file.read_file(Fname1, Contents1, !IO),
+                file.read_file(Fname2, Contents2, !IO)
  			)
  		),
  		% Now do the diff.
-		( { Contents1 = ok(File1), Contents2 = ok(File2) } ->
-			diff__do_diff(File1, File2)
-		; { Contents1 = error(Msg) } ->
-			usage_io_error(Msg)
-		; { Contents2 = error(Msg) } ->
-			usage_io_error(Msg)
+        (
+            Contents1 = ok(File1),
+            (
+                Contents2 = ok(File2),
+                diff.do_diff(File1, File2, !IO)
  		;
-			{ error("main2") }
+                Contents2 = error(Msg),
+                usage_io_error(Msg, !IO)
  		)
-	; { Rest = [] },
-		usage_error("missing operand")
+        ;
+            Contents1 = error(Msg),
+            usage_io_error(Msg, !IO)
+        )
+    ;
+        Rest = [],
+        usage_error("missing operand", !IO)
  	).

  %-----------------------------------------------------------------------------%

-	% diff__do_diff takes the files plus all the command
+    % do_diff takes the files plus all the command
  	% line options and determines what to do with them.
  	%
  	% At the moment, we're organised into four passes:
@@ -152,13 +165,14 @@
  	%	- display_diff outputs the diff in whatever output
  	%	  format the user chose.
  	%
-:- pred diff__do_diff(file, file, io__state, io__state).
-:- mode diff__do_diff(in, in, di, uo) is det.
-diff__do_diff(File1, File2) -->
-	build_matches(File1, File2, FileX, FileY),
-	diff_by_myers(FileX, FileY, Diff0),
-	filter_diff(Diff0, File1, File2, Diff),
-	display_diff(File1, File2, Diff).
+:- pred do_diff(file::in, file::in, io::di, io::uo) is det.
+
+do_diff(File1, File2, !IO) :-
+    build_matches(File1, File2, FileX, FileY, !IO),
+    diff_by_myers(FileX, FileY, Diff0, !IO),
+    filter_diff(File1, File2, Diff0, Diff, !IO),
+    display_diff(File1, File2, Diff, !IO).

  %-----------------------------------------------------------------------------%
+:- end_module diff.
  %-----------------------------------------------------------------------------%
Index: diff_out.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/diff_out.m,v
retrieving revision 1.3
diff -u -b -r1.3 diff_out.m
--- diff_out.m	28 Jun 2006 09:22:39 -0000	1.3
+++ diff_out.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1995-1998, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -20,13 +22,11 @@
  :- import_module difftype.
  :- import_module file.

-:- import_module int.
  :- import_module io.
-:- import_module string.

  %-----------------------------------------------------------------------------%

-:- type diff_out__output_style
+:- type output_style
  	--->	normal
  	;	help_only
  	;	version_only
@@ -41,29 +41,28 @@
  	;	cvs_merge_conflict.

  	% The default output style.
-:- pred diff_out__default_output_style(diff_out__output_style).
-:- mode diff_out__default_output_style(out) is det.
+    %
+:- pred diff_out.default_output_style(output_style::out) is det.

  	% Succeeds if, for this output style, an absence of differences
  	% means that no output should be generated.
-:- pred diff_out__no_diff_implies_no_output(diff_out__output_style).
-:- mode diff_out__no_diff_implies_no_output(in) is semidet.
+    %
+:- pred diff_out.no_diff_implies_no_output(output_style::in) is semidet.

  	% Succeeds if the user only wants to know about the presence
  	% of any differences, not what they actually are.
-:- pred diff_out__full_diff_not_required(diff_out__output_style).
-:- mode diff_out__full_diff_not_required(in) is semidet.
+    %
+:- pred diff_out.full_diff_not_required(output_style::in) is semidet.

-	% Succeeds if the output style is "robust", that is, the
-	% absence of a newline at the end of the file actually
-	% matters.
-:- pred diff_out__robust(diff_out__output_style).
-:- mode diff_out__robust(in) is semidet.
-
-	% display_diff takes a diff and displays it
-	% in the user's specified output format.
-:- pred display_diff(file, file, diff, io__state, io__state).
-:- mode display_diff(in, in, in, di, uo) is det.
+    % Succeeds if the output style is "robust", that is, the absence of a
+    % newline at the end of the file actually matters.
+    %
+:- pred diff_out.robust(output_style::in) is semidet.
+
+    % display_diff takes a diff and displays it in the user's specified output
+    % format.
+    %
+:- pred display_diff(file::in, file::in, diff::in, io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -75,6 +74,7 @@

  :- import_module bool.
  :- import_module char.
+:- import_module int.
  :- import_module list.
  :- import_module pair.
  :- import_module require.
@@ -82,345 +82,350 @@

  %-----------------------------------------------------------------------------%

-diff_out__default_output_style(normal).
+default_output_style(normal).

  %-----------------------------------------------------------------------------%

-diff_out__no_diff_implies_no_output(normal).
-diff_out__no_diff_implies_no_output(context(_)).
-diff_out__no_diff_implies_no_output(unified(_)).
-diff_out__no_diff_implies_no_output(ed).
-diff_out__no_diff_implies_no_output(forward_ed).
-diff_out__no_diff_implies_no_output(rcs).
-diff_out__no_diff_implies_no_output(brief).
+no_diff_implies_no_output(normal).
+no_diff_implies_no_output(context(_)).
+no_diff_implies_no_output(unified(_)).
+no_diff_implies_no_output(ed).
+no_diff_implies_no_output(forward_ed).
+no_diff_implies_no_output(rcs).
+no_diff_implies_no_output(brief).

  %-----------------------------------------------------------------------------%

-diff_out__full_diff_not_required(brief).
+full_diff_not_required(brief).

  %-----------------------------------------------------------------------------%

-diff_out__robust(normal).
-diff_out__robust(context(_)).
-diff_out__robust(unified(_)).
-diff_out__robust(rcs).
-diff_out__robust(ifdef(_)).
-diff_out__robust(side_by_side).
-diff_out__robust(cvs_merge_conflict).
+robust(normal).
+robust(context(_)).
+robust(unified(_)).
+robust(rcs).
+robust(ifdef(_)).
+robust(side_by_side).
+robust(cvs_merge_conflict).

  %-----------------------------------------------------------------------------%

-	% diff_out__show_file shows the segment of the file
-	% from Low to High, with each line preceeded by
-	% the Prefix characher and a space.  The diff(1)
-	% format specifies that the lines effected in the
-	% first file should be flagged by '<' and the
-	% lines effected in the second file should be
+    % diff_out.show_file shows the segment of the file from Low to High, with
+    % each line preceeded by the Prefix characher and a space.  The diff(1)
+    % format specifies that the lines effected in the first file should be
+    % flagged by '<' and the lines effected in the second file should be
  	% flagged by '>'.
  	%
-:- pred diff_out__show_file(file, string, pos, pos, io__state, io__state).
-:- mode diff_out__show_file(in, in, in, in, di, uo) is det.
+:- pred show_file(file::in, string::in, pos::in, pos::in,
+    io::di, io::uo) is det.

-diff_out__show_file(File, Prefix, Low, High) -->
-	globals__io_lookup_bool_option(expand_tabs, ExpandTabs),
-	diff_out__show_file_2(ExpandTabs, File, Prefix, Low, High).
-
-	% NOTE: GCC 2.7.2 under Digital Unix 3.2 doesn't compile
-	%       this predicate correctly with optimisation turned on.
-:- pred diff_out__show_file_2(bool, file, string, pos, pos,
-		io__state, io__state).
-:- mode diff_out__show_file_2(in, in, in, in, in, di, uo) is det.
-
-diff_out__show_file_2(ExpandTabs, File, Prefix, Low, High) -->
-	( { Low < High } ->
-		( { file__get_line(File, Low, Line) } ->
-			io__write_string(Prefix),
-			( { ExpandTabs = yes },
-				{ string__to_char_list(Line, LineList) },
-				diff_out__expand_tabs(LineList, 0)
-			; { ExpandTabs = no },
-				io__write_string(Line)
+show_file(File, Prefix, Low, High, !IO) :-
+    globals.io_lookup_bool_option(expand_tabs, ExpandTabs, !IO),
+    show_file_2(ExpandTabs, File, Prefix, Low, High, !IO).
+
+:- pred show_file_2(bool::in, file::in, string::in, pos::in, pos::in,
+    io::di, io::uo) is det.
+
+show_file_2(ExpandTabs, File, Prefix, Low, High, !IO) :-
+    ( Low < High ->
+        ( file.get_line(File, Low, Line) ->
+            io.write_string(Prefix, !IO),
+            (
+                ExpandTabs = yes,
+                string.to_char_list(Line, LineList),
+                expand_tabs(LineList, 0, !IO)
+            ;
+                ExpandTabs = no,
+                io.write_string(Line, !IO)
  			),
-			diff_out__show_file_2(ExpandTabs, File, Prefix,
-					Low + 1, High)
+            show_file_2(ExpandTabs, File, Prefix, Low + 1, High, !IO)
  		;
-			{ error("diff_out_show_file: file ended prematurely") }
+            error("diff_out_show_file: file ended prematurely")
  		)
  	;
-		[]
+        true
  	).

-:- pred diff_out__expand_tabs(list(char), int, io__state, io__state).
-:- mode diff_out__expand_tabs(in, in, di, uo) is det.
+:- pred expand_tabs(list(char)::in, int::in, io::di, io::uo) is det.

-diff_out__expand_tabs([], _) --> [].
-diff_out__expand_tabs([C | Cs], Pos) -->
-	( { C = '\t' } ->
-		{ Spaces = tab_width - (Pos rem tab_width) },
-		put_spaces(Spaces, Pos, NewPos),
-		diff_out__expand_tabs(Cs, NewPos)
+expand_tabs([], _, !IO).
+expand_tabs([C | Cs], Pos, !IO) :-
+    ( C = '\t' ->
+        Spaces = tab_width - (Pos rem tab_width),
+        put_spaces(Spaces, Pos, NewPos, !IO),
+        expand_tabs(Cs, NewPos, !IO)
  	;
-		io__write_char(C),
-		diff_out__expand_tabs(Cs, Pos + 1)
+        io.write_char(C, !IO),
+        expand_tabs(Cs, Pos + 1, !IO)
  	).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%

-
-	% display_diff: Determine which output style to use, then call
-	% the predicate to display that output.
+    % display_diff: Determine which output style to use, then call the
+    % predicate to display that output.
+    %
+    % Some of these options (notably the ones which require no output) should
+    % have been handled already by the time we reach here.  In those cases, we
+    % just call error/1.
  	%
-	% Some of these options (notably the ones which require no
-	% output) should have been handled already by the time we
-	% reach here.  In those cases, we just call error/1.
-display_diff(File1, File2, Diff) -->
-	globals__io_get_output_style(OutputStyle),
-	(
-		{ Diff = [],
-		  diff_out__no_diff_implies_no_output(OutputStyle)
-		}
+display_diff(File1, File2, Diff, !IO) :-
+    globals.io_get_output_style(OutputStyle, !IO),
+    (
+        Diff = [],
+        no_diff_implies_no_output(OutputStyle)
  	->
-		[]
+        true
  	;
-		display_diff_2(OutputStyle, File1, File2, Diff)
+        display_diff_2(OutputStyle, File1, File2, Diff, !IO)
  	).

+:- pred display_diff_2(output_style::in, file::in, file::in, diff::in,
+    io::di, io::uo) is det.

-:- pred display_diff_2(diff_out__output_style, file, file, diff,
-			io__state, io__state).
-:- mode display_diff_2(in, in, in, in, di, uo) is det.
+display_diff_2(normal, File1, File2, Diff, !IO) :-
+    display_diff_normal(File1, File2, Diff, !IO).

-display_diff_2(normal, File1, File2, Diff) -->
-	display_diff_normal(File1, File2, Diff).
+display_diff_2(help_only, _File1, _File2, _Diff, !IO) :-
+    error("display_diff: help_only").

-display_diff_2(help_only, _File1, _File2, _Diff) -->
-	{ error("display_diff: help_only") }.
+display_diff_2(version_only, _File1, _File2, _Diff, !IO) :-
+    error("display_diff: version_only").

-display_diff_2(version_only, _File1, _File2, _Diff) -->
-	{ error("display_diff: version_only") }.
+display_diff_2(context(Context), File1, File2, Diff, !IO) :-
+    display_context_diff(Context, File1, File2, Diff, !IO).

-display_diff_2(context(Context), File1, File2, Diff) -->
-	display_context_diff(Context, File1, File2, Diff).
+display_diff_2(unified(Context), File1, File2, Diff, !IO) :-
+    display_unified_diff(Context, File1, File2, Diff, !IO).

-display_diff_2(unified(Context), File1, File2, Diff) -->
-	display_unified_diff(Context, File1, File2, Diff).
+display_diff_2(ed, File1, File2, Diff, !IO) :-
+    display_diff_ed(File1, File2, Diff, !IO).

-display_diff_2(ed, File1, File2, Diff) -->
-	display_diff_ed(File1, File2, Diff).
+display_diff_2(forward_ed, File1, File2, Diff, !IO) :-
+    display_diff_forward_ed(File1, File2, Diff, !IO).

-display_diff_2(forward_ed, File1, File2, Diff) -->
-	display_diff_forward_ed(File1, File2, Diff).
+display_diff_2(rcs, File1, File2, Diff, !IO) :-
+    display_diff_rcs(File1, File2, Diff, !IO).

-display_diff_2(rcs, File1, File2, Diff) -->
-	display_diff_rcs(File1, File2, Diff).
+display_diff_2(ifdef(Sym), File1, File2, Diff, !IO) :-
+    display_diff_ifdef(Sym, File1, File2, Diff, !IO).

-display_diff_2(ifdef(Sym), File1, File2, Diff) -->
-	display_diff_ifdef(Sym, File1, File2, Diff).
-
-display_diff_2(brief, File1, File2, _Diff) -->
+display_diff_2(brief, File1, File2, _Diff, !IO) :-
  	% XXX For this output style, we really don't need to
  	%     perform a complete diff.  This should be handled
  	%     higher up for efficiency.
-	{ file__get_file_name(File1, FileName1) },
-	{ file__get_file_name(File2, FileName2) },
-	io__write_strings(["Files ", FileName1, " and ",
-		FileName2, " differ\n"]).
+    file.get_file_name(File1, FileName1),
+    file.get_file_name(File2, FileName2),
+    io.write_strings(["Files ", FileName1, " and ",
+        FileName2, " differ\n"], !IO).

-display_diff_2(side_by_side, File1, File2, Diff) -->
-	display_diff_side_by_side(File1, File2, Diff).
+display_diff_2(side_by_side, File1, File2, Diff, !IO) :-
+    display_diff_side_by_side(File1, File2, Diff, !IO).

-display_diff_2(cvs_merge_conflict, File1, File2, Diff) -->
-	display_diff_cvs_merge_conflict(File1, File2, Diff).
+display_diff_2(cvs_merge_conflict, File1, File2, Diff, !IO) :-
+    display_diff_cvs_merge_conflict(File1, File2, Diff, !IO).

  %-----------------------------------------------------------------------------%

  	% display_diff_normal takes a diff and displays it
  	% in the standard diff(1) output format.
-:- pred display_diff_normal(file, file, diff, io__state, io__state).
-:- mode display_diff_normal(in, in, in, di, uo) is det.
+    %
+:- pred display_diff_normal(file::in, file::in, diff::in,
+    io::di, io::uo) is det.

-display_diff_normal(File1, File2, Diff) -->
-	globals__io_lookup_bool_option(initial_tab, InitialTab),
-	{ InitialTab = no,
+display_diff_normal(File1, File2, Diff, !IO) :-
+    globals.io_lookup_bool_option(initial_tab, InitialTab, !IO),
+    (
+        InitialTab = no,
  		FromStr = "< ",
  		ToStr = "> "
-	; InitialTab = yes,
+    ;
+        InitialTab = yes,
  		FromStr = "<\t",
  		ToStr = ">\t"
-	},
-	display_diff_normal_2(File1, File2, Diff, FromStr, ToStr).
+    ),
+    display_diff_normal_2(File1, File2, Diff, FromStr, ToStr, !IO).

  	% display_diff_normal takes a diff and displays it
  	% in the standard diff(1) output format.
-:- pred display_diff_normal_2(file, file, diff, string, string,
-			io__state, io__state).
-:- mode display_diff_normal_2(in, in, in, in, in, di, uo) is det.
-
-display_diff_normal_2(_, _, [], _, _) --> [].
-display_diff_normal_2(File1, File2, [SingDiff | Diff], FromStr, ToStr) -->
-	( { SingDiff = add(X, Y1 - Y2) },
-		diff_out__write_command(X - X, 'a', Y1 - Y2),
-		diff_out__show_file(File2, ToStr, Y1, Y2)
-	; { SingDiff = delete(X1 - X2, Y) },
-		diff_out__write_command(X1 - X2, 'd', Y - Y),
-		diff_out__show_file(File1, FromStr, X1, X2)
-	; { SingDiff = change(X1 - X2, Y1 - Y2) },
-		diff_out__write_command(X1 - X2, 'c', Y1 - Y2),
-		diff_out__show_file(File1, FromStr, X1, X2),
-		io__write_string("---\n"),
-		diff_out__show_file(File2, ToStr, Y1, Y2)
-	),
-	display_diff_normal_2(File1, File2, Diff, FromStr, ToStr).
-
-
-	% diff_out__write_command displays a diff(1) command.
-	% Like ed(1), a pair of numbers which are identical
-	% are abbreviated by a single number.
+    %
+:- pred display_diff_normal_2(file::in, file::in, diff::in, string::in,
+    string::in, io::di, io::uo) is det.
+
+display_diff_normal_2(_, _, [], _, _, !IO).
+display_diff_normal_2(File1, File2, [SingDiff | Diff], FromStr, ToStr, !IO) :-
+    (
+        SingDiff = add(X, Y1 - Y2),
+        diff_out.write_command(X - X, 'a', Y1 - Y2, !IO),
+        diff_out.show_file(File2, ToStr, Y1, Y2, !IO)
+    ;
+        SingDiff = delete(X1 - X2, Y),
+        diff_out.write_command(X1 - X2, 'd', Y - Y, !IO),
+        diff_out.show_file(File1, FromStr, X1, X2, !IO)
+    ; 
+        SingDiff = change(X1 - X2, Y1 - Y2),
+        diff_out.write_command(X1 - X2, 'c', Y1 - Y2, !IO),
+        diff_out.show_file(File1, FromStr, X1, X2, !IO),
+        io.write_string("---\n", !IO),
+        diff_out.show_file(File2, ToStr, Y1, Y2, !IO)
+    ),
+    display_diff_normal_2(File1, File2, Diff, FromStr, ToStr, !IO).
+
+    % write_command displays a diff(1) command.
+    % Like ed(1), a pair of numbers which are identical are abbreviated by a
+    % single number.
  	% MK: Assumption X=<X2
  	% AJB: And, similarly, Y=<Y2.  This is actually an
  	%      invariant of the segment type.  See difftype.m.
-:- pred diff_out__write_command(segment, char, segment, io__state, io__state).
-:- mode diff_out__write_command(in, in, in, di, uo) is det.
+    %
+:- pred write_command(segment::in, char::in, segment::in,
+    io::di, io::uo) is det.

-diff_out__write_command(X - X2, C, Y - Y2) -->
-	{ X1 is X + 1 },	% Convert from pos to line number
-	( { X1 >= X2 } ->
-		% either empty or singleton segment
-		io__write_int(X2)
-	;
-		io__write_int(X1),
-		io__write_char(','),
-		io__write_int(X2)
-	),
-	io__write_char(C),
-	{ Y1 is Y + 1 },	% Convert from pos to line number
-	( { Y1 >= Y2 } ->
-		% either empty or singleton segment
-		io__write_int(Y2)
-	;
-		io__write_int(Y1),
-		io__write_char(','),
-		io__write_int(Y2)
-	),
-	io__write_char('\n').
+write_command(X - X2, C, Y - Y2, !IO) :-
+    X1 = X + 1,    % Convert from pos to line number.
+    ( X1 >= X2 ->
+        % Either empty or singleton segment.
+        io.write_int(X2, !IO)
+    ;
+        io.write_int(X1, !IO),
+        io.write_char(',', !IO),
+        io.write_int(X2, !IO)
+    ),
+    io.write_char(C, !IO),
+    Y1 = Y + 1,    % Convert from pos to line number.
+    ( Y1 >= Y2 ->
+        % Either empty or singleton segment.
+        io.write_int(Y2, !IO)
+    ;
+        io.write_int(Y1, !IO),
+        io.write_char(',', !IO),
+        io.write_int(Y2, !IO)
+    ),
+    io.write_char('\n', !IO).

  %-----------------------------------------------------------------------------%

-	% display_diff_rcs takes a diff and displays it
-	% in the RCS difference format.
-:- pred display_diff_rcs(file, file, diff, io__state, io__state).
-:- mode display_diff_rcs(in, in, in, di, uo) is det.
-
-display_diff_rcs(_File1, _File2, []) --> [].
-display_diff_rcs(File1, File2, [Cmd | Diff]) -->
-	( { Cmd = add(X, Y1 - Y2) },
-		diff_out__write_command_rcs('a', X, Y2-Y1),
-		diff_out__show_file(File2, "", Y1, Y2)
-	; { Cmd = delete(X1 - X2, _Y) },
-		diff_out__write_command_rcs('d', X1, X2-X1)
-	; { Cmd = change(X1 - X2, Y1 - Y2) },
-		diff_out__write_command_rcs('d', X1, X2-X1),
-		diff_out__write_command_rcs('a', X1, Y2-Y1),
-		diff_out__show_file(File2, "", Y1, Y2)
-	),
-	display_diff_rcs(File1, File2, Diff).
+    % display_diff_rcs takes a diff and displays it in the RCS difference
+    % format.
+    %
+:- pred display_diff_rcs(file::in, file::in, diff::in, io::di, io::uo) is det.

+display_diff_rcs(_File1, _File2, [], !IO).
+display_diff_rcs(File1, File2, [Cmd | Diff], !IO) :-
+    (
+        Cmd = add(X, Y1 - Y2),
+        write_command_rcs('a', X, Y2 - Y1, !IO),
+        show_file(File2, "", Y1, Y2, !IO)
+    ;
+        Cmd = delete(X1 - X2, _Y),
+        write_command_rcs('d', X1, X2 - X1, !IO)
+    ;
+        Cmd = change(X1 - X2, Y1 - Y2),
+        write_command_rcs('d', X1, X2 - X1, !IO),
+        write_command_rcs('a', X1, Y2 - Y1, !IO),
+        show_file(File2, "", Y1, Y2, !IO)
+    ),
+    display_diff_rcs(File1, File2, Diff, !IO).

-	% diff_out__write_command_rcs displays a diff command in
+    % diff_out.write_command_rcs displays a diff command in
  	% the RCS ,v format.
-:- pred diff_out__write_command_rcs(char, int, int, io__state, io__state).
-:- mode diff_out__write_command_rcs(in, in, in, di, uo) is det.
+    %
+:- pred write_command_rcs(char::in, int::in, int::in, io::di, io::uo) is det.

-diff_out__write_command_rcs(C, X, Y) -->
-	io__write_char(C),
-	io__write_int(X + 1),	% Convert from pos to line number
-	io__write_char(' '),
-	io__write_int(Y),
-	io__write_char('\n').
+write_command_rcs(C, X, Y, !IO) :-
+    io.write_char(C, !IO),
+    io.write_int(X + 1, !IO),    % Convert from pos to line number.
+    io.write_char(' ', !IO),
+    io.write_int(Y, !IO),
+    io.write_char('\n', !IO).

  %-----------------------------------------------------------------------------%

-	% display_diff_ed takes a diff and displays it
-	% in ed(1) format, but with all diffs backward.
-:- pred display_diff_ed(file, file, diff, io__state, io__state).
-:- mode display_diff_ed(in, in, in, di, uo) is det.
-
-display_diff_ed(_File1, _File2, []) --> [].
-display_diff_ed(File1, File2, [Cmd | Diff]) -->
-	display_diff_ed(File1, File2, Diff),
-	( { Cmd = add(X, Y1 - Y2) },
-		diff_out__write_command_ed(X - X, 'a'),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_string(".\n")
-	; { Cmd = delete(X, _Y) },
-		diff_out__write_command_ed(X, 'd')
-	; { Cmd = change(X, Y1 - Y2) },
-		diff_out__write_command_ed(X, 'c'),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_string(".\n")
+    % display_diff_ed takes a diff and displays it in ed(1) format, but with
+    % all diffs backward.
+    %
+:- pred display_diff_ed(file::in, file::in, diff::in, io::di, io::uo) is det.
+
+display_diff_ed(_File1, _File2, [], !IO).
+display_diff_ed(File1, File2, [Cmd | Diff], !IO) :-
+    display_diff_ed(File1, File2, Diff, !IO),
+    (
+        Cmd = add(X, Y1 - Y2),
+        write_command_ed(X - X, 'a', !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_string(".\n", !IO)
+    ;
+        Cmd = delete(X, _Y),
+        write_command_ed(X, 'd', !IO)
+    ;
+        Cmd = change(X, Y1 - Y2),
+        write_command_ed(X, 'c', !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_string(".\n", !IO)
  	).

+    % write_command_ed displays an ed(1) command.
+    %
+:- pred write_command_ed(segment::in, char::in, io::di, io::uo) is det.

-	% diff_out__write_command_ed displays an ed(1) command.
-:- pred diff_out__write_command_ed(segment, char, io__state, io__state).
-:- mode diff_out__write_command_ed(in, in, di, uo) is det.
-
-diff_out__write_command_ed(X - X2, C) -->
-	{ X1 is X + 1 },		% Convert from pos to line number
-	( { X1 >= X2 } ->
-		% either empty or singleton segment
-		io__write_int(X2)
-	;
-		io__write_int(X1),
-		io__write_char(','),
-		io__write_int(X2)
-	),
-	io__write_char(C),
-	io__write_char('\n').
+write_command_ed(X - X2, C, !IO) :-
+    X1 = X + 1,        % Convert from pos to line number
+    ( X1 >= X2 ->
+        % Either empty or singleton segment.
+        io.write_int(X2, !IO)
+    ;
+        io.write_int(X1, !IO),
+        io.write_char(',', !IO),
+        io.write_int(X2, !IO)
+    ),
+    io.write_char(C, !IO),
+    io.write_char('\n', !IO).

  %-----------------------------------------------------------------------------%

-	% display_diff_forward_ed takes a diff and displays it
-	% in ed(1) format, but with all diff_out forward.  This
-	% is actually useless for feeding to ed(1), but nicer
-	% to read.
-:- pred display_diff_forward_ed(file, file, diff, io__state, io__state).
-:- mode display_diff_forward_ed(in, in, in, di, uo) is det.
-
-display_diff_forward_ed(_File1, _File2, []) --> { true }.
-display_diff_forward_ed(File1, File2, [Cmd | Diff]) -->
-	( { Cmd = add(X, Y1 - Y2) },
-		diff_out__write_command_forward_ed(X - X, 'a'),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_string(".\n")
-	; { Cmd = delete(X, _Y) },
-		diff_out__write_command_forward_ed(X, 'd')
-	; { Cmd = change(X, Y1 - Y2) },
-		diff_out__write_command_forward_ed(X, 'c'),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_string(".\n")
-	),
-	display_diff_forward_ed(File1, File2, Diff).
-
-	% diff_out__write_command_forward_ed displays a forward ed(1)
-	% command.  The difference between this and write_command_ed is
-	% that the command char comes first here.  Who comes up with
-	% these dumb formats anyway?
-:- pred diff_out__write_command_forward_ed(segment, char, io__state, io__state).
-:- mode diff_out__write_command_forward_ed(in, in, di, uo) is det.
-diff_out__write_command_forward_ed(X - X2, C) -->
-	io__write_char(C),
-	{ X1 is X + 1 },		% Convert from pos to line number
-	( { X1 >= X2 } ->
-		% either empty or singleton segment
-		io__write_int(X2)
-	;
-		io__write_int(X1),
-		io__write_char(' '),
-		io__write_int(X2)
+    % display_diff_forward_ed takes a diff and displays it in ed(1) format, but
+    % with all diff_out forward.  This is actually useless for feeding to
+    % ed(1), but nicer to read.
+    %
+:- pred display_diff_forward_ed(file::in, file::in, diff::in,
+    io::di, io::uo) is det.
+
+display_diff_forward_ed(_File1, _File2, [], !IO).
+display_diff_forward_ed(File1, File2, [Cmd | Diff], !IO) :-
+    (
+        Cmd = add(X, Y1 - Y2),
+        write_command_forward_ed(X - X, 'a', !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_string(".\n", !IO)
+    ;
+        Cmd = delete(X, _Y),
+        write_command_forward_ed(X, 'd', !IO)
+    ;
+        Cmd = change(X, Y1 - Y2),
+        write_command_forward_ed(X, 'c', !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_string(".\n", !IO)
+    ),
+    display_diff_forward_ed(File1, File2, Diff, !IO).
+
+    % write_command_forward_ed displays a forward ed(1) command.
+    % The difference between this and write_command_ed is that the command char
+    % comes first here.  Who comes up with these dumb formats anyway?
+    %
+:- pred write_command_forward_ed(segment::in, char::in, io::di, io::uo) is det.
+
+write_command_forward_ed(X - X2, C, !IO) :-
+    io.write_char(C, !IO),
+    X1 = X + 1,        % Convert from pos to line number
+    ( X1 >= X2 ->
+        % Either empty or singleton segment.
+        io.write_int(X2, !IO)
+    ;
+        io.write_int(X1, !IO),
+        io.write_char(' ', !IO),
+        io.write_int(X2, !IO)
  	),
-	io__write_char('\n').
+    io.write_char('\n', !IO).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -430,45 +435,49 @@
  	%
  	% TO DO: GNU diff makes this output style much more
  	%        configurable.  We should too.
-:- pred display_diff_ifdef(string, file, file, diff, io__state, io__state).
-:- mode display_diff_ifdef(in, in, in, in, di, uo) is det.
+    %
+:- pred display_diff_ifdef(string::in, file::in, file::in, diff::in,
+    io::di, io::uo) is det.
+
+display_diff_ifdef(Sym, File1, File2, Diff, !IO) :-
+    display_diff_ifdef_2(0, Sym, File1, File2, Diff, !IO).

-display_diff_ifdef(Sym, File1, File2, Diff) -->
-	display_diff_ifdef_2(0, Sym, File1, File2, Diff).
+    % Argument 1 (prev) is the last pos displayed before the current edit (or
+    % end of edits, in the base case).
+    % This is important for when we have to display the "non-diffed" text
+    % between edits.
+    %
+:- pred display_diff_ifdef_2(int::in, string::in, file::in, file::in,
+    diff::in, io::di, io::uo) is det.

-	% Argument 1 (prev) is the last pos displayed before
-	% the current edit (or end of edits, in the base case).
-	% This is important for when we have to display the
-	% "non-diffed" text between edits.
-:- pred display_diff_ifdef_2(int, string, file, file, diff,
-		io__state, io__state).
-:- mode display_diff_ifdef_2(in, in, in, in, in, di, uo) is det.
-
-display_diff_ifdef_2(Prev, _Sym, File1, _File2, []) -->
-	{ file__get_numlines(File1, SegEnd) },
-	diff_out__show_file(File1, "", Prev, SegEnd).
-display_diff_ifdef_2(Prev, Sym, File1, File2, [Edit | Diff]) -->
-	{ first_mentioned_positions(Edit, StartOfEdit, _) },
-	diff_out__show_file(File1, "", Prev, StartOfEdit),
-	( { Edit = add(X, Y1 - Y2) },
-		io__write_strings(["#ifdef ", Sym, "\n"]),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_strings(["#endif /* ", Sym, " */\n"]),
-		{ Next = X }
-	; { Edit = delete(X1 - X2, _) },
-		io__write_strings(["#ifndef ", Sym, "\n"]),
-		diff_out__show_file(File1, "", X1, X2),
-		io__write_strings(["#endif /* not ", Sym, " */\n"]),
-		{ Next = X2 }
-	; { Edit = change(X1 - X2, Y1 - Y2) },
-		io__write_strings(["#ifndef ", Sym, "\n"]),
-		diff_out__show_file(File1, "", X1, X2),
-		io__write_strings(["#else /* ", Sym, " */\n"]),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_strings(["#endif /* ", Sym, " */\n"]),
-		{ Next = X2 }
+display_diff_ifdef_2(Prev, _Sym, File1, _File2, [], !IO) :-
+    file.get_numlines(File1, SegEnd),
+    show_file(File1, "", Prev, SegEnd, !IO).
+display_diff_ifdef_2(Prev, Sym, File1, File2, [Edit | Diff], !IO) :-
+    first_mentioned_positions(Edit, StartOfEdit, _),
+    show_file(File1, "", Prev, StartOfEdit, !IO),
+    (
+        Edit = add(X, Y1 - Y2),
+        io.write_strings(["#ifdef ", Sym, "\n"], !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_strings(["#endif /* ", Sym, " */\n"], !IO),
+        Next = X
+    ;
+        Edit = delete(X1 - X2, _),
+        io.write_strings(["#ifndef ", Sym, "\n"], !IO),
+        show_file(File1, "", X1, X2, !IO),
+        io.write_strings(["#endif /* not ", Sym, " */\n"], !IO),
+        Next = X2
+    ;
+        Edit = change(X1 - X2, Y1 - Y2),
+        io.write_strings(["#ifndef ", Sym, "\n"], !IO),
+        show_file(File1, "", X1, X2, !IO),
+        io.write_strings(["#else /* ", Sym, " */\n"], !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_strings(["#endif /* ", Sym, " */\n"], !IO),
+        Next = X2
  	),
-	display_diff_ifdef_2(Next, Sym, File1, File2, Diff).
+    display_diff_ifdef_2(Next, Sym, File1, File2, Diff, !IO).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -476,49 +485,52 @@
  	% display_diff_cvs_merge_conflict writes out the files in a
  	% unified diff, using CVS merge conflict marks around each edit.
  	%
-:- pred display_diff_cvs_merge_conflict(file, file, diff, io__state, io__state).
-:- mode display_diff_cvs_merge_conflict(in, in, in, di, uo) is det.
+:- pred display_diff_cvs_merge_conflict(file::in, file::in, diff::in,
+    io::di, io::uo) is det.

-display_diff_cvs_merge_conflict(File1, File2, Diff) -->
-	display_diff_cvs_merge_conflict_2(0, File1, File2, Diff).
+display_diff_cvs_merge_conflict(File1, File2, Diff, !IO) :-
+    display_diff_cvs_merge_conflict_2(0, File1, File2, Diff, !IO).

-	% Argument 1 (prev) is the last pos displayed before
-	% the current edit (or end of edits, in the base case).
-	% This is important for when we have to display the
-	% "non-diffed" text between edits.
-:- pred display_diff_cvs_merge_conflict_2(int, file, file, diff,
-		io__state, io__state).
-:- mode display_diff_cvs_merge_conflict_2(in, in, in, in, di, uo) is det.
-
-display_diff_cvs_merge_conflict_2(Prev, File1, _File2, []) -->
-	{ file__get_numlines(File1, SegEnd) },
-	diff_out__show_file(File1, "", Prev, SegEnd).
-display_diff_cvs_merge_conflict_2(Prev, File1, File2, [Edit | Diff]) -->
-	{ first_mentioned_positions(Edit, StartOfEdit, _) },
-	diff_out__show_file(File1, "", Prev, StartOfEdit),
-	{ file__get_file_name(File1, FileName1) },
-	{ file__get_file_name(File2, FileName2) },
-	( { Edit = add(X, Y1 - Y2) },
-		io__write_strings(["<<<<<<< ", FileName1, "\n"]),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_string("=======\n"),
-		io__write_strings([">>>>>>> ", FileName2, "\n"]),
-		{ Next = X }
-	; { Edit = delete(X1 - X2, _) },
-		io__write_strings(["<<<<<<< ", FileName1, "\n"]),
-		io__write_string("=======\n"),
-		diff_out__show_file(File1, "", X1, X2),
-		io__write_strings([">>>>>>> ", FileName2, "\n"]),
-		{ Next = X2 }
-	; { Edit = change(X1 - X2, Y1 - Y2) },
-		io__write_strings(["<<<<<<< ", FileName1, "\n"]),
-		diff_out__show_file(File1, "", X1, X2),
-		io__write_string("=======\n"),
-		diff_out__show_file(File2, "", Y1, Y2),
-		io__write_strings([">>>>>>> ", FileName2, "\n"]),
-		{ Next = X2 }
+    % Argument 1 (prev) is the last pos displayed before the current edit (or
+    % end of edits, in the base case).
+    % This is important for when we have to display the "non-diffed" text
+    % between edits.
+    %
+:- pred display_diff_cvs_merge_conflict_2(int::in, file::in, file::in,
+    diff::in, io::di, io::uo) is det.
+
+display_diff_cvs_merge_conflict_2(Prev, File1, _File2, [], !IO) :-
+    file.get_numlines(File1, SegEnd),
+    show_file(File1, "", Prev, SegEnd, !IO).
+display_diff_cvs_merge_conflict_2(Prev, File1, File2, [Edit | Diff], !IO) :-
+    first_mentioned_positions(Edit, StartOfEdit, _),
+    show_file(File1, "", Prev, StartOfEdit, !IO),
+    file.get_file_name(File1, FileName1),
+    file.get_file_name(File2, FileName2),
+    (
+        Edit = add(X, Y1 - Y2),
+        io.write_strings(["<<<<<<< ", FileName1, "\n"], !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_string("=======\n", !IO),
+        io.write_strings([">>>>>>> ", FileName2, "\n"], !IO),
+        Next = X
+    ;
+        Edit = delete(X1 - X2, _),
+        io.write_strings(["<<<<<<< ", FileName1, "\n"], !IO),
+        io.write_string("=======\n", !IO),
+        show_file(File1, "", X1, X2, !IO),
+        io.write_strings([">>>>>>> ", FileName2, "\n"], !IO),
+        Next = X2
+    ;
+        Edit = change(X1 - X2, Y1 - Y2),
+        io.write_strings(["<<<<<<< ", FileName1, "\n"], !IO),
+        show_file(File1, "", X1, X2, !IO),
+        io.write_string("=======\n", !IO),
+        show_file(File2, "", Y1, Y2, !IO),
+        io.write_strings([">>>>>>> ", FileName2, "\n"], !IO),
+        Next = X2
  	),
-	display_diff_cvs_merge_conflict_2(Next, File1, File2, Diff).
+    display_diff_cvs_merge_conflict_2(Next, File1, File2, Diff, !IO).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -533,7 +545,7 @@
  	% Because context and unified diffs both require the same
  	% kind of information, we factor out the code to turn a
  	% normal diff into a context diff.
-
+    %
  :- type context_edit
  	--->	context_edit(segment, segment, diff).

@@ -541,8 +553,8 @@

  %-----------------------------------------------------------------------------%

-:- pred diff_to_context_diff(int :: in, int :: in, int :: in, diff :: in,
-		context_diff :: out) is det.
+:- pred diff_to_context_diff(int::in, int::in, int::in, diff::in,
+    context_diff::out) is det.

  diff_to_context_diff(_Xsize, _Ysize, _Context, [], []).
  diff_to_context_diff(Xsize, Ysize, Context, [Edit | Diff], CDiff) :-
@@ -550,24 +562,26 @@

  		% Work out how far the context of this edit reaches.
  	first_mentioned_positions(Edit, Xfirst0, Yfirst0),
-	int__max(Xfirst0 - Context, 0, Xfirst),
-	int__max(Yfirst0 - Context, 0, Yfirst),
+    int.max(Xfirst0 - Context, 0, Xfirst),
+    int.max(Yfirst0 - Context, 0, Yfirst),
  	last_mentioned_positions(Edit, Xlast0, Ylast0),
-	int__min(Xlast0 + Context, Xsize, Xlast),
-	int__min(Ylast0 + Context, Ysize, Ylast),
+    int.min(Xlast0 + Context, Xsize, Xlast),
+    int.min(Ylast0 + Context, Ysize, Ylast),

-	( CDiff0 = [],
+    (
+        CDiff0 = [],
  		CDiff = [context_edit(Xfirst - Xlast, Yfirst - Ylast, [Edit])]
-	; CDiff0 = [context_edit(XsegLo - XsegHi, YsegLo - YsegHi, DDiff) |
-				CDiff1],
+    ;
+        CDiff0 =
+            [context_edit(XsegLo - XsegHi, YsegLo - YsegHi, DDiff) | CDiff1],
  		% Should we merge this edit into the next one?
  		(
  			( XsegLo =< Xlast
  			; YsegLo =< Ylast
  			)
  		->
-			CDiff = [context_edit(Xfirst - XsegHi, Yfirst - YsegHi,
-					[Edit | DDiff]) | CDiff1]
+            CDiff = [context_edit(Xfirst - XsegHi, Yfirst - YsegHi, [Edit
+                | DDiff]) | CDiff1]
  		;
  			CDiff = [context_edit(Xfirst - Xlast, Yfirst - Ylast,
  					[Edit]) | CDiff0]
@@ -578,175 +592,186 @@
  %-----------------------------------------------------------------------------%

  	% Display a diff in unified format.
-:- pred display_unified_diff(int, file, file, diff, io__state, io__state).
-:- mode display_unified_diff(in, in, in, in, di, uo) is det.
+    %
+:- pred display_unified_diff(int::in, file::in, file::in, diff::in,
+    io::di, io::uo) is det.

-display_unified_diff(Context, File1, File2, Diff) -->
-	{ file__get_numlines(File1, Size1) },
-	{ file__get_numlines(File2, Size2) },
-	{ diff_to_context_diff(Size1, Size2, Context, Diff, CDiff) },
-	{ file__get_file_name(File1, Name1) },
-	{ file__get_file_name(File2, Name2) },
+display_unified_diff(Context, File1, File2, Diff, !IO) :-
+    file.get_numlines(File1, Size1),
+    file.get_numlines(File2, Size2),
+    diff_to_context_diff(Size1, Size2, Context, Diff, CDiff),
+    file.get_file_name(File1, Name1),
+    file.get_file_name(File2, Name2),
  		% XXX Should also print out file dates.  But how?
-	io__write_strings(["--- ", Name1, "\n"]),
-	io__write_strings(["+++ ", Name2, "\n"]),
-	globals__io_lookup_bool_option(initial_tab, InitialTab),
-	{ InitialTab = no,
+    io.write_strings(["--- ", Name1, "\n"], !IO),
+    io.write_strings(["+++ ", Name2, "\n"], !IO),
+    globals.io_lookup_bool_option(initial_tab, InitialTab, !IO),
+    (
+        InitialTab = no,
  		NoneStr = " ",
  		AddStr = "+",
  		DelStr = "-"
-	; InitialTab = yes,
+    ;
+        InitialTab = yes,
  		NoneStr = "\t",
  		AddStr = "+\t",
  		DelStr = "-\t"
-	},
-	display_unified_diff_2(File1, File2, CDiff, NoneStr, AddStr, DelStr).
+    ),
+    display_unified_diff_2(File1, File2, CDiff, NoneStr, AddStr, DelStr, !IO).
+
+:- pred display_unified_diff_2(file::in, file::in, context_diff::in,
+    string::in, string::in, string::in, io::di, io::uo) is det.

-:- pred display_unified_diff_2(file, file, context_diff, string, string, string,
-				io__state, io__state).
-:- mode display_unified_diff_2(in, in, in, in, in, in, di, uo) is det.
-
-display_unified_diff_2(_File1, _File2, [], _, _, _) --> [].
-display_unified_diff_2(File1, File2, [Edit | CDiff],
-			NoneStr, AddStr, DelStr) -->
-	{ Edit = context_edit(Xlow - Xhigh, Ylow - Yhigh, Diff) },
-	io__format("@@ -%d,%d +%d,%d @@\n",
-		[i(Xlow + 1), i(Xhigh - Xlow), i(Ylow + 1), i(Yhigh - Ylow)]),
-	display_unified_diff_3(Xlow, Xhigh, File1, File2, Diff,
-			NoneStr, AddStr, DelStr),
-	display_unified_diff_2(File1, File2, CDiff, NoneStr, AddStr, DelStr).
-
-:- pred display_unified_diff_3(int, int, file, file, diff,
-				string, string, string, io__state, io__state).
-:- mode display_unified_diff_3(in, in, in, in, in, in, in, in, di, uo) is det.
+display_unified_diff_2(_File1, _File2, [], _, _, _, !IO).
+display_unified_diff_2(File1, File2, [Edit | CDiff], NoneStr, AddStr, DelStr,
+        !IO) :-
+    Edit = context_edit(Xlow - Xhigh, Ylow - Yhigh, Diff),
+    io.format("@@ -%d,%d +%d,%d @@\n",
+        [i(Xlow + 1), i(Xhigh - Xlow), i(Ylow + 1), i(Yhigh - Ylow)], !IO),
+    display_unified_diff_3(Xlow, Xhigh, File1, File2, Diff, NoneStr, AddStr,
+        DelStr, !IO),
+    display_unified_diff_2(File1, File2, CDiff, NoneStr, AddStr, DelStr, !IO).

-display_unified_diff_3(Prev, Size1, File1, _File2, [], NoneStr, _, _) -->
-	diff_out__show_file(File1, NoneStr, Prev, Size1).
+:- pred display_unified_diff_3(int::in, int::in, file::in, file::in, diff::in,
+    string::in, string::in, string::in, io::di, io::uo) is det.
+
+display_unified_diff_3(Prev, Size1, File1, _File2, [], NoneStr, _, _, !IO) :-
+    show_file(File1, NoneStr, Prev, Size1, !IO).
  display_unified_diff_3(Prev, Size1, File1, File2, [Edit | Diff],
-			NoneStr, AddStr, DelStr) -->
-	{ first_mentioned_positions(Edit, StartOfEdit, _) },
-	diff_out__show_file(File1, NoneStr, Prev, StartOfEdit),
-	( { Edit = add(X, Y1 - Y2) },
-		diff_out__show_file(File2, AddStr, Y1, Y2),
-		{ Next = X }
-	; { Edit = delete(X1 - X2, _) },
-		diff_out__show_file(File1, DelStr, X1, X2),
-		{ Next = X1 }
-	; { Edit = change(X1 - X2, Y1 - Y2) },
-		diff_out__show_file(File1, DelStr, X1, X2),
-		diff_out__show_file(File2, AddStr, Y1, Y2),
-		{ Next = X1 }
+        NoneStr, AddStr, DelStr, !IO) :-
+    first_mentioned_positions(Edit, StartOfEdit, _),
+    show_file(File1, NoneStr, Prev, StartOfEdit, !IO),
+    (
+        Edit = add(X, Y1 - Y2),
+        show_file(File2, AddStr, Y1, Y2, !IO),
+        Next = X
+    ;
+        Edit = delete(X1 - X2, _),
+        show_file(File1, DelStr, X1, X2, !IO),
+        Next = X1
+    ;
+        Edit = change(X1 - X2, Y1 - Y2),
+        show_file(File1, DelStr, X1, X2, !IO),
+        show_file(File2, AddStr, Y1, Y2, !IO),
+        Next = X1
  	),
  	display_unified_diff_3(Next, Size1, File1, File2, Diff,
-				NoneStr, AddStr, DelStr).
+        NoneStr, AddStr, DelStr, !IO).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%

  	% Display a diff in context format.
-:- pred display_context_diff(int, file, file, diff, io__state, io__state).
-:- mode display_context_diff(in, in, in, in, di, uo) is det.
+    %
+:- pred display_context_diff(int::in, file::in, file::in, diff::in,
+    io::di, io::uo) is det.

-display_context_diff(Context, File1, File2, Diff) -->
-	{ file__get_numlines(File1, Size1) },
-	{ file__get_numlines(File2, Size2) },
-	{ diff_to_context_diff(Size1, Size2, Context, Diff, CDiff) },
-	{ file__get_file_name(File1, Name1) },
-	{ file__get_file_name(File2, Name2) },
+display_context_diff(Context, File1, File2, Diff, !IO) :-
+    file.get_numlines(File1, Size1),
+    file.get_numlines(File2, Size2),
+    diff_to_context_diff(Size1, Size2, Context, Diff, CDiff),
+    file.get_file_name(File1, Name1),
+    file.get_file_name(File2, Name2),
  		% XXX Should also print out file dates.  But how??
-	io__write_strings(["*** ", Name1, "\n"]),
-	io__write_strings(["--- ", Name2, "\n"]),
+    io.write_strings(["*** ", Name1, "\n"], !IO),
+    io.write_strings(["--- ", Name2, "\n"], !IO),

-	globals__io_lookup_bool_option(initial_tab, InitialTab),
-	{ InitialTab = no,
+    globals.io_lookup_bool_option(initial_tab, InitialTab, !IO),
+    (
+        InitialTab = no,
  		NoneStr = "  ",
  		AddStr = "+ ",
  		DelStr = "- ",
  		ChgStr = "! "
-	; InitialTab = yes,
+    ;
+        InitialTab = yes,
  		NoneStr = "\t",
  		AddStr = "+\t",
  		DelStr = "-\t",
  		ChgStr = "!\t"
-	},
-	display_context_diff_2(File1, File2, CDiff,
-			NoneStr, AddStr, DelStr, ChgStr).
-
-:- pred display_context_diff_2(file, file, context_diff,
-		string, string, string, string, io__state, io__state).
-:- mode display_context_diff_2(in, in, in, in, in, in, in, di, uo) is det.
+    ),
+    display_context_diff_2(File1, File2, CDiff, NoneStr, AddStr, DelStr,
+        ChgStr, !IO).

-display_context_diff_2(_File1, _File2, [], _, _, _, _) --> [].
+:- pred display_context_diff_2(file::in, file::in, context_diff::in,
+    string::in, string::in, string::in, string::in, io::di, io::uo) is det.
+
+display_context_diff_2(_File1, _File2, [], _, _, _, _, !IO).
  display_context_diff_2(File1, File2, [Edit | CDiff],
-		NoneStr, AddStr, DelStr, ChgStr) -->
-	{ Edit = context_edit(Xlow - Xhigh, Ylow - Yhigh, Diff) },
-	io__write_string("***************\n"),
-	io__format("*** %d,%d ****\n", [i(Xlow + 1), i(Xhigh)]),
-
-		% Don't display the "context from" lines if there's
-		% nothing deleted or changed.
-	( { all [AEdit] list__member(AEdit, Diff) => AEdit = add(_, _) } ->
-		[]
-	;
-		display_context_diff_left(Xlow, Xhigh, File1, Diff,
-				NoneStr, DelStr, ChgStr)
-	),
-	io__format("--- %d,%d ----\n", [i(Ylow + 1), i(Yhigh)]),
-
-		% Don't display the "context to" lines if there's
-		% nothing added or changed.
-	( { all [DEdit] list__member(DEdit, Diff) => DEdit = delete(_, _) } ->
-		[]
-	;
-		display_context_diff_right(Ylow, Yhigh, File2, Diff,
-				NoneStr, AddStr, ChgStr)
-	),
-	display_context_diff_2(File1, File2, CDiff,
-			NoneStr, AddStr, DelStr, ChgStr).
-
-:- pred display_context_diff_left(int, int, file, diff, string, string, string,
-			io__state, io__state).
-:- mode display_context_diff_left(in, in, in, in, in, in, in, di, uo) is det.
-
-display_context_diff_left(Prev, Size1, File1, [], NoneStr, _, _) -->
-	diff_out__show_file(File1, NoneStr, Prev, Size1).
-display_context_diff_left(Prev, Size1, File1, [Edit | Diff],
-			NoneStr, DelStr, ChgStr) -->
-	{ first_mentioned_positions(Edit, StartOfEdit, _) },
-	diff_out__show_file(File1, NoneStr, Prev, StartOfEdit),
-	( { Edit = add(X, _) },
-		{ Next = X }
-	; { Edit = delete(X1 - X2, _) },
-		diff_out__show_file(File1, DelStr, X1, X2),
-		{ Next = X2 }
-	; { Edit = change(X1 - X2, _) },
-		diff_out__show_file(File1, ChgStr, X1, X2),
-		{ Next = X2 }
-	),
-	display_context_diff_left(Next, Size1, File1, Diff,
-			NoneStr, DelStr, ChgStr).
-
-:- pred display_context_diff_right(int, int, file, diff,
-			string, string, string, io__state, io__state).
-:- mode display_context_diff_right(in, in, in, in, in, in, in, di, uo) is det.
-
-display_context_diff_right(Prev, Size2, File2, [], NoneStr, _, _) -->
-	diff_out__show_file(File2, NoneStr, Prev, Size2).
-display_context_diff_right(Prev, Size2, File2, [Edit | Diff],
-			NoneStr, AddStr, ChgStr) -->
-	{ first_mentioned_positions(Edit, StartOfEdit, _) },
-	diff_out__show_file(File2, NoneStr, Prev, StartOfEdit),
-	( { Edit = add(_, Y1 - Y2) },
-		diff_out__show_file(File2, AddStr, Y1, Y2),
-		{ Next = Y2 }
-	; { Edit = delete(_, Y) },
-		{ Next = Y }
-	; { Edit = change(_, Y1 - Y2) },
-		diff_out__show_file(File2, ChgStr, Y1, Y2),
-		{ Next = Y2 }
+        NoneStr, AddStr, DelStr, ChgStr, !IO) :-
+    Edit = context_edit(Xlow - Xhigh, Ylow - Yhigh, Diff),
+    io.write_string("***************\n", !IO),
+    io.format("*** %d,%d ****\n", [i(Xlow + 1), i(Xhigh)], !IO),
+
+    % Don't display the "context from" lines if there's nothing deleted or
+    % changed.
+    %
+    ( all [AEdit] list.member(AEdit, Diff) => AEdit = add(_, _) ->
+        true 
+    ;
+        display_context_diff_left(Xlow, Xhigh, File1, Diff, NoneStr,
+            DelStr, ChgStr, !IO)
+    ),
+    io.format("--- %d,%d ----\n", [i(Ylow + 1), i(Yhigh)], !IO),
+
+    % Don't display the "context to" lines if there's nothing added or changed.
+    %
+    ( all [DEdit] list.member(DEdit, Diff) => DEdit = delete(_, _) ->
+        true 
+    ;
+        display_context_diff_right(Ylow, Yhigh, File2, Diff, NoneStr,
+            AddStr, ChgStr, !IO)
+    ),
+    display_context_diff_2(File1, File2, CDiff, NoneStr, AddStr, DelStr,
+        ChgStr, !IO).
+
+:- pred display_context_diff_left(int::in, int::in, file::in, diff::in,
+    string::in, string::in, string::in, io::di, io::uo) is det.
+
+display_context_diff_left(Prev, Size1, File1, [], NoneStr, _, _, !IO) :-
+    show_file(File1, NoneStr, Prev, Size1, !IO).
+display_context_diff_left(Prev, Size1, File1, [Edit | Diff], NoneStr,
+        DelStr, ChgStr, !IO) :-
+    first_mentioned_positions(Edit, StartOfEdit, _),
+    show_file(File1, NoneStr, Prev, StartOfEdit, !IO),
+    (
+        Edit = add(X, _),
+        Next = X
+    ;
+        Edit = delete(X1 - X2, _),
+        show_file(File1, DelStr, X1, X2, !IO),
+        Next = X2
+    ;
+        Edit = change(X1 - X2, _),
+        show_file(File1, ChgStr, X1, X2, !IO),
+        Next = X2
  	),
-	display_context_diff_right(Next, Size2, File2, Diff,
-				NoneStr, AddStr, ChgStr).
+    display_context_diff_left(Next, Size1, File1, Diff, NoneStr,
+        DelStr, ChgStr, !IO).
+
+:- pred display_context_diff_right(int::in, int::in, file::in, diff::in,
+    string::in, string::in, string::in, io::di, io::uo) is det.
+
+display_context_diff_right(Prev, Size2, File2, [], NoneStr, _, _, !IO) :-
+    diff_out.show_file(File2, NoneStr, Prev, Size2, !IO).
+display_context_diff_right(Prev, Size2, File2, [Edit | Diff], NoneStr,
+        AddStr, ChgStr, !IO) :-
+    first_mentioned_positions(Edit, StartOfEdit, _),
+    show_file(File2, NoneStr, Prev, StartOfEdit, !IO),
+    (
+        Edit = add(_, Y1 - Y2),
+        show_file(File2, AddStr, Y1, Y2, !IO),
+        Next = Y2
+    ;
+        Edit = delete(_, Y),
+        Next = Y
+    ;
+        Edit = change(_, Y1 - Y2),
+        show_file(File2, ChgStr, Y1, Y2, !IO),
+        Next = Y2
+    ),
+    display_context_diff_right(Next, Size2, File2, Diff, NoneStr, AddStr,
+        ChgStr, !IO).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -761,6 +786,7 @@
  	%        but do nothing with it.

  	% Parameters to pass around.
+    %
  :- type side_by_side_info
  	--->	side_by_side_info(
  			int,		% Half width
@@ -770,211 +796,213 @@
  			bool		% Help sdiff
  		).

-:- pred display_diff_side_by_side(file, file, diff, io__state, io__state).
-:- mode display_diff_side_by_side(in, in, in, di, uo) is det.
+:- pred display_diff_side_by_side(file::in, file::in, diff::in, io::di, io::uo) 
+    is det.

-display_diff_side_by_side(File1, File2, Diff) -->
-	globals__io_lookup_int_option(width, Width0),
+display_diff_side_by_side(File1, File2, Diff, !IO) :-
+    globals.io_lookup_int_option(width, Width0, !IO),

  	% Calculate the half-width and offset stuff.

  		% XXX If we're expanding tabs, we should
  		%     factor this in.
-	{ Off is (Width0 + 4) // 8 * 4 },
-	{ Max is Off - 3 },
-	{ HalfWidth0 is Width0 - Off + 1 },
-	{ HalfWidth0 =< 0 ->
+    Off = (Width0 + 4) // 8 * 4,
+    Max =  Off - 3,
+    HalfWidth0 = Width0 - Off + 1,
+    ( HalfWidth0 =< 0 ->
  		HalfWidth = 0
  	; HalfWidth0 > Max ->
  		HalfWidth = Max
  	;
  		HalfWidth = HalfWidth0
-	},
-	{ HalfWidth > 0 ->
+    ),
+    ( HalfWidth > 0 ->
  		Col2Off = Off
  	;
  		Col2Off = Width0
-	},
-	globals__io_lookup_bool_option(left_column, LeftCol),
-	globals__io_lookup_bool_option(suppress_common_lines, Suppress),
-	globals__io_lookup_bool_option(sdiff_merge_assist, Sdiff),
-	{ SBS = side_by_side_info(HalfWidth, Col2Off, LeftCol,
-		Suppress, Sdiff) },
-	display_diff_side_by_side_2(0, SBS, File1, File2, Diff).
-
-:- pred display_diff_side_by_side_2(int, side_by_side_info, file, file, diff,
-		io__state, io__state).
-:- mode display_diff_side_by_side_2(in, in, in, in, in, di, uo) is det.
-
-display_diff_side_by_side_2(Prev, SBS, File1, _File2, []) -->
-	{ SBS = side_by_side_info(_, _, _, Suppress, _) },
-	( { Suppress = no } ->
-		{ file__get_numlines(File1, SegEnd) },
-		show_sbs_same_lines(File1, SBS, Prev - SegEnd)
+    ),
+    globals.io_lookup_bool_option(left_column, LeftCol, !IO),
+    globals.io_lookup_bool_option(suppress_common_lines, Suppress, !IO),
+    globals.io_lookup_bool_option(sdiff_merge_assist, Sdiff, !IO),
+    SBS = side_by_side_info(HalfWidth, Col2Off, LeftCol, Suppress, Sdiff),
+    display_diff_side_by_side_2(0, SBS, File1, File2, Diff, !IO).
+
+:- pred display_diff_side_by_side_2(int::in, side_by_side_info::in,
+    file::in, file::in, diff::in, io::di, io::uo) is det.
+
+display_diff_side_by_side_2(Prev, SBS, File1, _File2, [], !IO) :-
+    SBS = side_by_side_info(_, _, _, Suppress, _),
+    (
+        Suppress = no,
+        file.get_numlines(File1, SegEnd),
+        show_sbs_same_lines(File1, SBS, Prev - SegEnd, !IO)
  	;
-		[]
+        Suppress = yes
  	).
-display_diff_side_by_side_2(Prev, SBS, File1, File2, [Edit | Diff]) -->
-	{ SBS = side_by_side_info(_, _, _, Suppress, _) },
-	{ first_mentioned_positions(Edit, StartOfEdit, _) },
-	( { Suppress = no } ->
-		show_sbs_same_lines(File1, SBS, Prev - StartOfEdit)
-	;
-		[]
-	),
-	( { Edit = add(X, Seg2) },
-		show_sbs_added_lines(File2, SBS, Seg2),
-		{ Next = X }
-	; { Edit = delete(X1 - X2, _) },
-		show_sbs_deleted_lines(File1, SBS, X1 - X2),
-		{ Next = X2 }
-	; { Edit = change(X1 - X2, Y1 - Y2) },
+display_diff_side_by_side_2(Prev, SBS, File1, File2, [Edit | Diff], !IO) :-
+    SBS = side_by_side_info(_, _, _, Suppress, _),
+    first_mentioned_positions(Edit, StartOfEdit, _),
+    (
+        Suppress = no,
+        show_sbs_same_lines(File1, SBS, Prev - StartOfEdit, !IO)
+    ;
+        Suppress = yes 
+    ),
+    (
+        Edit = add(X, Seg2),
+        show_sbs_added_lines(File2, SBS, Seg2, !IO),
+        Next = X
+    ;
+        Edit = delete(X1 - X2, _),
+        show_sbs_deleted_lines(File1, SBS, X1 - X2, !IO),
+        Next = X2
+    ;
+        Edit = change(X1 - X2, Y1 - Y2),
  		% The side-by-side change diff format is sort of weird.
-		% We have to compute the minimum of the two change sizes,
-		% and display "changed" lines for the minimum of these
-		% sizes.  Then we display "added" or "deleted" lines for
-		% whatever is left over.
-		{ int__min(X2 - X1, Y2 - Y1, Size) },
-		show_sbs_changed_lines(File1, File2, SBS, X1, Y1, Size),
-		show_sbs_deleted_lines(File1, SBS, (X1 + Size) - X2),
-		show_sbs_added_lines(File2, SBS, (Y1 + Size) - Y2),
-		{ Next = X2 }
-	),
-	display_diff_side_by_side_2(Next, SBS, File1, File2, Diff).
-
-:- pred show_sbs_changed_lines(file, file, side_by_side_info, int, int, int,
-		io__state, io__state).
-:- mode show_sbs_changed_lines(in, in, in, in, in, in, di, uo) is det.
-
-show_sbs_changed_lines(File1, File2, SBS, X1, Y1, Size) -->
-	( { Size > 0 } ->
-		(
-			{ file__get_line(File1, X1, Line1),
-			  file__get_line(File2, Y1, Line2)
-			}
+        % We have to compute the minimum of the two change sizes, and display
+        % "changed" lines for the minimum of these sizes.  Then we display
+        % "added" or "deleted" lines for whatever is left over.
+        int.min(X2 - X1, Y2 - Y1, Size),
+        show_sbs_changed_lines(File1, File2, SBS, X1, Y1, Size, !IO),
+        show_sbs_deleted_lines(File1, SBS, (X1 + Size) - X2, !IO),
+        show_sbs_added_lines(File2, SBS, (Y1 + Size) - Y2, !IO),
+        Next = X2
+    ),
+    display_diff_side_by_side_2(Next, SBS, File1, File2, Diff, !IO).
+
+:- pred show_sbs_changed_lines(file::in, file::in, side_by_side_info::in,
+    int::in, int::in, int::in, io::di, io::uo) is det.
+
+show_sbs_changed_lines(File1, File2, SBS, X1, Y1, Size, !IO) :-
+    ( Size > 0 ->
+        (
+            file.get_line(File1, X1, Line1),
+            file.get_line(File2, Y1, Line2)
  		->
-			{ SBS = side_by_side_info(Width, _, _, _, _) },
-			{ string__to_char_list(Line1, Chars1) },
-			print_half_line(Chars1, SBS, 0, 0, Width, OutPos),
-			tab_to_column(OutPos, Width),
-			io__write_string("|"),
-			tab_to_column(Width + 1, Width + 2),
-			{ string__to_char_list(Line2, Chars2) },
-			print_half_line(Chars2, SBS, 0, 0, Width, _),
-			io__write_string("\n"),
-			show_sbs_changed_lines(File1, File2, SBS,
-					X1 + 1, Y1 + 1, Size - 1)
+            SBS = side_by_side_info(Width, _, _, _, _),
+            string.to_char_list(Line1, Chars1),
+            print_half_line(Chars1, SBS, 0, 0, Width, OutPos, !IO),
+            tab_to_column(OutPos, Width, !IO),
+            io.write_string("|", !IO),
+            tab_to_column(Width + 1, Width + 2, !IO),
+            string.to_char_list(Line2, Chars2),
+            print_half_line(Chars2, SBS, 0, 0, Width, _, !IO),
+            io.write_string("\n", !IO),
+            show_sbs_changed_lines(File1, File2, SBS, X1 + 1, Y1 + 1,
+                Size - 1, !IO)
  		;
-			{ error("show_sbs_changed_lines: file ended prematurely") }
+            error("show_sbs_changed_lines: file ended prematurely")
  		)
  	;
-		[]
+        true
  	).

-:- pred show_sbs_same_lines(file, side_by_side_info, segment,
-		io__state, io__state).
-:- mode show_sbs_same_lines(in, in, in, di, uo) is det.
-
-show_sbs_same_lines(File, SBS, Low - High) -->
-	( { Low < High } ->
-		( { file__get_line(File, Low, Line) } ->
-			{ SBS = side_by_side_info(Width, _, LeftCol, _, _) },
-			{ string__to_char_list(Line, Chars) },
-			print_half_line(Chars, SBS, 0, 0, Width, OutPos),
-
-			% If the user specified --left, don't
-			% display the right column here.
-			( { LeftCol = yes } ->
-				tab_to_column(OutPos, Width),
-				io__write_string("(")
-			;
-				tab_to_column(OutPos, Width + 2),
-				print_half_line(Chars, SBS, 0, 0, Width, _)
+:- pred show_sbs_same_lines(file::in, side_by_side_info::in, segment::in,
+    io::di, io::uo) is det.
+
+show_sbs_same_lines(File, SBS, Low - High, !IO) :-
+    ( Low < High ->
+        ( file.get_line(File, Low, Line) ->
+            SBS = side_by_side_info(Width, _, LeftCol, _, _),
+            string.to_char_list(Line, Chars),
+            print_half_line(Chars, SBS, 0, 0, Width, OutPos, !IO),
+
+            % If the user specified --left, don't display the right column
+            % here.
+            %
+            (
+                LeftCol = yes,
+                tab_to_column(OutPos, Width, !IO),
+                io.write_string("(", !IO)
+            ;
+                LeftCol = no,
+                tab_to_column(OutPos, Width + 2, !IO),
+                print_half_line(Chars, SBS, 0, 0, Width, _, !IO)
  			),
-			io__write_string("\n"),
-			show_sbs_same_lines(File, SBS, (Low + 1) - High)
+            io.write_string("\n", !IO),
+            show_sbs_same_lines(File, SBS, (Low + 1) - High, !IO)
  		;
-			{ error("show_sbs_same_lines: file ended prematurely") }
+            error("show_sbs_same_lines: file ended prematurely")
  		)
  	;
-		[]
+        true
  	).

-:- pred show_sbs_added_lines(file, side_by_side_info, segment,
-		io__state, io__state).
-:- mode show_sbs_added_lines(in, in, in, di, uo) is det.
-
-show_sbs_added_lines(File, SBS, Low - High) -->
-	( { Low < High } ->
-		( { file__get_line(File, Low, Line) } ->
-			{ SBS = side_by_side_info(Width, _, _, _, _) },
-			{ string__to_char_list(Line, Chars) },
-			tab_to_column(0, Width),
-			io__write_string("> "),
-			print_half_line(Chars, SBS, 0, 0, Width, _),
-			io__write_string("\n"),
-			show_sbs_added_lines(File, SBS, (Low + 1) - High)
+:- pred show_sbs_added_lines(file::in, side_by_side_info::in,
+    segment::in, io::di, io::uo) is det.
+
+show_sbs_added_lines(File, SBS, Low - High, !IO) :-
+    ( Low < High ->
+        ( file.get_line(File, Low, Line) ->
+            SBS = side_by_side_info(Width, _, _, _, _),
+            string.to_char_list(Line, Chars),
+            tab_to_column(0, Width, !IO),
+            io.write_string("> ", !IO),
+            print_half_line(Chars, SBS, 0, 0, Width, _, !IO),
+            io.write_string("\n", !IO),
+            show_sbs_added_lines(File, SBS, (Low + 1) - High, !IO)
  		;
-			{ error("show_sbs_added_lines: file ended prematurely") }
+            error("show_sbs_added_lines: file ended prematurely")
  		)
  	;
-		[]
+        true
  	).

-:- pred show_sbs_deleted_lines(file, side_by_side_info, segment,
-		io__state, io__state).
-:- mode show_sbs_deleted_lines(in, in, in, di, uo) is det.
-
-show_sbs_deleted_lines(File, SBS, Low - High) -->
-	( { Low < High } ->
-		( { file__get_line(File, Low, Line) } ->
-			{ SBS = side_by_side_info(Width, _, _, _, _) },
-			{ string__to_char_list(Line, Chars) },
-			print_half_line(Chars, SBS, 0, 0, Width, OutPos),
-			tab_to_column(OutPos, Width),
-			io__write_string("<\n"),
-			show_sbs_deleted_lines(File, SBS, (Low + 1) - High)
+:- pred show_sbs_deleted_lines(file::in, side_by_side_info::in,
+    segment::in, io::di, io::uo) is det.
+
+show_sbs_deleted_lines(File, SBS, Low - High, !IO) :-
+    ( Low < High ->
+        ( file.get_line(File, Low, Line) ->
+            SBS = side_by_side_info(Width, _, _, _, _),
+            string.to_char_list(Line, Chars),
+            print_half_line(Chars, SBS, 0, 0, Width, OutPos, !IO),
+            tab_to_column(OutPos, Width, !IO),
+            io.write_string("<\n", !IO),
+            show_sbs_deleted_lines(File, SBS, (Low + 1) - High, !IO)
  		;
-			{ error("show_sbs_deleted_lines: file ended prematurely") }
+            error("show_sbs_deleted_lines: file ended prematurely")
  		)
  	;
-		[]
+        true
  	).

  :- func tab_width = int.
+
  tab_width = 8.

-	% Put a number of spaces on the output stream.  Update
-	% the output column as we go.
-:- pred put_spaces(int, int, int, io__state, io__state).
-:- mode put_spaces(in, in, out, di, uo) is det.
-
-put_spaces(Spaces, OutPos0, OutPos) -->
-	( { Spaces =< 0 } ->
-		{ OutPos = OutPos0 }
-	;
-		io__write_char(' '),
-		put_spaces(Spaces - 1, OutPos0 + 1, OutPos)
+    % Put a number of spaces on the output stream.
+    % Update % the output column as we go.
+    %
+:- pred put_spaces(int::in, int::in, int::out, io::di, io::uo) is det.
+
+put_spaces(Spaces, !OutPos, !IO) :-
+    ( Spaces =< 0 ->
+        true
+    ;
+        io.write_char(' ', !IO),
+        !:OutPos = !.OutPos + 1,
+        put_spaces(Spaces - 1, !OutPos, !IO)
  	).

  	% Given a "from" column and a "to" column, put sufficient
  	% spaces on the output stream to reach that column.  Use
  	% tabs if we can.
-:- pred tab_to_column(int, int, io__state, io__state).
-:- mode tab_to_column(in, in, di, uo) is det.
+    %
+:- pred tab_to_column(int::in, int::in, io::di, io::uo) is det.

-tab_to_column(From, To) -->
-	{ AfterTab is From + tab_width - (From rem tab_width) },
-	( { AfterTab > To } ->
-		( { From < To } ->
-			io__write_char(' '),
-			tab_to_column(From + 1, To)
+tab_to_column(From, To, !IO) :-
+    AfterTab = From + tab_width - (From rem tab_width), 
+    ( AfterTab > To ->
+        ( From < To ->
+            io.write_char(' ', !IO),
+            tab_to_column(From + 1, To, !IO)
  		;
-			[]
+            true
  		)
  	;
-		io__write_char('\t'),
-		tab_to_column(AfterTab, To)
+        io.write_char('\t', !IO),
+        tab_to_column(AfterTab, To, !IO)
  	).

  	% Display half a line in a side-by-side diff, stopping when
@@ -989,61 +1017,68 @@
  	%	OutPos: The current column in the output line.
  	%	OutBound: The column that we must stop at.
  	%
-:- pred print_half_line(list(char) :: in, side_by_side_info :: in,
-		int :: in, int :: in, int :: in, int :: out,
-		io__state :: di, io__state :: uo) is det.
-
-print_half_line([], _SBS, _InPos, OutPos, _OutBound, OutPos) --> [].
-print_half_line([C | Cs], SBS, InPos0, OutPos0, OutBound, OutPos) -->
-	( { C = '\t' } ->
+:- pred print_half_line(list(char)::in, side_by_side_info::in,
+    int::in, int::in, int::in, int::out,
+    io::di, io::uo) is det.
+
+print_half_line([], _SBS, _InPos, OutPos, _OutBound, OutPos, !IO).
+print_half_line([C | Cs], SBS, InPos0, OutPos0, OutBound, OutPos, !IO) :-
+    (
+        C = '\t'
+    ->
  			% Calculate how many spaces this tab is worth.
-		{ Spaces is tab_width - InPos0 rem tab_width },
-		( { InPos0 = OutPos0 } ->
-			globals__io_lookup_bool_option(expand_tabs, ExpandTabs),
-			( { ExpandTabs = yes } ->
+        Spaces = tab_width - InPos0 rem tab_width,
+        ( InPos0 = OutPos0 ->
+            globals.io_lookup_bool_option(expand_tabs, ExpandTabs, !IO),
+            (
+                ExpandTabs = yes,
  				% If we're expanding tabs, we just pretend that
  				% we had Spaces spaces and write them.
-				{ TabStop0 is OutPos0 + Spaces },
-				{ TabStop0 > OutBound ->
+                TabStop0 = OutPos0 + Spaces,
+                ( TabStop0 > OutBound ->
  					TabStop = OutBound
  				;
  					TabStop = TabStop0
-				},
-				put_spaces(TabStop - OutPos0, OutPos0, OutPos1)
+                ),
+                put_spaces(TabStop - OutPos0, OutPos0, OutPos1, !IO)
  			;
  				% If we're not exanding tabs, just print it and
  				% hope everything lines up okay.
-				io__write_char('\t'),
-				{ OutPos1 is OutPos0 + Spaces }
+                ExpandTabs = no,
+                io.write_char('\t', !IO),
+                OutPos1 = OutPos0 + Spaces
  			)
  		;
-			{ OutPos1 = OutPos0 }
+            OutPos1 = OutPos0
  		),
-		{ InPos is InPos0 + Spaces }
-	; { C = '\r' ; C = '\b' ; C = '\n' } ->
+        InPos = InPos0 + Spaces
+    ;
+        ( C = '\r' ; C = '\b' ; C = '\n' )
+    ->
  		% XXX What to do?  For the moment, we'll just ignore it.
-		{ InPos = InPos0, OutPos1 = OutPos0 }
+        InPos = InPos0, OutPos1 = OutPos0
  	/***********
  		% XXX Binary files aren't really supported.
-	; { \+ char__is_print(C) } ->
-		{ InPos = InPos0, OutPos1 = OutPos0 }
-		( { InPos < OutBound } ->
-			io__write_char(C)
+    ; \+ char.is_print(C) ->
+        InPos = InPos0, OutPos1 = OutPos0
+        ( InPos < OutBound ->
+            io.write_char(C, !IO)
  		;
-			[]
+            true
  		)
  	***********/
  	;
  		% The default case.  Print and be done with it.
-		{ InPos is InPos0 + 1 },
-		( { InPos < OutBound } ->
-			{ OutPos1 = InPos },
-			io__write_char(C)
+        InPos = InPos0 + 1,
+        ( InPos < OutBound ->
+            OutPos1 = InPos,
+            io.write_char(C, !IO)
  		;
-			{ OutPos1 = OutPos0 }
+            OutPos1 = OutPos0
  		)
  	),
-	print_half_line(Cs, SBS, InPos, OutPos1, OutBound, OutPos).
+    print_half_line(Cs, SBS, InPos, OutPos1, OutBound, OutPos, !IO).

  %-----------------------------------------------------------------------------%
+:- end_module diff_out.
  %-----------------------------------------------------------------------------%
Index: difftype.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/difftype.m,v
retrieving revision 1.3
diff -u -b -r1.3 difftype.m
--- difftype.m	28 Jun 2006 09:22:39 -0000	1.3
+++ difftype.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1995-1998, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -24,6 +26,7 @@
  	% A pos is a non-negative number representing a position in a
  	% list.  The position before all elements is 0, the one
  	% between the first and second elements is 1, etc.
+    %
  :- type pos == int.

  %-----------------------------------------------------------------------------%
@@ -34,40 +37,42 @@
  	%
  	% Invariant: In any segment X - Y, it should always be true
  	% that X =< Y.  If X=Y, the segment is empty.
+    %
  :- type segment == pair(pos,pos).

  	% An edit operation is an addition, a deletion or a change.
-:- type edit --->
-		add(pos,segment)
-	;	delete(segment,pos)
-	;	change(segment,segment).
+    %
+:- type edit
+    --->    add(pos, segment)
+    ;       delete(segment, pos)
+    ;       change(segment, segment).

-	% The complete diff of two file is a list of edit
-	% operations.
+    % The complete diff of two file is a list of edit operations.
+    %
+    % Invariant: The edits must be in order, and must not overlap or touch.
  	%
-	% Invariant: The edits must be in order, and must
-	% not overlap or touch.
  :- type diff == list(edit).

  %-----------------------------------------------------------------------------%

-:- pred first_mentioned_positions(edit :: in, pos :: out, pos :: out) is det.
+:- pred first_mentioned_positions(edit::in, pos::out, pos::out) is det.

-:- pred last_mentioned_positions(edit :: in, pos :: out, pos :: out) is det.
+:- pred last_mentioned_positions(edit::in, pos::out, pos::out) is det.

  %-----------------------------------------------------------------------------%

  	% Add an edit to the start of a diff, producing a new diff.
-	% This predicate determines what kind of edit this is, and
-	% merges with the adjacent edits if appropriate.
-:- pred difftype__add_edit(segment, segment, diff, diff).
-:- mode difftype__add_edit(in, in, in, out) is det.
+    % This predicate determines what kind of edit this is, and merges with the
+    % adjacent edits if appropriate.
+    %
+:- pred difftype.add_edit(segment::in, segment::in, diff::in, diff::out) is det.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%

  :- implementation.
-:- import_module int.
+
+%-----------------------------------------------------------------------------%

  first_mentioned_positions(add(X, Y - _), X, Y).
  first_mentioned_positions(delete(X - _, Y), X, Y).
@@ -79,7 +84,7 @@

  %-----------------------------------------------------------------------------%

-difftype__add_edit(X1 - X2, Y1 - Y2, [], Diff) :-
+add_edit(X1 - X2, Y1 - Y2, [], Diff) :-
  	( X1 = X2 ->
  		( Y1 = Y2 ->
  			Diff = []
@@ -93,7 +98,7 @@
  			Diff = [change(X1 - X2, Y1 - Y2)]
  		)
  	).
-difftype__add_edit(X1 - X2, Y1 - Y2, [Edit0 | Diff0], Diff) :-
+add_edit(X1 - X2, Y1 - Y2, [Edit0 | Diff0], Diff) :-
  	( Edit0 = add(X2, Y2 - Y3) ->
  		( X1 = X2 ->
  			Diff = [add(X1, Y1 - Y3) | Diff0]
@@ -126,4 +131,5 @@
  	).

  %-----------------------------------------------------------------------------%
+:- end_module difftype.
  %-----------------------------------------------------------------------------%
Index: file.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/file.m,v
retrieving revision 1.11
diff -u -b -r1.11 file.m
--- file.m	15 Sep 1998 04:54:26 -0000	1.11
+++ file.m	7 Jan 2011 16:31:59 -0000
@@ -1,141 +1,156 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1995-1998 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
  %-----------------------------------------------------------------------------%
-
+%
  % Main author: bromage
  % Simplified by Marnix Klooster <marnix at worldonline.nl>
-
+%
  % This module provides file input.  One can read a file entirely,
  % select a single line from a read file, get the number of lines
  % in a read file, and convert a read file to a list of strings.
  %
  % Every file has a filename attached to it.
-
+%
  %-----------------------------------------------------------------------------%

  :- module file.
  :- interface.

-:- import_module io, list, string.
+%-----------------------------------------------------------------------------%
+
+:- import_module io.
+:- import_module list.
+
+%-----------------------------------------------------------------------------%

  :- type file.

-	% file__read_file reads a file from a filename.
-:- pred file__read_file(string, io__res(file), io__state, io__state).
-:- mode file__read_file(in, out, di, uo) is det.
-
-	% file__read_input reads a file from the input
-	% stream.
-:- pred file__read_input(string, io__res(file), io__state, io__state).
-:- mode file__read_input(in, out, di, uo) is det.
+    % file.read_file reads a file from a filename.
+    %
+:- pred file.read_file(string::in, io.res(file)::out, io::di, io::uo) is det.
+
+    % file.read_input reads a file from the input stream.
+    %
+:- pred file.read_input(string::in, io.res(file)::out, io::di, io::uo) is det.

-	% file__get_line retrieves a line from a file.
+    % file.get_line retrieves a line from a file.
  	% (Lines are numbered from 0.)
  	% Fails if the line is out of bounds.
-:- pred file__get_line(file, int, string).
-:- mode file__get_line(in, in, out) is semidet.
+    %
+:- pred file.get_line(file::in, int::in, string::out) is semidet.

-	% file__get_numlines returns the number of lines
-	% in a file.
-:- pred file__get_numlines(file, int).
-:- mode file__get_numlines(in, out) is det.
-
-	% file__from_list converts a list of lines to a file.
-:- pred file__from_list(string, list(string), file).
-:- mode file__from_list(in, in, out) is det.
-
-	% file__to_list converts a file into a list of
-	% lines.
-:- pred file__to_list(file, list(string)).
-:- mode file__to_list(in, out) is det.
-
-	% file__get_file_name returns the name of the file.
-:- pred file__get_file_name(file, string).
-:- mode file__get_file_name(in, out) is det.
-
-	% file__set_file_name sets the name of the file.
-:- pred file__set_file_name(file, string, file).
-:- mode file__set_file_name(in, in, out) is det.
+    % file.get_numlines returns the number of lines in a file.
+    %
+:- pred file.get_numlines(file::in, int::out) is det.
+
+    % file.from_list converts a list of lines to a file.
+    %
+:- pred file.from_list(string::in, list(string)::in, file::out) is det.
+
+    % file.to_list converts a file into a list of lines.
+    %
+:- pred file.to_list(file::in, list(string)::out) is det.
+
+    % file.get_file_name returns the name of the file.
+    %
+:- pred file.get_file_name(file::in, string::out) is det.
+
+    % file.set_file_name sets the name of the file.
+    %
+:- pred file.set_file_name(file::in, string::in, file::out) is det.

  %-----------------------------------------------------------------------------%

  :- implementation.
-:- import_module array, require, int, bool.
+
+:- import_module array.
+:- import_module int.
+:- import_module require.

  %-----------------------------------------------------------------------------%

  :- type file
  	--->	file(
-			string,			% File name
-			array(string)		% Contents
+                file_name     :: string,
+                file_contents :: array(string)
  		).

-	% Open the stream, read from the stream, then close
-	% the stream.
-file__read_file(FileName, File) -->
-	io__open_input(FileName, Res),
-	( { Res = ok(InputStream) },
-		file__read_stream(InputStream, Contents),
-		io__close_input(InputStream),
-		{ File = ok(file(FileName, Contents)) }
-	; { Res = error(Error) },
-		{ File = error(Error) }
+    % Open the stream, read from the stream, then close the stream.
+    %
+file.read_file(FileName, File, !IO) :-
+    io.open_input(FileName, Res, !IO),
+    (
+        Res = ok(InputStream),
+        file.read_stream(InputStream, Contents, !IO),
+        io.close_input(InputStream, !IO),
+        File = ok(file(FileName, Contents))
+    ;
+        Res = error(Error),
+        File = error(Error)
  	).

  	% Get the input stream, then read from it.
-file__read_input(FileName, ok(file(FileName, Contents))) -->
-	io__input_stream(InputStream),
-	file__read_stream(InputStream, Contents).
-
-	% file__read_stream is the "real" file reader.
-:- pred file__read_stream(io__input_stream, array(string),
-		io__state, io__state).
-:- mode file__read_stream(in, array_uo, di, uo) is det.
-file__read_stream(Stream, File) -->
-	file__read_stream2(Stream, 0, File).
+file.read_input(FileName, ok(file(FileName, Contents)), !IO) :-
+    io.input_stream(InputStream, !IO),
+    file.read_stream(InputStream, Contents, !IO).
+
+    % file.read_stream is the "real" file reader.
+    %
+:- pred file.read_stream(io.input_stream::in, array(string)::array_uo,
+    io::di, io::uo) is det.
+
+file.read_stream(Stream, File, !IO) :-
+    file.read_stream2(Stream, 0, File, !IO).

  	% Given a Stream from which LinesIn lines have already been
  	% read, fill File[LinesIn] to File[LinesOut-1] with the rest
  	% of the lines.  LinesOut is the number of lines in the file.
  	% (Note that line numbering starts at zero.)
-:- pred file__read_stream2(io__input_stream, int, array(string),
-		io__state, io__state).
-:- mode file__read_stream2(in, in, array_uo, di, uo) is det.
-file__read_stream2(Stream, LineNo, File) -->
-	io__read_line_as_string(Stream, Res),
-	( { Res = eof },
-		{ array__init(LineNo, "", File) }
-	; { Res = ok(Line) },
-		file__read_stream2(Stream, LineNo + 1, File1),
-		{ array__set(File1, LineNo, Line, File) }
-	; { Res = error(Error) },
-		{ io__error_message(Error, Msg) },
-		{ error(Msg) }
+    %
+:- pred file.read_stream2(io.input_stream::in, int::in,
+    array(string)::array_uo, io::di, io::uo) is det.
+
+file.read_stream2(Stream, LineNo, File, !IO) :-
+    io.read_line_as_string(Stream, Res, !IO),
+    (
+        Res = eof,
+        array.init(LineNo, "", File)
+    ;
+        Res = ok(Line),
+        file.read_stream2(Stream, LineNo + 1, File1, !IO),
+        array.set(File1, LineNo, Line, File)
+    ;
+        Res = error(Error),
+        io.error_message(Error, Msg),
+        error(Msg)
  	).

  %-----------------------------------------------------------------------------%

-file__get_line(file(_, Contents), LineNo, Line) :-
-	array__semidet_lookup(Contents, LineNo, Line).
+file.get_line(file(_, Contents), LineNo, Line) :-
+    array.semidet_lookup(Contents, LineNo, Line).

-file__get_numlines(file(_, Contents), NumLines1 + 1) :-
-	array__bounds(Contents, _, NumLines1).
+file.get_numlines(file(_, Contents), NumLines1 + 1) :-
+    array.bounds(Contents, _, NumLines1).

  %-----------------------------------------------------------------------------%

-file__to_list(file(_, Contents), List) :-
-	array__to_list(Contents, List).
+file.to_list(file(_, Contents), List) :-
+    array.to_list(Contents, List).

-file__from_list(FileName, List, file(FileName, Contents)) :-
-	array__from_list(List, Contents).
+file.from_list(FileName, List, file(FileName, Contents)) :-
+    array.from_list(List, Contents).

  %-----------------------------------------------------------------------------%

-file__get_file_name(file(FileName, _), FileName).
+file.get_file_name(file(FileName, _), FileName).

-file__set_file_name(file(_, B), FileName, file(FileName, B)).
+file.set_file_name(file(_, B), FileName, file(FileName, B)).

  %-----------------------------------------------------------------------------%
+:- end_module file.
  %-----------------------------------------------------------------------------%
Index: filter.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/filter.m,v
retrieving revision 1.3
diff -u -b -r1.3 filter.m
--- filter.m	28 Jun 2006 09:22:39 -0000	1.3
+++ filter.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1998, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -32,8 +34,8 @@

  %-----------------------------------------------------------------------------%

-:- pred filter_diff(diff::in, file::in, file::in, diff::out, io::di, io::uo)
-	is det.
+:- pred filter_diff(file::in, file::in, diff::in, diff::out,
+    io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -52,36 +54,38 @@

  %-----------------------------------------------------------------------------%

-filter_diff(Diff0, File1, File2, Diff) -->
-	globals__io_lookup_bool_option(ignore_blank_lines, FilterBlank),
+filter_diff(File1, File2, !Diff, !IO) :-
+    globals.io_lookup_bool_option(ignore_blank_lines, FilterBlank, !IO),

-	{ FilterBlank = no ->
+    (
  		% If we didn't request a filter, skip this pass.
-
-		Diff = Diff0
+        FilterBlank = no
  	;
-		filter__blank_lines(Diff0, File1, File2, Diff)
-	}.
+        FilterBlank = yes,
+        filter.blank_lines(!.Diff, File1, File2, !:Diff)
+    ).

-:- pred filter__blank_lines(diff :: in, file :: in, file :: in, diff :: out)
-		is det.
+:- pred filter.blank_lines(diff::in, file::in, file::in, diff::out) is det.

-filter__blank_lines([], _, _, []).
-filter__blank_lines([Edit | Diff0], File1, File2, Diff) :-
-	filter__blank_lines(Diff0, File1, File2, Diff1),
-	( Edit = add(_, Y1 - Y2),
+filter.blank_lines([], _, _, []).
+filter.blank_lines([Edit | Diff0], File1, File2, Diff) :-
+    filter.blank_lines(Diff0, File1, File2, Diff1),
+    (
+        Edit = add(_, Y1 - Y2),
  		( range_has_only_blank_lines(Y1, Y2, File2) ->
  			Diff = Diff1
  		;
  			Diff = [Edit | Diff1]
  		)
-	; Edit = delete(X1 - X2, _),
+    ;
+        Edit = delete(X1 - X2, _),
  		( range_has_only_blank_lines(X1, X2, File1) ->
  			Diff = Diff1
  		;
  			Diff = [Edit | Diff1]
  		)
-	; Edit = change(X1 - X2, Y1 - Y2),
+    ;
+        Edit = change(X1 - X2, Y1 - Y2),
  		(
  			range_has_only_blank_lines(X1, X2, File1),
  			range_has_only_blank_lines(Y1, Y2, File2)
@@ -94,24 +98,24 @@

  %-----------------------------------------------------------------------------%

-:- pred range_has_only_blank_lines(int, int, file).
-:- mode range_has_only_blank_lines(in, in, in) is semidet.
+:- pred range_has_only_blank_lines(int::in, int::in, file::in) is semidet.

  range_has_only_blank_lines(First, Last, File) :-
  	(
  		First < Last
  	=>
  		(
-			file__get_line(File, First, Line),
-			string__to_char_list(Line, Chars),
+            file.get_line(File, First, Line),
+            string.to_char_list(Line, Chars),
  			all [C] (
-				list__member(C, Chars)
+                list.member(C, Chars)
  			=>
-				char__is_whitespace(C)
+                char.is_whitespace(C)
  			),
  			range_has_only_blank_lines(First + 1, Last, File)
  		)
  	).

  %-----------------------------------------------------------------------------%
+:- end_module filter.
  %-----------------------------------------------------------------------------%
Index: globals.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/globals.m,v
retrieving revision 1.4
diff -u -b -r1.4 globals.m
--- globals.m	28 Jun 2006 09:22:39 -0000	1.4
+++ globals.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1994-1998, 2001, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -23,10 +25,8 @@

  :- import_module bool.
  :- import_module getopt.
-:- import_module int.
  :- import_module io.
  :- import_module list.
-:- import_module string.

  %-----------------------------------------------------------------------------%

@@ -34,67 +34,64 @@

  	% Access predicates for the `globals' structure.

-:- pred globals__init(option_table::in, globals::out) is det.
+:- pred globals.init(option_table::in, globals::out) is det.

-:- pred globals__get_options(globals::in, option_table::out) is det.
+:- pred globals.get_options(globals::in, option_table::out) is det.

-:- pred globals__set_options(globals::in, option_table::in, globals::out)
+:- pred globals.set_options(globals::in, option_table::in, globals::out)
  		is det.

-:- pred globals__get_output_style(globals::in, diff_out__output_style::out)
+:- pred globals.get_output_style(globals::in, output_style::out)
  		is det.

-:- pred globals__set_output_style(globals::in, diff_out__output_style::in,
+:- pred globals.set_output_style(globals::in, output_style::in,
  		globals::out) is det.

-:- pred globals__lookup_option(globals::in, option::in, option_data::out)
+:- pred globals.lookup_option(globals::in, option::in, option_data::out)
  		is det.

-:- pred globals__lookup_bool_option(globals, option, bool).
-:- mode globals__lookup_bool_option(in, in, out) is det.
-:- pred globals__lookup_int_option(globals::in, option::in, int::out) is det.
-:- pred globals__lookup_string_option(globals::in, option::in, string::out)
-		is det.
-:- pred globals__lookup_accumulating_option(globals::in, option::in,
+:- pred globals.lookup_bool_option(globals::in, option::in, bool::out) is det.
+
+:- pred globals.lookup_int_option(globals::in, option::in, int::out) is det.
+
+:- pred globals.lookup_string_option(globals::in, option::in,
+    string::out) is det.
+
+:- pred globals.lookup_accumulating_option(globals::in, option::in,
  		list(string)::out) is det.

  %-----------------------------------------------------------------------------%

  	% Access predicates for storing a `globals' structure in the
-	% io__state using io__set_globals and io__get_globals.
+    % I/O state using io.set_globals/3 and io.get_globals/3.

-:- pred globals__io_init(option_table::in,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_init(option_table::in, io::di, io::uo) is det.

-:- pred globals__io_get_globals(globals::out, io__state::di, io__state::uo)
-			is det.
+:- pred globals.io_get_globals(globals::out, io::di, io::uo) is det.

-:- pred globals__io_set_globals(globals::in, io__state::di, io__state::uo)
-			is det.
+:- pred globals.io_set_globals(globals::in, io::di, io::uo) is det.

-:- pred globals__io_get_output_style(diff_out__output_style::out,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_get_output_style(output_style::out, io::di, io::uo) is det.

-:- pred globals__io_set_output_style(diff_out__output_style::in,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_set_output_style(output_style::in, io::di, io::uo) is det.

-:- pred globals__io_lookup_option(option::in, option_data::out,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_lookup_option(option::in, option_data::out,
+    io::di, io::uo) is det.

-:- pred globals__io_set_option(option::in, option_data::in,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_set_option(option::in, option_data::in,
+    io::di, io::uo) is det.

-:- pred globals__io_lookup_bool_option(option, bool, io__state, io__state).
-:- mode globals__io_lookup_bool_option(in, out, di, uo) is det.
+:- pred globals.io_lookup_bool_option(option::in, bool::out,
+    io::di, io::uo) is det.

-:- pred globals__io_lookup_int_option(option::in, int::out,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_lookup_int_option(option::in, int::out,
+    io::di, io::uo) is det.

-:- pred globals__io_lookup_string_option(option::in, string::out,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_lookup_string_option(option::in, string::out,
+    io::di, io::uo) is det.

-:- pred globals__io_lookup_accumulating_option(option::in, list(string)::out,
-			io__state::di, io__state::uo) is det.
+:- pred globals.io_lookup_accumulating_option(option::in, list(string)::out,
+    io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -109,123 +106,124 @@

  :- type globals
  	--->	globals(
-			option_table,		% Current options
-			diff_out__output_style	% Current module name
+                option_table,  % Current options.
+                output_style   % Current module name.
  		).

-globals__init(Options, globals(Options, OutputType)) :-
-	diff_out__default_output_style(OutputType).
+globals.init(Options, globals(Options, OutputType)) :-
+    default_output_style(OutputType).

-globals__get_options(globals(Options, _), Options).
+globals.get_options(globals(Options, _), Options).

-globals__set_options(globals(_, Scanner), Options, globals(Options, Scanner)).
+globals.set_options(globals(_, Scanner), Options, globals(Options, Scanner)).

-globals__get_output_style(globals(_, Output), Output).
+globals.get_output_style(globals(_, Output), Output).

-globals__set_output_style(globals(A, _), Output, globals(A, Output)).
+globals.set_output_style(globals(A, _), Output, globals(A, Output)).

-globals__lookup_option(Globals, Option, OptionData) :-
-	globals__get_options(Globals, OptionTable),
-	map__lookup(OptionTable, Option, OptionData).
+globals.lookup_option(Globals, Option, OptionData) :-
+    globals.get_options(Globals, OptionTable),
+    map.lookup(OptionTable, Option, OptionData).

  %-----------------------------------------------------------------------------%

-globals__lookup_bool_option(Globals, Option, Value) :-
-	globals__lookup_option(Globals, Option, OptionData),
+globals.lookup_bool_option(Globals, Option, Value) :-
+    globals.lookup_option(Globals, Option, OptionData),
  	( OptionData = bool(Bool) ->
  		Value = Bool
  	;
-		error("globals__lookup_bool_option: invalid bool option")
+        error("globals.lookup_bool_option: invalid bool option")
  	).

-globals__lookup_string_option(Globals, Option, Value) :-
-	globals__lookup_option(Globals, Option, OptionData),
+globals.lookup_string_option(Globals, Option, Value) :-
+    globals.lookup_option(Globals, Option, OptionData),
  	( OptionData = string(String) ->
  		Value = String
  	;
-		error("globals__lookup_string_option: invalid string option")
+        error("globals.lookup_string_option: invalid string option")
  	).

-globals__lookup_int_option(Globals, Option, Value) :-
-	globals__lookup_option(Globals, Option, OptionData),
+globals.lookup_int_option(Globals, Option, Value) :-
+    globals.lookup_option(Globals, Option, OptionData),
  	( OptionData = int(Int) ->
  		Value = Int
  	;
-		error("globals__lookup_int_option: invalid int option")
+        error("globals.lookup_int_option: invalid int option")
  	).

-globals__lookup_accumulating_option(Globals, Option, Value) :-
-	globals__lookup_option(Globals, Option, OptionData),
+globals.lookup_accumulating_option(Globals, Option, Value) :-
+    globals.lookup_option(Globals, Option, OptionData),
  	( OptionData = accumulating(Accumulating) ->
  		Value = Accumulating
  	;
-		error("globals__lookup_accumulating_option: invalid accumulating option")
+        error("globals.lookup_accumulating_option: invalid accumulating option")
  	).

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%

-globals__io_init(Options) -->
-	{ globals__init(Options, Globals) },
-	globals__io_set_globals(Globals).
-
-globals__io_get_globals(Globals) -->
-	io__get_globals(UnivGlobals),
-	{
+globals.io_init(Options, !IO) :-
+    globals.init(Options, Globals),
+    globals.io_set_globals(Globals, !IO).
+
+globals.io_get_globals(Globals, !IO) :-
+    io.get_globals(UnivGlobals, !IO),
+    (
  		univ_to_type(UnivGlobals, Globals0)
  	->
  		Globals = Globals0
  	;
-		error("globals__io_get_globals: univ_to_type failed")
-	}.
+        error("globals.io_get_globals: univ_to_type failed")
+    ).

-globals__io_set_globals(Globals) -->
-	{ unsafe_promise_unique(Globals, UniqGlobals) },
-	{ type_to_univ(UniqGlobals, UnivGlobals) },
-	io__set_globals(UnivGlobals).
+globals.io_set_globals(Globals, !IO) :-
+    unsafe_promise_unique(Globals, UniqGlobals),
+    type_to_univ(UniqGlobals, UnivGlobals),
+    io.set_globals(UnivGlobals, !IO).

  %-----------------------------------------------------------------------------%

-globals__io_lookup_option(Option, OptionData) -->
-	globals__io_get_globals(Globals),
-	{ globals__get_options(Globals, OptionTable) },
-	{ map__lookup(OptionTable, Option, OptionData) }.
+globals.io_lookup_option(Option, OptionData, !IO) :-
+    globals.io_get_globals(Globals, !IO),
+    globals.get_options(Globals, OptionTable),
+    map.lookup(OptionTable, Option, OptionData).

-globals__io_set_option(Option, OptionData) -->
-	globals__io_get_globals(Globals0),
-	{ globals__get_options(Globals0, OptionTable0) },
-	{ map__set(OptionTable0, Option, OptionData, OptionTable) },
-	{ globals__set_options(Globals0, OptionTable, Globals) },
-	globals__io_set_globals(Globals).
+globals.io_set_option(Option, OptionData, !IO) :-
+    globals.io_get_globals(Globals0, !IO),
+    globals.get_options(Globals0, OptionTable0),
+    map.set(OptionTable0, Option, OptionData, OptionTable),
+    globals.set_options(Globals0, OptionTable, Globals),
+    globals.io_set_globals(Globals, !IO).

  %-----------------------------------------------------------------------------%

-globals__io_lookup_bool_option(Option, Value) -->
-	globals__io_get_globals(Globals),
-	{ globals__lookup_bool_option(Globals, Option, Value) }.
+globals.io_lookup_bool_option(Option, Value, !IO) :-
+    globals.io_get_globals(Globals, !IO),
+    globals.lookup_bool_option(Globals, Option, Value).

-globals__io_lookup_int_option(Option, Value) -->
-	globals__io_get_globals(Globals),
-	{ globals__lookup_int_option(Globals, Option, Value) }.
+globals.io_lookup_int_option(Option, Value, !IO) :-
+    globals.io_get_globals(Globals, !IO),
+    globals.lookup_int_option(Globals, Option, Value).

-globals__io_lookup_string_option(Option, Value) -->
-	globals__io_get_globals(Globals),
-	{ globals__lookup_string_option(Globals, Option, Value) }.
+globals.io_lookup_string_option(Option, Value, !IO) :-
+    globals.io_get_globals(Globals, !IO),
+    globals.lookup_string_option(Globals, Option, Value).

-globals__io_lookup_accumulating_option(Option, Value) -->
-	globals__io_get_globals(Globals),
-	{ globals__lookup_accumulating_option(Globals, Option, Value) }.
+globals.io_lookup_accumulating_option(Option, Value, !IO) :-
+    globals.io_get_globals(Globals, !IO),
+    globals.lookup_accumulating_option(Globals, Option, Value).

  %-----------------------------------------------------------------------------%

-globals__io_get_output_style(Output) -->
-	globals__io_get_globals(Globals),
-	{ globals__get_output_style(Globals, Output) }.
+globals.io_get_output_style(Output, !IO) :-
+    globals.io_get_globals(Globals, !IO),
+    globals.get_output_style(Globals, Output).

-globals__io_set_output_style(Output) -->
-	globals__io_get_globals(Globals0),
-	{ globals__set_output_style(Globals0, Output, Globals) },
-	globals__io_set_globals(Globals).
+globals.io_set_output_style(Output, !IO) :-
+    globals.io_get_globals(Globals0, !IO),
+    globals.set_output_style(Globals0, Output, Globals),
+    globals.io_set_globals(Globals, !IO).

  %-----------------------------------------------------------------------------%
+:- end_module globals.
  %-----------------------------------------------------------------------------%
Index: match.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/match.m,v
retrieving revision 1.1
diff -u -b -r1.1 match.m
--- match.m	15 Sep 1998 04:54:33 -0000	1.1
+++ match.m	7 Jan 2011 16:31:59 -0000
@@ -1,21 +1,23 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1998 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
  %-----------------------------------------------------------------------------%
-
+%
  % Main author: bromage
-
+%
  % This module contains code to match common lines before diffing, based on
  % the command-line options presented.  The important command-line options
  % are --ignore-case, --ignore-all-space and --ignore-space-change.
-
+%
  % The output of build_matches is two arrays of integers, where any two
  % lines are assigned the same integer iff they are identical (modulo case,
  % space and/or space change depending on the command line options).  An
  % added benefit of doing this here is that the diff algorithm (myers.m)
  % only has to compare integers instead of strings.
-
+%
  % TO DO: We should collapse sequences of lines which only appear in one
  %        file and pretend the whole sequence is just one line.  (GNU
  %        diff does the same thing a slightly different way, but this
@@ -23,24 +25,39 @@
  %	 algorithm runs in O(ND) time, and performing this pre-filtering
  %	 here would reduce the value of D (by quite a lot in real-world
  %	 cases), things should speed up.
-
+%
  %-----------------------------------------------------------------------------%

  :- module match.
-
  :- interface.
-:- import_module file, io, array.

-:- pred build_matches(file :: in, file :: in,
-		array(int) :: out, array(int) :: out,
-		io__state :: di, io__state :: uo) is det.
+:- import_module file.
+
+:- import_module array.
+:- import_module io.
+
+%-----------------------------------------------------------------------------%
+
+:- pred build_matches(file::in, file::in, array(int)::out, array(int)::out,
+    io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%

  :- implementation.
-:- import_module globals, options.
-:- import_module bool, list, int, std_util, string, char, map, require.
+
+:- import_module globals.
+:- import_module options.
+
+:- import_module bool.
+:- import_module char.
+:- import_module int.
+:- import_module list.
+:- import_module map.
+:- import_module require.
+:- import_module string.
+
+%-----------------------------------------------------------------------------%

  :- type match_options
  	--->	match_options(
@@ -50,90 +67,86 @@
  			bool		% --ignore-space-change
  		).

-build_matches(File1, File2, FileX, FileY) -->
-	globals__io_lookup_bool_option(ignore_case, IgnCase),
-	globals__io_lookup_bool_option(ignore_all_space, IgnAllSpc),
-	globals__io_lookup_bool_option(ignore_space_change, IgnSpcChg),
-	{
-		bool__or_list([IgnCase, IgnAllSpc, IgnSpcChg], AnyOpts),
-		bool__not(AnyOpts, NoOpts),
+build_matches(File1, File2, FileX, FileY, !IO) :-
+    globals.io_lookup_bool_option(ignore_case, IgnCase, !IO),
+    globals.io_lookup_bool_option(ignore_all_space, IgnAllSpc, !IO),
+    globals.io_lookup_bool_option(ignore_space_change, IgnSpcChg, !IO),
+    (
+        bool.or_list([IgnCase, IgnAllSpc, IgnSpcChg], AnyOpts),
+        bool.not(AnyOpts, NoOpts),
  		Opts = match_options(NoOpts, IgnCase, IgnAllSpc, IgnSpcChg),
-		map__init(MatchMap0),
-		file__get_numlines(File1, SizeX),
-		array__init(SizeX, -1, FileX0),
+        map.init(MatchMap0),
+        file.get_numlines(File1, SizeX),
+        array.init(SizeX, -1, FileX0),
  		build_matches_for_file(Opts, File1, SizeX - 1, MatchMap0,
  			MatchMap1, 0, ID1, FileX0, FileX),
-		file__get_numlines(File2, SizeY),
-		array__init(SizeY, -1, FileY0),
+        file.get_numlines(File2, SizeY),
+        array.init(SizeY, -1, FileY0),
  		build_matches_for_file(Opts, File2, SizeY - 1, MatchMap1, _,
  			ID1, _, FileY0, FileY)
-	}.
+    ).

-:- pred build_matches_for_file(match_options, file, int,
-	map(string, int), map(string, int), int, int, array(int), array(int)).
-:- mode build_matches_for_file(in, in, in, in, out, in, out,
-	array_di, array_uo) is det.
+:- pred build_matches_for_file(match_options::in, file::in, int::in,
+    map(string, int)::in, map(string, int)::out,
+    int::in, int::out,
+    array(int)::array_di, array(int)::array_uo) is det.

-build_matches_for_file(Opts, OrigFile, I, MatchMap0, MatchMap, ID0, ID,
-		File0, File) :-
+build_matches_for_file(Opts, OrigFile, I, !MatchMap, !ID, !File) :-
  	( I < 0 ->
-		MatchMap = MatchMap0,
-		ID = ID0,
-		File = File0
+        true
  	;
-		( file__get_line(OrigFile, I, Line0) ->
+        ( file.get_line(OrigFile, I, Line0) ->
  			Line1 = Line0
  		;
  			error("build_matches_for_file")
  		),
  		Opts = match_options(NoOpts, IgnCase, IgnAllSpc, IgnSpcChg),
-		( NoOpts = yes ->
+        (
+            NoOpts = yes,
  			Line = Line1
  		;
-			string__to_char_list(Line1, Chars0),
-			normalise_line(no, IgnCase, IgnAllSpc, IgnSpcChg,
-				Chars0, Chars1),
-			string__from_char_list(Chars1, Line)
+            NoOpts = no,
+            string.to_char_list(Line1, Chars0),
+            normalise_line(no, IgnCase, IgnAllSpc, IgnSpcChg, Chars0, Chars1),
+            string.from_char_list(Chars1, Line)
  		),
-		( map__search(MatchMap0, Line, MaybeID) ->
-			array__set(File0, I, MaybeID, File1),
-			MatchMap1 = MatchMap0,
-			ID1 = ID0
-		;
-			array__set(File0, I, ID0, File1),
-			map__det_insert(MatchMap0, Line, ID0, MatchMap1),
-			ID1 is ID0 + 1
+        ( map.search(!.MatchMap, Line, MaybeID) ->
+            array.set(!.File, I, MaybeID, !:File)
+        ;
+            array.set(!.File, I, !.ID, !:File),
+            map.det_insert(!.MatchMap, Line, !.ID, !:MatchMap),
+            !:ID = !.ID + 1
  		),
-		build_matches_for_file(Opts, OrigFile, I - 1, MatchMap1,
-			MatchMap, ID1, ID, File1, File)
+        build_matches_for_file(Opts, OrigFile, I - 1, !MatchMap, !ID, !File)
  	).

-:- pred normalise_line(bool, bool, bool, bool, list(char), list(char)).
-:- mode normalise_line(in, in, in, in, in, out) is det.
+:- pred normalise_line(bool::in, bool::in, bool::in, bool::in,
+    list(char)::in, list(char)::out) is det.

  normalise_line(_, _, _, _, [], []).
  normalise_line(LastSpace, IgnCase, IgnAllSpc, IgnSpcChg, [C0 | Cs0], Cs) :-
-	( IgnCase = yes ->
-		char__to_lower(C0, C)
+    (
+        IgnCase = yes,
+        char.to_lower(C0, C)
  	;
+        IgnCase = no,
  		C = C0
  	),
  	(
-		char__is_whitespace(C),
+        char.is_whitespace(C),
  		(
  			IgnAllSpc = yes
  		->
-			normalise_line(LastSpace, IgnCase, IgnAllSpc, IgnSpcChg,
-					Cs0, CsX)
+            normalise_line(LastSpace, IgnCase, IgnAllSpc, IgnSpcChg, Cs0, CsX)
  		;
  			IgnSpcChg = yes
  		->
-			( LastSpace = yes ->
-				normalise_line(yes, IgnCase, IgnAllSpc,
-						IgnSpcChg, Cs0, CsX)
+            (
+                LastSpace = yes,
+                normalise_line(yes, IgnCase, IgnAllSpc, IgnSpcChg, Cs0, CsX)
  			;
-				normalise_line(yes, IgnCase, IgnAllSpc,
-						IgnSpcChg, Cs0, Cs1),
+                LastSpace = no,
+                normalise_line(yes, IgnCase, IgnAllSpc, IgnSpcChg, Cs0, Cs1),
  				CsX = [' ' | Cs1]

  			)
@@ -143,10 +156,10 @@
  	->
  		Cs = CsX
  	;
-		normalise_line(no, IgnCase, IgnAllSpc, IgnSpcChg,
-				Cs0, Cs1),
+        normalise_line(no, IgnCase, IgnAllSpc, IgnSpcChg, Cs0, Cs1),
  		Cs = [C | Cs1]
  	).

  %-----------------------------------------------------------------------------%
+:- end_module match.
  %-----------------------------------------------------------------------------%
Index: myers.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/myers.m,v
retrieving revision 1.2
diff -u -b -r1.2 myers.m
--- myers.m	28 Jun 2006 09:22:39 -0000	1.2
+++ myers.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1998, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -30,8 +32,8 @@

  %-----------------------------------------------------------------------------%

-:- pred diff_by_myers(array(int), array(int), diff, io__state, io__state).
-:- mode diff_by_myers(in, in, out, di, uo) is det.
+:- pred diff_by_myers(array(int)::in, array(int)::in, diff::out,
+    io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%
  %-----------------------------------------------------------------------------%
@@ -42,10 +44,8 @@
  :- import_module options.

  :- import_module bool.
-:- import_module char.
  :- import_module int.
  :- import_module list.
-:- import_module map.
  :- import_module pair.
  :- import_module require.

@@ -57,11 +57,10 @@
  %
  % This uses the variation in section 4b.

-diff_by_myers(FileX, FileY, Diff) -->
-	globals__io_lookup_bool_option(minimal, Minimal),
-	{
-		array__size(FileX, SizeX),
-		array__size(FileY, SizeY),
+diff_by_myers(FileX, FileY, Diff, !IO) :-
+    globals.io_lookup_bool_option(minimal, Minimal, !IO),
+    array.size(FileX, SizeX),
+    array.size(FileY, SizeY),
  		SizeMax = SizeX + SizeY + 3,
  		DOffset = SizeY + 1,

@@ -72,11 +71,13 @@
  		% O(n ** (1.5 log n)) at the expense of finding a
  		% possibly non-minimal diff.

-		( Minimal = yes,
+    (
+        Minimal = yes,
  			Heur = none
-		; Minimal = no,
-			int__log2(SizeMax, SizeLog2),
-			int__max(minimum_too_expensive, 1 << (SizeLog2 // 2),
+    ;
+        Minimal = no,
+        int.log2(SizeMax, SizeLog2),
+        int.max(minimum_too_expensive, 1 << (SizeLog2 // 2),
  					SizeHeuristic),
  			Heur = too_expensive(SizeHeuristic)
  		),
@@ -84,54 +85,45 @@
  			% Fill the arrays with nondescript numbers which
  			% the algorithm shouldn't produce.  (For debugging
  			% purposes.)
-		array__init(SizeMax, -65537, Fwd),
-		array__init(SizeMax, -65537, Bwd),
-		myers__bsearch(DOffset, FileX, FileY, 0, SizeX, 0, SizeY,
-			Heur, Fwd, _, Bwd, _, [], Diff)
-	}.
+    array.init(SizeMax, -65537, Fwd),
+    array.init(SizeMax, -65537, Bwd),
+    myers.bsearch(DOffset, FileX, FileY, 0, SizeX, 0, SizeY,
+        Heur, Fwd, _, Bwd, _, [], Diff).

  	% XXX This lower bound is a guess.  Need to do some measurements
  	%     to see if it's good or not.
  :- func minimum_too_expensive = int.
-minimum_too_expensive = 256.

-:- pred myers__bsearch(int, array(int), array(int), int, int, int, int, heur,
-		array(int), array(int), array(int), array(int),
-		diff, diff).
-:- mode myers__bsearch(in, in, in, in, in, in, in, in,
-		array_di, array_uo, array_di, array_uo,
-		in, out) is det.
-
-myers__bsearch(DOffset, FileX, FileY, Xlow0, Xhigh0, Ylow0, Yhigh0, Heur,
-			Fwd0, Fwd, Bwd0, Bwd, Diff0, Diff) :-
-	myers__scan_forward(FileX, FileY, Xhigh0, Yhigh0,
-		Xlow0, Xlow, Ylow0, Ylow),
-	myers__scan_backward(FileX, FileY, Xlow, Ylow,
-		Xhigh0, Xhigh, Yhigh0, Yhigh),
+minimum_too_expensive = 256.

+:- pred myers.bsearch(int::in, array(int)::in, array(int)::in, int::in,
+    int::in, int::in, int::in, heur::in,
+    array(int)::array_di, array(int)::array_uo,
+    array(int)::array_di, array(int)::array_uo,
+    diff::in, diff::out) is det.
+
+myers.bsearch(DOffset, FileX, FileY, Xlow0, Xhigh0, Ylow0, Yhigh0, Heur,
+            !Fwd, !Bwd, !Diff) :-
+    scan_forward(FileX, FileY, Xhigh0, Yhigh0, Xlow0, Xlow, Ylow0, Ylow),
+    scan_backward(FileX, FileY, Xlow, Ylow, Xhigh0, Xhigh, Yhigh0, Yhigh),
  	(
  		( Xlow >= Xhigh
  		; Ylow >= Yhigh
  		)
  	->
-		Fwd = Fwd0, Bwd = Bwd0,
-		difftype__add_edit(Xlow - Xhigh, Ylow - Yhigh, Diff0, Diff)
+        add_edit(Xlow - Xhigh, Ylow - Yhigh, !Diff)
  	;
-		myers__find_middle(DOffset, FileX, FileY,
-			Xlow, Xhigh, Ylow, Yhigh, Heur,
-			Fwd0, Fwd1, Bwd0, Bwd1, Xmid, Ymid, Cost,
-			LeftHeur - RightHeur),
+        find_middle(DOffset, FileX, FileY, Xlow, Xhigh, Ylow, Yhigh, Heur,
+            !Fwd, !Bwd, Xmid, Ymid, Cost, LeftHeur - RightHeur),
  		(
  			Cost > 0
  		->
-			myers__bsearch(DOffset, FileX, FileY,
-				Xmid, Xhigh, Ymid, Yhigh, LeftHeur,
-				Fwd1, Fwd2, Bwd1, Bwd2, Diff0, Diff1),
-			myers__bsearch(DOffset, FileX, FileY,
-				Xlow, Xmid, Ylow, Ymid, RightHeur,
-				Fwd2, Fwd, Bwd2, Bwd, Diff1, Diff)
+            myers.bsearch(DOffset, FileX, FileY, Xmid, Xhigh, Ymid, Yhigh,
+                LeftHeur, !Fwd, !Bwd, !Diff),
+            myers.bsearch(DOffset, FileX, FileY, Xlow, Xmid, Ylow, Ymid,
+                RightHeur, !Fwd, !Bwd, !Diff)
  		;
-			error("myers__bsearch")
+            error("myers.bsearch")
  		)
  	).

@@ -159,24 +151,24 @@
  	% an estimate to it.  If we don't find the exact middle,
  	% we will have a correct diff, but it won't necessarily be
  	% minimal.
-:- pred myers__find_middle(int, array(int), array(int), pos, pos, pos, pos,
+:- pred myers.find_middle(int, array(int), array(int), pos, pos, pos, pos,
  		heur,
  		array(int), array(int), array(int), array(int),
  		pos, pos, int, pair(heur)).
-:- mode myers__find_middle(in, in, in, in, in, in, in, in,
+:- mode myers.find_middle(in, in, in, in, in, in, in, in,
  		array_di, array_uo, array_di, array_uo,
  		out, out, out, out) is det.

-myers__find_middle(DOffset, FileX, FileY, Xlow, Xhigh, Ylow, Yhigh, Heur,
+myers.find_middle(DOffset, FileX, FileY, Xlow, Xhigh, Ylow, Yhigh, Heur,
  		Fwd0, Fwd, Bwd0, Bwd, Xmid, Ymid, Cost, HeurReq) :-

  	Dmin = Xlow - Yhigh,
  	Dmax = Xhigh - Ylow,

  	Fmid = Xlow - Ylow,
-	array__set(Fwd0, Fmid + DOffset, Xlow, Fwd1),
+    array.set(Fwd0, Fmid + DOffset, Xlow, Fwd1),
  	Bmid = Xhigh - Yhigh,
-	array__set(Bwd0, Bmid + DOffset, Xhigh, Bwd1),
+    array.set(Bwd0, Bmid + DOffset, Xhigh, Bwd1),

  	( 1 = (Fmid - Bmid) /\ 1 ->
  		DeltaOdd = yes
@@ -189,72 +181,72 @@
  		Dmin, Dmax, DeltaOdd, Heur
  	),

-	myers__find_middle_2(Constants, Fwd1, Fwd, Bwd1, Bwd,
+    myers.find_middle_2(Constants, Fwd1, Fwd, Bwd1, Bwd,
  		Fmid, Fmid, Bmid, Bmid, 1, Cost, Xmid - Ymid, HeurReq).


-:- pred myers__find_middle_2(myers_constants,
+:- pred myers.find_middle_2(myers_constants,
  		array(int), array(int), array(int), array(int),
  		int, int, int, int, int, int, pair(pos), pair(heur)).
-:- mode myers__find_middle_2(in, array_di, array_uo, array_di, array_uo,
+:- mode myers.find_middle_2(in, array_di, array_uo, array_di, array_uo,
  		in, in, in, in, in, out, out, out) is det.

-myers__find_middle_2(Constants, Fwd0, Fwd, Bwd0, Bwd,
+myers.find_middle_2(Constants, Fwd0, Fwd, Bwd0, Bwd,
  		Fmin, Fmax, Bmin, Bmax, Cost0, Cost, Mid, HeurReq) :-
  	Constants = constants(DOffset, _, _, _, _, _, _, Dmin, Dmax, _, _),
  	( Fmin > Dmin ->
  		Fmin1 = Fmin - 1,
-		array__set(Fwd0, Fmin1 + DOffset - 1, -1, Fwd1)
+        array.set(Fwd0, Fmin1 + DOffset - 1, -1, Fwd1)
  	;
  		Fmin1 = Fmin + 1,
  		Fwd1 = Fwd0
  	),
  	( Fmax < Dmax ->
  		Fmax1 = Fmax + 1,
-		array__set(Fwd1, Fmax1 + DOffset + 1, -1, Fwd2)
+        array.set(Fwd1, Fmax1 + DOffset + 1, -1, Fwd2)
  	;
  		Fmax1 = Fmax - 1,
  		Fwd2 = Fwd1
  	),
-	myers__find_forward_reaching_path(Constants, Fwd2, Fwd, Bwd0, Bwd,
+    myers.find_forward_reaching_path(Constants, Fwd2, Fwd, Bwd0, Bwd,
  		Fmin1, Fmax1, Bmin, Bmax, Fmax1, Cost0, Cost, Mid, HeurReq).


-:- pred myers__find_forward_reaching_path(myers_constants,
+:- pred myers.find_forward_reaching_path(myers_constants,
  		array(int), array(int), array(int), array(int),
  		int, int, int, int, int, int, int, pair(pos), pair(heur)).
-:- mode myers__find_forward_reaching_path(in, array_di, array_uo,
+:- mode myers.find_forward_reaching_path(in, array_di, array_uo,
  		array_di, array_uo, in, in, in, in, in, in, out, out, out)
  				is det.

-myers__find_forward_reaching_path(Constants, Fwd0, Fwd, Bwd0, Bwd,
+myers.find_forward_reaching_path(Constants, Fwd0, Fwd, Bwd0, Bwd,
  		Fmin, Fmax, Bmin, Bmax, SearchCost, Cost0, Cost, Mid,
  		HeurReq) :-
  	( SearchCost < Fmin ->
  		Constants = constants(DOffset, _, _, _, _, _, _, Dmin, Dmax, _,
  					_),
-		int__max_int(MaxInt),
+        int.max_int(MaxInt),
  		( Bmin > Dmin ->
  			Bmin1 = Bmin - 1,
-			array__set(Bwd0, Bmin1 + DOffset - 1, MaxInt, Bwd1)
+            array.set(Bwd0, Bmin1 + DOffset - 1, MaxInt, Bwd1)
  		;
  			Bmin1 = Bmin + 1,
  			Bwd1 = Bwd0
  		),
  		( Bmax < Dmax ->
  			Bmax1 = Bmax + 1,
-			array__set(Bwd1, Bmax1 + DOffset + 1, MaxInt, Bwd2)
+            array.set(Bwd1, Bmax1 + DOffset + 1, MaxInt, Bwd2)
  		;
  			Bmax1 = Bmax - 1,
  			Bwd2 = Bwd1
  		),
-		myers__find_backward_reaching_path(Constants,
+        myers.find_backward_reaching_path(Constants,
  			Fwd0, Fwd, Bwd2, Bwd, Fmin, Fmax, Bmin1, Bmax1,
  			Bmax1, Cost0, Cost, Mid, HeurReq)
  	;
  		Constants = constants(DOffset, _, _, _, _, _, _, _, _, _, _),
-		array__lookup(Fwd0, SearchCost + DOffset - 1, Tlo),
-		array__lookup(Fwd0, SearchCost + DOffset + 1, Thi),
+        array.lookup(Fwd0, SearchCost + DOffset - 1, Tlo),
+        array.lookup(Fwd0, SearchCost + DOffset + 1, Thi),
  		( Tlo >= Thi ->
  			X0 = Tlo + 1
  		;
@@ -263,15 +255,15 @@
  		Y0 = X0 - SearchCost,
  		Constants = constants(_, FileX, FileY, _, Xhigh, _, Yhigh,
  			_, _, _, _),
-		myers__scan_forward(FileX, FileY, Xhigh, Yhigh, X0, X, Y0, Y),
-		array__set(Fwd0, SearchCost + DOffset, X, Fwd1),
+        myers.scan_forward(FileX, FileY, Xhigh, Yhigh, X0, X, Y0, Y),
+        array.set(Fwd0, SearchCost + DOffset, X, Fwd1),

  		Constants = constants(_, _, _, _, _, _, _, _, _, DeltaOdd, _),
  		(
  			DeltaOdd = yes,
  			Bmin =< SearchCost,
  			SearchCost =< Bmax,
-			array__lookup(Bwd0, SearchCost + DOffset, BB),
+            array.lookup(Bwd0, SearchCost + DOffset, BB),
  			BB =< X
  		->
  			Mid = X - Y,
@@ -280,30 +272,30 @@
  			Bwd = Bwd0,
  			HeurReq = none - none
  		;
-			myers__find_forward_reaching_path(Constants,
+            myers.find_forward_reaching_path(Constants,
  				Fwd1, Fwd, Bwd0, Bwd, Fmin, Fmax, Bmin, Bmax,
  				SearchCost - 2, Cost0, Cost, Mid, HeurReq)
  		)
  	).


-:- pred myers__find_backward_reaching_path(myers_constants,
+:- pred myers.find_backward_reaching_path(myers_constants,
  		array(int), array(int), array(int), array(int),
  		int, int, int, int, int, int, int, pair(pos), pair(heur)).
-:- mode myers__find_backward_reaching_path(in, array_di, array_uo,
+:- mode myers.find_backward_reaching_path(in, array_di, array_uo,
  		array_di, array_uo, in, in, in, in, in, in,
  		out, out, out) is det.

-myers__find_backward_reaching_path(Constants, Fwd0, Fwd, Bwd0, Bwd,
+myers.find_backward_reaching_path(Constants, Fwd0, Fwd, Bwd0, Bwd,
  		Fmin, Fmax, Bmin, Bmax, SearchCost, Cost0, Cost, Mid,
  		HeurReq) :-
  	( SearchCost < Bmin ->
-		myers__try_heuristics(Constants, Fwd0, Fwd, Bwd0, Bwd,
+        myers.try_heuristics(Constants, Fwd0, Fwd, Bwd0, Bwd,
  			Fmin, Fmax, Bmin, Bmax, Cost0, Cost, Mid, HeurReq)
  	;
  		Constants = constants(DOffset, _, _, _, _, _, _, _, _, _, _),
-		array__lookup(Bwd0, SearchCost + DOffset - 1, Tlo),
-		array__lookup(Bwd0, SearchCost + DOffset + 1, Thi),
+        array.lookup(Bwd0, SearchCost + DOffset - 1, Tlo),
+        array.lookup(Bwd0, SearchCost + DOffset + 1, Thi),
  		( Tlo < Thi ->
  			X0 = Tlo
  		;
@@ -312,15 +304,15 @@
  		Y0 = X0 - SearchCost,
  		Constants = constants(_, FileX, FileY, Xlow, _, Ylow, _,
  			_, _, _, _),
-		myers__scan_backward(FileX, FileY, Xlow, Ylow, X0, X, Y0, Y),
-		array__set(Bwd0, SearchCost + DOffset, X, Bwd1),
+        myers.scan_backward(FileX, FileY, Xlow, Ylow, X0, X, Y0, Y),
+        array.set(Bwd0, SearchCost + DOffset, X, Bwd1),

  		Constants = constants(_, _, _, _, _, _, _, _, _, DeltaOdd, _),
  		(
  			DeltaOdd = no,
  			Fmin =< SearchCost,
  			SearchCost =< Fmax,
-			array__lookup(Fwd0, SearchCost + DOffset, FF),
+            array.lookup(Fwd0, SearchCost + DOffset, FF),
  			X =< FF
  		->
  			Mid = X - Y,
@@ -329,7 +321,7 @@
  			Bwd = Bwd1,
  			HeurReq = none - none
  		;
-			myers__find_backward_reaching_path(Constants,
+            myers.find_backward_reaching_path(Constants,
  				Fwd0, Fwd, Bwd1, Bwd, Fmin, Fmax, Bmin, Bmax,
  				SearchCost - 2, Cost0, Cost, Mid, HeurReq)
  		)
@@ -337,13 +329,13 @@


  	% Try applying some heuristics to see if we can avoid some work.
-:- pred myers__try_heuristics(myers_constants,
+:- pred myers.try_heuristics(myers_constants,
  		array(int), array(int), array(int), array(int),
  		int, int, int, int, int, int, pair(pos), pair(heur)).
-:- mode myers__try_heuristics(in, array_di, array_uo,
+:- mode myers.try_heuristics(in, array_di, array_uo,
  		array_di, array_uo, in, in, in, in, in, out, out, out) is det.

-myers__try_heuristics(Constants, Fwd0, Fwd, Bwd0, Bwd,
+myers.try_heuristics(Constants, Fwd0, Fwd, Bwd0, Bwd,
  		Fmin, Fmax, Bmin, Bmax, Cost0, Cost, Mid, HeurReq) :-
  	Constants = constants(_, _, _, _, _, _, _, _, _, _, Heur),
  	(
@@ -352,25 +344,25 @@
  	->
  			% If we've done too much work, stop here.
  		Fwd = Fwd0, Bwd = Bwd0,
-		myers__too_expensive_heuristic(Constants, Fwd, Bwd,
+        myers.too_expensive_heuristic(Constants, Fwd, Bwd,
  			Fmin, Fmax, Bmin, Bmax, Cost0, Cost, Mid, HeurReq)
  	;
  		% Can't apply heuristic, so try looking for a diff of size
  		% Cost0 + 1.

-		myers__find_middle_2(Constants, Fwd0, Fwd, Bwd0, Bwd,
+        myers.find_middle_2(Constants, Fwd0, Fwd, Bwd0, Bwd,
  			Fmin, Fmax, Bmin, Bmax, Cost0 + 1, Cost, Mid, HeurReq)
  	).

  %-----------------------------------------------------------------------------%

  	% We've done too much work, so make our best guess.
-:- pred myers__too_expensive_heuristic(myers_constants, array(int), array(int),
+:- pred myers.too_expensive_heuristic(myers_constants, array(int), array(int),
  		int, int, int, int, int, int, pair(pos), pair(heur)).
-:- mode myers__too_expensive_heuristic(in, array_ui, array_ui,
+:- mode myers.too_expensive_heuristic(in, array_ui, array_ui,
  		in, in, in, in, in, out, out, out) is det.

-myers__too_expensive_heuristic(Constants, Fwd, Bwd,
+myers.too_expensive_heuristic(Constants, Fwd, Bwd,
  		Fmin, Fmax, Bmin, Bmax, Cost0, Cost, Mid, HeurReq) :-
  	% Find the best diagonal that we can, take the end of
  	% that diagonal as the "middle".  Do not apply the
@@ -380,12 +372,12 @@
  			_, _, _, Heur),

  		% Find the best forward diagonal.
-	myers__find_best_forward_diagonal(Fmax, Fmin, Fwd,
+    myers.find_best_forward_diagonal(Fmax, Fmin, Fwd,
  			Xhigh, Yhigh, DOffset, -1, FXYBest, 0, FXBest),

  		% Find the best backward diagonal.
-	int__max_int(MaxInt),
-	myers__find_best_backward_diagonal(Bmax, Bmin, Bwd,
+    int.max_int(MaxInt),
+    myers.find_best_backward_diagonal(Bmax, Bmin, Bwd,
  			Xlow, Ylow, DOffset, MaxInt, BXYBest, 0, BXBest),

  		% Choose which of these diagonals is the better one
@@ -404,19 +396,19 @@
  	Mid = Xmid - Ymid,
  	Cost = 2 * Cost0 - 1.

-:- pred myers__find_best_forward_diagonal(int, int, array(int), int, int, int,
+:- pred myers.find_best_forward_diagonal(int, int, array(int), int, int, int,
  			int, int, int, int).
-:- mode myers__find_best_forward_diagonal(in, in, array_ui, in, in, in,
+:- mode myers.find_best_forward_diagonal(in, in, array_ui, in, in, in,
  			in, out, in, out) is det.

-myers__find_best_forward_diagonal(D, Fmin, Fwd, Xhigh, Yhigh, DOffset,
+myers.find_best_forward_diagonal(D, Fmin, Fwd, Xhigh, Yhigh, DOffset,
  			FXYBest0, FXYBest, FXBest0, FXBest) :-
  	( D < Fmin ->
  		FXYBest = FXYBest0,
  		FXBest = FXBest0
  	;
-		array__lookup(Fwd, D + DOffset, X0),
-		int__min(Xhigh, X0, X1),
+        array.lookup(Fwd, D + DOffset, X0),
+        int.min(Xhigh, X0, X1),
  		Y0 = X1 - D,

  		( Yhigh < Y0 ->
@@ -429,29 +421,29 @@

  		NewFXY = X + Y,
  		( FXYBest0 < NewFXY ->
-			myers__find_best_forward_diagonal(D - 2, Fmin, Fwd,
+            myers.find_best_forward_diagonal(D - 2, Fmin, Fwd,
  				Xhigh, Yhigh, DOffset, NewFXY, FXYBest,
  				X, FXBest)
  		;
-			myers__find_best_forward_diagonal(D - 2, Fmin, Fwd,
+            myers.find_best_forward_diagonal(D - 2, Fmin, Fwd,
  				Xhigh, Yhigh, DOffset, FXYBest0, FXYBest,
  				FXBest0, FXBest)
  		)
  	).

-:- pred myers__find_best_backward_diagonal(int, int, array(int), int, int, int,
+:- pred myers.find_best_backward_diagonal(int, int, array(int), int, int, int,
  			int, int, int, int).
-:- mode myers__find_best_backward_diagonal(in, in, array_ui, in, in, in,
+:- mode myers.find_best_backward_diagonal(in, in, array_ui, in, in, in,
  			in, out, in, out) is det.

-myers__find_best_backward_diagonal(D, Bmin, Bwd, Xlow, Ylow, DOffset,
+myers.find_best_backward_diagonal(D, Bmin, Bwd, Xlow, Ylow, DOffset,
  			BXYBest0, BXYBest, BXBest0, BXBest) :-
  	( D < Bmin ->
  		BXYBest = BXYBest0,
  		BXBest = BXBest0
  	;
-		array__lookup(Bwd, D + DOffset, X0),
-		int__max(Xlow, X0, X1),
+        array.lookup(Bwd, D + DOffset, X0),
+        int.max(Xlow, X0, X1),
  		Y0 = X1 - D,

  		( Y0 < Ylow ->
@@ -464,11 +456,11 @@

  		NewBXY = X + Y,
  		( NewBXY < BXYBest0 ->
-			myers__find_best_backward_diagonal(D - 2, Bmin, Bwd,
+            myers.find_best_backward_diagonal(D - 2, Bmin, Bwd,
  				Xlow, Ylow, DOffset, NewBXY, BXYBest,
  				X, BXBest)
  		;
-			myers__find_best_backward_diagonal(D - 2, Bmin, Bwd,
+            myers.find_best_backward_diagonal(D - 2, Bmin, Bwd,
  				Xlow, Ylow, DOffset, BXYBest0, BXYBest,
  				BXBest0, BXBest)
  		)
@@ -477,18 +469,18 @@
  %-----------------------------------------------------------------------------%

  	% Travel forwards along a snake.
-:- pred myers__scan_forward(array(int), array(int), int, int,
+:- pred myers.scan_forward(array(int), array(int), int, int,
  		int, int, int, int).
-:- mode myers__scan_forward(in, in, in, in, in, out, in, out) is det.
+:- mode myers.scan_forward(in, in, in, in, in, out, in, out) is det.

-myers__scan_forward(FileX, FileY, Xhigh, Yhigh, Xlow0, Xlow, Ylow0, Ylow) :-
+myers.scan_forward(FileX, FileY, Xhigh, Yhigh, Xlow0, Xlow, Ylow0, Ylow) :-
  	(
  		Xlow0 < Xhigh,
  		Ylow0 < Yhigh,
-		array__lookup(FileX, Xlow0, Line),
-		array__lookup(FileY, Ylow0, Line)
+        array.lookup(FileX, Xlow0, Line),
+        array.lookup(FileY, Ylow0, Line)
  	->
-		myers__scan_forward(FileX, FileY, Xhigh, Yhigh,
+        myers.scan_forward(FileX, FileY, Xhigh, Yhigh,
  			Xlow0 + 1, Xlow, Ylow0 + 1, Ylow)
  	;
  		Xlow = Xlow0, Ylow = Ylow0
@@ -496,22 +488,23 @@


  	% Travel backwards along a snake.
-:- pred myers__scan_backward(array(int), array(int), int, int,
+:- pred myers.scan_backward(array(int), array(int), int, int,
  		int, int, int, int).
-:- mode myers__scan_backward(in, in, in, in, in, out, in, out) is det.
+:- mode myers.scan_backward(in, in, in, in, in, out, in, out) is det.

-myers__scan_backward(FileX, FileY, Xlow, Ylow, Xhigh0, Xhigh, Yhigh0, Yhigh) :-
+myers.scan_backward(FileX, FileY, Xlow, Ylow, Xhigh0, Xhigh, Yhigh0, Yhigh) :-
  	(
  		Xhigh0 > Xlow,
  		Yhigh0 > Ylow,
-		array__lookup(FileX, Xhigh0 - 1, Line),
-		array__lookup(FileY, Yhigh0 - 1, Line)
+        array.lookup(FileX, Xhigh0 - 1, Line),
+        array.lookup(FileY, Yhigh0 - 1, Line)
  	->
-		myers__scan_backward(FileX, FileY, Xlow, Ylow,
+        myers.scan_backward(FileX, FileY, Xlow, Ylow,
  			Xhigh0 - 1, Xhigh, Yhigh0 - 1, Yhigh)
  	;
  		Xhigh = Xhigh0, Yhigh = Yhigh0
  	).

  %-----------------------------------------------------------------------------%
+:- end_module myers.
  %-----------------------------------------------------------------------------%
Index: options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/samples/diff/options.m,v
retrieving revision 1.4
diff -u -b -r1.4 options.m
--- options.m	7 Jan 2011 06:40:22 -0000	1.4
+++ options.m	7 Jan 2011 16:31:59 -0000
@@ -1,4 +1,6 @@
  %-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et wm=0 tw=0
+%-----------------------------------------------------------------------------%
  % Copyright (C) 1998, 2006 The University of Melbourne.
  % This file may only be copied under the terms of the GNU General
  % Public License - see the file COPYING in the Mercury distribution.
@@ -17,21 +19,22 @@
  :- import_module getopt.
  :- import_module io.
  :- import_module maybe.
-:- import_module string.

  %-----------------------------------------------------------------------------%

-:- pred options__get_option_ops(option_ops(option) :: out(option_ops)) is det.
+:- pred options.get_option_ops(option_ops(option) :: out(option_ops)) is det.

  	% Process the option table, perhaps returning an error message
  	% if there was some inconsistentcy or other error.
-:- pred postprocess_options(maybe_option_table :: in, maybe(string) :: out,
-		io__state::di, io__state::uo) is det.
+    %
+:- pred postprocess_options(maybe_option_table::in, maybe(string)::out,
+    io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%

  	% Info on the accepted options, displayed in response to --help.
-:- pred options_help(io__state::di, io__state::uo) is det.
+    %
+:- pred options_help(io::di, io::uo) is det.

  %-----------------------------------------------------------------------------%

@@ -39,10 +42,10 @@
  :- type maybe_option_table	== maybe_option_table(option).

  	% The master list of options.
-
-:- type option --->
+    %
+:- type option
  	% Output styles
-	 	help
+    --->    help
  	;	version
  	;	context
  	;	context_style_output
@@ -115,10 +118,19 @@
  %-----------------------------------------------------------------------------%

  :- implementation.
-:- import_module globals, diff_out.
-:- import_module list, int, bool, string, map, require.
+
+:- import_module diff_out.
+:- import_module globals.
+
+:- import_module bool.
+:- import_module list.
+:- import_module map.
+:- import_module require.
+
+%-----------------------------------------------------------------------------%

  :- pred long_option(string::in, option::out) is semidet.
+
  long_option("ignore-blank-lines",	ignore_blank_lines).
  long_option("context",			context).
  long_option("ifdef",			ifdef).
@@ -173,6 +185,7 @@
  %-----------------------------------------------------------------------------%

  :- pred short_option(character::in, option::out) is semidet.
+
  short_option('B', ignore_blank_lines).
  short_option('C', context).
  short_option('D', ifdef).
@@ -283,23 +296,28 @@
  		maybe_option_table :: out) is semidet.

  special_handler(context_style_output, bool(yes), Options0, ok(Options)) :-
-	map__lookup(Options0, context, maybe_int(Context0)),
-	( Context0 = no,
+    map.lookup(Options0, context, maybe_int(Context0)),
+    (
+        Context0 = no,
  		Context = yes(3)
-	; Context0 = yes(C),
+    ; 
+        Context0 = yes(C),
  		Context = yes(C)
  	),
-	map__set(Options0, context, maybe_int(Context), Options).
+    map.set(Options0, context, maybe_int(Context), Options).
  special_handler(unified_style_output, bool(yes), Options0, ok(Options)) :-
-	map__lookup(Options0, unified, maybe_int(Unified0)),
-	( Unified0 = no,
+    map.lookup(Options0, unified, maybe_int(Unified0)),
+    (
+        Unified0 = no,
  		Unified = yes(3)
-	; Unified0 = yes(C),
+    ;
+        Unified0 = yes(C),
  		Unified = yes(C)
  	),
-	map__set(Options0, unified, maybe_int(Unified), Options).
+    map.set(Options0, unified, maybe_int(Unified), Options).

-	% Special handlers for unhandled options
+    % Special handlers for unhandled options.
+    %
  special_handler(show_c_function, _, _, error(Msg)) :-
  	Msg = "Option not handled: --show-c-function".
  special_handler(show_function_line, _, _, error(Msg)) :-
@@ -353,7 +371,7 @@

  %-----------------------------------------------------------------------------%

-options__get_option_ops(OptionOps) :-
+options.get_option_ops(OptionOps) :-
  	OptionOps = option_ops_multi(
  		short_option,
  		long_option,
@@ -363,49 +381,47 @@

  %-----------------------------------------------------------------------------%

-	% Postprocess the options
-postprocess_options(ok(OptionTable0), Result) -->
-	( { postprocess_output_style(OptionTable0, OutputStyle) } ->
-		globals__io_init(OptionTable0),
-		globals__io_set_output_style(OutputStyle),
-		{ Result = no }
+    % Postprocess the options.
+    %
+postprocess_options(ok(OptionTable0), Result, !IO) :-
+    ( postprocess_output_style(OptionTable0, OutputStyle) ->
+        globals.io_init(OptionTable0, !IO),
+        globals.io_set_output_style(OutputStyle, !IO),
+        Result = no
  	;
-		{ Result = yes("Can't set more than one output style.") }
+        Result = yes("Can't set more than one output style.")
  	).
-postprocess_options(error(Msg), yes(Msg)) --> [].
+postprocess_options(error(Msg), yes(Msg), !IO).

-	% Determine which output style to use from the provided
-	% options.
-:- pred postprocess_output_style(option_table :: in,
-		diff_out__output_style :: out) is semidet.
+    % Determine which output style to use from the provided options.
+    %
+:- pred postprocess_output_style(option_table::in, output_style::out)
+    is semidet.

  postprocess_output_style(OptionTable, Style) :-
  	(
-		map__search(OptionTable, help, bool(UseHelp)),
-		map__search(OptionTable, version, bool(UseVersion)),
-		map__search(OptionTable, context, maybe_int(UseContext)),
-		map__search(OptionTable, unified, maybe_int(UseUnified)),
-		map__search(OptionTable, ed, bool(UseEd)),
-		map__search(OptionTable, forward_ed, bool(UseForwardEd)),
-		map__search(OptionTable, rcs, bool(UseRCS)),
-		map__search(OptionTable, brief, bool(UseBrief)),
-		map__search(OptionTable, ifdef, maybe_string(UseIfdef)),
-		map__search(OptionTable, side_by_side, bool(UseSideBySide)),
-		map__search(OptionTable, cvs_merge_conflict, bool(CVS))
+        map.search(OptionTable, help, bool(UseHelp)),
+        map.search(OptionTable, version, bool(UseVersion)),
+        map.search(OptionTable, context, maybe_int(UseContext)),
+        map.search(OptionTable, unified, maybe_int(UseUnified)),
+        map.search(OptionTable, ed, bool(UseEd)),
+        map.search(OptionTable, forward_ed, bool(UseForwardEd)),
+        map.search(OptionTable, rcs, bool(UseRCS)),
+        map.search(OptionTable, brief, bool(UseBrief)),
+        map.search(OptionTable, ifdef, maybe_string(UseIfdef)),
+        map.search(OptionTable, side_by_side, bool(UseSideBySide)),
+        map.search(OptionTable, cvs_merge_conflict, bool(CVS))
  	->
  		postprocess_output_style_2(UseHelp, UseVersion, UseContext,
  			UseUnified, UseEd, UseForwardEd, UseRCS, UseBrief,
-			UseIfdef, UseSideBySide, CVS,
-			Style)
+            UseIfdef, UseSideBySide, CVS, Style)
  	;
  		error("postprocess_output_style")
  	).

-:- pred postprocess_output_style_2(bool, bool, maybe(int), maybe(int), bool,
-		bool, bool, bool, maybe(string), bool, bool,
-		diff_out__output_style).
-:- mode postprocess_output_style_2(in, in, in, in, in, in, in, in, in, in, in,
-		out) is semidet.
+:- pred postprocess_output_style_2(bool::in, bool::in, maybe(int)::in,
+    maybe(int)::in, bool::in, bool::in, bool::in, bool::in,
+    maybe(string)::in, bool::in, bool::in, output_style::out) is semidet.

  postprocess_output_style_2(no, no, no, no, no, no, no, no, no, no, no,
  					normal).
@@ -435,39 +451,43 @@
  %-----------------------------------------------------------------------------%

  	% Help text for the options.
-options_help -->
-	io__write_string("Output styles:\n"),
-	io__write_string("\t--help\n"),
-	io__write_string("\t\tOutput this help.\n"),
-	io__write_string("\t-v, --version\n"),
-	io__write_string("\t\tOutput version info.\n"),
-	io__write_string("\t-c, -C <num>, --context <num>\n"),
-	io__write_string("\t\tOutput <num> (default 2) lines of copied context.\n"),
-	io__write_string("\t-u, -U <num>, --unified <num>\n"),
-	io__write_string("\t\tOutput <num> (default 2) lines of unified context.\n"),
-	io__write_string("\t\t-L <label>, --label <label>  Use <label> instead of file name.\n"),
-	io__write_string("\t-e, --ed\n"),
-	io__write_string("\t\tOutput an ed script.\n"),
-	io__write_string("\t-f, --forward-ed\n"),
-	io__write_string("\t\tProduce output similar to --ed, not useful to ed(1),\n"),
-	io__write_string("\t\tand in the opposite order.\n"),
-	io__write_string("\t-n, --rcs\n"),
-	io__write_string("\t\tOutput an RCS format diff.\n"),
-	io__write_string("\t-q, --brief\n"),
-	io__write_string("\t\tOutput only whether or not files differ.\n"),
-	io__write_string("\t-D <name>, --ifdef <name>\n"),
-	io__write_string("\t\tProduce output in #ifdef <name> format.\n"), 
-	io__write_string("\t-y, --side-by-side\n"),
-	io__write_string("\t\tProduce output in side-by-side format.\n"),
-	io__write_string("\t\t-w <num>, --width <num>  Output at most <num> (default 130)\n"),
-	io__write_string("\t\t\tcharacters per line.\n"),
-	io__write_string("\t\t--left-column  Output only the left column of common lines.\n"),
-	io__write_string("\t\t--suppress-common-lines  Do not output common lines.\n"),
-	io__write_string("\nMatching options:\n"),
-	io__write_string("\t-d, --minimal\n"),
-	io__write_string("\t\tTry hard to find as small a set of changes as possible.\n"),
-	io__write_string("\t-B, --ignore-blank-lines\n"),
-	io__write_string("\t\tIgnore changes whose lines are all blank.\n").
+    %
+options_help(!IO) :-
+    io.write_strings([
+        "Output styles:\n",
+        "\t--help\n",
+        "\t\tOutput this help.\n",
+        "\t-v, --version\n",
+        "\t\tOutput version info.\n",
+        "\t-c, -C <num>, --context <num>\n",
+        "\t\tOutput <num> (default 2) lines of copied context.\n",
+        "\t-u, -U <num>, --unified <num>\n",
+        "\t\tOutput <num> (default 2) lines of unified context.\n",
+        "\t\t-L <label>, --label <label>  Use <label> instead of file name.\n",
+        "\t-e, --ed\n",
+        "\t\tOutput an ed script.\n",
+        "\t-f, --forward-ed\n",
+        "\t\tProduce output similar to --ed, not useful to ed(1),\n",
+        "\t\tand in the opposite order.\n",
+        "\t-n, --rcs\n",
+        "\t\tOutput an RCS format diff.\n",
+        "\t-q, --brief\n",
+        "\t\tOutput only whether or not files differ.\n",
+        "\t-D <name>, --ifdef <name>\n",
+        "\t\tProduce output in #ifdef <name> format.\n", 
+        "\t-y, --side-by-side\n",
+        "\t\tProduce output in side-by-side format.\n",
+        "\t\t-w <num>, --width <num>  Output at most <num> (default 130)\n",
+        "\t\t\tcharacters per line.\n",
+        "\t\t--left-column  Output only the left column of common lines.\n",
+        "\t\t--suppress-common-lines  Do not output common lines.\n",
+        "\nMatching options:\n",
+        "\t-d, --minimal\n",
+        "\t\tTry hard to find as small a set of changes as possible.\n",
+        "\t-B, --ignore-blank-lines\n",
+        "\t\tIgnore changes whose lines are all blank.\n"
+    ], !IO).

  %-----------------------------------------------------------------------------%
+:- end_module options.
  %-----------------------------------------------------------------------------%

--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list