[m-rev.] for review: paths up to nonexistent term subterms

Zoltan Somogyi zs at csse.unimelb.edu.au
Fri Dec 5 16:47:21 AEDT 2008


I am seeking feedback on the format of the updated error message (seen in the diffs
to the .exp files) as well as on the code.

Zoltan.

When the user asks for the printing of a non-existent part of a term, make
mdb print the path up to the nonexistent part as part of the error message.

trace/mercury_trace_var.[ch]:
	Give to the function that generates those error messages a pointer
	not just to the bad part of the path, but to the full path as well,
	so it can print the good part.

	Remove fixed limits on the size of error messages.

trace/mercury_trace_spy.c:
	Conform to the change in mercury_trace_var.h.

runtime/mercury_memory.[ch]:
	Provide a mechanism for dynamically resizing character buffers
	for use by mercury_trace_vars.c. We use this instead of snprint
	because snprint isn't available or doesn't work properly on some
	platforms.

	Document a previously overlooked function.

tests/debugger/browser_test.exp3:
tests/debugger/field_names.exp:
	Update these test cases to expect the new, more informative
	error messages.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/base64
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/mopenssl
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_memory.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_memory.c,v
retrieving revision 1.39
diff -u -b -r1.39 mercury_memory.c
--- runtime/mercury_memory.c	1 Nov 2006 02:31:14 -0000	1.39
+++ runtime/mercury_memory.c	4 Dec 2008 02:34:59 -0000
@@ -289,6 +289,20 @@
     }
 }
 
+void
+MR_ensure_big_enough_buffer(char **buffer_ptr, int *buffer_size_ptr,
+    int needed_size)
+{
+    if (*buffer_size_ptr < needed_size) {
+        *buffer_size_ptr = 2 * needed_size;
+        if (*buffer_ptr == NULL) {
+            *buffer_ptr = MR_malloc(*buffer_size_ptr);
+        } else {
+            *buffer_ptr = MR_realloc((void *) *buffer_ptr, *buffer_size_ptr);
+        }
+    }
+}
+
 /*---------------------------------------------------------------------------*/
 
 /*
Index: runtime/mercury_memory.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_memory.h,v
retrieving revision 1.22
diff -u -b -r1.22 mercury_memory.h
--- runtime/mercury_memory.h	30 Jan 2008 07:01:36 -0000	1.22
+++ runtime/mercury_memory.h	4 Dec 2008 02:34:47 -0000
@@ -90,12 +90,26 @@
 ** MR_malloc(bytes):
 **	Allocates the given number of bytes.
 **
+** MR_realloc(old, bytes):
+**	Allocates the given number of bytes, copies over the old contents of
+**	the previously allocated block pointed to by old, and then frees that
+**	old block.
+**
+** MR_ensure_big_enough_buffer(buffer_ptr, buffer_size_ptr, needed_size):
+**	Given a character buffer pointed to by buffer_ptr whose is given by
+**	*buffer_size_ptr, ensure that the buffer is big enough to hold
+**	needed_size characters. If it needs to make the block bigger,
+**	this function will update both *buffer_ptr and *buffer_size_ptr.
+**
 ** MR_free(ptr):
 **	Deallocates the memory.
 */
 
 extern	void	*MR_malloc(size_t n);
 extern	void	*MR_realloc(void *old, size_t n);
+extern	void 	MR_ensure_big_enough_buffer(char **buffer_ptr,
+			int *buffer_size_ptr, int needed_size);
+
 
 #define MR_free(ptr) free(ptr)
 #define MR_free_func free
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/standalone_c
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing slice
cvs diff: Diffing ssdb
cvs diff: Diffing tests
cvs diff: Diffing tests/analysis
cvs diff: Diffing tests/analysis/ctgc
cvs diff: Diffing tests/analysis/excp
cvs diff: Diffing tests/analysis/ext
cvs diff: Diffing tests/analysis/sharing
cvs diff: Diffing tests/analysis/table
cvs diff: Diffing tests/analysis/trail
cvs diff: Diffing tests/analysis/unused_args
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
Index: tests/debugger/browser_test.exp3
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/browser_test.exp3,v
retrieving revision 1.2
diff -u -b -r1.2 browser_test.exp3
--- tests/debugger/browser_test.exp3	2 Sep 2007 22:43:01 -0000	1.2
+++ tests/debugger/browser_test.exp3	4 Dec 2008 05:35:41 -0000
@@ -178,7 +178,7 @@
 mdb> print Data/1/2
        Data (arg 1)/1/2       	2
 mdb> print 1^1^2^3
