[m-rev.] For review: use XML browser to browse terms in mdb

Ian MacLarty maclarty at cs.mu.OZ.AU
Thu Dec 9 12:50:24 AEDT 2004


Note this is a sub-diff of the previous post with the same subject.  The 
other parts of the original diff are now being posted seperately.

For review by anyone.

Estimated hours taken: 5
Branches: main

Allow terms to be saved as XML in mdb and allow an XML browser to be invoked on
browsable objects in mdb.  The user can set two options which control where the
XML is dumped and the command used to browse the XML.  The defaults assume
xsltproc and mozilla are installed.

browser/browse.m
	Add a predicate to save a browser term as XML to a file.

doc/user_guide.texi
	Document new --xml option for the mdb `browse' command.
	Document new --xml option for the mdb `save_to_file' command.
	Document the `set xml_tmp_filename' and `set xml_browser_cmd' commands.

scripts/Mmakefile
	Copy extras/xml_stylesheets/xul_tree.xsl to the mdb install 
	directory so it can be used by the default XML browser command.

scripts/mdbrc.in
	Set default values for xml_browser_cmd and xml_tmp_filename.

tests/debugger/browser_test.inp
tests/debugger/browser_test.exp
	Test --xml option for `browse' command.

trace/mercury_trace_browse.c
trace/mercury_trace_browse.h
	Add functions to save a term as XML to a file and then
	invoke the user's XML browser.

trace/mercury_trace_internal.c
	Add --xml option to `browse' and `save_to_file' mdb commands and
	handle this option.

Index: browser/browse.m
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/browse.m,v
retrieving revision 1.47
diff -u -r1.47 browse.m
--- browser/browse.m	5 Nov 2004 06:30:19 -0000	1.47
+++ browser/browse.m	9 Dec 2004 01:38:16 -0000
@@ -94,6 +94,13 @@
 :- pred save_term_to_file(string::in, string::in, browser_term::in,
 	io__output_stream::in, io::di, io::uo) is cc_multi.
 
+	% save_term_to_file_xml(FileName, BrowserTerm, Out, !IO):
+	% Save BrowserTerm to FileName as an XML document.  If there
+	% is an error, print an error message to Out.
+	%
+:- pred save_term_to_file_xml(string::in, browser_term::in,
+	io__output_stream::in, io::di, io::uo) is cc_multi.
+
 %---------------------------------------------------------------------------%
 
 :- implementation.
@@ -103,7 +110,7 @@
 :- import_module mdb__frame.
 :- import_module mdb__sized_pretty.
 
-:- import_module bool, string, int, char, map, std_util.
+:- import_module bool, string, int, char, map, std_util, term_to_xml.
 :- import_module parser, require, pprint, getopt, deconstruct.
 
 %---------------------------------------------------------------------------%
@@ -126,6 +133,9 @@
 :- pragma export(save_term_to_file(in, in, in, in, di, uo),
 	"ML_BROWSE_save_term_to_file").
 
+:- pragma export(save_term_to_file_xml(in, in, in, di, uo),
+	"ML_BROWSE_save_term_to_file_xml").
+
 %---------------------------------------------------------------------------%
 %
 % If the term browser is called from the internal debugger, input is
@@ -176,6 +186,49 @@
 				io__write_string("=\n", !IO),
 				save_univ(1, Result, !IO),
 				io__write_string("\n", !IO)
