chainlint.sed: improve ?!AMP?! placement accuracy

When chainlint.sed detects a broken &&-chain, it places an ?!AMP?!
annotation at the beginning of the line. However, this is an unusual
location for programmers accustomed to error messages (from compilers,
for instance) indicating the exact point of the problem. Therefore,
relocate the ?!AMP?! annotation to the end of the line in order to
better direct the programmer's attention to the source of the problem.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff --git a/t/chainlint.sed b/t/chainlint.sed
index 8a25c5b..883a2b3 100644
--- a/t/chainlint.sed
+++ b/t/chainlint.sed
@@ -236,7 +236,7 @@
 # line ends with pipe "...|" -- valid; not missing "&&"
 /|[ 	]*$/bcont
 # missing end-of-line "&&" -- mark suspect
-/&&[ 	]*$/!s/^/?!AMP?!/
+/&&[ 	]*$/!s/$/ ?!AMP?!/
 :cont
 # retrieve and print previous line
 x
@@ -303,7 +303,7 @@
 # that line legitimately lacks "&&"
 :else
 x
-s/?!AMP?!//
+s/ ?!AMP?!$//
 x
 bcont
 
@@ -311,7 +311,7 @@
 # "suspect" from final contained line since that line legitimately lacks "&&"
 :done
 x
-s/?!AMP?!//
+s/ ?!AMP?!$//
 x
 # is 'done' or 'fi' cuddled with ")" to close subshell?
 /done.*)/bclose
@@ -354,7 +354,7 @@
 # since that line legitimately lacks "&&" and exit subshell loop
 :clssolo
 x
-s/?!AMP?!//
+s/ ?!AMP?!$//
 p
 x
 s/^/>/
diff --git a/t/chainlint/arithmetic-expansion.expect b/t/chainlint/arithmetic-expansion.expect
index 09457d3..56cd5b6 100644
--- a/t/chainlint/arithmetic-expansion.expect
+++ b/t/chainlint/arithmetic-expansion.expect
@@ -4,6 +4,6 @@
 	baz
 >) &&
 (
-?!AMP?!	bar=$((42 + 1))
+	bar=$((42 + 1)) ?!AMP?!
 	baz
 >)
diff --git a/t/chainlint/block.expect b/t/chainlint/block.expect
index fed7e89..6333237 100644
--- a/t/chainlint/block.expect
+++ b/t/chainlint/block.expect
@@ -7,6 +7,6 @@
 	bar &&
 	{
 		echo c
-?!AMP?!	}
+	} ?!AMP?!
 	baz
 >)
diff --git a/t/chainlint/broken-chain.expect b/t/chainlint/broken-chain.expect
index 55b0f42..0960a8c 100644
--- a/t/chainlint/broken-chain.expect
+++ b/t/chainlint/broken-chain.expect
@@ -1,6 +1,6 @@
 (
 	foo &&
-?!AMP?!	bar
+	bar ?!AMP?!
 	baz &&
 	wop
 >)
diff --git a/t/chainlint/case.expect b/t/chainlint/case.expect
index 41f121f..a4b92d4 100644
--- a/t/chainlint/case.expect
+++ b/t/chainlint/case.expect
@@ -9,11 +9,11 @@
 	case "$x" in
 	x) foo ;;
 	*) bar ;;
-?!AMP?!	esac
+	esac ?!AMP?!
 	foobar
 >) &&
 (
 	case "$x" in 1) true;; esac &&
-?!AMP?!	case "$y" in 2) false;; esac
+	case "$y" in 2) false;; esac ?!AMP?!
 	foobar
 >)
diff --git a/t/chainlint/command-substitution.expect b/t/chainlint/command-substitution.expect
index ad4118e..f276067 100644
--- a/t/chainlint/command-substitution.expect
+++ b/t/chainlint/command-substitution.expect
@@ -4,6 +4,6 @@
 	baz
 >) &&
 (
-?!AMP?!	bar=$(gobble blocks)
+	bar=$(gobble blocks) ?!AMP?!
 	baz
 >)
diff --git a/t/chainlint/cuddled.expect b/t/chainlint/cuddled.expect
index b506d46..b6c4ed9 100644
--- a/t/chainlint/cuddled.expect
+++ b/t/chainlint/cuddled.expect
@@ -4,7 +4,7 @@
 >) &&
 
 (
-?!AMP?!cd foo
+cd foo ?!AMP?!
 	bar
 >) &&
 
