瀏覽代碼

handle indentation in proxy driver template code more flexibly

use the indentation of the placeholder, not the replacement.
this doesn't matter right now, as all placeholders are indented by one
step, but that will change soon.

the indent function cannot be inlined into the substitution, as for some
reason ^ then matches the end of the string, not the embedded line
starts (with perl v5.32). also, $1 needs to go into a temporary anyway.
Oswald Buddenhagen 4 年之前
父節點
當前提交
cd6f18fd2b
共有 1 個文件被更改,包括 8 次插入1 次删除
  1. 8 1
      src/drv_proxy_gen.pl

+ 8 - 1
src/drv_proxy_gen.pl

@@ -50,6 +50,7 @@ while (<$ins>) {
 			$defines{$define} = $conts;
 			$define = undef;
 		} else {
+			($_ eq "\n") or s/^\t// or die("DEFINE content is not indented: $_");
 			$conts .= $_;
 		}
 	} else {
@@ -122,6 +123,12 @@ sub make_format($)
 	return $_;
 }
 
+sub indent($$)
+{
+	my ($str, $indent) = @_;
+	return $str =~ s,^(?=.),$indent,smgr;
+}
+
 open(my $outh, ">".$out_source) or die("Cannot create $out_source: $!\n");
 
 for (@ptypes) {
@@ -161,7 +168,7 @@ for (@ptypes) {
 		$replace{$1} = $defines{$_} if (/^${cmd_name}_(.*)$/);
 	}
 	my $text = $templates{$template};
-	$text =~ s/^\h*\@(\w+)\@\n/$replace{$1} \/\/ ""/smeg;
+	$text =~ s/^(\h*)\@(\w+)\@\n/indent($replace{$2} \/\/ "", $1)/smeg;
 	$text =~ s/\@(\w+)\@/$replace{$1} \/\/ ""/eg;
 	print $outh $text."\n";
 }