[m-rev.] for review: allow comments and blank lines in mdb scripts

Ian MacLarty maclarty at csse.unimelb.edu.au
Mon Jun 18 14:32:48 AEST 2007


On Fri, Jun 15, 2007 at 05:36:11PM +1000, Ian MacLarty wrote:
> On Fri, Jun 15, 2007 at 05:18:02PM +1000, Julien Fischer wrote:
> > 
> >  On Fri, 15 Jun 2007, Ian MacLarty wrote:
> > 
> > > Ignore empty lines, or lines that start with `#', in sourced mdb scripts.
> > > This is useful for formatting and documenting mdb scripts.
> > >
> > > Create a local copy of the mdbrc file so that we can test new mdb scripts
> > > in the test suite.
> > >
> > 
> >  That looks fine.
> > 
> 
> Actually I've just discovered that this screws up the formatting of the
> mdb help, since whitespace is removed from the 'document' mdb commands.
> I'll have a think about it and submit an interdiff.
> 

Ignoring blank lines is going to be a problem: mdb gets its commands
from a buffer.  The `source' command simply adds more lines to this
buffer.  We cannot ignore blank lines when we're filling the buffer,
since some of the lines may be help documentation (and we can't easily
tell what lines are help documentation when filling the buffer).  We
also cannot ignore blank lines when reading from the buffer, because by
this stage we don't know what lines have come from sourced files and
what lines have been entered by the user directly (blank lines entered
by the user shouldn't be ignored as they are equivalent to entering the
`step' command).

I've therefore removed the part of the change that ignores blank lines,
but left the part that ignores comment lines.

Here is the interdiff:

diff -u doc/user_guide.texi doc/user_guide.texi
--- doc/user_guide.texi	15 Jun 2007 04:29:58 -0000
+++ doc/user_guide.texi	18 Jun 2007 04:00:27 -0000
@@ -2004,9 +2004,8 @@
 The file named @samp{.mdbrc} in the current working directory.
 You can put program-specific aliases and settings here.
 @end enumerate
-mdb will ignore blank lines,
-or lines that start with the character #,
-in any of the files mentioned above.
+mdb will ignore any lines starting with the character #
+in any of the above mentioned files.
 
 mdb accepts the following options from the command line.  The options
 should be given to mdb before the name of the executable to be debugged.
@@ -4280,9 +4279,7 @@
 will be replaced by the corresponding arguments given in the source
 command before the commands in the sourced file are executed.
 @sp 1
-Lines containing only whitespace,
-or lines that start with zero or more whitespace characters followed by a hash
-(#) character are ignored.
+Lines that start with a hash (#) character are ignored.
 Hash characters can be used to place comments in your mdb scripts.
 @sp 1
 The option @samp{-i} or @samp{--ignore-errors} tells @samp{mdb}
diff -u scripts/mdb_grep scripts/mdb_grep
--- scripts/mdb_grep	15 Jun 2007 04:29:58 -0000
+++ scripts/mdb_grep	18 Jun 2007 04:00:27 -0000
@@ -2,7 +2,7 @@
 # It is useful for checking if a data structure contains a particular value.
 # $1 is a regular expression to search for.
 # $2 is any valid term reference accepted by the dump command.
-
+#
 dump $2 .mdb_grep_tmp
 shell grep $1 .mdb_grep_tmp
 shell rm .mdb_grep_tmp
diff -u scripts/mdb_open scripts/mdb_open
--- scripts/mdb_open	15 Jun 2007 04:29:58 -0000
+++ scripts/mdb_open	18 Jun 2007 04:00:27 -0000
@@ -1,7 +1,7 @@
 # This script saves a term to a file and then opens the file with an
 # editor.
 # $1 is any valid term reference accepted by the dump command.
-
+#
 dump $1 .mdb_open_tmp
 shell ${EDITOR-vi} .mdb_open_tmp
 shell rm .mdb_open_tmp
diff -u scripts/mdb_track scripts/mdb_track
--- scripts/mdb_track	15 Jun 2007 04:29:58 -0000
+++ scripts/mdb_track	18 Jun 2007 04:00:27 -0000
@@ -1,7 +1,7 @@
 # This script invokes the declarative debugger's track command.
 # $1 is the argument the term to track is in.
 # $2 is the path to the term in the argument.
-
+#
 dd
 browse $1
 cd $2
diff -u trace/mercury_trace_readline.c trace/mercury_trace_readline.c
--- trace/mercury_trace_readline.c	15 Jun 2007 04:29:58 -0000
+++ trace/mercury_trace_readline.c	18 Jun 2007 04:00:27 -0000
@@ -168,8 +168,7 @@
 char *
 MR_trace_readline_from_script(FILE *fp, char **args, int num_args)
 {
-    char    *line;
-    char    *orig_line = NULL;
+    char    *line = NULL;
     size_t  line_length;
     int     line_index;
     size_t  expanded_line_length;
@@ -180,22 +179,19 @@
     char    *arg;
 
     do {
-        if (orig_line != NULL) {
-            MR_free(orig_line);
+        if (line != NULL) {
+            MR_free(line);
         }
-        orig_line = MR_trace_readline_raw(fp);
-        line = orig_line;
+        line = MR_trace_readline_raw(fp);
         if (line == NULL) {
             return NULL;
         }
         /*
-        ** Chomp whitespace.
+        ** Ignore lines starting with '#'.
         */
-        while (MR_isspace(*line)) {
-            line++;
-        }
-        line_length = strlen(line);
-    } while (line_length == 0 || *line == '#');
+    } while (*line == '#');
+
+    line_length = strlen(line);
 
     expanded_line_length = line_length;
     expanded_line = (char*) MR_malloc(line_length + 1);
@@ -231,7 +227,7 @@
         }
     }
 
-    MR_free(orig_line);
+    MR_free(line);
     expanded_line[expanded_line_index] = '\0';
 
     return expanded_line;

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