+			)
+		),
+		io__told(!IO)
+	;
+		FileStreamRes = error(Error),
+		io__error_message(Error, Msg),
+		io__write_string(OutStream, Msg, !IO)
+	).
+
+:- type xml_predicate_wrapper
+	--->	predicate(
+			predicate_name		:: string, 
+			predicate_arguments	:: list(univ)
+		).
+
+:- type xml_function_wrapper
+	--->	function(
+			function_name		:: string, 
+			function_arguments	:: list(univ), 
+			return_value		:: univ
+		).
+
+save_term_to_file_xml(FileName, BrowserTerm, OutStream, !IO) :-
+	io__tell(FileName, FileStreamRes, !IO),
+	(
+		FileStreamRes = ok,
+		(
+			BrowserTerm = plain_term(Univ),
+			Term = univ_value(Univ),
+			term_to_xml.write_xml_doc_cc(Term, simple,
+				no_stylesheet, 	no_dtd, _, !IO)
+		;
+			BrowserTerm = synthetic_term(Functor, Args, MaybeRes),
+			(
+				MaybeRes = no,
+				PredicateTerm = predicate(Functor, Args),
+				term_to_xml.write_xml_doc_cc(PredicateTerm, 
+					simple, no_stylesheet, no_dtd, _, !IO)
+			;
+				MaybeRes = yes(Result),
+				FunctionTerm = function(Functor, Args, Result),
+				term_to_xml.write_xml_doc_cc(FunctionTerm, 
+					simple, no_stylesheet, no_dtd, _, !IO)
 			)
 		),
 		io__told(!IO)
Index: doc/user_guide.texi
===================================================================
RCS file: /home/mercury1/repository/mercury/doc/user_guide.texi,v
retrieving revision 1.399
diff -u -r1.399 user_guide.texi
--- doc/user_guide.texi	9 Dec 2004 01:03:09 -0000	1.399
+++ doc/user_guide.texi	9 Dec 2004 01:38:16 -0000
@@ -2527,8 +2527,8 @@
 @c The options @samp{-f} or @samp{--flat}, @samp{-p} or @samp{--pretty},
 @c and @samp{-v} or @samp{--verbose} specify the format to use for printing.
 @sp 1
- at item browse [-fpv] @var{name}
- at itemx browse [-fpv] @var{num}
+ at item browse [-fpvx] @var{name}
+ at itemx browse [-fpvx] @var{num}
 @kindex browse (mdb command)
 Invokes an interactive term browser to browse
 the value of the variable in the current environment
@@ -2543,42 +2543,65 @@
 @sp 1
 The options @samp{-f} or @samp{--flat}, @samp{-p} or @samp{--pretty},
 and @samp{-v} or @samp{--verbose} specify the format to use for browsing.
+The @samp{-x} or @samp{--xml} option tells mdb to dump the value of the
+variable to an XML file and then invoke an XML browser on the file.
+The XML filename as well as the command to invoke the XML browser can
+be set using the @samp{set} command.  See the documentation for @samp{set}
+for more details.
 @sp 1
 For further documentation on the interactive term browser,
 invoke the @samp{browse} command from within @samp{mdb} and then
 type @samp{help} at the @samp{browser>} prompt.
 @sp 1
- at item browse [-fpv]
- at itemx browse [-fpv] goal
+ at item browse [-fpvx]
+ at itemx browse [-fpvx] goal
 Invokes the interactive term browser to browse
 the goal of the current call in its present state of instantiation.
 @sp 1
 The options @samp{-f} or @samp{--flat}, @samp{-p} or @samp{--pretty},
 and @samp{-v} or @samp{--verbose} specify the format to use for browsing.
+The @samp{-x} or @samp{--xml} option tells mdb to dump the goal to an XML file
+and then invoke an XML browser on the file.  The XML filename as well as the
+command to invoke the XML browser can be set using the @samp{set} command.  See
+the documentation for @samp{set} for more details.
 @sp 1
- at item browse [-fpv] exception
+ at item browse [-fpvx] exception
 Invokes the interactive term browser to browse
 the value of the exception at an EXCP port.
 Reports an error if the current event does not refer to such a port.
 @sp 1
 The options @samp{-f} or @samp{--flat}, @samp{-p} or @samp{--pretty},
 and @samp{-v} or @samp{--verbose} specify the format to use for browsing.
+The @samp{-x} or @samp{--xml} option tells mdb to dump the exception to an 
+XML file and then invoke an XML browser on the file.  The XML filename as well
+as the command to invoke the XML browser can be set using the @samp{set}
+command.  See the documentation for @samp{set} for more details.
 @sp 1
- at item browse [-fpv] action @var{num}
+ at item browse [-fpvx] action @var{num}
 Invokes an interactive term browser to browse a representation
 of the @var{num}'th I/O action executed by the program.
 @sp 1
 The options @samp{-f} or @samp{--flat}, @samp{-p} or @samp{--pretty},
 and @samp{-v} or @samp{--verbose} specify the format to use for browsing.
+The @samp{-x} or @samp{--xml} option tells mdb to dump the io action
+representation to an XML file and then invoke an XML browser on the file.  The
+XML filename as well as the command to invoke the XML browser can be set using
+the @samp{set} command.  See the documentation for @samp{set} for more details.
 @c @sp 1
- at c @item browse [-fpv] proc_body
+ at c @item browse [-fpvx] proc_body
 @c Invokes an interactive term browser to browse a representation
 @c of the body of the current procedure, if it is available.
 @c @sp 1
 @c The options @samp{-f} or @samp{--flat}, @samp{-p} or @samp{--pretty},
 @c and @samp{-v} or @samp{--verbose} specify the format to use for browsing.
+ at c The @samp{-x} or @samp{--xml} option tells mdb to dump the procedure
+ at c body representation to an XML file and then invoke an XML browser on the
+ at c file.  The XML filename as well as the command to invoke the XML
+ at c browser can be set using the @samp{set} command.  See the documentation
+ at c for @samp{set} for more details.
 @sp 1
- at item stack [-d] [@var{num}]
+
+ at item stack [-d] [@var{num}] 
 @kindex stack (mdb command)
 Prints the names of the ancestors of the call
 specified by the current event.
@@ -2664,9 +2687,12 @@
 @kindex size (mdb command)
 @kindex width (mdb command)
 @kindex lines (mdb command)
+ at kindex xml_browser_cmd (mdb command)
+ at kindex xml_tmp_filename (mdb command)
 Updates the configuration parameters of the browser.
 The parameters that can be configured are
- at samp{format}, @samp{depth}, @samp{size}, @samp{width} and @samp{lines}.
+ at samp{format}, @samp{depth}, @samp{size}, @samp{width}, @samp{lines}, 
+ at samp{xml_browser_cmd} and @samp{xml_tmp_filename}.
 @sp 1
 @itemize @bullet
 @item
@@ -2698,6 +2724,19 @@
 @sp 1
 @item
 @samp{lines} is the maximum number of lines of one term to display.
+ at sp 1
+ at item
+ at samp{xml_tmp_filename} is the name of the file to dump XML to before
+invoking your XML browser.
+on 
+ at sp 1
+ at item
+ at samp{xml_browser_cmd} is the shell command used to invoke your xml browser.  
+By default the program @samp{xsltproc} is invoked to apply the 
+xul_tree.xsl stylesheet in extras/xml_stylesheets, then @samp{mozilla} is
+invoked on the resulting XUL file.  You can use the apostrophe character (')
+to quote the command string when using the @samp{set} command, for example
+"set xml_browser_cmd 'firefox file:///tmp/mdbtmp.xml'".
 @end itemize
 @sp 1
 The browser maintains separate configuration parameters
@@ -2782,26 +2821,31 @@
 The option @samp{-t} (or @samp{--timeout}) specifies
 the maximum number of seconds to wait for the server to start.
 @sp 1
- at item save_to_file goal @var{filename}
+ at item save_to_file [-x] goal @var{filename}
 @kindex save_to_file (mdb command)
 Writes the goal of the current call in its present state of instantiation
-to the specified file.
+to the specified file.  The option @samp{-x} (or @samp{--xml}) causes the
+output to be in XML.
 @sp 1
- at item save_to_file exception @var{filename}
+ at item save_to_file [-x] exception @var{filename}
 Writes the value of the exception at an EXCP port
 to the specified file.
 Reports an error if the current event does not refer to such a port.
+The option @samp{-x} (or @samp{--xml}) causes the
+output to be in XML.
 @sp 1
- at item save_to_file @var{name} @var{filename}
- at itemx save_to_file @var{num} @var{filename}
+ at item save_to_file [-x] @var{name} @var{filename}
+ at itemx save_to_file [-x] @var{num} @var{filename}
 Writes the value of the variable in the current environment
 with the given ordinal number or with the given name
-to the specified file.
+to the specified file. The option @samp{-x} (or @samp{--xml}) causes the
+output to be in XML.
 @c @sp 1
- at c @item save_to_file proc_body @var{filename}
+ at c @item save_to_file [-x] proc_body @var{filename}
 @c Writes the representation of the body of the current procedure,
 @c if it is available,
- at c to the specified file.
+ at c to the specified file. The option @samp{-x} (or @samp{--xml}) causes the
+ at c output to be in XML.
 @end table
 
 @sp 1
Index: scripts/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmakefile,v
retrieving revision 1.32
diff -u -r1.32 Mmakefile
--- scripts/Mmakefile	15 May 2003 07:23:43 -0000	1.32
+++ scripts/Mmakefile	9 Dec 2004 01:38:16 -0000
@@ -18,7 +18,7 @@
 	  mtags vpath_find mercury_update_interface \
 	  mkfifo_using_mknod mercury_cleanup_install canonical_grade \
 	  mercury_config mercury.bat
-DEBUGGER_SCRIPTS = mdbrc
+DEBUGGER_SCRIPTS = mdbrc ../extras/xml_stylesheets/xul_tree.xsl
 EMACS_SCRIPTS = gud.el
 
 #-----------------------------------------------------------------------------#
Index: scripts/mdbrc.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/mdbrc.in,v
retrieving revision 1.4
diff -u -r1.4 mdbrc.in
--- scripts/mdbrc.in	19 Jul 2000 01:35:01 -0000	1.4
+++ scripts/mdbrc.in	9 Dec 2004 01:38:16 -0000
@@ -15,3 +15,5 @@
 alias	e	exception
 alias	EMPTY	step
 alias	NUMBER	step
+set xml_browser_cmd 'xsltproc @DEFAULT_MERCURY_DEBUGGER_INIT_DIR@/xul_tree.xsl /tmp/mdbtmp.xml > /tmp/mdbtmp.xul && mozilla file:///tmp/mdbtmp.xul'
+set xml_tmp_filename '/tmp/mdbtmp.xml'
Index: tests/debugger/browser_test.exp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browser_test.exp,v
retrieving revision 1.20
diff -u -r1.20 browser_test.exp
--- tests/debugger/browser_test.exp	16 Nov 2004 00:16:38 -0000	1.20
+++ tests/debugger/browser_test.exp	9 Dec 2004 01:38:16 -0000
@@ -106,6 +106,62 @@
   3, 
   big(big(small, 4, big(small, 5, small)), 6, small))
 browser> quit
+mdb> set xml_tmp_filename './tmp.xml'
+mdb> set xml_browser_cmd 'cat ./tmp.xml'
+mdb> browse --xml 1
+<?xml version="1.0"?>
+<big functor="big" type="browser_test.big" arity="3">
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">1</Int>
+			<small functor="small" type="browser_test.big" arity="0" />
+		</big>
+		<Int type="int">2</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+	<Int type="int">3</Int>
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">4</Int>
+			<big functor="big" type="browser_test.big" arity="3">
+				<small functor="small" type="browser_test.big" arity="0" />
+				<Int type="int">5</Int>
+				<small functor="small" type="browser_test.big" arity="0" />
+			</big>
+		</big>
+		<Int type="int">6</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+</big>
+mdb> browse -x Data
+<?xml version="1.0"?>
+<big functor="big" type="browser_test.big" arity="3">
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">1</Int>
+			<small functor="small" type="browser_test.big" arity="0" />
+		</big>
+		<Int type="int">2</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+	<Int type="int">3</Int>
+	<big functor="big" type="browser_test.big" arity="3">
+		<big functor="big" type="browser_test.big" arity="3">
+			<small functor="small" type="browser_test.big" arity="0" />
+			<Int type="int">4</Int>
+			<big functor="big" type="browser_test.big" arity="3">
+				<small functor="small" type="browser_test.big" arity="0" />
+				<Int type="int">5</Int>
+				<small functor="small" type="browser_test.big" arity="0" />
+			</big>
+		</big>
+		<Int type="int">6</Int>
+		<small functor="small" type="browser_test.big" arity="0" />
+	</big>
+</big>
 mdb> set -A -f depth 1
 mdb> print *
        Data (arg 1)           	big(big/3, 3, big/3)
Index: tests/debugger/browser_test.inp
===================================================================
RCS file: /home/mercury1/repository/tests/debugger/browser_test.inp,v
retrieving revision 1.11
diff -u -r1.11 browser_test.inp
--- tests/debugger/browser_test.inp	5 Nov 2004 06:30:20 -0000	1.11
+++ tests/debugger/browser_test.inp	9 Dec 2004 01:38:16 -0000
@@ -36,6 +36,10 @@
 cdr 3 ../1/..
 ls
 quit
+set xml_tmp_filename './tmp.xml'
+set xml_browser_cmd 'cat ./tmp.xml'
+browse --xml 1
+browse -x Data
 set -A -f depth 1
 print *
 print Data/1
Index: trace/mercury_trace_browse.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.c,v
retrieving revision 1.33
diff -u -r1.33 mercury_trace_browse.c
--- trace/mercury_trace_browse.c	25 Oct 2004 05:30:19 -0000	1.33
+++ trace/mercury_trace_browse.c	9 Dec 2004 01:38:16 -0000
@@ -100,6 +100,21 @@
 }
 
 void
