From cd6f18fd2b295e50bbbd6b8eb4f749f27ee391f2 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 17 Dec 2020 20:14:39 +0100 Subject: [PATCH] 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. --- src/drv_proxy_gen.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/drv_proxy_gen.pl b/src/drv_proxy_gen.pl index 70313cf..95e4ff5 100755 --- a/src/drv_proxy_gen.pl +++ b/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"; }