for review: bug fix for browser output streams.
Tyson Dowd
trd at cs.mu.OZ.AU
Mon Dec 7 17:59:17 AEDT 1998
Hi,
Here's a bug fix for the browser library.
I guess Bert would be the logical choice to review this, but
others may want to have a look.
===================================================================
Estimated hours taken: 3
Fix a bug in the debugger -- the term printing wasn't working after
you had changed the output stream -- output would be sent to the
program's output stream instead of the debugger's output stream.
browser/browse.m:
Fix the output and streams used for the term browser.
Index: browser/browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.3
diff -u -r1.3 browse.m
--- browse.m 1998/11/15 16:47:32 1.3
+++ browse.m 1998/12/02 04:36:28
@@ -59,14 +59,14 @@
%---------------------------------------------------------------------------%
browse__init_state(State) -->
- { default_state(State) }.
+ default_state(State).
% return the type_info for a browser_state type
:- pred browse__browser_state_type(type_info).
:- mode browse__browser_state_type(out) is det.
browse__browser_state_type(Type) :-
- default_state(State),
+ dummy_state(State),
Type = type_of(State).
%---------------------------------------------------------------------------%
@@ -93,12 +93,15 @@
{ get_term(State, Univ) },
{ term_size(Univ, Size) },
{ max_print_size(MaxSize) },
+ { get_output_stream(State, OutStream) },
+ io__set_output_stream(OutStream, OldStream),
( { Size =< MaxSize } ->
io__write_univ(Univ),
io__nl
;
portray_fmt(State, flat)
- ).
+ ),
+ io__set_output_stream(OldStream, _).
% The maximum estimated size for which we use `io__write'.
:- pred max_print_size(int::out) is det.
@@ -128,8 +131,14 @@
browse__browse(Object, State0, State) -->
{ type_to_univ(Object, Univ) },
{ set_term(Univ, State0, State1) },
+ { get_output_stream(State1, OutStream) },
+ { get_input_stream(State1, InStream) },
+ io__set_output_stream(OutStream, OldOutStream),
+ io__set_input_stream(InStream, OldInStream),
% startup_message,
- browse_main_loop(State1, State).
+ browse_main_loop(State1, State),
+ io__set_output_stream(OldOutStream, _),
+ io__set_input_stream(OldInStream, _).
:- pred browse_main_loop(browser_state, browser_state, io__state, io__state).
:- mode browse_main_loop(in, out, di, uo) is det.
@@ -664,86 +673,125 @@
list(dir), % root rel `present working directory'
portray_format, % format for ls.
int, % X clipping for verbose display
- int % Y clipping for verbose display
+ int, % Y clipping for verbose display
+ io__input_stream, % read input from here
+ io__output_stream % write output to here
).
% access predicates
-:- pred default_state(browser_state).
-:- mode default_state(out) is det.
-default_state(State) :-
+:- pred default_state(browser_state, io__state, io__state).
+:- mode default_state(out, di, uo) is det.
+default_state(State) -->
% We need to supply an object to initialize the state,
% but this object won't be used, since the first call
% to browse__browse will overwrite it. So we just supply
% a dummy object -- it doesn't matter what its type or value is.
- DummyObject = "",
- type_to_univ(DummyObject, Univ),
- default_depth(DefaultDepth),
- State = browser_state(Univ, 3, DefaultDepth, [], verbose, 79, 25).
+ { DummyObject = "" },
+ { type_to_univ(DummyObject, Univ) },
+ { default_depth(DefaultDepth) },
+ io__stderr_stream(StdErr),
+ io__stdin_stream(StdIn),
+ { State = browser_state(Univ, 3, DefaultDepth, [], verbose, 79, 25,
+ StdIn, StdErr) }.
+
+ % This is simply used to provide a variable of the type
+ % browser_state.
+:- pred dummy_state(browser_state).
+:- mode dummy_state(unused) is det.
+
+dummy_state(_).
:- pred get_term(browser_state, univ).
:- mode get_term(in, out) is det.
-get_term(browser_state(Univ, _Depth, _Size, _Path, _Fmt, _X, _Y), Univ).
+get_term(browser_state(Univ, _Depth, _Size, _Path, _Fmt, _X, _Y, _IS, _OS),
+ Univ).
:- pred get_depth(browser_state, int).
:- mode get_depth(in, out) is det.
-get_depth(browser_state(_Univ, Depth, _Size, _Path, _Fmt, _X, _Y), Depth).
+get_depth(browser_state(_Univ, Depth, _Size, _Path, _Fmt, _X, _Y, _IS, _OS),
+ Depth).
:- pred get_size(browser_state, int).
:- mode get_size(in, out) is det.
-get_size(browser_state(_Univ, _Depth, Size, _Path, _Fmt, _X, _Y), Size).
+get_size(browser_state(_Univ, _Depth, Size, _Path, _Fmt, _X, _Y, _IS, _OS),
+ Size).
:- pred get_clipx(browser_state, int).
:- mode get_clipx(in, out) is det.
-get_clipx(browser_state(_Univ, _Depth, _Size, _Path, _Fmt, X, _Y), X).
+get_clipx(browser_state(_Univ, _Depth, _Size, _Path, _Fmt, X, _Y, _IS, _OS),
+ X).
:- pred get_clipy(browser_state, int).
:- mode get_clipy(in, out) is det.
-get_clipy(browser_state(_Univ, _Depth, _Size, _Path, _Fmt, _X, Y), Y).
+get_clipy(browser_state(_Univ, _Depth, _Size, _Path, _Fmt, _X, Y, _IS, _OS),
+ Y).
:- pred get_dirs(browser_state, list(dir)).
:- mode get_dirs(in, out) is det.
-get_dirs(browser_state(_Univ, _Depth, _Size, Dirs, _Fmt, _X, _Y), Dirs).
+get_dirs(browser_state(_Univ, _Depth, _Size, Dirs, _Fmt, _X, _Y, _IS, _OS),
+ Dirs).
:- pred get_path(browser_state, path).
:- mode get_path(in, out) is det.
-get_path(browser_state(_Univ, _Depth, _Size, Dirs, _Fmt, _X, _Y),
+get_path(browser_state(_Univ, _Depth, _Size, Dirs, _Fmt, _X, _Y, _IS, _OS),
root_rel(Dirs)).
:- pred get_fmt(browser_state, portray_format).
:- mode get_fmt(in, out) is det.
-get_fmt(browser_state(_Univ, _Depth, _Size, _Path, Fmt, _X, _Y), Fmt).
+get_fmt(browser_state(_Univ, _Depth, _Size, _Path, Fmt, _X, _Y, _IS, _OS),
+ Fmt).
+:- pred get_input_stream(browser_state, io__input_stream).
+:- mode get_input_stream(in, out) is det.
+get_input_stream(browser_state(_Univ, _Depth, _Size, _Path, _Fmt, _X, _Y, IS,
+ _OS), IS).
+
+:- pred get_output_stream(browser_state, io__output_stream).
+:- mode get_output_stream(in, out) is det.
+get_output_stream(browser_state(_Univ, _Depth, _Size, _Path, _Fmt, _X, _Y, _IS,
+ OS), OS).
+
:- pred set_depth(int, browser_state, browser_state).
:- mode set_depth(in, in, out) is det.
set_depth(NewMaxDepth, State, NewState) :-
- State = browser_state(Univ, _MaxDepth, MaxSize, Dirs, Fmt, X, Y),
- NewState = browser_state(Univ, NewMaxDepth, MaxSize, Dirs, Fmt, X, Y).
+ State = browser_state(Univ, _MaxDepth, MaxSize, Dirs, Fmt, X, Y, IS,
+ OS),
+ NewState = browser_state(Univ, NewMaxDepth, MaxSize, Dirs, Fmt, X, Y,
+ IS, OS).
:- pred set_size(int, browser_state, browser_state).
:- mode set_size(in, in, out) is det.
set_size(NewMaxSize, State, NewState) :-
- State = browser_state(Univ, MaxDepth, _MaxSize, Dirs, Fmt, X, Y),
- NewState = browser_state(Univ, MaxDepth, NewMaxSize, Dirs, Fmt, X, Y).
+ State = browser_state(Univ, MaxDepth, _MaxSize, Dirs, Fmt, X, Y, IS,
+ OS),
+ NewState = browser_state(Univ, MaxDepth, NewMaxSize, Dirs, Fmt, X, Y,
+ IS, OS).
:- pred set_clipx(int, browser_state, browser_state).
:- mode set_clipx(in, in, out) is det.
set_clipx(NewX, State, NewState) :-
- State = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, _X, Y),
- NewState = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, NewX, Y).
+ State = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, _X, Y, IS,
+ OS),
+ NewState = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, NewX, Y,
+ IS, OS).
:- pred set_clipy(int, browser_state, browser_state).
:- mode set_clipy(in, in, out) is det.
set_clipy(NewY, State, NewState) :-
- State = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, X, _Y),
- NewState = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, X, NewY).
+ State = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, X, _Y, IS,
+ OS),
+ NewState = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, X, NewY,
+ IS, OS).
:- pred set_path(path, browser_state, browser_state).
:- mode set_path(in, in, out) is det.
set_path(NewPath, State, NewState) :-
- State = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, X, Y),
+ State = browser_state(Univ, MaxDepth, MaxSize, Dirs, Fmt, X, Y, IS,
+ OS),
change_dir(Dirs, NewPath, NewDirs),
- NewState = browser_state(Univ, MaxDepth, MaxSize, NewDirs, Fmt, X, Y).
+ NewState = browser_state(Univ, MaxDepth, MaxSize, NewDirs, Fmt, X, Y,
+ IS, OS).
:- pred change_dir(list(dir), path, list(dir)).
:- mode change_dir(in, in, out) is det.
@@ -759,8 +807,20 @@
:- pred set_fmt(portray_format, browser_state, browser_state).
:- mode set_fmt(in, in, out) is det.
-set_fmt(NewFmt, browser_state(Univ, Depth, Size, Path, _OldFmt, X, Y),
- browser_state(Univ, Depth, Size, Path, NewFmt, X, Y)).
+set_fmt(NewFmt, browser_state(Univ, Depth, Size, Path, _OldFmt, X, Y, IS, OS),
+ browser_state(Univ, Depth, Size, Path, NewFmt, X, Y, IS, OS)).
+
+:- pred set_input_stream(io__input_stream, browser_state, browser_state).
+:- mode set_input_stream(in, in, out) is det.
+set_input_stream(NewIS, browser_state(Univ, Depth, Size, Path, Fmt, X, Y,
+ _OldIS, OS),
+ browser_state(Univ, Depth, Size, Path, Fmt, X, Y, NewIS, OS)).
+
+:- pred set_output_stream(io__output_stream, browser_state, browser_state).
+:- mode set_output_stream(in, in, out) is det.
+set_output_stream(NewOS, browser_state(Univ, Depth, Size, Path, Fmt, X, Y, IS,
+ _OldOS),
+ browser_state(Univ, Depth, Size, Path, Fmt, X, Y, IS, NewOS)).
:- pred set_term(T, browser_state, browser_state).
:- mode set_term(in, in, out) is det.
@@ -773,8 +833,8 @@
:- pred set_univ(univ, browser_state, browser_state).
:- mode set_univ(in, in, out) is det.
-set_univ(NewUniv, browser_state(_OldUniv, Dep, Siz, Path, Fmt, X, Y),
- browser_state(NewUniv, Dep, Siz, Path, Fmt, X, Y)).
+set_univ(NewUniv, browser_state(_OldUniv, Dep, Siz, Path, Fmt, X, Y, IS, OS),
+ browser_state(NewUniv, Dep, Siz, Path, Fmt, X, Y, IS, OS)).
%---------------------------------------------------------------------------%
%
@@ -785,7 +845,7 @@
:- mode show_settings(in, di, uo) is det.
show_settings(State) -->
{ State = browser_state(_Univ, MaxDepth, MaxSize,
- CurPath, Fmt, X, Y) },
+ CurPath, Fmt, X, Y, _IS, _OS) },
io__write_string("Max depth is: "), io__write_int(MaxDepth), io__nl,
io__write_string("Max size is: "), io__write_int(MaxSize), io__nl,
io__write_string("X clip is: "), io__write_int(X), io__nl,
--
Tyson Dowd # There isn't any reason why Linux can't be
# implemented as an enterprise computing solution.
trd at cs.mu.oz.au # Find out what you've been missing while you've
http://www.cs.mu.oz.au/~trd # been rebooting Windows NT. -- InfoWorld, 1998.
More information about the developers
mailing list