+MR_trace_save_term_xml(const char *filename, MR_Word browser_term)
+{
+	MercuryFile	mdb_out;
+	MR_String	mercury_filename;
+
+	mercury_filename = (MR_String) (MR_Integer) filename;
+
+	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
+	MR_TRACE_CALL_MERCURY(
+		ML_BROWSE_save_term_to_file_xml(mercury_filename, 
+			browser_term, &mdb_out);
+	);
+}
+
+void
 MR_trace_browse(MR_Word type_info, MR_Word value, MR_Browse_Format format)
 {
 	MercuryFile	mdb_in;
Index: trace/mercury_trace_browse.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.h,v
retrieving revision 1.17
diff -u -r1.17 mercury_trace_browse.h
--- trace/mercury_trace_browse.h	25 Oct 2004 05:30:19 -0000	1.17
+++ trace/mercury_trace_browse.h	9 Dec 2004 01:38:16 -0000
@@ -35,6 +35,8 @@
 */
 
 extern	void	MR_trace_save_term(const char *filename, MR_Word browser_term);
+extern	void	MR_trace_save_term_xml(const char *filename, 
+			MR_Word browser_term);
 
 /*
 ** The following types must correspond with browse_caller_type and
Index: trace/mercury_trace_internal.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_internal.c,v
retrieving revision 1.181
diff -u -r1.181 mercury_trace_internal.c
--- trace/mercury_trace_internal.c	9 Dec 2004 01:03:22 -0000	1.181
+++ trace/mercury_trace_internal.c	9 Dec 2004 01:40:44 -0000
@@ -84,6 +84,12 @@
 /* If a number has more than this many chars, the user is in trouble. */
 #define	MR_NUMBER_LEN		80
 
+/* An upper bound on the length of the xml browser temporary file name */
+#define MR_XML_TMP_FILENAME_LENGTH	1024
+
+/* An upper bound on the length of the xml browser command */
+#define MR_XML_BROWSER_COMMAND_LENGTH	4096
+
 #define	MDBRC_FILENAME		".mdbrc"
 #define	DEFAULT_MDBRC_FILENAME	"mdbrc"
 
@@ -171,6 +177,13 @@
 static	MR_bool			MR_print_optionals = MR_FALSE;
 
 /*
+** These variables tell mdb how to invoke the user's xml browser.
+*/
+
+static	char	MR_xml_browser_command[MR_XML_BROWSER_COMMAND_LENGTH] = "";
+static	char	MR_xml_tmp_filename[MR_XML_TMP_FILENAME_LENGTH] = "";
+
+/*
 ** MR_context_position specifies whether we print context at events,
 ** and if so, where.
 */
@@ -518,7 +531,7 @@
 			const char *cat, const char *item);
 static	MR_bool	MR_trace_options_confirmed(MR_bool *confirmed, char ***words,
 			int *word_count, const char *cat, const char *item);
