[m-rev.] for review: fix an infinite loop in mtags

Peter Wang novalazy at gmail.com
Thu Mar 12 13:51:55 AEDT 2009


Branches: main

Fix a case where mtags got into an infinite loop on a ugly type
definition, where the file was in CR/LF format.

    :- type stupid --->
                    % moron
                    idiot(useless)
                    % imbecile
                ;   retard(string, string)
                .

scripts/mtags.in:
        As above.

	Add an option `--debug' to help narrow down the problematic file in
	future.

diff --git a/scripts/mtags.in b/scripts/mtags.in
index b2ca413..8b5575d 100755
--- a/scripts/mtags.in
+++ b/scripts/mtags.in
@@ -118,6 +118,10 @@ Options:
         Output extra attributes as for `--vim-extended-attributes',
         but in the format required by elvis.

+    --debug
+        Output the name of each source file as it is being processed
+        to standard error.
+
     -h, --help
         Display this help message and exit.

@@ -131,6 +135,7 @@ $emacs = 0;
 $extended_attributes = "vim";
 $keep_dups = 1;
 $search_definitions = 1;
+$debug = 0;

 OPTION:
 while ($#ARGV >= 0 && $ARGV[0] =~ /^-/) {
@@ -203,6 +208,11 @@ while ($#ARGV >= 0 && $ARGV[0] =~ /^-/) {
         shift(@ARGV);
         next OPTION;
     }
+    if ($ARGV[0] eq "--debug") {
+        $debug = 1;
+        shift(@ARGV);
+        next OPTION;
+    }
     if ($ARGV[0] eq "-h" || $ARGV[0] eq "--help") {
         print "$help";
         exit(0);
@@ -347,6 +357,10 @@ while ($#ARGV >= 0)
         open(OUT, ">> TAGS") ||
             die "mtags: error opening pipe: $!\n";
     }
+
+    if ($debug) {
+        print STDERR "Processing $file\n";
+    }

     $module = $file;
     $module =~ s/.*\///;    # Delete the directory name, if any.
@@ -500,7 +514,7 @@ while ($#ARGV >= 0)
                     }
                 }

-                last if $_ =~ /^[^%]*\.[ \t]*$/ || $_ =~ /\.[ \t]*%.*$/;
+                last if $_ =~ /^[^%]*\.[ \t\r]*$/ || $_ =~ /\.[ \t]*%.*$/;
                 $_ = <SRCFILE> || last;
                 chop;
                 $body = $_;
--------------------------------------------------------------------------
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