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

Ian MacLarty maclarty at cs.mu.OZ.AU
Thu Dec 9 16:47:26 AEDT 2004


On Thu, Dec 09, 2004 at 02:32:22PM +1100, Zoltan Somogyi wrote:
> On 09-Dec-2004, Ian MacLarty <maclarty at cs.mu.OZ.AU> wrote:
> > XML is dumped and the command used to browse the XML.  The defaults assume
> > xsltproc and mozilla are installed.
> 
> How easy would it be to not require xsltproc? For example, my laptop doesn't
> have it installed. This is a question, not an objection.
> 
An <?xml-stylesheet ... ?> tag could be included in the XML with a reference to
the XSL stylesheet.  Then in theory the browser should apply the stylesheet
before displaying the XML, however in practice browser support for this seems
to be a bit flaky.  Mozilla seems to have limited support for XSL stylesheets:
for example when I included a reference to the mercury_term.xsl stylesheet then
the stylesheet was applied and the Mercury term was displayed as text, however
when I included a reference to the xul_tree.xsl stylesheet nothing was
displayed, even when I specify a media-type of
"application/vnd.mozilla.xul+xml".  So that's why I explicitly apply the
stylesheet using xsltproc before calling mozilla.

Another option is to include a binding to an XML library that supports XSL
stylesheets (this could be added to Peter's expat binding for example), then
the stylesheet could be applied in Mercury code before being passed to mozilla.
However this would rely on you having the expat libraries installed.

> > +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)
> >  			)
> >  		),
> 
> The format of the synthetic terms is not the best possible, but it is OK
> for now. However, you should put an XXX there as a reminder.
> 
I agree, though I think this is more a change to the stylesheet to get it to 
print the predicate and function elements as atoms and remove the univ_cons
wrappers around the arguments.

> > --- 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
> 
> You should add tmp.xml to the list of filenames to be removed by mmake clean
> in that directory.
>

I've renamed tmp.xml to browser_test.xml.out, so this should be a problem now.

> > +static	char	MR_xml_browser_command[MR_XML_BROWSER_COMMAND_LENGTH] = "";
> > +static	char	MR_xml_tmp_filename[MR_XML_TMP_FILENAME_LENGTH] = "";
> 
> The command name definitely should have dynamic size; as big as needed.
> This would also be nice for the filename.
> 
They are both now dynamically sized:

 /*
+** These variables tell mdb how to invoke the user's xml browser.
+*/
+
+static	char	*MR_xml_browser_command = NULL;
+static	char	*MR_xml_tmp_filename = NULL;
+
+/*

...

+	if (word_count == 3 && MR_streq(words[1], "xml_browser_cmd")) {
+		if (MR_xml_browser_command == NULL) {
+			MR_xml_browser_command = 
+				(char*)malloc(strlen(words[2]) + 1);
+		} else {
+			MR_xml_browser_command = (char*)realloc(
+				MR_xml_browser_command, strlen(words[2]) + 1);
+		}
+		strcpy(MR_xml_browser_command, words[2]);
+	} else if (word_count == 3 && MR_streq(words[1], "xml_tmp_filename")) {
+		if (MR_xml_tmp_filename == NULL) {
+			MR_xml_tmp_filename =
+				(char*)malloc(strlen(words[2]) + 1);
+		} else {
+			MR_xml_tmp_filename = (char*)realloc(
+				MR_xml_tmp_filename, strlen(words[2]) + 1);
+		}
+		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,

> > +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);
> > +}
> 
> Why the fixed filename here?
> 

This is a mistake.  The call to MR_trace_save_term_xml shouldn't even be here
since MR_trace_save_and_invoke_xml_browser calls it.

> > -	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,
> 
> At the very least, check the length of words[2] before doing the assignment.
> 

See above.

> Otherwise, the diff is fine. Commit when you have fixed the above.
> 

I'll commit it once the term_to_xml changes are reviewed, since this depends
on that diff.

Thanks for the comments,

Ian.
--------------------------------------------------------------------------
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