-static	MR_bool	MR_trace_options_format(MR_Browse_Format *format,
+static	MR_bool	MR_trace_options_format(MR_Browse_Format *format, MR_bool *xml,
 			char ***words, int *word_count, const char *cat,
 			const char *item);
 static	MR_bool	MR_trace_options_param_set(MR_Word *print_set,
@@ -544,6 +557,9 @@
 static	MR_bool	MR_trace_options_all_procedures(MR_bool *separate,
 			MR_bool *uci, char ***words, int *word_count,
 			const char *cat, const char *item);
+static	MR_bool	MR_trace_options_save_to_file(MR_bool *xml,
+			char ***words, int *word_count, const char *cat, 
+			const char *item);
 static	void	MR_trace_usage(const char *cat, const char *item);
 static	void	MR_trace_do_noop(void);
 
@@ -634,6 +650,14 @@
 			MR_Browser browser, MR_Browse_Caller_Type caller,
 			MR_Browse_Format format);
 
+/* Functions to invoke the user's XML browser on terms or goals */
+static	void	MR_trace_save_and_invoke_xml_browser(MR_Word browser_term);
+static	void	MR_trace_browse_xml(MR_Word type_info, MR_Word value,
+			MR_Browse_Caller_Type caller, MR_Browse_Format format);
+static	void	MR_trace_browse_goal_xml(MR_ConstString name,
+			MR_Word arg_list, MR_Word is_func,
+			MR_Browse_Caller_Type caller, MR_Browse_Format format);
+
 static	const char *MR_trace_read_help_text(void);
 static	const char *MR_trace_parse_line(char *line,
 			char ***words, int *word_max, int *word_count);
@@ -1204,6 +1228,33 @@
 }
 
 static void
