+ # substitute all format parameter
+ while ($template =~ /(\%\%)|\%([ASDX])(\d)|\%([COM])|\%(\w+)/) {
+ $res .= $`; # get everything before the match
+
+ if ($1) {
+ $res .= "%%";
+ }
+ elsif ($2 && $2 eq "S") {
+ push(@params, "n");
+ $res .= "%".$3."S"; # substitute %Sx with %xS
+ }
+ elsif ($2 && $2 eq "D") {
+ push(@params, "n");
+ $res .= "%".$3."D"; # substitute %Dx with %xD
+ }
+ elsif ($2 && $2 eq "X") {
+ push(@params, "n");
+ $res .= "%".$3."X"; # substitute %Xx with %xX
+ }
+ elsif ($2 && $2 eq "A") {
+ push(@params, "get_irn_n(n, ".($3 - 1).")");
+ $res .= "%+F";
+ }
+ elsif ($4) {
+ push(@params, "n");
+ $res .= "%".$4;
+ }
+ elsif ($5) { # backend provided function to call, has to return a string
+ push(@params, $5."(n, env)");
+ $res .= "\%s";
+ }
+
+ $template = $'; # scan everything after the match
+ }
+ $res .= $template; # get the remaining string