git: 9front

Download patch

ref: ffe5c852c9f8b03e37796bb3601cc985f8923f95
parent: 2546587ecff22fa075c69e15dd80cdbfd7dbca45
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Sat Sep 7 14:42:40 EDT 2013

mk: handle rc blocks in shell quote

this is so we cna handle:

foo = `{echo `{echo bar}}

thanks to erik and friedrich psiorz on 9fans for
bringing the issue up.

--- a/sys/src/cmd/mk/lex.c
+++ b/sys/src/cmd/mk/lex.c
@@ -67,7 +67,7 @@
 static int
 bquote(Biobuf *bp, Bufblock *buf)
 {
-	int c, line, term;
+	int c, line, term, depth;
 	int start;
 
 	line = mkinline;
@@ -80,9 +80,12 @@
 	} else
 		term = '`';		/* sh style */
 
+	depth = 1;
 	start = buf->current-buf->start;
 	for(;c > 0; c = nextrune(bp, 0)){
-		if(c == term){
+		if(c == '{' && term == '}')
+			depth++;
+		if(c == term && --depth == 0){
 			insert(buf, '\n');
 			insert(buf,0);
 			buf->current = buf->start+start;
--