+MR_trace_save_and_invoke_xml_browser(MR_Word browser_term)
+{
+	MR_trace_save_term_xml(MR_xml_tmp_filename, browser_term);
+
+	if (system(MR_xml_browser_command) == -1) {
+		fflush(MR_mdb_out);
+		fprintf(MR_mdb_err, 
+			"\nmdb: Error invoking XML browser using command:\n"
+			"\"%s\"\n", MR_xml_browser_command);
+	}
+}
+
+static void
+MR_trace_browse_xml(MR_Word type_info, MR_Word value,
+		MR_Browse_Caller_Type caller, MR_Browse_Format format)
+{
+	MR_Word		browser_term;
+
+	browser_term = MR_type_value_to_browser_term((MR_TypeInfo) type_info,
+		value);
+	
+	MR_trace_save_term_xml("tmp.xml", browser_term);
+
+	MR_trace_save_and_invoke_xml_browser(browser_term);
+}
+
+static void
 MR_trace_browse_goal_internal(MR_ConstString name, MR_Word arg_list,
 	MR_Word is_func, MR_Browse_Caller_Type caller, MR_Browse_Format format)
 {
@@ -1228,6 +1279,17 @@
 	}
 }
 
+static void
+MR_trace_browse_goal_xml(MR_ConstString name, MR_Word arg_list,
+	MR_Word is_func, MR_Browse_Caller_Type caller, MR_Browse_Format format)
+{
+	MR_Word		browser_term;
+
+	browser_term = MR_synthetic_to_browser_term(name, arg_list, is_func);
+
+	MR_trace_save_and_invoke_xml_browser(browser_term);
+}
+
 static const char *
 MR_trace_browse_exception(MR_Event_Info *event_info, MR_Browser browser,
 	MR_Browse_Caller_Type caller, MR_Browse_Format format)