@@ -17,5 +17,5 @@
 >	bar) &&
 
 (
-?!AMP?!cd foo
+cd foo ?!AMP?!
 >	bar)
diff --git a/t/chainlint/for-loop.expect b/t/chainlint/for-loop.expect
index c33cf56..dc209e2 100644
--- a/t/chainlint/for-loop.expect
+++ b/t/chainlint/for-loop.expect
@@ -1,9 +1,9 @@
 (
 	for i in a b c
 	do
-?!AMP?!		echo $i
+		echo $i ?!AMP?!
 		cat
-?!AMP?!	done
+	done ?!AMP?!
 	for i in a b c; do
 		echo $i &&
 		cat $i
diff --git a/t/chainlint/here-doc-multi-line-command-subst.expect b/t/chainlint/here-doc-multi-line-command-subst.expect
index e5fb752..3a35bb0 100644
--- a/t/chainlint/here-doc-multi-line-command-subst.expect
+++ b/t/chainlint/here-doc-multi-line-command-subst.expect
@@ -1,5 +1,5 @@
 (
 	x=$(bobble &&
-?!AMP?!>>		wiffle)
+>>		wiffle) ?!AMP?!
 	echo $x
 >)
diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect
index 32038a0..a3b9a54 100644
--- a/t/chainlint/here-doc-multi-line-string.expect
+++ b/t/chainlint/here-doc-multi-line-string.expect
@@ -1,4 +1,4 @@
 (
-?!AMP?!	cat && echo "multi-line	string"
+	cat && echo "multi-line	string" ?!AMP?!
 	bap
 >)
diff --git a/t/chainlint/if-in-loop.expect b/t/chainlint/if-in-loop.expect
index 03d3ceb..7d91837 100644
--- a/t/chainlint/if-in-loop.expect
+++ b/t/chainlint/if-in-loop.expect
@@ -3,10 +3,10 @@
 	do
 		if false
 		then
-?!AMP?!			echo "err"
+			echo "err" ?!AMP?!
 			exit 1
-?!AMP?!		fi
+		fi ?!AMP?!
 		foo
-?!AMP?!	done
+	done ?!AMP?!
 	bar
 >)
diff --git a/t/chainlint/if-then-else.expect b/t/chainlint/if-then-else.expect
index a80f5e6..3055d56 100644
--- a/t/chainlint/if-then-else.expect
+++ b/t/chainlint/if-then-else.expect
@@ -1,7 +1,7 @@
 (
 	if test -n ""
 	then
-?!AMP?!		echo very
+		echo very ?!AMP?!
 		echo empty
 	elif test -z ""
 	then
@@ -9,7 +9,7 @@
 	else
 		echo foo &&
 		cat
-?!AMP?!	fi
+	fi ?!AMP?!
 	echo poodle
 >) &&
 (
diff --git a/t/chainlint/inline-comment.expect b/t/chainlint/inline-comment.expect
index fc9f250..3d655a3 100644
--- a/t/chainlint/inline-comment.expect
+++ b/t/chainlint/inline-comment.expect
@@ -1,6 +1,6 @@
 (
 	foobar &&
-?!AMP?!	barfoo
+	barfoo ?!AMP?!
 	flibble "not a # comment"
 >) &&
 
diff --git a/t/chainlint/loop-in-if.expect b/t/chainlint/loop-in-if.expect
index 088e622..cebd3ae 100644
--- a/t/chainlint/loop-in-if.expect
+++ b/t/chainlint/loop-in-if.expect
@@ -3,10 +3,10 @@
 	then
 		while true
 		do
-?!AMP?!			echo "pop"
+			echo "pop" ?!AMP?!
 			echo "glup"
-?!AMP?!		done
+		done ?!AMP?!
 		foo
-?!AMP?!	fi
+	fi ?!AMP?!
 	bar
 >)