-mdb: the path 3 does not exist in variable 1.
+mdb: at 1^2^ the path 3 does not exist in variable 1.
 mdb> retry
       E2:     C2 CALL pred browser_test.big_data/1-0 (det) browser_test.m:37 (browser_test.m:20)
 mdb> break list_data
Index: tests/debugger/field_names.exp
===================================================================
RCS file: /home/mercury/mercury1/repository/tests/debugger/field_names.exp,v
retrieving revision 1.9
diff -u -b -r1.9 field_names.exp
--- tests/debugger/field_names.exp	15 Feb 2007 00:41:50 -0000	1.9
+++ tests/debugger/field_names.exp	4 Dec 2008 03:25:20 -0000
@@ -13,7 +13,7 @@
 mdb> p 5^1x
 mdb: bad component selector.
 mdb> p 5^1^x
-mdb: the path x does not exist in variable 5.
+mdb: at 1^ the path x does not exist in variable 5.
 mdb> p 5^x
 mdb: the path x does not exist in variable 5.
 mdb> p 5^1
@@ -113,19 +113,19 @@
 mdb> p 5^3^t1b
        HeadVar__5^3^t1b       	42
 mdb> p 5^3^t1c
-mdb: the path t1c does not exist in variable 5.
+mdb: at 3^ the path t1c does not exist in variable 5.
 mdb> p 5^3^t1d
        HeadVar__5^3^t1d       	44
 mdb> p 5^3^t1e
-mdb: the path t1e does not exist in variable 5.
+mdb: at 3^ the path t1e does not exist in variable 5.
 mdb> p 5^4
        HeadVar__5^4           	t1f2(51, 52, 53)
 mdb> p 5^4^t1a
-mdb: the path t1a does not exist in variable 5.
+mdb: at 4^ the path t1a does not exist in variable 5.
 mdb> p 5^4^t1e
        HeadVar__5^4^t1e       	51
 mdb> p 5^4^t1f
-mdb: the path t1f does not exist in variable 5.
+mdb: at 4^ the path t1f does not exist in variable 5.
 mdb> p 5^4^t1g
        HeadVar__5^4^t1g       	53
 mdb> p 5^t2a
@@ -137,19 +137,19 @@
 mdb> p 5^t2b^t1b
        HeadVar__5^t2b^t1b     	42
 mdb> p 5^t2b^t1c
-mdb: the path t1c does not exist in variable 5.
+mdb: at t2b^ the path t1c does not exist in variable 5.
 mdb> p 5^t2b^t1d
        HeadVar__5^t2b^t1d     	44
 mdb> p 5^t2b^t1e
-mdb: the path t1e does not exist in variable 5.
+mdb: at t2b^ the path t1e does not exist in variable 5.
 mdb> p 5^t2c
        HeadVar__5^t2c         	t1f2(51, 52, 53)
 mdb> p 5^t2c^t1a
-mdb: the path t1a does not exist in variable 5.
+mdb: at t2c^ the path t1a does not exist in variable 5.
 mdb> p 5^t2c^t1e
        HeadVar__5^t2c^t1e     	51
 mdb> p 5^t2c^t1f
-mdb: the path t1f does not exist in variable 5.
+mdb: at t2c^ the path t1f does not exist in variable 5.
 mdb> p 5^t2c^t1g
        HeadVar__5^t2c^t1g     	53
 mdb> browse 5
@@ -182,7 +182,7 @@
 mdb> p 4^1^1
        HeadVar__4^1^1         	51
 mdb> p 4^1^t1a
-mdb: the path t1a does not exist in variable 4.
+mdb: at 1^ the path t1a does not exist in variable 4.
 mdb> p 4^1^t1e
        HeadVar__4^1^t1e       	51
 mdb> p 4^1^t1g
@@ -192,9 +192,9 @@
 mdb> p 4^3
        HeadVar__4^3           	"xyzzy"
 mdb> p 4^3^1
-mdb: the path 1 does not exist in variable 4.
+mdb: at 3^ the path 1 does not exist in variable 4.
 mdb> p 4^3^t1a
-mdb: the path t1a does not exist in variable 4.
+mdb: at 3^ the path t1a does not exist in variable 4.
 mdb> p 4^4
        HeadVar__4^4           	t1f1(41, 42, 43, 44)
 mdb> p 4^4^t1a
@@ -202,17 +202,17 @@
 mdb> p 4^4^t1b
        HeadVar__4^4^t1b       	42
 mdb> p 4^4^t1c
