[m-dev.] for review: print parts of variables
Fergus Henderson
fjh at cs.mu.OZ.AU
Tue Jul 18 14:04:41 AEST 2000
On 18-Jul-2000, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> Allow users to request the printouts of only parts of variables.
> Instead of the old sequence
>
> browse Varnameornum
> ^1^2^3^4
> p
> ^D
>
> users can now just a single command: print Varnameornum^1^2^3^4, or print
> Varnameornum/1/2/3/4. The required component is given by a sequence of
> argument numbers, separated by ^s or /s.
That sounds like a good idea.
> +++ mercury_trace_util.c Mon Jul 17 17:18:48 2000
> @@ -0,0 +1,38 @@
> +
> +/*
> +** Copyright (C) 2000 The University of Melbourne.
> +** This file may only be copied under the terms of the GNU Library General
> +** Public License - see the file COPYING.LIB in the Mercury distribution.
> +*/
> +
> +/*
> +** This file contains utility functions for debugger.
> +**
> +** Author: zs.
> +*/
> +
> +#include "mercury_imp.h"
> +#include "mercury_trace_util.h"
> +
> +#include <ctype.h>
> +
> +bool MR_trace_is_number(const char *word, int *value);
> +
> +bool
> +MR_trace_is_number(const char *word, int *value)
> +{
Why is that declared before it is defined?
The declaration should be in the header file,
so there should be no need for a duplicate declaration here.
> @@ -628,25 +632,96 @@
> }
>
> const char *
> +MR_trace_parse_browse_one(FILE *out, char *word_spec, MR_Browser browser,
> + bool must_be_unique)
> +{
> + MR_Var_Spec var_spec;
> + char *path;
> + char *s;
> + int n;
> +
> + s = word_spec;
> + while (*s != '\0' && *s != '^' && *s != '/') {
> + s++;
> + }
> +
> + if (*s == '\0') {
You could write that more concisely as
s = strpbrk(word_spec, "^/");
if (s == NULL) {
> @@ -685,6 +777,26 @@
> return NULL;
> }
>
> +#define BAD_PATH_BUFFER_SIZE 128
> +#define BAD_PATH_MSG_PREFIX "the path "
> +#define BAD_PATH_MSG_SUFFIX " does not exist"
> +
> +static const char *
> +MR_trace_bad_path(char *path)
> +{
> + static char buffer[BAD_PATH_BUFFER_SIZE];
> +
> + if (strlen(BAD_PATH_MSG_PREFIX) + strlen(path) +
> + strlen(BAD_PATH_MSG_SUFFIX) < BAD_PATH_BUFFER_SIZE)
> + {
> + sprintf(buffer, "%s%s%s", BAD_PATH_MSG_PREFIX, path,
> + BAD_PATH_MSG_SUFFIX);
> + return buffer;
> + } else {
> + return "the given path does not exist";
> + }
> +}
s/char *path/const char *path/
It might be nice to double-check all the other places where you use
`char *' rather than `const char *'.
> +/* ML_arg() is defined in std_util.m */
> +extern bool ML_arg(MR_TypeInfo term_type_info, Word *term, int arg_index,
> + MR_TypeInfo *arg_type_info_ptr, Word **arg_ptr);
Rather than declaring this manually, it would be better to include the header file:
#ifdef MR_HIGHLEVEL_CODE
#include "mercury.std_util.h"
#else
#include "std_util.h"
#endif
Apart from that, this change looks fine.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list