]> git.madduck.net Git - code/myrepos.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Correct printing of line numbers when includes are used. Closes: #650952
authorJoey Hess <joey@kitenet.net>
Sun, 4 Dec 2011 16:03:48 +0000 (12:03 -0400)
committerJoey Hess <joey@kitenet.net>
Sun, 4 Dec 2011 16:03:48 +0000 (12:03 -0400)
Turned out unexapectedly subtle.

debian/changelog
mr

index fe70063222f1d13a62463ea1524b772a4fd44a49..b02ee83d1d624ee7269ef7f49b6f340c812f71e9 100644 (file)
@@ -3,7 +3,7 @@ mr (1.07) UNRELEASED; urgency=low
   * Added support for vcsh, enable with: include = cat /usr/share/mr/vcsh
     Thanks, Richard Hartmann 
   * Block tty control codes in untrusted mr config files.
-  * Show the line when failing to parse a config file. Closes: #650952
+  * Correct printing of line numbers when includes are used. Closes: #650952
 
  -- Joey Hess <joeyh@debian.org>  Tue, 29 Nov 2011 18:15:51 -0400
 
diff --git a/mr b/mr
index 9a81f61a654070fa2b3318c417af5dada3b8bdf6..d3c79ac94fa2954b55c62f6fe252cad63befbae2 100755 (executable)
--- a/mr
+++ b/mr
@@ -1179,11 +1179,38 @@ sub loadconfig {
        close $in unless ref $f eq 'GLOB';
 
        my $section;
+
+       # Keep track of the current line in the config file;
+       # when a file is included track the current line from the include.
        my $line=0;
+       my $included=undef;
+       my $includeline=0;
+       my $nextline = sub {
+               if ($included) {
+                       $includeline++;
+                       $included--;
+               }
+               else {
+                       $included=undef;
+                       $includeline=0;
+                       $line++;
+               }
+               my $l=shift @lines;
+               chomp $l;
+               return $l
+       };
+       my $lineerror = sub {
+               my $msg=shift;
+               if (defined $included) {
+                       die "mr: $f line $line include line $includeline: $msg\n";
+               }
+               else {
+                       die "mr: $f line $line: $msg\n";
+               }
+       };
+
        while (@lines) {
-               $_=shift @lines;
-               $line++;
-               chomp;
+               $_=$nextline->();
 
                if (! $trusted && /[[:cntrl:]]/) {
                        trusterror("mr: illegal control character", $f, $line, $bootstrap_url);
@@ -1214,10 +1241,9 @@ sub loadconfig {
 
                        # continued value
                        while (@lines && $lines[0]=~/^\s(.+)/) {
-                               shift(@lines);
-                               $line++;
                                $value.="\n$1";
                                chomp $value;
+                               $nextline->();
                        }
 
                        if (! $trusted) {
@@ -1243,15 +1269,17 @@ sub loadconfig {
 
                        if ($parameter eq "include") {
                                print "mr: including output of \"$value\"\n" if $verbose;
-                               unshift @lines, `$value`;
+                               my @inc=`$value`;
                                if ($?) {
                                        print STDERR "mr: include command exited nonzero ($?)\n";
                                }
+                               $included += @inc;
+                               unshift @lines, @inc;
                                next;
                        }
 
                        if (! defined $section) {
-                               die "$f line $.: parameter ($parameter) not in section\n";
+                               $lineerror->("parameter ($parameter) not in section");
                        }
                        if ($section eq 'ALIAS') {
                                $alias{$parameter}=$value;
@@ -1292,7 +1320,7 @@ sub loadconfig {
                        }
                }
                else {
-                       die "$f line $line: '$_': parse error\n";
+                       $lineerror->("parse error");
                }
        }