-mdb: the path t1c does not exist in variable 4.
+mdb: at 4^ the path t1c does not exist in variable 4.
 mdb> p 4^4^t1d
        HeadVar__4^4^t1d       	44
 mdb> p 4^4^t1e
-mdb: the path t1e does not exist in variable 4.
+mdb: at 4^ the path t1e does not exist in variable 4.
 mdb> p 4^t3a
        HeadVar__4^t3a         	t1f2(51, 52, 53)
 mdb> p 4^t3a^1
        HeadVar__4^t3a^1       	51
 mdb> p 4^t3a^t1a
-mdb: the path t1a does not exist in variable 4.
+mdb: at t3a^ the path t1a does not exist in variable 4.
 mdb> p 4^t3a^t1e
        HeadVar__4^t3a^t1e     	51
 mdb> p 4^t3a^t1g
@@ -228,11 +228,11 @@
 mdb> p 4^t3d^t1b
        HeadVar__4^t3d^t1b     	42
 mdb> p 4^t3d^t1c
-mdb: the path t1c does not exist in variable 4.
+mdb: at t3d^ the path t1c does not exist in variable 4.
 mdb> p 4^t3d^t1d
        HeadVar__4^t3d^t1d     	44
 mdb> p 4^t3d^t1e
-mdb: the path t1e does not exist in variable 4.
+mdb: at t3d^ the path t1e does not exist in variable 4.
 mdb> p 4^t3e^t1a
 mdb: the path t3e^t1a does not exist in variable 4.
 mdb> step
@@ -250,19 +250,19 @@
 mdb> p 2^3^t1b
        A(1) (arg 2)^3^t1b     	42
 mdb> p 2^3^t1c
-mdb: the path t1c does not exist in variable 2.
+mdb: at 3^ the path t1c does not exist in variable 2.
 mdb> p 2^3^t1d
        A(1) (arg 2)^3^t1d     	44
 mdb> p 2^3^t1e
-mdb: the path t1e does not exist in variable 2.
+mdb: at 3^ the path t1e does not exist in variable 2.
 mdb> p 2^4
        A(1) (arg 2)^4         	t1f2(51, 52, 53)
 mdb> p 2^4^t1a
-mdb: the path t1a does not exist in variable 2.
+mdb: at 4^ the path t1a does not exist in variable 2.
 mdb> p 2^4^t1e
        A(1) (arg 2)^4^t1e     	51
 mdb> p 2^4^t1f
-mdb: the path t1f does not exist in variable 2.
+mdb: at 4^ the path t1f does not exist in variable 2.
 mdb> p 2^4^t1g
        A(1) (arg 2)^4^t1g     	53
 mdb> p 2^t2a
@@ -274,19 +274,19 @@
 mdb> p 2^t2b^t1b
        A(1) (arg 2)^t2b^t1b   	42
 mdb> p 2^t2b^t1c
-mdb: the path t1c does not exist in variable 2.
+mdb: at t2b^ the path t1c does not exist in variable 2.
 mdb> p 2^t2b^t1d
        A(1) (arg 2)^t2b^t1d   	44
 mdb> p 2^t2b^t1e
-mdb: the path t1e does not exist in variable 2.
+mdb: at t2b^ the path t1e does not exist in variable 2.
 mdb> p 2^t2c
        A(1) (arg 2)^t2c       	t1f2(51, 52, 53)
 mdb> p 2^t2c^t1a
-mdb: the path t1a does not exist in variable 2.
+mdb: at t2c^ the path t1a does not exist in variable 2.
 mdb> p 2^t2c^t1e
        A(1) (arg 2)^t2c^t1e   	51
 mdb> p 2^t2c^t1f