@@ -1948,12 +2010,16 @@
 	MR_Code **jumpaddr)
 {
 	MR_Browse_Format	format;
+	MR_bool			xml;
 	int			n;
 
-	if (! MR_trace_options_format(&format, &words, &word_count,
+	if (! MR_trace_options_format(&format, &xml, &words, &word_count,
 		"browsing", "print"))
 	{
 		; /* the usage message has already been printed */
+	} else if (xml) {
+		/* the --xml option is not valid for print */
+		MR_trace_usage("browsing", "print");
 	} else if (word_count == 1) {
 		const char	*problem;
 
@@ -2020,64 +2086,76 @@
 	MR_Code **jumpaddr)
 {
 	MR_Browse_Format	format;
+	MR_bool			xml;
 	int			n;
+	MR_GoalBrowser		goal_browser;
+	MR_Browser		browser;
 
-	if (! MR_trace_options_format(&format, &words, &word_count,
+	if (! MR_trace_options_format(&format, &xml, &words, &word_count,
 		"browsing", "browse"))
 	{
 		; /* the usage message has already been printed */
-	} else if (word_count == 1) {
-		const char	*problem;
-
-		problem = MR_trace_browse_one_goal(MR_mdb_out,
-			MR_trace_browse_goal_internal,
-			MR_BROWSE_CALLER_BROWSE, format);
-
-		if (problem != NULL) {
-			fflush(MR_mdb_out);
-			fprintf(MR_mdb_err, "mdb: %s.\n", problem);
+	} else {
+		if (xml) {
+			goal_browser = MR_trace_browse_goal_xml;
+			browser = MR_trace_browse_xml;
+		} else {
+			goal_browser = MR_trace_browse_goal_internal;
+			browser = MR_trace_browse_internal;
 		}
-	} else if (word_count == 2) {
-		const char	*problem;
+		if (word_count == 1) {
+			const char	*problem;
 
-		if (MR_streq(words[1], "goal")) {
 			problem = MR_trace_browse_one_goal(MR_mdb_out,
-				MR_trace_browse_goal_internal,
-				MR_BROWSE_CALLER_BROWSE, format);
-		} else if (MR_streq(words[1], "exception")) {
-			problem = MR_trace_browse_exception(event_info,
-				MR_trace_browse_internal,
+				goal_browser,
 				MR_BROWSE_CALLER_BROWSE, format);
-		} else if (MR_streq(words[1], "proc_body")) {
-			problem = MR_trace_browse_proc_body(event_info,
-				MR_trace_browse_internal,
-				MR_BROWSE_CALLER_BROWSE, format);
-		} else {
-			problem = MR_trace_parse_browse_one(MR_mdb_out,
-				MR_FALSE, words[1], MR_trace_browse_internal,
-				MR_BROWSE_CALLER_BROWSE, format,
-				MR_TRUE);
-		}
 
-		if (problem != NULL) {
-			fflush(MR_mdb_out);
-			fprintf(MR_mdb_err, "mdb: %s.\n", problem);
-		}
-	} else if (word_count == 3 && MR_streq(words[1], "action")
-		&& MR_trace_is_natural_number(words[2], &n))
-	{
-		const char	*problem;
+			if (problem != NULL) {
+				fflush(MR_mdb_out);
+				fprintf(MR_mdb_err, "mdb: %s.\n", problem);
+			}
+		} else if (word_count == 2) {
+			const char	*problem;
 
-		problem = MR_trace_browse_action(MR_mdb_out, n,
-				MR_trace_browse_goal_internal,
-				MR_BROWSE_CALLER_BROWSE, format);
+			if (MR_streq(words[1], "goal")) {
+				problem = MR_trace_browse_one_goal(MR_mdb_out,
+					goal_browser, MR_BROWSE_CALLER_BROWSE,
+					format);
+			} else if (MR_streq(words[1], "exception")) {
+				problem = MR_trace_browse_exception(event_info,
+					browser, MR_BROWSE_CALLER_BROWSE,
+					format);
+			} else if (MR_streq(words[1], "proc_body")) {
+				problem = MR_trace_browse_proc_body(event_info,
+					browser, MR_BROWSE_CALLER_BROWSE,
+					format);
+			} else {
+				problem = MR_trace_parse_browse_one(MR_mdb_out,
+					MR_FALSE, words[1], browser,
+					MR_BROWSE_CALLER_BROWSE, format,
+					MR_TRUE);
+			}
 
-		if (problem != NULL) {
-			fflush(MR_mdb_out);
-			fprintf(MR_mdb_err, "mdb: %s.\n", problem);
+			if (problem != NULL) {
+				fflush(MR_mdb_out);
+				fprintf(MR_mdb_err, "mdb: %s.\n", problem);
+			}
+		} else if (word_count == 3 && MR_streq(words[1], "action")
+			&& MR_trace_is_natural_number(words[2], &n))
+		{
+			const char	*problem;
+
+			problem = MR_trace_browse_action(MR_mdb_out, n,
+					goal_browser, MR_BROWSE_CALLER_BROWSE,
+					format);
+
+			if (problem != NULL) {
+				fflush(MR_mdb_out);
+				fprintf(MR_mdb_err, "mdb: %s.\n", problem);
+			}
+		} else {
+			MR_trace_usage("browsing", "browse");
 		}
-	} else {
-		MR_trace_usage("browsing", "browse");
 	}
 
 	return KEEP_INTERACTING;
@@ -2159,13 +2237,17 @@
 	MR_Word			verbose_format;
 	MR_Word			pretty_format;
 
-	if (! MR_trace_options_param_set(&print_set, &browse_set,
+	if (word_count == 3 && MR_streq(words[1], "xml_browser_cmd")) {
+		strcpy(MR_xml_browser_command, words[2]);
+	} else if (word_count == 3 && MR_streq(words[1], "xml_tmp_filename")) {
+		strcpy(MR_xml_tmp_filename, words[2]);
+	} else if (! MR_trace_options_param_set(&print_set, &browse_set,
 		&print_all_set, &flat_format, &raw_pretty_format,
 		&verbose_format, &pretty_format, &words, &word_count,
 		"parameter", "set"))
 	{
 		; /* the usage message has already been printed */
-	}
+	} 
 	else if (word_count != 3 ||
 		! MR_trace_set_browser_param(print_set, browse_set,
 			print_all_set, flat_format, raw_pretty_format,
@@ -2223,8 +2305,13 @@
 	MR_bool			verbose = MR_FALSE;
 	MR_Word			browser_term;
 	const char		*problem = NULL;
+	MR_bool			xml = MR_FALSE;
 
-	if (word_count != 3) {
+	if (! MR_trace_options_save_to_file(&xml, &words, &word_count,
+		"browsing", "save_to_file"))
+	{
+		; /* the usage message has already been printed */
+	} else if (word_count != 3) {
 		MR_trace_usage("browsing", "save_to_file");
 	} else {
 		if (MR_streq(words[1], "goal")) {
@@ -2276,7 +2363,11 @@
 			fflush(MR_mdb_out);
 			fprintf(MR_mdb_err, "mdb: %s.\n", problem);
 		} else {
-			MR_trace_save_term(words[2], browser_term);
+			if (xml) {
+				MR_trace_save_term_xml(words[2], browser_term);
+			} else {
+				MR_trace_save_term(words[2], browser_term);
+			}
 		}
 	}
 
@@ -6180,18 +6271,20 @@
 	{ "raw_pretty",	MR_no_argument,	NULL,	'r' },
 	{ "verbose",	MR_no_argument,	NULL,	'v' },
 	{ "pretty",	MR_no_argument,	NULL,	'p' },
+	{ "xml",	MR_no_argument,	NULL,	'x' },
 	{ NULL,		MR_no_argument,	NULL,	0 }
 };
 
 static MR_bool
-MR_trace_options_format(MR_Browse_Format *format, char ***words,
+MR_trace_options_format(MR_Browse_Format *format, MR_bool *xml, char ***words,
 	int *word_count, const char *cat, const char *item)
 {
 	int	c;
 
 	*format = MR_BROWSE_DEFAULT_FORMAT;
+	*xml = MR_FALSE;
 	MR_optind = 0;
-	while ((c = MR_getopt_long(*word_count, *words, "frvp",
+	while ((c = MR_getopt_long(*word_count, *words, "frvpx",
 		MR_trace_format_opts, NULL)) != EOF)
 	{
 		switch (c) {
@@ -6212,6 +6305,10 @@
 				*format = MR_BROWSE_FORMAT_PRETTY;
 				break;
 
+			case 'x':
+				*xml = MR_TRUE;
+				break;
+
 			default:
 				MR_trace_usage(cat, item);
 				return MR_FALSE;
@@ -6563,6 +6660,39 @@
 	return MR_TRUE;
 }
 
+static struct MR_option MR_trace_save_to_file_opts[] =
+{
+	{ "xml",		MR_no_argument,		NULL,	'x' },
+	{ NULL,			MR_no_argument,		NULL,	0 }
+};
+
+static MR_bool
+MR_trace_options_save_to_file(MR_bool *xml,
+	char ***words, int *word_count, const char *cat, const char *item)
+{
+	int	c;
+
+	MR_optind = 0;
+	while ((c = MR_getopt_long(*word_count, *words, "x", 
+		MR_trace_save_to_file_opts, NULL)) != EOF)
+	{
+		switch (c) {
+
+			case 'x':
+				*xml = MR_TRUE;
+				break;
+
+			default:
+				MR_trace_usage(cat, item);
+				return MR_FALSE;
+		}
+	}
+
+	*words = *words + MR_optind - 1;
+	*word_count = *word_count - MR_optind + 1;
+	return MR_TRUE;
+}
+
 static void
 MR_trace_usage(const char *cat, const char *item)
 /* cat is unused now, but could be used later */
@@ -7238,9 +7368,9 @@
 static const char *const	MR_trace_set_cmd_args[] =
 	{ "-A", "-B", "-P", "-f", "-p", "-v",
 	"--print-all", "--print", "--browse",
-	"--flat", "--pretty", "--verbose",
-	"format", "depth", "size", "width", "lines",
-	"flat", "pretty", "verbose", NULL };
+	"--flat", "--pretty", "--verbose", "xml_tmp_filename",
+	"xml_browser_cmd", "format", "depth", "size", "width", "lines", "flat",
+	"pretty", "verbose", NULL };
 
 static const char *const	MR_trace_view_cmd_args[] =
 	{ "-c", "-f", "-n", "-s", "-t", "-v", "-w", "-2",
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list