[m-rev.] for review: fix mdb output redirection bug

Simon Taylor stayl at cs.mu.OZ.AU
Wed Jan 23 03:56:53 AEDT 2002


Estimated hours taken: 1

Fix a bug which caused the output of mdb's help command
to go to the program's output stream, not mdb's.

trace/mercury_trace_help.c:
	Fix the output stream handling.

trace/mercury_trace_browse.c:
trace/mercury_trace_util.c:
trace/mercury_trace_util.h:
	Move `MR_c_file_to_mercury_file()' to mercury_trace_util.c,
	for use by mercury_trace_help.c.


Index: trace/mercury_trace_browse.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_browse.c,v
retrieving revision 1.22
diff -u -u -r1.22 mercury_trace_browse.c
--- trace/mercury_trace_browse.c	12 Jan 2002 09:08:14 -0000	1.22
+++ trace/mercury_trace_browse.c	22 Jan 2002 04:20:25 -0000
@@ -48,12 +48,6 @@
 static	bool		MR_trace_is_portray_format(const char *str,
 				MR_Browse_Format *format);
 
-static void
-MR_c_file_to_mercury_file(FILE *c_file, MercuryFile *mercury_file)
-{
-	MR_mercuryfile_init(c_file, 1, mercury_file);
-}
-
 void
 MR_trace_browse(MR_Word type_info, MR_Word value, MR_Browse_Format format)
 {
Index: trace/mercury_trace_help.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_help.c,v
retrieving revision 1.14
diff -u -u -r1.14 mercury_trace_help.c
--- trace/mercury_trace_help.c	23 Nov 2000 02:01:09 -0000	1.14
+++ trace/mercury_trace_help.c	22 Jan 2002 16:50:06 -0000
@@ -28,6 +28,7 @@
 #include "mercury_deep_copy.h"
 
 #include "mercury_trace_help.h"
+#include "mercury_trace_internal.h"
 #include "mercury_trace_util.h"
 
 #ifdef MR_HIGHLEVEL_CODE
@@ -43,7 +44,6 @@
 
 static	MR_Word		MR_trace_help_system;
 static	MR_TypeInfo	MR_trace_help_system_type;
-static	MR_Word		MR_trace_help_stdout;
 
 static	const char	*MR_trace_help_add_node(MR_Word path, const char *name,
 				int slot, const char *text);
@@ -110,10 +110,14 @@
 void
 MR_trace_help(void)
 {
+	MercuryFile mdb_out;
+
 	MR_trace_help_ensure_init();
 
+	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
+
 	MR_TRACE_CALL_MERCURY(
-		ML_HELP_help(MR_trace_help_system, MR_trace_help_stdout);
+		ML_HELP_help(MR_trace_help_system, (MR_Word) &mdb_out);
 	);
 }
 
@@ -121,6 +125,7 @@
 MR_trace_help_word(const char *word)
 {
 	char	*word_on_heap;
+	MercuryFile mdb_out;
 
 	MR_trace_help_ensure_init();
 
@@ -128,9 +133,10 @@
 		MR_make_aligned_string_copy(word_on_heap, word);
 	);
 
+	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
 	MR_TRACE_CALL_MERCURY(
 		ML_HELP_name(MR_trace_help_system, word_on_heap,
-			MR_trace_help_stdout);
+			(MR_Word) &mdb_out);
 	);
 }
 
@@ -143,6 +149,7 @@
 	char	*category_on_heap;
 	char	*item_on_heap;
 	bool	error;
+	MercuryFile mdb_out;
 
 	MR_trace_help_ensure_init();
 
@@ -154,8 +161,10 @@
 		path = MR_list_cons((MR_Word) category_on_heap, path);
 	);
 
+	MR_c_file_to_mercury_file(MR_mdb_out, &mdb_out);
 	MR_TRACE_CALL_MERCURY(
-		ML_HELP_path(MR_trace_help_system, path, MR_trace_help_stdout, &result);
+		ML_HELP_path(MR_trace_help_system, path,
+			(MR_Word) &mdb_out, &result);
 		error = ML_HELP_result_is_error(result, &msg);
 	);
 
@@ -169,7 +178,6 @@
 {
 	static	bool	done = FALSE;
 	MR_Word		typeinfo_type;
-	MR_Word		output_stream_type;
 	MR_Word		MR_trace_help_system_type_word;
 
 	if (! done) {
@@ -180,8 +188,6 @@
 			MR_trace_help_system_type =
 				(MR_TypeInfo) MR_trace_help_system_type_word;
 			ML_HELP_init(&MR_trace_help_system);
-			ML_io_output_stream_type(&output_stream_type);
-			ML_io_stdout_stream(&MR_trace_help_stdout);
 		);
 
 		MR_trace_help_system_type = (MR_TypeInfo) MR_make_permanent(
@@ -189,9 +195,6 @@
 					(MR_TypeInfo) typeinfo_type);
 		MR_trace_help_system = MR_make_permanent(MR_trace_help_system,
 					MR_trace_help_system_type);
-		MR_trace_help_stdout = MR_make_permanent(MR_trace_help_stdout,
-					(MR_TypeInfo) output_stream_type);
-
 		done = TRUE;
 	}
 }
Index: trace/mercury_trace_util.c
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_util.c,v
retrieving revision 1.6
diff -u -u -r1.6 mercury_trace_util.c
--- trace/mercury_trace_util.c	22 Nov 2001 11:37:20 -0000	1.6
+++ trace/mercury_trace_util.c	22 Jan 2002 04:20:08 -0000
@@ -13,8 +13,15 @@
 
 #include "mercury_imp.h"
 #include "mercury_trace_util.h"
+#include "mercury_file.h"
 
 #include <ctype.h>
+
+void
+MR_c_file_to_mercury_file(FILE *c_file, MercuryFile *mercury_file)
+{
+	MR_mercuryfile_init(c_file, 1, mercury_file);
+}
 
 bool
 MR_trace_is_number(const char *word, int *value)
Index: trace/mercury_trace_util.h
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/mercury_trace_util.h,v
retrieving revision 1.5
diff -u -u -r1.5 mercury_trace_util.h
--- trace/mercury_trace_util.h	13 Feb 2001 08:28:27 -0000	1.5
+++ trace/mercury_trace_util.h	22 Jan 2002 16:51:04 -0000
@@ -15,9 +15,10 @@
 #ifndef MERCURY_TRACE_UTIL_H
 #define MERCURY_TRACE_UTIL_H
 
-#include "mercury_std.h"	/* for bool        */
-#include "mercury_types.h"	/* for MR_Word etc */
-#include <stdio.h>		/* for FILE        */
+#include "mercury_std.h"		/* for bool        */
+#include "mercury_types.h"		/* for MR_Word etc */
+#include "mercury_library_types.h"	/* for MercuryFile */
+#include <stdio.h>			/* for FILE        */
 
 /*
 ** When using the heap pointer, we need to restore it, in case it is
@@ -43,6 +44,13 @@
 		MR_restore_registers();					\
 		MR_save_transient_registers();				\
 	} while (0)
+
+/*
+** MR_c_file_to_mercury_file is used to convert MR_mdb_in and MR_mdb_out
+** into Mercury streams suitable for use by the browser.
+*/
+extern	void	MR_c_file_to_mercury_file(FILE *c_file,
+			MercuryFile *mercury_file);
 
 /*
 ** MR_trace_is_number checks whether the given word contains a natural number,
--------------------------------------------------------------------------
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