-mdb: the path t1f does not exist in variable 2.
+mdb: at t2c^ the path t1f does not exist in variable 2.
 mdb> p 2^t2c^t1g
        A(1) (arg 2)^t2c^t1g   	53
 mdb> step
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/par_conj
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/trailing
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
Index: trace/mercury_trace_spy.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_spy.c,v
retrieving revision 1.36
diff -u -b -r1.36 mercury_trace_spy.c
--- trace/mercury_trace_spy.c	25 Nov 2008 07:46:57 -0000	1.36
+++ trace/mercury_trace_spy.c	3 Dec 2008 08:58:13 -0000
@@ -587,7 +587,8 @@
 
     if (bad_path != NULL) {
         if (cond->MR_cond_require_var) {
-            MR_spy_point_cond_problem = MR_trace_bad_path(bad_path);
+            MR_spy_point_cond_problem = MR_trace_bad_path(cond->MR_cond_path,
+                bad_path);
             retval = MR_TRUE;
         } else {
             MR_spy_point_cond_problem = NULL;
Index: trace/mercury_trace_vars.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_vars.c,v
retrieving revision 1.81
diff -u -b -r1.81 mercury_trace_vars.c
--- trace/mercury_trace_vars.c	25 Nov 2008 07:46:57 -0000	1.81
+++ trace/mercury_trace_vars.c	4 Dec 2008 02:51:49 -0000
@@ -1453,7 +1453,7 @@
         bad_path = MR_trace_browse_var(out, print_var_name, type_info, value,
             name, path, browser, caller, format);
         if (bad_path != NULL) {
-            return MR_trace_bad_path_in_var(&var_spec, bad_path);
+            return MR_trace_bad_path_in_var(&var_spec, path, bad_path);
         }
     } else {
         int success_count;
@@ -1564,38 +1564,92 @@
 #endif
 }
 
-#define BAD_PATH_BUFFER_SIZE    128
-#define BAD_PATH_MSG_PREFIX     "the path "
-#define BAD_PATH_MSG_SUFFIX     " does not exist"
-
-static  char    MR_trace_bad_path_buffer[BAD_PATH_BUFFER_SIZE];
+#define BAD_PATH_MSG_AT                 "at "
+#define BAD_PATH_MSG_THE_PATH           "the path "
+#define BAD_PATH_MSG_DOES_NOT_EXIST     " does not exist"
+
+static  char    *MR_trace_bad_path_buffer = NULL;
+static  int     MR_trace_bad_path_buffer_size = 0;
+static  char    *MR_trace_good_path_buffer = NULL;
+static  int     MR_trace_good_path_buffer_size = 0;
 
 const char *
-MR_trace_bad_path(const char *path)
+MR_trace_bad_path(char *fullpath, char *badpath)
 {
-    if (strlen(BAD_PATH_MSG_PREFIX) + strlen(path) +
-        strlen(BAD_PATH_MSG_SUFFIX) < BAD_PATH_BUFFER_SIZE)
-    {
-        sprintf(MR_trace_bad_path_buffer, "%s%s%s", BAD_PATH_MSG_PREFIX, path,
-            BAD_PATH_MSG_SUFFIX);
-        return MR_trace_bad_path_buffer;
+    char    *s;
+    MR_bool found;
+    int     needed_bad_buf_len;
+    int     needed_good_buf_len;
+    char    *good_buf_ptr;
+
+    found = MR_FALSE;
+    s = fullpath;
+    needed_good_buf_len = 0;
+    while (*s != '\0') {
+        if (s == badpath) {
+            found = MR_TRUE;
+            break;
+        }
+
+        s++;
+        needed_good_buf_len++;
+    }
+
+    if (! found) {
+        MR_fatal_error("MR_trace_bad_path: bad_path is not in fullpath");
+    }
+
+    if (needed_good_buf_len == 0) {
+        needed_bad_buf_len = strlen(BAD_PATH_MSG_THE_PATH) + strlen(badpath) +
+            strlen(BAD_PATH_MSG_DOES_NOT_EXIST);
+        MR_ensure_big_enough_buffer(&MR_trace_bad_path_buffer,
+            &MR_trace_bad_path_buffer_size, needed_bad_buf_len);
+        sprintf(MR_trace_bad_path_buffer, "%s%s%s",
+            BAD_PATH_MSG_THE_PATH, badpath, BAD_PATH_MSG_DOES_NOT_EXIST);
     } else {
-        return "the given path does not exist";
+        MR_ensure_big_enough_buffer(&MR_trace_good_path_buffer,
+            &MR_trace_good_path_buffer_size, needed_good_buf_len);
+
+        s = fullpath;
+        good_buf_ptr = MR_trace_good_path_buffer;
+        while (*s != '\0') {
+            if (s == badpath) {
+                break;
     }
+
+            *good_buf_ptr = *s;
+            s++;
+            good_buf_ptr++;
+        }
+
+        *good_buf_ptr = '\0';
+
+        needed_bad_buf_len = strlen(BAD_PATH_MSG_AT) + needed_good_buf_len +
+            1 + strlen(BAD_PATH_MSG_THE_PATH) + strlen(badpath) +
+            strlen(BAD_PATH_MSG_DOES_NOT_EXIST);
+        MR_ensure_big_enough_buffer(&MR_trace_bad_path_buffer,
+            &MR_trace_bad_path_buffer_size, needed_bad_buf_len);
+        sprintf(MR_trace_bad_path_buffer, "%s%s %s%s%s",
+            BAD_PATH_MSG_AT, MR_trace_good_path_buffer,
+            BAD_PATH_MSG_THE_PATH, badpath, BAD_PATH_MSG_DOES_NOT_EXIST);
+    }
+
+    return MR_trace_bad_path_buffer;
 }
 
-#define BAD_VAR_PATH_BUFFER_SIZE    128
-#define BAD_VAR_PATH_MSG_MIDDLE     " in variable "
+#define BAD_VAR_PATH_MSG_IN_VAR     " in variable "
 
-static char MR_trace_bad_path_in_var_buffer[BAD_VAR_PATH_BUFFER_SIZE];
+static  char    *MR_trace_bad_path_in_var_buffer = NULL;
+static  int     MR_trace_bad_path_in_var_buffer_size = 0;
 
 const char *
-MR_trace_bad_path_in_var(MR_VarSpec *var_spec, const char *path)
+MR_trace_bad_path_in_var(MR_VarSpec *var_spec, char *fullpath, char *badpath)
 {
     const char  *path_msg;
     int         suffix_len;
+    int         needed_len;
 
-    path_msg = MR_trace_bad_path(path);
+    path_msg = MR_trace_bad_path(fullpath, badpath);
     suffix_len = 0;
     switch (var_spec->MR_var_spec_kind) {
         case MR_VAR_SPEC_NUMBER:
@@ -1616,40 +1670,38 @@
             break;
     }
 
-    if (strlen(path_msg) + strlen(BAD_VAR_PATH_MSG_MIDDLE) + suffix_len
-        < BAD_PATH_BUFFER_SIZE)
-    {
+    needed_len = strlen(path_msg) + strlen(BAD_VAR_PATH_MSG_IN_VAR) +
+        suffix_len;
+    MR_ensure_big_enough_buffer(&MR_trace_bad_path_in_var_buffer,
+        &MR_trace_bad_path_in_var_buffer_size, needed_len);
         switch (var_spec->MR_var_spec_kind) {
             case MR_VAR_SPEC_NUMBER:
                 sprintf(MR_trace_bad_path_in_var_buffer,
                 "%s%s%" MR_INTEGER_LENGTH_MODIFIER "u",
-                    path_msg, BAD_VAR_PATH_MSG_MIDDLE,
+                path_msg, BAD_VAR_PATH_MSG_IN_VAR,
                     var_spec->MR_var_spec_number);
                 break;
 
             case MR_VAR_SPEC_NAME:
                 sprintf(MR_trace_bad_path_in_var_buffer, "%s%s%s",
-                    path_msg, BAD_VAR_PATH_MSG_MIDDLE,
+                path_msg, BAD_VAR_PATH_MSG_IN_VAR,
                     var_spec->MR_var_spec_name);
                 break;
 
             case MR_VAR_SPEC_HELD_NAME:
                 sprintf(MR_trace_bad_path_in_var_buffer, "%s%s$%s",
-                    path_msg, BAD_VAR_PATH_MSG_MIDDLE,
+                path_msg, BAD_VAR_PATH_MSG_IN_VAR,
                     var_spec->MR_var_spec_name);
                 break;
 
             case MR_VAR_SPEC_ATTRIBUTE:
                 sprintf(MR_trace_bad_path_in_var_buffer, "%s%s!%s",
-                    path_msg, BAD_VAR_PATH_MSG_MIDDLE,
+                path_msg, BAD_VAR_PATH_MSG_IN_VAR,
                     var_spec->MR_var_spec_name);
                 break;
         }
 
         return MR_trace_bad_path_in_var_buffer;
-    } else {
-        return path_msg;
-    }
 }
 
 const char *
Index: trace/mercury_trace_vars.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/trace/mercury_trace_vars.h,v
retrieving revision 1.34
diff -u -b -r1.34 mercury_trace_vars.h
--- trace/mercury_trace_vars.h	2 Oct 2007 03:37:29 -0000	1.34
+++ trace/mercury_trace_vars.h	4 Dec 2008 02:47:29 -0000
@@ -312,7 +312,7 @@
 ** or MR_trace_bad_path_in_var.
 */
 
-extern  const char  *MR_trace_bad_path(const char *path);
+extern  const char  *MR_trace_bad_path(char *fullpath, char *badpath);
 
 /*
 ** Given a path specification that does not exist within the specified
@@ -323,7 +323,7 @@
 */
 
 extern  const char  *MR_trace_bad_path_in_var(MR_VarSpec *var_spec,
-                        const char *path);
+                        char *fullpath, char *badpath);
 
 /*
 ** Print the size of the specified variable(s) to the specified file.
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
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