diff --git a/t/chainlint/multi-line-string.expect b/t/chainlint/multi-line-string.expect
index 2829516..f1be2ba 100644
--- a/t/chainlint/multi-line-string.expect
+++ b/t/chainlint/multi-line-string.expect
@@ -1,6 +1,6 @@
 (
 	x="line 1		line 2		line 3" &&
-?!AMP?!	y="line 1		line2"
+	y="line 1		line2" ?!AMP?!
 	foobar
 >) &&
 (
diff --git a/t/chainlint/nested-cuddled-subshell.expect b/t/chainlint/nested-cuddled-subshell.expect
index c2a59ff..aa52265 100644
--- a/t/chainlint/nested-cuddled-subshell.expect
+++ b/t/chainlint/nested-cuddled-subshell.expect
@@ -4,16 +4,16 @@
 >>	) &&
 	(cd foo &&
 		bar
-?!AMP?!>>	)
+>>	) ?!AMP?!
 	(
 		cd foo &&
 >>		bar) &&
 	(
 		cd foo &&
-?!AMP?!>>		bar)
+>>		bar) ?!AMP?!
 	(cd foo &&
 >>		bar) &&
 	(cd foo &&
-?!AMP?!>>		bar)
+>>		bar) ?!AMP?!
 	foobar
 >)
diff --git a/t/chainlint/nested-here-doc.expect b/t/chainlint/nested-here-doc.expect
index 0c9ef1c..f9604d3 100644
--- a/t/chainlint/nested-here-doc.expect
+++ b/t/chainlint/nested-here-doc.expect
@@ -2,6 +2,6 @@
 
 (
 	cat &&
-?!AMP?!	cat
+	cat ?!AMP?!
 	foobar
 >)
diff --git a/t/chainlint/nested-subshell-comment.expect b/t/chainlint/nested-subshell-comment.expect
index 15b68d4..925e49b 100644
--- a/t/chainlint/nested-subshell-comment.expect
+++ b/t/chainlint/nested-subshell-comment.expect
@@ -6,6 +6,6 @@
 		# minor numbers of cows (or do they?)
 		baz &&
 		snaff
-?!AMP?!>>	)
+>>	) ?!AMP?!
 	fuzzy
 >)
diff --git a/t/chainlint/pipe.expect b/t/chainlint/pipe.expect
index 211b901..ede6bcc 100644
--- a/t/chainlint/pipe.expect
+++ b/t/chainlint/pipe.expect
@@ -3,6 +3,6 @@
 	bar |
 	baz &&
 	fish |
-?!AMP?!	cow
+	cow ?!AMP?!
 	sunder
 >)
diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect
index 1d79384..ffc87bd 100644
--- a/t/chainlint/semicolon.expect
+++ b/t/chainlint/semicolon.expect
@@ -1,5 +1,5 @@
 (
-?!AMP?!?!SEMI?!	cat foo ; echo bar
+?!SEMI?!	cat foo ; echo bar ?!AMP?!
 ?!SEMI?!	cat foo ; echo bar
 >) &&
 (
diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect
index 7e057ae..9d3f25b 100644
--- a/t/chainlint/subshell-here-doc.expect
+++ b/t/chainlint/subshell-here-doc.expect
@@ -1,6 +1,6 @@
 (
 	echo wobba 	       gorgo snoot 	       wafta snurb &&
-?!AMP?!	cat >bip
+	cat >bip ?!AMP?!
 	echo >bop
 >) &&
 (
diff --git a/t/chainlint/subshell-one-liner.expect b/t/chainlint/subshell-one-liner.expect
index 5116282..ec77aa5 100644
--- a/t/chainlint/subshell-one-liner.expect
+++ b/t/chainlint/subshell-one-liner.expect
@@ -8,7 +8,7 @@
 	(foo || exit 1) &&
 	(foo || exit 1) |
 	(foo || exit 1) >baz &&
-?!AMP?!	(foo && bar)
-?!AMP?!?!SEMI?!	(foo && bar; baz)
+	(foo && bar) ?!AMP?!
+?!SEMI?!	(foo && bar; baz) ?!AMP?!
 	foobar
 >)
diff --git a/t/chainlint/while-loop.expect b/t/chainlint/while-loop.expect
index 13cff2c..f8b9fcf 100644
--- a/t/chainlint/while-loop.expect
+++ b/t/chainlint/while-loop.expect
@@ -1,9 +1,9 @@
 (
 	while true
 	do
-?!AMP?!		echo foo
+		echo foo ?!AMP?!
 		cat
-?!AMP?!	done
+	done ?!AMP?!
 	while true; do
 		echo foo &&
 		cat bar